aboutsummaryrefslogtreecommitdiff
path: root/cmd/nvedit.c
AgeCommit message (Collapse)AuthorFilesLines
2022-04-07cmd: env: Add `indirect` to indirectly set valuesSamuel Dionne-Riel1-0/+45
This allows an ergonomic-enough approximation of ${!variable} expansion. This could be used the following way: ``` for target in ${boot_targets}; do env indirect target_name target_name_${target} # ... done ``` Assuming `target_name_mmc0` and similar are set appropriately. A default value can be optionally provided. Note: this acts on environment variables, not hush variables. Signed-off-by: Samuel Dionne-Riel <samuel@dionne-riel.com> Cc: Simon Glass <sjg@chromium.org> Cc: "Marek Behún" <marek.behun@nic.cz> [trini: Don't enable by default]
2021-10-21env: Move non-cli env functions to env/common.cMarek Behún1-175/+0
Move the following functions from cmd/nvedit.c to env/common.c: env_set_ulong() env_set_hex() env_get_hex() eth_env_get_enetaddr() eth_env_set_enetaddr() env_get() from_env() env_get_f() env_get_ulong() since these functions are not specific for U-Boot's CLI. We leave env_set() in cmd/nvedit.c, since it calls _do_env_set(), which is a static function in that file. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-10-21env: Simplify env_match() and inline into env_get_f()Marek Behún1-14/+5
In the past the env_match() function was used to match envs with - name, i.e. string "name" - variable assignment, i.e. string "name=other_value" The latter is not the case anymore, since the env_match() function is now used only in env_get_f(), and so we can simplify the function into a simple strncmp() with an additional comparison to '='. Let's do this, and since the resulting function is quite simple, let's also inline its code into env_get_f(). Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-10-21env: Use memcpy() instead of ad-hoc code to copy variable valueMarek Behún1-12/+6
Copy the value of the found variable into given buffer with memcpy() instead of ad-hoc code. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-10-21env: Make return value of env_get_f() behave like sprintf() on successMarek Behún1-3/+5
Currently the env_get_f() function's return value behaves weirdly: it returns the number of bytes written into `buf`, but whether this is excluding the terminating NULL-byte or including it depends on whether there was enough space in `buf`. Change the function to always return the actual length of the value of the environment variable (excluding the terminating NULL-byte) on success. This makes it behave like sprintf(). All users of this function in U-Boot are compatible with this change. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-10-21env: Early return from env_get_f() on NULL nameMarek Behún1-3/+3
Test non-NULL name immediately, not in env_match(). Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-10-21env: Don't match empty variable name in env_match()Marek Behún1-1/+1
Do we really allow zero-length variable name? I guess not. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-10-21env: Use better name for variable in env_get_f()Marek Behún1-4/+4
The `nxt` variable actually points to the terminating null-byte of the current env var, and the next env var is at `nxt + 1`, not `nxt`. So a better name for this variable is `end`. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-10-21env: Use string pointer instead of indexes in env_get_f()Marek Behún1-16/+16
Since we no longer use env_get_char() to access n-th character of linearized environment data, but rather access the arrays themselves, we can convert the iteration to use string pointers instead of position indexes. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-10-21env: Inline env_get_char() into its only userMarek Behún1-14/+14
This function is a relic from the past when environment was read from underlying device one character at a time. It is used only in the case when getting an environemnt variable prior relocation, and the function is simple enough to be inlined there. Since env_get_char() is being changed to simple access to an array, we can drop the failing cases and simplify the code (this could have been done before, since env_get_char() did not fail even before). Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-10-21env: Change env_match() to static and remove from headerMarek Behún1-15/+15
This function was used by other parts of U-Boot in the past when environment was read from underlying device one character at a time. This is not the case anymore. Signed-off-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-08-02global: Convert simple_strtoul() with decimal to dectoul()Simon Glass1-1/+1
It is a pain to have to specify the value 10 in each call. Add a new dectoul() function and update the code to use it. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-08-02global: Convert simple_strtoul() with hex to hextoul()Simon Glass1-5/+5
It is a pain to have to specify the value 16 in each call. Add a new hextoul() function and update the code to use it. Add a proper comment to simple_strtoul() while we are here. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-02-02common: Drop asm/global_data.h from common headerSimon Glass1-0/+1
Move this out of the common header and include it only where needed. In a number of cases this requires adding "struct udevice;" to avoid adding another large header or in other cases replacing / adding missing header files that had been pulled in, very indirectly. Finally, we have a few cases where we did not need to include <asm/global_data.h> at all, so remove that include. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com>
2020-12-04env: Allow returning errors from hdelete_r()Simon Glass1-2/+4
At present this function returns 1 on success and 0 on failure. But in the latter case it provides no indication of what went wrong. If an attempt is made to delete a non-existent variable, the caller may want to ignore this error. This happens when setting a non-existent variable to "", for example. Update the function to return 0 on success and a useful error code on failure. Add a function comment too. Make sure that env_set() does not return an error if it is deleting a variable that doesn't exist. We could update env_set() to return useful error numbers also, but that is beyond the scope of this change. Signed-off-by: Simon Glass <sjg@chromium.org> wip
2020-09-18efi: change 'env -e -i' usage syntaxMaxim Uvarov1-2/+2
'env -e -i' syntax was changed from "," to ":". Account for this also in the documentation. Fixes: 2b3fbcb59f41 ("efi_loader: use ':' as separator for setenv -i") Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> Correct the usage description for setenv -e too. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-09-11env: Crash in 'env import' when using checksum and a specific sizePedro Aguilar1-0/+5
This patch adds a sanity check that avoids 'size' to overflow and crash when importing an environment that contains a checksum. Example with the wrong size that causes the crash: => env import -c 0x4100000 3 v1 This assumes that v1 has already been successfully exported with 'env export -c -s 0x100 0x4100000 v1' Signed-off-by: Pedro Aguilar <pedro.aguilar@vimar.com>
2020-07-31cmd: env: add env select commandPatrick Delaunay1-0/+15
Add the new command 'env select' to force the persistent storage of environment, saved in gd->env_load_prio. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2020-07-31cmd: env: add env load commandPatrick Delaunay1-0/+14
Add the new command env load to load the environment from the current location gd->env_load_prio. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2020-07-26cmd: env: check real location for env info commandPatrick Delaunay1-3/+12
Check the current ENV location, dynamically provided by the weak function env_get_location to be sure that the environment can be persistent. The compilation flag ENV_IS_IN_DEVICE is not enough when the board dynamically select the available storage location (according boot device for example). This patch solves issue for stm32mp1 platform, when the boot device is USB. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2020-07-26cmd: env: add option for quiet output on env infoPatrick Delaunay1-7/+19
The "env info" can be use for test with -d and -p parameter, in scripting case the output of the command is not needed. This patch allows to deactivate this output with a new option "-q". For example, we can save the environment if default environment is used and persistent storage is managed with: if env info -p -d -q; then env save; fi Without the quiet option, I have the unnecessary traces First boot: Default environment is used Environment can be persisted Saving Environment to EXT4... File System is consistent Next boot: Environment was loaded from persistent storage Environment can be persisted Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2020-07-16efi_loader: simplify 'printenv -e'Heinrich Schuchardt1-3/+4
Currently default output of 'printenv -e' is restricted to variables with GUID EFI_GLOBAL_VARIABLE. This excludes db and dbx. As the number of variables is small there is no need for this restriction. If no GUID is provided, print all matching variables irrespective of GUID. Always show the numeric value of the GUID. If the GUID provided to 'setenv -e' is invalid, return CMD_RET_USAGE. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-07-07cmd: env: use ENV_IS_IN_DEVICE in env infoPatrick Delaunay1-1/+1
Use the define ENV_IS_IN_DEVICE to test if one the CONFIG_ENV_IS_IN_... is defined and correct the detection of persistent storage support in the command "env info" if CONFIG_ENV_IS_NOWHERE is activated. Since commit 60d5ed2593c9 ("env: allow ENV_IS_NOWHERE with other storage target") test CONFIG_ENV_IS_NOWHERE is not enough; see also commit 953db29a1e9c6 ("env: enable saveenv command when one CONFIG_ENV_IS_IN is activated"). This patch avoids issue for this command in stm32mp1 platform. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
2020-05-18common: Drop linux/bitops.h from common headerSimon Glass1-0/+1
Move this uncommon header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-18common: Drop log.h from common headerSimon Glass1-0/+1
Move this header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-18command: Remove the cmd_tbl_t typedefSimon Glass1-30/+32
We should not use typedefs in U-Boot. They cannot be used as forward declarations which means that header files must include the full header to access them. Drop the typedef and rename the struct to remove the _s suffix which is now not useful. This requires quite a few header-file additions. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-18common: Drop net.h from common headerSimon Glass1-0/+1
Move this header out of the common header. Network support is used in quite a few places but it still does not warrant blanket inclusion. Note that this net.h header itself has quite a lot in it. It could be split into the driver-mode support, functions, structures, checksumming, etc. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-04-16cmd: env: add "-at" option to "env set -e" commandAKASHI Takahiro1-2/+3
With "-at" option, EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS will be passed to SetVariable() to authenticate the variable. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2019-12-09net: Always build the string_to_enetaddr() helperJoe Hershberger1-1/+1
Part of the env cleanup moved this out of the environment code and into the net code. However, this helper is sometimes needed even when the net stack isn't included. Move the helper to lib/net_utils.c like it's similarly-purposed string_to_ip(). Also rename the moved function to similar naming. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Reported-by: Ondrej Jirman <megous@megous.com>
2019-12-06cmd: Migrate from_env() from pxe.c to nvedit.cPatrice Chotard1-0/+17
Migrate from_env() from pxe.c to nvedit.c as it's not pxe specific. Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
2019-12-02crc32: Use the crc.h header for crc functionsSimon Glass1-0/+1
Drop inclusion of crc.h in common.h and use the correct header directly instead. With this we can drop the conflicting definition in fw_env.h and rely on the crc.h header, which is already included. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2019-10-30cmd: env: extend "env [set|print] -e" to manage UEFI variablesAKASHI Takahiro1-5/+14
With this patch, when setting UEFI variable with "env set -e" command, we will be able to - specify vendor guid with "-guid guid", - specify variable attributes, BOOTSERVICE_ACCESS, RUNTIME_ACCESS, respectively with "-bs" and "-rt", - append a value instead of overwriting with "-a", - use memory as variable's value instead of explicit values given at the command line with "-i address,size" If guid is not explicitly given, default value will be used. Meanwhile, "env print -e," will be modified so that it will NOT dump a variable's value if '-n' is specified. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-08-11env: Rename environment.h to env_internal.hSimon Glass1-1/+1
This file contains lots of internal details about the environment. Most code can include env.h instead, calling the functions there as needed. Rename this file and add a comment at the top to indicate its internal nature. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> [trini: Fixup apalis-tk1.c] Signed-off-by: Tom Rini <trini@konsulko.com>
2019-08-11env: Drop the ACTION typedefSimon Glass1-4/+4
Avoid using a typedef here which is unnecessary. Add an 'env_' prefix to both the enum and its members to make it clear that these are related to the environment. Add an ENV prefix to these two flags so that it is clear what they relate to. Also move them to env.h since they are part of the public API. Use an enum rather than a #define to tie them together. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-08-11env: Rename the redundancy flagsSimon Glass1-1/+1
Add an ENV prefix to these two flags so that it is clear what they relate to. Also move them to env.h since they are part of the public API. Use an enum rather than a #define to tie them together. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-08-11env: Drop the ENTRY typedefSimon Glass1-6/+6
U-Boot is not supposed to use typedef for structs anymore. Also this name is the same as the ENTRY() macro used in assembler files, and 'entry' itself is widely used in U-Boot (>8k matches). Drop the typedef and rename the struct to env_entry to reduce confusion. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2019-08-11env: Move get/set_default_env() to env.hSimon Glass1-1/+1
Move these functions to the new header file and rename set_default_env() to env_set_default() so that it has a consistent env_ prefix. Acked-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Simon Glass <sjg@chromium.org>
2019-08-11env: Move set_default_vars to env.hSimon Glass1-1/+1
Move this function to the new header file and rename it so it has an env_ prefix. Acked-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Simon Glass <sjg@chromium.org>
2019-08-11env: net: Move eth_parse_enetaddr() to net.c/hSimon Glass1-12/+0
This function fits better with the network subsystem, so move it. Signed-off-by: Simon Glass <sjg@chromium.org> Suggested-by: Joe Hershberger <joe.hershberger@ni.com>
2019-08-11env: Move envmatch() to env.hSimon Glass1-10/+2
Move envmatch() over to the new header file. Also rename it to env_match() to better line up with other functions. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2019-08-11env: Move get_env_id() to env.hSimon Glass1-2/+3
Move this function over to the new header file. Also rename it to have an env_ prefix like the other functions. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2019-07-18env: register erase commandFrank Wunderlich1-0/+20
this patch adds basic changes for adding a erase-subcommand to env with this command the environment stored on non-volatile storage written by saveenv can be cleared. Signed-off-by: Frank Wunderlich <frank-w@public-files.de> squashed fixes - start message with "Erasing" - mark erase-function as optional - env: separate eraseenv from saveenv Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
2019-07-13cmd: nvedit: Add sub-command 'env info'Leo Ruan1-0/+108
Add sub-command 'env info' to display environment information: - env_valid : is environment valid - env_ready : is environment imported into hash table - env_use_default : is default environment using This command can be optionally used for evaluation in scripts: [-d] : evaluate whether default environment is used [-p] : evaluate whether environment can be persisted The result of multiple evaluations will be combined with AND. Signed-off-by: Leo Ruan <tingquan.ruan@cn.bosch.com> Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com> Reviewed-by: Simon Glass <sjg@chromium.org> [trini: Do not enable by default] Signed-off-by: Tom Rini <trini@konsulko.com>
2019-06-11Merge tag 'u-boot-stm32-20190606' of https://github.com/pchotard/u-bootTom Rini1-15/+21
- Add Ethernet support for STM32MP1 - Add saveenv support for STM32MP1 - Add STM32MP1 Avenger96 board support - Add SPI driver suport for STM32MP1 - Add watchdog support for STM32MP1 - Update power supply check via USB TYPE-C for STM32MP1 discovery board
2019-06-06env: enable saveenv command when one CONFIG_ENV_IS_IN is activatedPatrick Delaunay1-15/+21
Introduce ENV_IS_IN_DEVICE to test if one the CONFIG_ENV_IS_IN_ is defined and support the command saveenv even if CONFIG_ENV_IS_NOWHERE is activated Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2019-06-04cmd: env: add -nv option for UEFI non-volatile variableAKASHI Takahiro1-1/+2
With this option, -nv, at "setenv -e" command, a variable will be defined as non-volatile. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-25cmd: env: add "-e" option for handling UEFI variablesAKASHI Takahiro1-1/+27
"env [print|set] -e" allows for handling uefi variables without knowing details about mapping to corresponding u-boot variables. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-01-15cmd: nvedit: use correct format codeHeinrich Schuchardt1-2/+2
len is defined as unsigned. So use %u for printf(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2018-09-30cmd: env: Fix CRC calculation for 'env export -c -s'Neil Stainton1-1/+2
Fix failure to reimport exported checksummed, size constrained data block. 'env export -c' command ignores optional -s size argument when calculating checksum causing subsequent 'env import -c' to fail. Signed-off-by: Neil Stainton <nstainton@asl-control.co.uk>
2018-07-20cmd: nvedit: env import can now import only variables passed as parametersQuentin Schulz1-7/+19
While the `env export` can take as parameters variables to be exported, `env import` does not have such a mechanism of variable selection. Let's add the ability to add parameters at the end of the command for variables to be imported. Every env variable from the env to be imported passed by parameter to this command will override the value of the variable in the current env. If a variable exists in the current env but not in the imported env, if this variable is passed as a parameter to env import, the variable will be unset ONLY if the -d option is passed to env import, otherwise the current value of the variable is kept. If a variable exists in the imported env, the variable in the current env will be set to the value of the one from the imported env. All the remaining variables are left untouched. As the size parameter of env import is positional but optional, let's add the possibility to use the sentinel '-' for when we don't want to give the size parameter (when the env is '\0' terminated) but we pass a list of variables at the end of the command. env import addr env import addr - env import addr size env import addr - foo1 foo2 env import addr size foo1 foo2 are all valid. env import -c addr env import -c addr - env import -c addr - foo1 foo2 are all invalid because they don't pass the size parameter required for checking, while the following are valid. env import addr size env import addr size foo1 foo2 Nothing's changed for the other parameters or the overall behaviour. One of its use case could be to load a secure environment from the signed U-Boot binary and load only a handful of variables from an other, unsecure, environment without completely losing control of U-Boot. Signed-off-by: Quentin Schulz <quentin.schulz@bootlin.com> Tested-by: Alex Kiernan <alex.kiernan@gmail.com> Tested-by: Stephen Warren <swarren@nvidia.com>