summaryrefslogtreecommitdiffstats
path: root/common/globalvar.c
Commit message (Collapse)AuthorAgeFilesLines
* globalvar: fix crash if CONFIG_NVVAR is not setAntony Pavlov2018-12-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | At the moment globalvar code tries to use nv_device even if nv_device is not registered. How to reproduce the problem: barebox$ make sandbox_defconfig ... barebox$ sed -i "s/\(CONFIG_NVVAR\)=y/# \1 is not set/" .config barebox$ sed -i "s/\(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW\)=y/# \1 is not set\n# CONFIG_DEFAULT_ENVIRONMENT_GENERIC is not set/" .config barebox$ make oldconfig ... barebox$ make ... barebox$ ./barebox Segmentation fault This patch blocks nv_device use if CONFIG_NVVAR is not set. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/net'Sascha Hauer2018-01-051-2/+4
|\
| * nvvar: when setting a nvvar to NULL just free the contentSascha Hauer2017-12-011-2/+4
| | | | | | | | | | | | | | | | | | | | When a nvvar is about to be removed then it is set to NULL by barebox. This means for the variable to free it's memory. In this case also do not pass the value to the corresponding globalvar, since that would set the globalvar to NULL aswell, but we want to keep its current value. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2018-01-051-3/+42
|\ \
| * | nvvar: Initialze from underlying device parameterSascha Hauer2017-11-241-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | When a nvvar is added with a NULL parameter then it's initialized with the value of the underlying global variable. Do this aswell when the nvvar is a device parameter. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | nv: add device parameter overwrites to completion listSascha Hauer2017-11-231-2/+31
| | | | | | | | | | | | | | | | | | | | | | | | nv variables in the form dev.<devname>.* can be used to make device parameters persistent. Add these to the completion list to make setting these variables more convenient. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | globalvar: When a globalvar is created with a NULL value, use empty stringSascha Hauer2017-11-231-0/+3
| | | | | | | | | | | | | | | | | | | | | As a convenience for users of globalvar_add_simple_string() create an empty value for the variable when passed a NULL pointer as value. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | common: globalvar: fix removing multiple nvvars with wildcardsSascha Hauer2017-11-301-2/+3
|/ / | | | | | | | | | | | | | | | | | | | | nvvar_remove takes wildcards, so it can remove multiple variables. This means we cannot return after the first loop iteration, but instead must continue. Fixes: 609d3edc3ad9 (common: globvar: let nvvar_remove() report non-existing variable) Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Cc:
* / common: globvar: let nvvar_remove() report non-existing variableEnrico Jorns2017-11-031-1/+3
|/ | | | | | | | | | | The former implementation did not allow to detect whether the call to nvvar_remove() succeeded or failed and always returned 0. This changes the implementation to return 0 only if a variable with the given name was found and return ENOENT otherwise. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Revert "nv: Do not create globalvars from nvvars"Sascha Hauer2017-06-131-21/+21
| | | | This reverts commit 35d8e858bea17ec4796069c9c27fd0b134125eaf.
* Revert "globalvar: remove code for unqualified globalvars"Sascha Hauer2017-06-131-1/+42
| | | | This reverts commit e4f81050e098074792730b61563538d9e394e3d6.
* Revert "globalvar: make globalvar functions more consistent"Sascha Hauer2017-06-131-7/+21
| | | | This reverts commit 1b4a05c9263ae26083526acfabdea1ef96531a1d.
* Revert "param: remove unnecessary device_d * argument"Sascha Hauer2017-06-131-7/+7
| | | | This reverts commit 0071bacb4c7cab21c9fab8540f5aa9922a270a85.
* Revert "globalvar: don't use nv_device if CONFIG_NVVAR is disabled"Sascha Hauer2017-06-131-11/+1
| | | | This reverts commit b378e8c9427b45d856d052a6df4a879a2cee670c.
* Revert "globalvar: make nv_device static"Sascha Hauer2017-06-131-1/+1
| | | | This reverts commit f655902cfad63b9ba5cea7d0c9fc9c3632143e02.
* Revert "nv: Fix setting of nv.dev.<devname>.<param> variables"Sascha Hauer2017-06-131-23/+42
| | | | This reverts commit eaf884ba55def055fd81ff3291a1a534fc8bd8f9.
* Revert "globalvar: Fix value of new globalvar when nvvar exists"Sascha Hauer2017-06-131-2/+2
| | | | This reverts commit f8a177478c1b79e369ecc65501d9d15ff573339f.
* globalvar: Fix value of new globalvar when nvvar existsSascha Hauer2017-05-081-2/+2
| | | | | | | | | | | | | When a new globalvar with a value is created and the corresponding nvvar exists, then the globalvar gets the value of the nvvar, not from the newly assigned value as expected. nv quux=foo; global quux=bar; echo ${global.quux} Should give "bar", not "foo". Fix this. Reported-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: Fix setting of nv.dev.<devname>.<param> variablesSascha Hauer2017-05-081-42/+23
| | | | | | | | | | | | | | | | | | nv variables with the form nv.dev.<devname>.<param> shall be mirrored to the device parameter <param> of the device named <devname>. This is broken since: | commit 35d8e858bea17ec4796069c9c27fd0b134125eaf | Author: Sascha Hauer <s.hauer@pengutronix.de> | Date: Thu Apr 6 15:23:56 2017 +0200 | | nv: Do not create globalvars from nvvars Fix this by attaching the setting of the mirror device parameter directly to the nv device rather than to the global device. Reported-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/parameter-types'Sascha Hauer2017-05-051-28/+14
|\
| * param: remove unnecessary device_d * argumentSascha Hauer2017-04-111-7/+7
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * globalvar: make globalvar functions more consistentSascha Hauer2017-04-111-21/+7
| | | | | | | | | | | | | | | | | | Similar to the device parameter functions also make the globalvar functions more consistent. This also adds support for readonly globalvars and changes several existing globalvars which should really be readonly to readonly. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/misc'Sascha Hauer2017-05-051-1/+1
|\ \
| * | globalvar: make nv_device staticAntony Pavlov2017-04-281-1/+1
| |/ | | | | | | | | | | | | | | nv_device isn't used outside of common/globalvar.c so make it static. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / globalvar: don't use nv_device if CONFIG_NVVAR is disabledAntony Pavlov2017-04-251-1/+11
|/ | | | | | | | | | | | | | | | | | | At the moment barebox crashes if CONFIG_NVVAR is disabled because of access to unregistered nv_device in get_param_by_name(&nv_device, "version"). How to reproduce the crash: barebox$ unset ARCH barebox$ unset CROSS_COMPILE barebox$ make sandbox_defconfig barebox$ sed -i "s/CONFIG_ENV_HANDLING=y/# CONFIG_ENV_HANDLING is not set/" .config barebox$ make oldconfig barebox$ ./barebox Segmentation fault Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2017-04-071-78/+24
|\
| * globalvar: remove code for unqualified globalvarsSascha Hauer2017-04-071-42/+1
| | | | | | | | | | | | | | | | | | | | | | | | The globalvar_add_simple_* functions will fail when a globalvar of the name already exists. This happened when the globalvar was created previously because a corresponding nvvar existed. For this reason we removed the globalvars that have been previously created by nvvar creation (we called these unqualified globalvars). Since we no longer create the corresponding globalvars on nvvar creation this code is no longer needed. Remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * nv: Do not create globalvars from nvvarsSascha Hauer2017-04-071-21/+21
| | | | | | | | | | | | | | | | | | | | When we create a new nvvar there's no need to create the corresponding globalvar, because whoever wants to use the corresponding globalvar will create it before usage anyway. Doing this means that we have to test for existence of a corresponding nvvar when we create a globalvar, and if it does, set the value of the globalvar from the nvvar. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * globalvar: remove unused globalvar_add()Sascha Hauer2017-04-071-16/+0
| | | | | | | | | | | | globalvar_add() is unused in the tree. Remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * global command: print info about variablesSascha Hauer2017-04-041-1/+4
| | | | | | | | | | | | | | | | The info contains useful information at least for enums, for these the possible values are printed. This makes the output of the "global" command more useful and similar to "devinfo global" Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | nvvar: Fix creation without valueSascha Hauer2017-04-071-3/+9
|/ | | | | | | | | | When a new nvvar is added without a value we want to get the value from the corresponding globalvar. We do this by using nv_set which ends up freeing the exact string that we passed into nv_set as value. This results in a corrupt value. Fix this by assigning a value manually without calling nv_set. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Fix compiler warningSascha Hauer2017-01-101-1/+1
| | | | | | | | | | Fixes: common/globalvar.c:393:7: warning: 'pname' may be used uninitialized in this function [-Wmaybe-uninitialized] This is a false positive, pname cannot be uninitialized. Silence this warning. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Make locally used function staticSascha Hauer2017-01-101-1/+1
| | | | | | | | Fixes: common/globalvar.c:382:5: warning: no previous prototype for 'globalvar_simple_set' [-Wmissing-prototypes] Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* complete: Add completion for nv and globalvar commandsSascha Hauer2016-10-181-0/+28
| | | | | | | | The 'nv' command is often used to create a nv variable for an existing global variable, so add a command completion function for this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: introduce globalvar_add_simple_bitmaskSascha Hauer2016-09-221-0/+14
| | | | | | | Using the just introduced param_bitmask this adds the corresponding globalvar convenience function. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Allow full variable name in globalvar_addSascha Hauer2016-09-221-0/+3
| | | | | | | As a convenience for users allow to pass the full name, including the leading "global.", to globalvar_add(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: Allow full variable name in nvvar_addSascha Hauer2016-09-221-0/+3
| | | | | | | As a convenience for users allow to pass the full name, including the leading "nv.", to nvvar_add(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Also create globalvars from for nonvolatile device varsSascha Hauer2016-09-221-45/+30
| | | | | | | | | | | | | | | | | | | | nv variables beginning with "nv.dev.<devname>.<varname>" are directly mirrored to <devname>.<varname> and there is no globalvar for it. To make it a bit more consistent and to increase the visibility of the nonvolatile device variables create globalvars for them aswell. With this the propagation flow has changed from: nv.dev.<devname>.<varname> -> <devname>.<varname> to: nv.dev.<devname>.<varname> -> global.dev.<devname>.<varname> -> <devname>.<varname> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: simplify nvvar_addSascha Hauer2016-09-221-18/+7
| | | | | | | | We do not need to have an extra code path when the variable already exists, instead setting an existing variable can be done in the variable creation code path aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Allow to remove multiple globalvars using wildcardsSascha Hauer2016-09-221-4/+6
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: sync with nvvarsSascha Hauer2016-09-221-4/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes the behaviour when a driver creates a globalvar using globalvar_add_simple_[string|int|bool|enum|ip]) *after* nvvars are initialized and this globalvar is overwritten with a nvvar. Currently this fix is not needed because all globalvars are registered before the nvvars are initialized. We have two different typed of globalvars. The first type, here referred to as qualified globalvars, has a backend variable storage (the ones created with globalvar_add_simple_[string|int|bool|enum|ip]), the other created with globalvar_add_simple only has a dynamically allocted string as backend. Normally during startup of barebox the qualified globalvars are registered and during load of nvvars are synced with the values from the nvvars. Everything works fine in this case. However, when during nvvar initialisation a globalvar for a nvvar does not exist, then it is registered as unqualified globalvar. When then later some driver wants to register a qualified globalvar for which a unqualified globalvar already exists, it will get a -EEXIST. This is not the expected behaviour. Instead, the current unqualified globalvar should be removed, recreated as qualified globalvar and then afterwards synced with the corresponding nvvar. This behaviour is fixed with this patch. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Move static inline functions to common/Sascha Hauer2016-09-221-0/+67
| | | | | | | These functions will get bigger in the next patch which disqualifies them as static inline functions. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: Fix variable removal in nvvar_save()Sascha Hauer2016-09-221-0/+1
| | | | | | | | | When nv variables are removed during runtime then they are present again when saved with nvvar_save(). This is because nvvar_save() does not delete variables that exist on the saved environment. Delete /nv on the saved environment before saving the new variables. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: Allow wildcards when removing NV varsSascha Hauer2016-07-251-8/+10
| | | | | | | With this patch 'nv -r' can also take "*" and "?" wildcards for nv variables. This makes it easier to remove multiple nv variables. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: Use dev_remove_param to delete nv variableSascha Hauer2016-07-221-4/+3
| | | | | | | | dev_remove_param() is exactly for the purpose of removing a device parameter, so use this function instead of open coding the functionality. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: Save nv variables on shutdownSascha Hauer2016-07-221-3/+78
| | | | | | | | | | | | | | | | | | | With this patch nv variables are automatically saved whenever barebox shuts down (that is 'reset' is executed or a kernel is started). With this the additional 'saveenv' step becomes unnecessary. The nv variables are stored in the environment and the estasblished behaviour is that files in the environment must be manually saved using 'saveenv'. This behaviour shall be kept for now, so this patch cannot just call 'saveenv' since that would save the modified environment files aswell. Instead we read the environment from the device, modifiy the nv variables and save the environment back. Since this changes a long existing behaviour messages are printed the first time a nv variable is modified and during shutdown when the variables are actually saved. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: Do not save nv variables while loadingSascha Hauer2016-07-221-5/+27
| | | | | | | | When reading nv variables from the storage in /env/nv we do not need to write back the value to the file we just read from. Optimize this a bit and make it unnecessary. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Introduce non volatile device variablesSascha Hauer2016-07-061-10/+127
| | | | | | | | | | | | | | Non volatile device variables are used to make device parameters persistent. They are like normal non volatile variables, but set the values of the device parameters with the corresponding name. Every nv variable beginning with nv.dev is a non volatile device variable. They have the form nv.dev.<devname>.<paramname> and act on the parameter <paramname> of the device named <devname>. The non volatile device variables are designated for example for video modes, ethernet device ip addresses or mtd partitioning. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nvvar: Simplify by using dev_set_param()Sascha Hauer2016-07-061-6/+1
| | | | | | | The combination of get_param_by_name()/param->set() can be replaced by using dev_set_param() Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nvvar: Simplify by using nv_set()Sascha Hauer2016-07-061-11/+2
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>