diff options
| author | Tom Rini <[email protected]> | 2022-04-08 08:27:50 -0400 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2022-04-08 08:27:50 -0400 |
| commit | 03a8a797e5dccaffe172d3b5224bc3c3fcd304d6 (patch) | |
| tree | 86204244c902ae70775c787d23427da8961f77d1 /cmd | |
| parent | 545eceb52062cdc995c45b9581174b7ae66b0e6f (diff) | |
| parent | 6910dbe3413e684bff9a194945df60345ecbc623 (diff) | |
Merge branch '2022-04-08-env-updates'
- Assorted env tooling updates
- Bug fix around multiple possible env locations and ENV_IS_NOWHERE
- Add 'indirect' sub-command to env
- Allow for FAT env to have the location overridden by the board code.
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/Kconfig | 3 | ||||
| -rw-r--r-- | cmd/nvedit.c | 45 |
2 files changed, 48 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig index 7bd95466131..c5eb71cea6c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -518,6 +518,9 @@ config CMD_NVEDIT_EFI If enabled, we are allowed to set/print UEFI variables using "env" command with "-e" option without knowing details. +config CMD_NVEDIT_INDIRECT + bool "env indirect - Sets environment value from another" + config CMD_NVEDIT_INFO bool "env info - print or evaluate environment information" help diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 3bb6e764c08..53e6b57b60e 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -1018,6 +1018,45 @@ sep_err: } #endif +#if defined(CONFIG_CMD_NVEDIT_INDIRECT) +static int do_env_indirect(struct cmd_tbl *cmdtp, int flag, + int argc, char *const argv[]) +{ + char *to = argv[1]; + char *from = argv[2]; + char *default_value = NULL; + int ret = 0; + + if (argc < 3 || argc > 4) { + return CMD_RET_USAGE; + } + + if (argc == 4) { + default_value = argv[3]; + } + + if (env_get(from) == NULL && default_value == NULL) { + printf("## env indirect: Environment variable for <from> (%s) does not exist.\n", from); + + return CMD_RET_FAILURE; + } + + if (env_get(from) == NULL) { + ret = env_set(to, default_value); + } + else { + ret = env_set(to, env_get(from)); + } + + if (ret == 0) { + return CMD_RET_SUCCESS; + } + else { + return CMD_RET_FAILURE; + } +} +#endif + #if defined(CONFIG_CMD_NVEDIT_INFO) /* * print_env_info - print environment information @@ -1181,6 +1220,9 @@ static struct cmd_tbl cmd_env_sub[] = { #if defined(CONFIG_CMD_IMPORTENV) U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""), #endif +#if defined(CONFIG_CMD_NVEDIT_INDIRECT) + U_BOOT_CMD_MKENT(indirect, 3, 0, do_env_indirect, "", ""), +#endif #if defined(CONFIG_CMD_NVEDIT_INFO) U_BOOT_CMD_MKENT(info, 3, 0, do_env_info, "", ""), #endif @@ -1265,6 +1307,9 @@ static char env_help_text[] = #if defined(CONFIG_CMD_IMPORTENV) "env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment\n" #endif +#if defined(CONFIG_CMD_NVEDIT_INDIRECT) + "env indirect <to> <from> [default] - sets <to> to the value of <from>, using [default] when unset\n" +#endif #if defined(CONFIG_CMD_NVEDIT_INFO) "env info - display environment information\n" "env info [-d] [-p] [-q] - evaluate environment information\n" |
