summaryrefslogtreecommitdiffstats
path: root/commands/nv.c
Commit message (Collapse)AuthorAgeFilesLines
* commands: implement and use parse_assignment helperAhmad Fatoum2020-11-271-7/+2
| | | | | | | | | | | | We have the split by '=' snippet at multiple locations that parse key=value pairs. Consolidate them to a single location. This makes code a bit easier to read at the cost of an extra 8 bytes (LZO-compressed THUMB2 barebox, static inline version is bigger). No functional change. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: nv: pass empty string for nvAhmad Fatoum2020-11-271-0/+2
| | | | | | | | | | | | | | | | Setting a variable via the nv command results in the call chain nvar_add() -> nv_save() -> __nv_save(). __nv_save isn't supposed to be called with val=NULL argument however: dprintf(fd, "%s", val); Avoid this from happening by translating NULL into the empty string. This aligns nv with the behavior of hush and setenv (but not global, this will need to be looked at separately). Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: nv: fix set/remove of multiple variables in one goAhmad Fatoum2020-11-271-1/+1
| | | | | | | | | | | | | | | | | | | | | Multiple nonopt arguments seems to have never worked, because the value was always extracted out of the first non-opt argument. After the first iteration, it'll have it's '=' stripped and thus value == NULL for all i > 0. Fix this. Before: $ nv a=1 b=2 c=3 $ echo "[$nv.a $nv.b $nv.c]" [1 ] After: $ nv a=1 b=2 c=3 $ echo "[$nv.a $nv.b $nv.c]" [1 2 3] Fixes: 0c2fccceb625 ("nv: Allow to set/remove multiple variables with one command") Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands/*: Replace license and copyright boilerplate by SPDX identfiersUwe Kleine-König2020-04-271-18/+5
| | | | | | | | | | | | | While at it also drop references to the non-existing CREDITS file and do some small rearrangements for some uniform formatting. (SPDX-License-Identifier first, then copyright texts and then an empty line.) The advantage is that these specifiers are machine-parseable which helps license conformance. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Allow usage of default environment without environment file storageAlbert Schwarzkopf2019-12-111-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the default environment is only used when the barebox environment on the persistent store is not valid or when ENVFS_FLAGS_FORCE_BUILT_IN is set in the super block. However, ENVFS_FLAGS_FORCE_BUILT_IN can be cleared and the environmnet variables in the persistent store will be used again. This may not be desirable. This patch allows building CONFIG_DEFAULT_ENVIRONMENT independent of CONFIG_ENV_HANDLING. This can be useful if you never want to load or write values from the persistent store and you only need to read environment variables from your default environment. If CONFIG_ENV_HANDLING is not set, a message will be printed to the user indicating that changes to non-volatile variables won't be persisted. Move envfs functions that are needed when CONFIG_DEFAULT_ENVIRONMENT and/or CONFIG_ENV_HANDLING is set to a new file common/envfs-core.c. Signed-off-by: Albert Schwarzkopf <a.schwarzkopf@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: add device parameter overwrites to completion listSascha Hauer2017-11-231-1/+1
| | | | | | | | 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>
* command: nv: rewrap help text linesEnrico Jorns2017-11-031-3/+3
| | | | | | | Just let the help text appear a bit more aligned. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: nv: adjust command helpEnrico Jorns2017-11-031-5/+5
| | | | | | | | | | Help did not point out that -r option requires n arguments and did not mention support for removing variables in help text. Also introduce and consistently reuse 'NV' as abbreviation for 'non volatile'. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: nv: assure error code will be returned when an error occurredEnrico Jorns2017-11-031-4/+14
| | | | | | | | | | | | | | Due to iteration over possibly multiple variables, the return value of an individual call to nvvar_remove() / nvvar_add() gets lost. This will result in do_nv() returning success (0) if any variable processing failed as long as processing of the last variable succeeded. Processing will not be aborted on individual errors, such as the 'cp' handles it for invalid files. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: nv: call nvvar_print() only if no argument is givenEnrico Jorns2017-11-031-4/+5
| | | | | | | | Printing the nv variables (before performing any modification!) is useless and irritating. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: nv: fail with verbose message if invoked without argsEnrico Jorns2017-11-031-1/+3
| | | | | Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* complete: Add completion for nv and globalvar commandsSascha Hauer2016-10-181-0/+2
| | | | | | | | 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>
* nv: Allow to set/remove multiple variables with one commandSascha Hauer2016-07-221-13/+15
| | | | | | | | It's convenient to set/remove multiple nv variables in one go. With this patch we iterate over the remaining nonopts instead of expecting exactly one nonopt. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: Add option to explicitly save nv variablesSascha Hauer2016-07-221-4/+11
| | | | | | | | | We now have code to save the nv variables without saving the rest of the environment. This gives us the possibility to explicitly save the nv variables. This patch adds an option to the 'nv' command for this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Add support for non volatile variablesSascha Hauer2014-11-061-0/+84
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>