int rcode = 0;
int env_flag = H_HIDE_DOT;
+#if defined(CONFIG_CMD_NVEDIT_EFI)
+ if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e')
+ return do_env_print_efi(cmdtp, flag, --argc, ++argv);
+#endif
+
if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
argc--;
argv++;
ENTRY e, *ep;
debug("Initial value for argc=%d\n", argc);
+
+#if CONFIG_IS_ENABLED(CMD_NVEDIT_EFI)
+ if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e')
+ return do_env_set_efi(NULL, flag, --argc, ++argv);
+#endif
+
while (argc > 1 && **(argv + 1) == '-') {
char *arg = *++argv;
if (n)
*--buf = '\0';
- printf("env_buf [%d bytes] too small for value of \"%s\"\n",
- len, name);
+ printf("env_buf [%u bytes] too small for value of \"%s\"\n",
+ len, name);
return n;
}
}
#ifndef CONFIG_SPL_BUILD
-static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
+static int do_env_default(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
- int all = 0, flag = 0;
+ int all = 0, env_flag = H_INTERACTIVE;
debug("Initial value for argc=%d\n", argc);
while (--argc > 0 && **++argv == '-') {
all = 1;
break;
case 'f': /* force */
- flag |= H_FORCE;
+ env_flag |= H_FORCE;
break;
default:
return cmd_usage(cmdtp);
debug("Final value for argc=%d\n", argc);
if (all && (argc == 0)) {
/* Reset the whole environment */
- set_default_env("## Resetting to default environment\n");
+ set_default_env("## Resetting to default environment\n",
+ env_flag);
return 0;
}
if (!all && (argc > 0)) {
/* Reset individual variables */
- set_default_vars(argc, argv);
+ set_default_vars(argc, argv, env_flag);
return 0;
}
H_MATCH_KEY | H_MATCH_IDENT,
&ptr, size, argc, argv);
if (len < 0) {
- pr_err("Cannot export environment: errno = %d\n", errno);
+ pr_err("## Error: Cannot export environment: errno = %d\n",
+ errno);
return 1;
}
sprintf(buf, "%zX", (size_t)len);
H_MATCH_KEY | H_MATCH_IDENT,
&res, ENV_SIZE, argc, argv);
if (len < 0) {
- pr_err("Cannot export environment: errno = %d\n", errno);
+ pr_err("## Error: Cannot export environment: errno = %d\n",
+ errno);
return 1;
}
if (chk) {
- envp->crc = crc32(0, envp->data, ENV_SIZE);
+ envp->crc = crc32(0, envp->data,
+ size ? size - offsetof(env_t, data) : ENV_SIZE);
#ifdef CONFIG_ENV_ADDR_REDUND
envp->flags = ACTIVE_FLAG;
#endif
return 0;
sep_err:
- printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
+ printf("## Error: %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
+ cmd);
return 1;
}
#endif
#ifdef CONFIG_CMD_IMPORTENV
/*
- * env import [-d] [-t [-r] | -b | -c] addr [size]
- * -d: delete existing environment before importing;
+ * env import [-d] [-t [-r] | -b | -c] addr [size] [var ...]
+ * -d: delete existing environment before importing if no var is
+ * passed; if vars are passed, if one var is in the current
+ * environment but not in the environment at addr, delete var from
+ * current environment;
* otherwise overwrite / append to existing definitions
* -t: assume text format; either "size" must be given or the
* text data must be '\0' terminated
* addr: memory address to read from
* size: length of input data; if missing, proper '\0'
* termination is mandatory
+ * if var is set and size should be missing (i.e. '\0'
+ * termination), set size to '-'
+ * var... List of the names of the only variables that get imported from
+ * the environment at address 'addr'. Without arguments, the whole
+ * environment gets imported.
*/
static int do_env_import(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
int fmt = 0;
int del = 0;
int crlf_is_lf = 0;
+ int wl = 0;
size_t size;
cmd = *argv;
addr = simple_strtoul(argv[0], NULL, 16);
ptr = map_sysmem(addr, 0);
- if (argc == 2) {
+ if (argc >= 2 && strcmp(argv[1], "-")) {
size = simple_strtoul(argv[1], NULL, 16);
- } else if (argc == 1 && chk) {
+ } else if (chk) {
puts("## Error: external checksum format must pass size\n");
return CMD_RET_FAILURE;
} else {
printf("## Info: input data size = %zu = 0x%zX\n", size, size);
}
+ if (argc > 2)
+ wl = 1;
+
if (chk) {
uint32_t crc;
env_t *ep = (env_t *)ptr;
ptr = (char *)ep->data;
}
- if (himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
- crlf_is_lf, 0, NULL) == 0) {
- pr_err("Environment import failed: errno = %d\n", errno);
+ if (!himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
+ crlf_is_lf, wl ? argc - 2 : 0, wl ? &argv[2] : NULL)) {
+ pr_err("## Error: Environment import failed: errno = %d\n",
+ errno);
return 1;
}
gd->flags |= GD_FLG_ENV_READY;
#endif
#endif
#if defined(CONFIG_CMD_IMPORTENV)
- "env import [-d] [-t [-r] | -b | -c] addr [size] - import environment\n"
+ "env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment\n"
#endif
"env print [-a | name ...] - print environment\n"
+#if defined(CONFIG_CMD_NVEDIT_EFI)
+ "env print -e [name ...] - print UEFI environment\n"
+#endif
#if defined(CONFIG_CMD_RUN)
"env run var [...] - run commands in an environment variable\n"
#endif
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
"env save - save environment\n"
#endif
+#if defined(CONFIG_CMD_NVEDIT_EFI)
+ "env set -e name [arg ...] - set UEFI variable; unset if 'arg' not specified\n"
+#endif
"env set [-f] name [arg ...]\n";
#endif
printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
"print environment variables",
"[-a]\n - print [all] values of all environment variables\n"
+#if defined(CONFIG_CMD_NVEDIT_EFI)
+ "printenv -e [name ...]\n"
+ " - print UEFI variable 'name' or all the variables\n"
+#endif
"printenv name ...\n"
" - print value of environment variable 'name'",
var_complete
U_BOOT_CMD_COMPLETE(
setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
"set environment variables",
- "[-f] name value ...\n"
+#if defined(CONFIG_CMD_NVEDIT_EFI)
+ "-e name [value ...]\n"
+ " - set UEFI variable 'name' to 'value' ...'\n"
+ " - delete UEFI variable 'name' if 'value' not specified\n"
+#endif
+ "setenv [-f] name value ...\n"
" - [forcibly] set environment variable 'name' to 'value ...'\n"
"setenv [-f] name\n"
" - [forcibly] delete environment variable 'name'",