d91b9904cbd0e9ffe1eef2adfb03a638dace853f
[openwrt/staging/jow.git] / package / boot / uboot-mediatek / patches / 220-cmd-env-readmem.patch
1 --- a/cmd/Kconfig
2 +++ b/cmd/Kconfig
3 @@ -602,6 +602,12 @@ config CMD_ENV_EXISTS
4 Check if a variable is defined in the environment for use in
5 shell scripting.
6
7 +config CMD_ENV_READMEM
8 + bool "env readmem"
9 + default y
10 + help
11 + Store memory content into environment variable.
12 +
13 config CMD_ENV_CALLBACK
14 bool "env callbacks - print callbacks and their associated variables"
15 help
16 --- a/cmd/nvedit.c
17 +++ b/cmd/nvedit.c
18 @@ -408,6 +408,60 @@ int do_env_ask(struct cmd_tbl *cmdtp, in
19 }
20 #endif
21
22 +#if defined(CONFIG_CMD_ENV_READMEM)
23 +int do_env_readmem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
24 +{
25 + char varstr[CONFIG_SYS_CBSIZE];
26 + const void *buf;
27 + char *local_args[4];
28 + ulong addr, bytes = 6;
29 + int hexdump = 0;
30 +
31 + /*
32 + * Check the syntax:
33 + *
34 + * readmem [-b] name address [size]
35 + */
36 + if (argc < 3)
37 + return CMD_RET_USAGE;
38 +
39 + local_args[0] = argv[0];
40 +
41 + if (!strncmp(argv[1], "-b", 3))
42 + hexdump = 1;
43 +
44 + local_args[1] = argv[hexdump + 1];
45 + local_args[2] = varstr;
46 + local_args[3] = NULL;
47 +
48 + addr = simple_strtoul(argv[hexdump + 2], NULL, 16);
49 +
50 + if (!hexdump)
51 + bytes = simple_strtoul(argv[hexdump + 3], NULL, 16);
52 +
53 + if (bytes < 1)
54 + return 1;
55 +
56 + if ((hexdump * 3) * bytes >= CONFIG_SYS_CBSIZE)
57 + return 1;
58 +
59 + buf = map_sysmem(addr, bytes);
60 + if (!buf)
61 + return 1;
62 +
63 + if (hexdump) {
64 + sprintf(varstr, "%pM", buf);
65 + } else {
66 + memcpy(varstr, buf, bytes);
67 + varstr[bytes] = '\0';
68 + }
69 + unmap_sysmem(buf);
70 +
71 + /* Continue calling setenv code */
72 + return _do_env_set(flag, 3, local_args, H_INTERACTIVE);
73 +}
74 +#endif
75 +
76 #if defined(CONFIG_CMD_ENV_CALLBACK)
77 static int print_static_binding(const char *var_name, const char *callback_name,
78 void *priv)
79 @@ -1228,6 +1282,9 @@ static struct cmd_tbl cmd_env_sub[] = {
80 U_BOOT_CMD_MKENT(load, 1, 0, do_env_load, "", ""),
81 #endif
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, "", ""),
85 +#endif
86 #if defined(CONFIG_CMD_RUN)
87 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
88 #endif
89 @@ -1319,6 +1376,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"
92 #endif
93 +#if defined(CONFIG_CMD_ENV_READMEM)
94 + "env readmem [-b] name address size - read variable from memory\n"
95 +#endif
96 #if defined(CONFIG_CMD_RUN)
97 "env run var [...] - run commands in an environment variable\n"
98 #endif
99 @@ -1428,6 +1488,17 @@ U_BOOT_CMD(
100 );
101 #endif
102
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",
110 + var_complete
111 +);
112 +#endif
113 +
114 #if defined(CONFIG_CMD_RUN)
115 U_BOOT_CMD_COMPLETE(
116 run, CONFIG_SYS_MAXARGS, 1, do_run,