summaryrefslogtreecommitdiffstats
path: root/common/globalvar.c
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* Merge branch 'for-next/misc'Sascha Hauer2016-05-091-2/+16
|\
| * Kconfig: Create Kconfig symbol for NVVARSascha Hauer2016-04-281-2/+16
| | | | | | | | | | | | | | | | | | | | nvvar support not only needs globalvar, but also persistent environment storage. Add a separate default-y option which depends on ENV_HANDLING for this case. Make the option visible to let the user decide whether he wants to have this option and add a help text to make this decision easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/include-cleanup'Sascha Hauer2016-05-091-4/+5
|\ \
| * | stdio: Replace FILE functions with filedescriptor functionsSascha Hauer2016-04-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have defined stdin, stdout and stderr as integer file descriptors, but normally they should be FILE *. Also fprintf, fputc and fputs take file descriptors instead of FILE *. As FILE * are inconvenient in the barebox environment replace the f* functions with the corresponding d* functions. dprintf is POSIX conform whereas dputc and dputs are barebox specific, but do not conflict with any stdc function. fgetc is unused and can be removed without replacing it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | string: Fix (v)asprintf prototypesSascha Hauer2016-04-151-3/+4
| |/ | | | | | | | | | | | | | | | | | | Our asprintf and vasprintf have different prototypes than the glibc functions. This causes trouble when we want to share barebox code with userspace code. Change the prototypes for (v)asprintf to match the glibc prototypes. Since the current (v)asprintf are convenient to use change the existing functions to b(v)asprintf. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / globalvar: Allow to remove globalvarsSascha Hauer2016-04-291-0/+10
|/ | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Add support for printing all global variablesSascha Hauer2014-11-061-0/+5
| | | | | | | | | This could previously only be done with 'devinfo global'. While this is still possible this adds a more direct access via the globalvar command. This variant also adds a '*' in front of the variable if the corresponding non volatile variable exists. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Add support for non volatile variablesSascha Hauer2014-11-061-0/+173
| | | | | | | | | | | | | | | This adds (back) support for non volatile variables. Non volatile variables are variables which are stored in the environment over reboot. They are used in the same way as the global variables, but with a 'nv' command and device. The variables are stored under /env/nv/, one variable per file. Adding a nv variable automatically adds a global variable with the same name. Changing a nv variable also changes the same global variable, but not the other way round. This allows for example to configure the username as: nv user=sha; saveenv Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* param: let dev_add_param return the newly created paramSascha Hauer2014-10-081-1/+6
| | | | | | | | dev_add_param creates a new parameter so it makes more sense to return it than to return an error code. Since the return value is hardly ever checked this is only a small patch. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Add missing includesSascha Hauer2013-11-081-0/+1
| | | | | | | | A lot of files rely on include/driver.h including include/of.h (and this including include/errno.h. include the files explicitly so we can eventually get rid of including of.h from driver.h Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2013-10-071-0/+3
|\ | | | | | | | | Conflicts: commands/Makefile
| * globalvar: Do not modify already existing variablesSascha Hauer2013-09-271-0/+3
| | | | | | | | | | | | | | | | | | When globalvar_add_simple was called on previously existing variables then the value was overwritten, even when value was passed as NULL. Do not overwrite the value in this case which allows us to do a 'global' on the same variable multiple times without loosing the values. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | globalvar: add globalvar_add_simple_int/bool/enum/ip supportJean-Christophe PLAGNIOL-VILLARD2013-09-181-1/+1
|/ | | | | | | so we can types var Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: move globalvar init to pure_initcallSascha Hauer2013-08-161-1/+1
| | | | | | | globalvar has no dependencies. Move it to pure_initcall to make it available earlier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Add a global.version variableSascha Hauer2013-08-161-0/+5
| | | | | | | | So far we only had the version command which is able to print the barebox version. To make the barebox version available for scripts add a globalvar for it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: Allow to set initial valueSascha Hauer2013-08-161-2/+10
| | | | | | | Calling globalvar_add_simple() and setting a value is more than common. Add a parameter for the initial value. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Fix typo seperate -> separateSascha Hauer2013-05-211-2/+2
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* globalvar: add support to set a value to of all globalvars beginning with ↵Jean-Christophe PLAGNIOL-VILLARD2012-09-141-0/+10
| | | | | | | | 'match' via c global_set_match and global -r Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
* add 'global' commandSascha Hauer2012-05-141-0/+65
This implements global shell variable support. This is done by registering a new device named 'global', so global variables are just plain device parameters. Global variables are useful for storing the global state in the environment. Currently we do this by sourcing scripts instead of executing them which is quite limiting. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>