3 @@ -571,6 +571,12 @@ config CMD_ENV_EXISTS
4 Check if a variable is defined in the environment for use in
7 +config CMD_ENV_READMEM
11 + Store memory content into environment variable.
13 config CMD_ENV_CALLBACK
14 bool "env callbacks - print callbacks and their associated variables"
18 @@ -469,6 +469,60 @@ int do_env_ask(struct cmd_tbl *cmdtp, in
22 +#if defined(CONFIG_CMD_ENV_READMEM)
23 +int do_env_readmem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
25 + char varstr[CONFIG_SYS_CBSIZE];
27 + char *local_args[4];
28 + ulong addr, bytes = 6;
34 + * readmem [-b] name address [size]
37 + return CMD_RET_USAGE;
39 + local_args[0] = argv[0];
41 + if (!strncmp(argv[1], "-b", 3))
44 + local_args[1] = argv[hexdump + 1];
45 + local_args[2] = varstr;
46 + local_args[3] = NULL;
48 + addr = simple_strtoul(argv[hexdump + 2], NULL, 16);
51 + bytes = simple_strtoul(argv[hexdump + 3], NULL, 16);
56 + if ((hexdump * 3) * bytes >= CONFIG_SYS_CBSIZE)
59 + buf = map_sysmem(addr, bytes);
64 + sprintf(varstr, "%pM", buf);
66 + memcpy(varstr, buf, bytes);
67 + varstr[bytes] = '\0';
71 + /* Continue calling setenv code */
72 + return _do_env_set(flag, 3, local_args, H_INTERACTIVE);
76 #if defined(CONFIG_CMD_ENV_CALLBACK)
77 static int print_static_binding(const char *var_name, const char *callback_name,
79 @@ -1373,6 +1427,9 @@ static struct cmd_tbl cmd_env_sub[] = {
80 U_BOOT_CMD_MKENT(load, 1, 0, do_env_load, "", ""),
82 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
83 +#if defined(CONFIG_CMD_ENV_READMEM)
84 + U_BOOT_CMD_MKENT(readmem, CONFIG_SYS_MAXARGS, 3, do_env_readmem, "", ""),
86 #if defined(CONFIG_CMD_RUN)
87 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
89 @@ -1461,6 +1518,9 @@ static char env_help_text[] =
90 #if defined(CONFIG_CMD_NVEDIT_EFI)
91 "env print -e [-guid guid] [-n] [name ...] - print UEFI environment\n"
93 +#if defined(CONFIG_CMD_ENV_READMEM)
94 + "env readmem [-b] name address size - read variable from memory\n"
96 #if defined(CONFIG_CMD_RUN)
97 "env run var [...] - run commands in an environment variable\n"
99 @@ -1570,6 +1630,17 @@ U_BOOT_CMD(
103 +#if defined(CONFIG_CMD_ENV_READMEM)
104 +U_BOOT_CMD_COMPLETE(
105 + readmem, CONFIG_SYS_MAXARGS, 3, do_env_readmem,
106 + "get environment variable from memory address",
107 + "name [-b] address size\n"
108 + " - store memory address to env variable\n"
109 + " \"-b\": read binary ethaddr",
114 #if defined(CONFIG_CMD_RUN)
116 run, CONFIG_SYS_MAXARGS, 1, do_run,