]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
a68d3ed0 | 2 | /* |
ea009d47 | 3 | * (C) Copyright 2000-2013 |
a68d3ed0 WD |
4 | * Wolfgang Denk, DENX Software Engineering, [email protected]. |
5 | * | |
6 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
7 | * Andreas Heppel <[email protected]> | |
a000b795 KP |
8 | * |
9 | * Copyright 2011 Freescale Semiconductor, Inc. | |
a68d3ed0 WD |
10 | */ |
11 | ||
ea882baf | 12 | /* |
a68d3ed0 WD |
13 | * Support for persistent environment data |
14 | * | |
ea882baf WD |
15 | * The "environment" is stored on external storage as a list of '\0' |
16 | * terminated "name=value" strings. The end of the list is marked by | |
fc0b5948 | 17 | * a double '\0'. The environment is preceded by a 32 bit CRC over |
ea882baf WD |
18 | * the data part and, in case of redundant environment, a byte of |
19 | * flags. | |
a68d3ed0 | 20 | * |
ea882baf WD |
21 | * This linearized representation will also be used before |
22 | * relocation, i. e. as long as we don't have a full C runtime | |
23 | * environment. After that, we use a hash table. | |
a68d3ed0 WD |
24 | */ |
25 | ||
26 | #include <common.h> | |
18d66533 | 27 | #include <cli.h> |
a68d3ed0 | 28 | #include <command.h> |
24b852a7 | 29 | #include <console.h> |
f1f0ae6a | 30 | #include <env.h> |
f3998fdc | 31 | #include <env_internal.h> |
f7ae49fc | 32 | #include <log.h> |
90526e9f | 33 | #include <net.h> |
ea882baf WD |
34 | #include <search.h> |
35 | #include <errno.h> | |
246c6922 | 36 | #include <malloc.h> |
0eb25b61 | 37 | #include <mapmem.h> |
401d1c4f | 38 | #include <asm/global_data.h> |
cd93d625 | 39 | #include <linux/bitops.h> |
3db71108 | 40 | #include <u-boot/crc.h> |
2a3cb020 | 41 | #include <watchdog.h> |
a68d3ed0 WD |
42 | #include <linux/stddef.h> |
43 | #include <asm/byteorder.h> | |
fd37dac9 | 44 | #include <asm/io.h> |
a68d3ed0 | 45 | |
d87080b7 WD |
46 | DECLARE_GLOBAL_DATA_PTR; |
47 | ||
2643c85d PD |
48 | #if defined(CONFIG_ENV_IS_IN_EEPROM) || \ |
49 | defined(CONFIG_ENV_IS_IN_FLASH) || \ | |
50 | defined(CONFIG_ENV_IS_IN_MMC) || \ | |
51 | defined(CONFIG_ENV_IS_IN_FAT) || \ | |
52 | defined(CONFIG_ENV_IS_IN_EXT4) || \ | |
53 | defined(CONFIG_ENV_IS_IN_NAND) || \ | |
54 | defined(CONFIG_ENV_IS_IN_NVRAM) || \ | |
55 | defined(CONFIG_ENV_IS_IN_ONENAND) || \ | |
56 | defined(CONFIG_ENV_IS_IN_SATA) || \ | |
57 | defined(CONFIG_ENV_IS_IN_SPI_FLASH) || \ | |
58 | defined(CONFIG_ENV_IS_IN_REMOTE) || \ | |
59 | defined(CONFIG_ENV_IS_IN_UBI) | |
60 | ||
61 | #define ENV_IS_IN_DEVICE | |
62 | ||
63 | #endif | |
64 | ||
65 | #if !defined(ENV_IS_IN_DEVICE) && \ | |
f3c615b8 | 66 | !defined(CONFIG_ENV_IS_NOWHERE) |
7b7341d7 | 67 | # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|MMC|FAT|EXT4|\ |
d1b88cd3 | 68 | NAND|NVRAM|ONENAND|SATA|SPI_FLASH|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE |
a68d3ed0 WD |
69 | #endif |
70 | ||
ea882baf WD |
71 | /* |
72 | * Maximum expected input data size for import command | |
73 | */ | |
74 | #define MAX_ENV_SIZE (1 << 20) /* 1 MiB */ | |
a68d3ed0 | 75 | |
da95427c | 76 | /* |
ea882baf | 77 | * This variable is incremented on each do_env_set(), so it can |
f1f0ae6a | 78 | * be used via env_get_id() as an indication, if the environment |
da95427c HS |
79 | * has changed or not. So it is possible to reread an environment |
80 | * variable only if the environment was changed ... done so for | |
81 | * example in NetInitLoop() | |
82 | */ | |
2f70c49e | 83 | static int env_id = 1; |
a68d3ed0 | 84 | |
f1f0ae6a | 85 | int env_get_id(void) |
2f70c49e HS |
86 | { |
87 | return env_id; | |
88 | } | |
a68d3ed0 | 89 | |
7ac2fe2d | 90 | #ifndef CONFIG_SPL_BUILD |
4c94f6c5 | 91 | /* |
ea882baf WD |
92 | * Command interface: print one or all environment variables |
93 | * | |
94 | * Returns 0 in case of error, or length of printed string | |
4c94f6c5 | 95 | */ |
be11235a | 96 | static int env_print(char *name, int flag) |
a68d3ed0 | 97 | { |
ea882baf | 98 | char *res = NULL; |
22a4a6c5 | 99 | ssize_t len; |
ea882baf WD |
100 | |
101 | if (name) { /* print a single name */ | |
dd2408ca | 102 | struct env_entry e, *ep; |
ea882baf WD |
103 | |
104 | e.key = name; | |
105 | e.data = NULL; | |
3f0d6807 | 106 | hsearch_r(e, ENV_FIND, &ep, &env_htab, flag); |
ea882baf WD |
107 | if (ep == NULL) |
108 | return 0; | |
f3c615b8 | 109 | len = printf("%s=%s\n", ep->key, ep->data); |
ea882baf WD |
110 | return len; |
111 | } | |
a68d3ed0 | 112 | |
ea882baf | 113 | /* print whole list */ |
be11235a | 114 | len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL); |
a68d3ed0 | 115 | |
ea882baf WD |
116 | if (len > 0) { |
117 | puts(res); | |
118 | free(res); | |
119 | return len; | |
a68d3ed0 WD |
120 | } |
121 | ||
ea882baf | 122 | /* should never happen */ |
22a4a6c5 | 123 | printf("## Error: cannot export environment\n"); |
ea882baf | 124 | return 0; |
4c94f6c5 | 125 | } |
a68d3ed0 | 126 | |
09140113 SG |
127 | static int do_env_print(struct cmd_tbl *cmdtp, int flag, int argc, |
128 | char *const argv[]) | |
4c94f6c5 MF |
129 | { |
130 | int i; | |
131 | int rcode = 0; | |
be11235a JH |
132 | int env_flag = H_HIDE_DOT; |
133 | ||
49d81fdf AT |
134 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
135 | if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') | |
136 | return do_env_print_efi(cmdtp, flag, --argc, ++argv); | |
137 | #endif | |
138 | ||
be11235a JH |
139 | if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') { |
140 | argc--; | |
141 | argv++; | |
142 | env_flag &= ~H_HIDE_DOT; | |
143 | } | |
a68d3ed0 | 144 | |
4c94f6c5 MF |
145 | if (argc == 1) { |
146 | /* print all env vars */ | |
be11235a | 147 | rcode = env_print(NULL, env_flag); |
ea882baf | 148 | if (!rcode) |
4c94f6c5 MF |
149 | return 1; |
150 | printf("\nEnvironment size: %d/%ld bytes\n", | |
151 | rcode, (ulong)ENV_SIZE); | |
152 | return 0; | |
153 | } | |
a68d3ed0 | 154 | |
4c94f6c5 | 155 | /* print selected env vars */ |
be11235a | 156 | env_flag &= ~H_HIDE_DOT; |
4c94f6c5 | 157 | for (i = 1; i < argc; ++i) { |
be11235a | 158 | int rc = env_print(argv[i], env_flag); |
ea882baf WD |
159 | if (!rc) { |
160 | printf("## Error: \"%s\" not defined\n", argv[i]); | |
4c94f6c5 | 161 | ++rcode; |
a68d3ed0 WD |
162 | } |
163 | } | |
4c94f6c5 | 164 | |
a68d3ed0 WD |
165 | return rcode; |
166 | } | |
167 | ||
a000b795 | 168 | #ifdef CONFIG_CMD_GREPENV |
09140113 SG |
169 | static int do_env_grep(struct cmd_tbl *cmdtp, int flag, |
170 | int argc, char *const argv[]) | |
a000b795 | 171 | { |
5a31ea04 | 172 | char *res = NULL; |
be29df6a | 173 | int len, grep_how, grep_what; |
a000b795 KP |
174 | |
175 | if (argc < 2) | |
4c12eeb8 | 176 | return CMD_RET_USAGE; |
a000b795 | 177 | |
be29df6a WD |
178 | grep_how = H_MATCH_SUBSTR; /* default: substring search */ |
179 | grep_what = H_MATCH_BOTH; /* default: grep names and values */ | |
d87244d5 | 180 | |
9a832331 PA |
181 | while (--argc > 0 && **++argv == '-') { |
182 | char *arg = *argv; | |
d87244d5 WD |
183 | while (*++arg) { |
184 | switch (*arg) { | |
be29df6a WD |
185 | #ifdef CONFIG_REGEX |
186 | case 'e': /* use regex matching */ | |
187 | grep_how = H_MATCH_REGEX; | |
188 | break; | |
189 | #endif | |
d87244d5 | 190 | case 'n': /* grep for name */ |
be29df6a | 191 | grep_what = H_MATCH_KEY; |
d87244d5 WD |
192 | break; |
193 | case 'v': /* grep for value */ | |
be29df6a | 194 | grep_what = H_MATCH_DATA; |
d87244d5 WD |
195 | break; |
196 | case 'b': /* grep for both */ | |
be29df6a | 197 | grep_what = H_MATCH_BOTH; |
d87244d5 WD |
198 | break; |
199 | case '-': | |
200 | goto DONE; | |
201 | default: | |
202 | return CMD_RET_USAGE; | |
203 | } | |
204 | } | |
205 | } | |
206 | ||
207 | DONE: | |
5a31ea04 | 208 | len = hexport_r(&env_htab, '\n', |
be29df6a | 209 | flag | grep_what | grep_how, |
5a31ea04 | 210 | &res, 0, argc, argv); |
a000b795 | 211 | |
5a31ea04 WD |
212 | if (len > 0) { |
213 | puts(res); | |
214 | free(res); | |
a000b795 KP |
215 | } |
216 | ||
5a31ea04 WD |
217 | if (len < 2) |
218 | return 1; | |
219 | ||
220 | return 0; | |
a000b795 KP |
221 | } |
222 | #endif | |
7ac2fe2d | 223 | #endif /* CONFIG_SPL_BUILD */ |
a000b795 | 224 | |
c3f65258 GF |
225 | /* |
226 | * Set a new environment variable, | |
227 | * or replace or delete an existing one. | |
2598090b | 228 | */ |
09140113 | 229 | static int _do_env_set(int flag, int argc, char *const argv[], int env_flag) |
c3f65258 GF |
230 | { |
231 | int i, len; | |
232 | char *name, *value, *s; | |
dd2408ca | 233 | struct env_entry e, *ep; |
c3f65258 | 234 | |
24ab5a19 | 235 | debug("Initial value for argc=%d\n", argc); |
49d81fdf AT |
236 | |
237 | #if CONFIG_IS_ENABLED(CMD_NVEDIT_EFI) | |
238 | if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') | |
239 | return do_env_set_efi(NULL, flag, --argc, ++argv); | |
240 | #endif | |
241 | ||
24ab5a19 JH |
242 | while (argc > 1 && **(argv + 1) == '-') { |
243 | char *arg = *++argv; | |
244 | ||
245 | --argc; | |
246 | while (*++arg) { | |
247 | switch (*arg) { | |
248 | case 'f': /* force */ | |
249 | env_flag |= H_FORCE; | |
250 | break; | |
251 | default: | |
252 | return CMD_RET_USAGE; | |
253 | } | |
254 | } | |
255 | } | |
256 | debug("Final value for argc=%d\n", argc); | |
c3f65258 | 257 | name = argv[1]; |
c3f65258 GF |
258 | |
259 | if (strchr(name, '=')) { | |
260 | printf("## Error: illegal character '='" | |
261 | "in variable name \"%s\"\n", name); | |
262 | return 1; | |
263 | } | |
264 | ||
265 | env_id++; | |
c3f65258 | 266 | |
a68d3ed0 | 267 | /* Delete only ? */ |
d09b1787 | 268 | if (argc < 3 || argv[2] == NULL) { |
24ab5a19 | 269 | int rc = hdelete_r(name, &env_htab, env_flag); |
96434a76 SG |
270 | |
271 | /* If the variable didn't exist, don't report an error */ | |
272 | return rc && rc != -ENOENT ? 1 : 0; | |
a68d3ed0 WD |
273 | } |
274 | ||
275 | /* | |
ea882baf | 276 | * Insert / replace new value |
a68d3ed0 | 277 | */ |
f3c615b8 | 278 | for (i = 2, len = 0; i < argc; ++i) |
a68d3ed0 | 279 | len += strlen(argv[i]) + 1; |
f3c615b8 ML |
280 | |
281 | value = malloc(len); | |
282 | if (value == NULL) { | |
ea882baf | 283 | printf("## Can't malloc %d bytes\n", len); |
a68d3ed0 WD |
284 | return 1; |
285 | } | |
f3c615b8 | 286 | for (i = 2, s = value; i < argc; ++i) { |
ea882baf | 287 | char *v = argv[i]; |
a68d3ed0 | 288 | |
ea882baf | 289 | while ((*s++ = *v++) != '\0') |
a68d3ed0 | 290 | ; |
d09b1787 | 291 | *(s - 1) = ' '; |
ea882baf WD |
292 | } |
293 | if (s != value) | |
294 | *--s = '\0'; | |
295 | ||
d09b1787 IG |
296 | e.key = name; |
297 | e.data = value; | |
3f0d6807 | 298 | hsearch_r(e, ENV_ENTER, &ep, &env_htab, env_flag); |
ea882baf WD |
299 | free(value); |
300 | if (!ep) { | |
301 | printf("## Error inserting \"%s\" variable, errno=%d\n", | |
302 | name, errno); | |
303 | return 1; | |
a68d3ed0 | 304 | } |
a68d3ed0 | 305 | |
a68d3ed0 WD |
306 | return 0; |
307 | } | |
308 | ||
382bee57 | 309 | int env_set(const char *varname, const char *varvalue) |
a68d3ed0 | 310 | { |
84b5e802 WD |
311 | const char * const argv[4] = { "setenv", varname, varvalue, NULL }; |
312 | ||
a7eb1d66 JH |
313 | /* before import into hashtable */ |
314 | if (!(gd->flags & GD_FLG_ENV_READY)) | |
315 | return 1; | |
316 | ||
d09b1787 | 317 | if (varvalue == NULL || varvalue[0] == '\0') |
94b467b1 | 318 | return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC); |
9ffd451a | 319 | else |
94b467b1 | 320 | return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC); |
a68d3ed0 WD |
321 | } |
322 | ||
d67f10ce SG |
323 | /** |
324 | * Set an environment variable to an integer value | |
325 | * | |
9602286d | 326 | * @param varname Environment variable to set |
d67f10ce SG |
327 | * @param value Value to set it to |
328 | * @return 0 if ok, 1 on error | |
329 | */ | |
018f5303 | 330 | int env_set_ulong(const char *varname, ulong value) |
d67f10ce SG |
331 | { |
332 | /* TODO: this should be unsigned */ | |
333 | char *str = simple_itoa(value); | |
334 | ||
382bee57 | 335 | return env_set(varname, str); |
d67f10ce SG |
336 | } |
337 | ||
338 | /** | |
bfc59966 | 339 | * Set an environment variable to an value in hex |
d67f10ce | 340 | * |
9602286d | 341 | * @param varname Environment variable to set |
bfc59966 | 342 | * @param value Value to set it to |
d67f10ce SG |
343 | * @return 0 if ok, 1 on error |
344 | */ | |
018f5303 | 345 | int env_set_hex(const char *varname, ulong value) |
d67f10ce SG |
346 | { |
347 | char str[17]; | |
348 | ||
bfc59966 | 349 | sprintf(str, "%lx", value); |
382bee57 | 350 | return env_set(varname, str); |
d67f10ce SG |
351 | } |
352 | ||
bfebc8c9 | 353 | ulong env_get_hex(const char *varname, ulong default_val) |
76b8f79c SG |
354 | { |
355 | const char *s; | |
356 | ulong value; | |
357 | char *endp; | |
358 | ||
00caae6d | 359 | s = env_get(varname); |
76b8f79c SG |
360 | if (s) |
361 | value = simple_strtoul(s, &endp, 16); | |
362 | if (!s || endp == s) | |
363 | return default_val; | |
364 | ||
365 | return value; | |
366 | } | |
367 | ||
9925f1db AK |
368 | int eth_env_get_enetaddr(const char *name, uint8_t *enetaddr) |
369 | { | |
fb8977c5 | 370 | string_to_enetaddr(env_get(name), enetaddr); |
9925f1db AK |
371 | return is_valid_ethaddr(enetaddr); |
372 | } | |
373 | ||
374 | int eth_env_set_enetaddr(const char *name, const uint8_t *enetaddr) | |
375 | { | |
376 | char buf[ARP_HLEN_ASCII + 1]; | |
377 | ||
378 | if (eth_env_get_enetaddr(name, (uint8_t *)buf)) | |
379 | return -EEXIST; | |
380 | ||
381 | sprintf(buf, "%pM", enetaddr); | |
382 | ||
383 | return env_set(name, buf); | |
384 | } | |
385 | ||
7ac2fe2d | 386 | #ifndef CONFIG_SPL_BUILD |
09140113 SG |
387 | static int do_env_set(struct cmd_tbl *cmdtp, int flag, int argc, |
388 | char *const argv[]) | |
a68d3ed0 | 389 | { |
47e26b1b | 390 | if (argc < 2) |
4c12eeb8 | 391 | return CMD_RET_USAGE; |
a68d3ed0 | 392 | |
94b467b1 | 393 | return _do_env_set(flag, argc, argv, H_INTERACTIVE); |
a68d3ed0 WD |
394 | } |
395 | ||
ea882baf | 396 | /* |
a68d3ed0 WD |
397 | * Prompt for environment variable |
398 | */ | |
c76fe474 | 399 | #if defined(CONFIG_CMD_ASKENV) |
09140113 | 400 | int do_env_ask(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
a68d3ed0 | 401 | { |
6d0f6bcf | 402 | char message[CONFIG_SYS_CBSIZE]; |
7d85591d | 403 | int i, len, pos, size; |
a68d3ed0 | 404 | char *local_args[4]; |
7d85591d | 405 | char *endptr; |
a68d3ed0 WD |
406 | |
407 | local_args[0] = argv[0]; | |
408 | local_args[1] = argv[1]; | |
409 | local_args[2] = NULL; | |
410 | local_args[3] = NULL; | |
411 | ||
7d85591d WD |
412 | /* |
413 | * Check the syntax: | |
414 | * | |
415 | * env_ask envname [message1 ...] [size] | |
416 | */ | |
417 | if (argc == 1) | |
4c12eeb8 | 418 | return CMD_RET_USAGE; |
a68d3ed0 | 419 | |
7d85591d WD |
420 | /* |
421 | * We test the last argument if it can be converted | |
422 | * into a decimal number. If yes, we assume it's | |
423 | * the size. Otherwise we echo it as part of the | |
424 | * message. | |
425 | */ | |
426 | i = simple_strtoul(argv[argc - 1], &endptr, 10); | |
427 | if (*endptr != '\0') { /* no size */ | |
428 | size = CONFIG_SYS_CBSIZE - 1; | |
429 | } else { /* size given */ | |
430 | size = i; | |
431 | --argc; | |
432 | } | |
a68d3ed0 | 433 | |
7d85591d WD |
434 | if (argc <= 2) { |
435 | sprintf(message, "Please enter '%s': ", argv[1]); | |
436 | } else { | |
437 | /* env_ask envname message1 ... messagen [size] */ | |
bf52fcde | 438 | for (i = 2, pos = 0; i < argc && pos+1 < sizeof(message); i++) { |
f3c615b8 | 439 | if (pos) |
a68d3ed0 | 440 | message[pos++] = ' '; |
f3c615b8 | 441 | |
c667723f | 442 | strncpy(message + pos, argv[i], sizeof(message) - pos); |
a68d3ed0 WD |
443 | pos += strlen(argv[i]); |
444 | } | |
c667723f TR |
445 | if (pos < sizeof(message) - 1) { |
446 | message[pos++] = ' '; | |
447 | message[pos] = '\0'; | |
448 | } else | |
449 | message[CONFIG_SYS_CBSIZE - 1] = '\0'; | |
a68d3ed0 WD |
450 | } |
451 | ||
6d0f6bcf JCPV |
452 | if (size >= CONFIG_SYS_CBSIZE) |
453 | size = CONFIG_SYS_CBSIZE - 1; | |
a68d3ed0 WD |
454 | |
455 | if (size <= 0) | |
456 | return 1; | |
457 | ||
458 | /* prompt for input */ | |
e1bf824d | 459 | len = cli_readline(message); |
a68d3ed0 WD |
460 | |
461 | if (size < len) | |
462 | console_buffer[size] = '\0'; | |
463 | ||
464 | len = 2; | |
465 | if (console_buffer[0] != '\0') { | |
466 | local_args[2] = console_buffer; | |
467 | len = 3; | |
468 | } | |
469 | ||
470 | /* Continue calling setenv code */ | |
94b467b1 | 471 | return _do_env_set(flag, len, local_args, H_INTERACTIVE); |
a68d3ed0 | 472 | } |
90253178 | 473 | #endif |
a68d3ed0 | 474 | |
5e2b3e0c | 475 | #if defined(CONFIG_CMD_ENV_CALLBACK) |
cca98fd6 JH |
476 | static int print_static_binding(const char *var_name, const char *callback_name, |
477 | void *priv) | |
5e2b3e0c JH |
478 | { |
479 | printf("\t%-20s %-20s\n", var_name, callback_name); | |
480 | ||
481 | return 0; | |
482 | } | |
483 | ||
dd2408ca | 484 | static int print_active_callback(struct env_entry *entry) |
5e2b3e0c JH |
485 | { |
486 | struct env_clbk_tbl *clbkp; | |
487 | int i; | |
488 | int num_callbacks; | |
489 | ||
490 | if (entry->callback == NULL) | |
491 | return 0; | |
492 | ||
493 | /* look up the callback in the linker-list */ | |
494 | num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk); | |
495 | for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk); | |
496 | i < num_callbacks; | |
497 | i++, clbkp++) { | |
498 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) | |
499 | if (entry->callback == clbkp->callback + gd->reloc_off) | |
500 | #else | |
501 | if (entry->callback == clbkp->callback) | |
502 | #endif | |
503 | break; | |
504 | } | |
505 | ||
506 | if (i == num_callbacks) | |
507 | /* this should probably never happen, but just in case... */ | |
508 | printf("\t%-20s %p\n", entry->key, entry->callback); | |
509 | else | |
510 | printf("\t%-20s %-20s\n", entry->key, clbkp->name); | |
511 | ||
512 | return 0; | |
513 | } | |
514 | ||
515 | /* | |
516 | * Print the callbacks available and what they are bound to | |
517 | */ | |
09140113 SG |
518 | int do_env_callback(struct cmd_tbl *cmdtp, int flag, int argc, |
519 | char *const argv[]) | |
5e2b3e0c JH |
520 | { |
521 | struct env_clbk_tbl *clbkp; | |
522 | int i; | |
523 | int num_callbacks; | |
524 | ||
525 | /* Print the available callbacks */ | |
526 | puts("Available callbacks:\n"); | |
527 | puts("\tCallback Name\n"); | |
528 | puts("\t-------------\n"); | |
529 | num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk); | |
530 | for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk); | |
531 | i < num_callbacks; | |
532 | i++, clbkp++) | |
533 | printf("\t%s\n", clbkp->name); | |
534 | puts("\n"); | |
535 | ||
536 | /* Print the static bindings that may exist */ | |
537 | puts("Static callback bindings:\n"); | |
538 | printf("\t%-20s %-20s\n", "Variable Name", "Callback Name"); | |
539 | printf("\t%-20s %-20s\n", "-------------", "-------------"); | |
cca98fd6 | 540 | env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding, NULL); |
5e2b3e0c JH |
541 | puts("\n"); |
542 | ||
543 | /* walk through each variable and print the callback if it has one */ | |
544 | puts("Active callback bindings:\n"); | |
545 | printf("\t%-20s %-20s\n", "Variable Name", "Callback Name"); | |
546 | printf("\t%-20s %-20s\n", "-------------", "-------------"); | |
547 | hwalk_r(&env_htab, print_active_callback); | |
548 | return 0; | |
549 | } | |
550 | #endif | |
551 | ||
fffad71b | 552 | #if defined(CONFIG_CMD_ENV_FLAGS) |
cca98fd6 JH |
553 | static int print_static_flags(const char *var_name, const char *flags, |
554 | void *priv) | |
fffad71b JH |
555 | { |
556 | enum env_flags_vartype type = env_flags_parse_vartype(flags); | |
267541f7 | 557 | enum env_flags_varaccess access = env_flags_parse_varaccess(flags); |
fffad71b | 558 | |
267541f7 JH |
559 | printf("\t%-20s %-20s %-20s\n", var_name, |
560 | env_flags_get_vartype_name(type), | |
561 | env_flags_get_varaccess_name(access)); | |
fffad71b JH |
562 | |
563 | return 0; | |
564 | } | |
565 | ||
dd2408ca | 566 | static int print_active_flags(struct env_entry *entry) |
fffad71b JH |
567 | { |
568 | enum env_flags_vartype type; | |
267541f7 | 569 | enum env_flags_varaccess access; |
fffad71b JH |
570 | |
571 | if (entry->flags == 0) | |
572 | return 0; | |
573 | ||
574 | type = (enum env_flags_vartype) | |
575 | (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK); | |
267541f7 JH |
576 | access = env_flags_parse_varaccess_from_binflags(entry->flags); |
577 | printf("\t%-20s %-20s %-20s\n", entry->key, | |
578 | env_flags_get_vartype_name(type), | |
579 | env_flags_get_varaccess_name(access)); | |
fffad71b JH |
580 | |
581 | return 0; | |
582 | } | |
583 | ||
584 | /* | |
585 | * Print the flags available and what variables have flags | |
586 | */ | |
09140113 | 587 | int do_env_flags(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
fffad71b JH |
588 | { |
589 | /* Print the available variable types */ | |
590 | printf("Available variable type flags (position %d):\n", | |
591 | ENV_FLAGS_VARTYPE_LOC); | |
592 | puts("\tFlag\tVariable Type Name\n"); | |
593 | puts("\t----\t------------------\n"); | |
594 | env_flags_print_vartypes(); | |
595 | puts("\n"); | |
596 | ||
267541f7 JH |
597 | /* Print the available variable access types */ |
598 | printf("Available variable access flags (position %d):\n", | |
599 | ENV_FLAGS_VARACCESS_LOC); | |
600 | puts("\tFlag\tVariable Access Name\n"); | |
601 | puts("\t----\t--------------------\n"); | |
602 | env_flags_print_varaccess(); | |
603 | puts("\n"); | |
604 | ||
fffad71b JH |
605 | /* Print the static flags that may exist */ |
606 | puts("Static flags:\n"); | |
267541f7 JH |
607 | printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type", |
608 | "Variable Access"); | |
609 | printf("\t%-20s %-20s %-20s\n", "-------------", "-------------", | |
610 | "---------------"); | |
cca98fd6 | 611 | env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags, NULL); |
fffad71b JH |
612 | puts("\n"); |
613 | ||
614 | /* walk through each variable and print the flags if non-default */ | |
615 | puts("Active flags:\n"); | |
267541f7 JH |
616 | printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type", |
617 | "Variable Access"); | |
618 | printf("\t%-20s %-20s %-20s\n", "-------------", "-------------", | |
619 | "---------------"); | |
fffad71b JH |
620 | hwalk_r(&env_htab, print_active_flags); |
621 | return 0; | |
622 | } | |
623 | #endif | |
624 | ||
ea882baf | 625 | /* |
246c6922 PT |
626 | * Interactively edit an environment variable |
627 | */ | |
628 | #if defined(CONFIG_CMD_EDITENV) | |
09140113 SG |
629 | static int do_env_edit(struct cmd_tbl *cmdtp, int flag, int argc, |
630 | char *const argv[]) | |
246c6922 PT |
631 | { |
632 | char buffer[CONFIG_SYS_CBSIZE]; | |
633 | char *init_val; | |
246c6922 | 634 | |
47e26b1b | 635 | if (argc < 2) |
4c12eeb8 | 636 | return CMD_RET_USAGE; |
246c6922 | 637 | |
94b467b1 JH |
638 | /* before import into hashtable */ |
639 | if (!(gd->flags & GD_FLG_ENV_READY)) | |
640 | return 1; | |
641 | ||
246c6922 | 642 | /* Set read buffer to initial value or empty sting */ |
00caae6d | 643 | init_val = env_get(argv[1]); |
246c6922 | 644 | if (init_val) |
5d49b4cd | 645 | snprintf(buffer, CONFIG_SYS_CBSIZE, "%s", init_val); |
246c6922 PT |
646 | else |
647 | buffer[0] = '\0'; | |
648 | ||
e1bf824d | 649 | if (cli_readline_into_buffer("edit: ", buffer, 0) < 0) |
18a3cce9 | 650 | return 1; |
246c6922 | 651 | |
94b467b1 JH |
652 | if (buffer[0] == '\0') { |
653 | const char * const _argv[3] = { "setenv", argv[1], NULL }; | |
654 | ||
655 | return _do_env_set(0, 2, (char * const *)_argv, H_INTERACTIVE); | |
656 | } else { | |
657 | const char * const _argv[4] = { "setenv", argv[1], buffer, | |
658 | NULL }; | |
659 | ||
660 | return _do_env_set(0, 3, (char * const *)_argv, H_INTERACTIVE); | |
661 | } | |
246c6922 PT |
662 | } |
663 | #endif /* CONFIG_CMD_EDITENV */ | |
7ac2fe2d | 664 | #endif /* CONFIG_SPL_BUILD */ |
246c6922 | 665 | |
ea882baf | 666 | /* |
a68d3ed0 WD |
667 | * Look up variable from environment, |
668 | * return address of storage for that variable, | |
669 | * or NULL if not found | |
670 | */ | |
00caae6d | 671 | char *env_get(const char *name) |
a68d3ed0 | 672 | { |
d09b1787 | 673 | if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */ |
dd2408ca | 674 | struct env_entry e, *ep; |
a68d3ed0 | 675 | |
91a76751 | 676 | WATCHDOG_RESET(); |
2a3cb020 | 677 | |
d09b1787 IG |
678 | e.key = name; |
679 | e.data = NULL; | |
3f0d6807 | 680 | hsearch_r(e, ENV_FIND, &ep, &env_htab, 0); |
91a76751 | 681 | |
f3c615b8 | 682 | return ep ? ep->data : NULL; |
a68d3ed0 WD |
683 | } |
684 | ||
ea882baf | 685 | /* restricted capabilities before import */ |
00caae6d | 686 | if (env_get_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0) |
ea882baf | 687 | return (char *)(gd->env_buf); |
91a76751 | 688 | |
ea882baf | 689 | return NULL; |
a68d3ed0 WD |
690 | } |
691 | ||
1ac2cb97 PC |
692 | /* |
693 | * Like env_get, but prints an error if envvar isn't defined in the | |
694 | * environment. It always returns what env_get does, so it can be used in | |
695 | * place of env_get without changing error handling otherwise. | |
696 | */ | |
697 | char *from_env(const char *envvar) | |
698 | { | |
699 | char *ret; | |
700 | ||
701 | ret = env_get(envvar); | |
702 | ||
703 | if (!ret) | |
704 | printf("missing environment variable: %s\n", envvar); | |
705 | ||
706 | return ret; | |
707 | } | |
708 | ||
ea882baf WD |
709 | /* |
710 | * Look up variable from environment for restricted C runtime env. | |
711 | */ | |
00caae6d | 712 | int env_get_f(const char *name, char *buf, unsigned len) |
a68d3ed0 | 713 | { |
87c7fb39 | 714 | int i, nxt, c; |
a68d3ed0 | 715 | |
d09b1787 | 716 | for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) { |
a68d3ed0 WD |
717 | int val, n; |
718 | ||
87c7fb39 SG |
719 | for (nxt = i; (c = env_get_char(nxt)) != '\0'; ++nxt) { |
720 | if (c < 0) | |
721 | return c; | |
f3c615b8 ML |
722 | if (nxt >= CONFIG_ENV_SIZE) |
723 | return -1; | |
a68d3ed0 | 724 | } |
f3c615b8 | 725 | |
b9ca02c2 | 726 | val = env_match((uchar *)name, i); |
f3c615b8 | 727 | if (val < 0) |
a68d3ed0 | 728 | continue; |
9ed4a958 | 729 | |
a68d3ed0 | 730 | /* found; copy out */ |
f3c615b8 | 731 | for (n = 0; n < len; ++n, ++buf) { |
87c7fb39 SG |
732 | c = env_get_char(val++); |
733 | if (c < 0) | |
734 | return c; | |
735 | *buf = c; | |
d09b1787 | 736 | if (*buf == '\0') |
9ed4a958 WD |
737 | return n; |
738 | } | |
739 | ||
740 | if (n) | |
741 | *--buf = '\0'; | |
742 | ||
82919517 HS |
743 | printf("env_buf [%u bytes] too small for value of \"%s\"\n", |
744 | len, name); | |
9ed4a958 WD |
745 | |
746 | return n; | |
a68d3ed0 | 747 | } |
d09b1787 | 748 | |
f3c615b8 | 749 | return -1; |
a68d3ed0 WD |
750 | } |
751 | ||
4a9b4131 SG |
752 | /** |
753 | * Decode the integer value of an environment variable and return it. | |
754 | * | |
919d25c9 | 755 | * @param name Name of environment variable |
4a9b4131 SG |
756 | * @param base Number base to use (normally 10, or 16 for hex) |
757 | * @param default_val Default value to return if the variable is not | |
758 | * found | |
759 | * @return the decoded value, or default_val if not found | |
760 | */ | |
bfebc8c9 | 761 | ulong env_get_ulong(const char *name, int base, ulong default_val) |
4a9b4131 SG |
762 | { |
763 | /* | |
00caae6d | 764 | * We can use env_get() here, even before relocation, since the |
4a9b4131 SG |
765 | * environment variable value is an integer and thus short. |
766 | */ | |
00caae6d | 767 | const char *str = env_get(name); |
4a9b4131 SG |
768 | |
769 | return str ? simple_strtoul(str, NULL, base) : default_val; | |
770 | } | |
771 | ||
7ac2fe2d | 772 | #ifndef CONFIG_SPL_BUILD |
2643c85d | 773 | #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) |
09140113 SG |
774 | static int do_env_save(struct cmd_tbl *cmdtp, int flag, int argc, |
775 | char *const argv[]) | |
a68d3ed0 | 776 | { |
01510091 | 777 | return env_save() ? 1 : 0; |
a68d3ed0 | 778 | } |
8bde7f77 | 779 | |
ba69dc26 | 780 | U_BOOT_CMD( |
ea882baf | 781 | saveenv, 1, 0, do_env_save, |
2fb2604d | 782 | "save environment variables to persistent storage", |
a89c33db | 783 | "" |
ba69dc26 | 784 | ); |
cd121bdb FW |
785 | |
786 | #if defined(CONFIG_CMD_ERASEENV) | |
09140113 SG |
787 | static int do_env_erase(struct cmd_tbl *cmdtp, int flag, int argc, |
788 | char *const argv[]) | |
cd121bdb FW |
789 | { |
790 | return env_erase() ? 1 : 0; | |
791 | } | |
792 | ||
793 | U_BOOT_CMD( | |
794 | eraseenv, 1, 0, do_env_erase, | |
795 | "erase environment variables from persistent storage", | |
796 | "" | |
797 | ); | |
798 | #endif | |
a68d3ed0 | 799 | #endif |
0115dd3a PD |
800 | |
801 | #if defined(CONFIG_CMD_NVEDIT_LOAD) | |
802 | static int do_env_load(struct cmd_tbl *cmdtp, int flag, int argc, | |
803 | char *const argv[]) | |
804 | { | |
805 | return env_reload() ? 1 : 0; | |
806 | } | |
807 | #endif | |
a97d22eb PD |
808 | |
809 | #if defined(CONFIG_CMD_NVEDIT_SELECT) | |
810 | static int do_env_select(struct cmd_tbl *cmdtp, int flag, int argc, | |
811 | char *const argv[]) | |
812 | { | |
813 | return env_select(argv[1]) ? 1 : 0; | |
814 | } | |
815 | #endif | |
816 | ||
7ac2fe2d | 817 | #endif /* CONFIG_SPL_BUILD */ |
a68d3ed0 | 818 | |
b9ca02c2 | 819 | int env_match(uchar *s1, int i2) |
a68d3ed0 | 820 | { |
586197df JH |
821 | if (s1 == NULL) |
822 | return -1; | |
823 | ||
a68d3ed0 WD |
824 | while (*s1 == env_get_char(i2++)) |
825 | if (*s1++ == '=') | |
f3c615b8 | 826 | return i2; |
d09b1787 | 827 | |
a68d3ed0 | 828 | if (*s1 == '\0' && env_get_char(i2-1) == '=') |
f3c615b8 | 829 | return i2; |
d09b1787 | 830 | |
f3c615b8 | 831 | return -1; |
a68d3ed0 | 832 | } |
8bde7f77 | 833 | |
7ac2fe2d | 834 | #ifndef CONFIG_SPL_BUILD |
09140113 SG |
835 | static int do_env_default(struct cmd_tbl *cmdtp, int flag, |
836 | int argc, char *const argv[]) | |
ea882baf | 837 | { |
5a04264e | 838 | int all = 0, env_flag = H_INTERACTIVE; |
f3c615b8 | 839 | |
b64b7c3d GF |
840 | debug("Initial value for argc=%d\n", argc); |
841 | while (--argc > 0 && **++argv == '-') { | |
842 | char *arg = *argv; | |
843 | ||
844 | while (*++arg) { | |
845 | switch (*arg) { | |
846 | case 'a': /* default all */ | |
847 | all = 1; | |
848 | break; | |
849 | case 'f': /* force */ | |
30091494 | 850 | env_flag |= H_FORCE; |
b64b7c3d GF |
851 | break; |
852 | default: | |
853 | return cmd_usage(cmdtp); | |
854 | } | |
855 | } | |
856 | } | |
857 | debug("Final value for argc=%d\n", argc); | |
858 | if (all && (argc == 0)) { | |
859 | /* Reset the whole environment */ | |
0ac7d722 | 860 | env_set_default("## Resetting to default environment\n", |
c5d548a9 | 861 | env_flag); |
b64b7c3d GF |
862 | return 0; |
863 | } | |
864 | if (!all && (argc > 0)) { | |
865 | /* Reset individual variables */ | |
0b9d8a05 | 866 | env_set_default_vars(argc, argv, env_flag); |
b64b7c3d GF |
867 | return 0; |
868 | } | |
869 | ||
870 | return cmd_usage(cmdtp); | |
ea882baf WD |
871 | } |
872 | ||
09140113 SG |
873 | static int do_env_delete(struct cmd_tbl *cmdtp, int flag, |
874 | int argc, char *const argv[]) | |
ea882baf | 875 | { |
9d8d661d JH |
876 | int env_flag = H_INTERACTIVE; |
877 | int ret = 0; | |
878 | ||
879 | debug("Initial value for argc=%d\n", argc); | |
880 | while (argc > 1 && **(argv + 1) == '-') { | |
881 | char *arg = *++argv; | |
882 | ||
883 | --argc; | |
884 | while (*++arg) { | |
885 | switch (*arg) { | |
886 | case 'f': /* force */ | |
887 | env_flag |= H_FORCE; | |
888 | break; | |
889 | default: | |
890 | return CMD_RET_USAGE; | |
891 | } | |
892 | } | |
893 | } | |
894 | debug("Final value for argc=%d\n", argc); | |
895 | ||
896 | env_id++; | |
897 | ||
898 | while (--argc > 0) { | |
899 | char *name = *++argv; | |
900 | ||
96434a76 | 901 | if (hdelete_r(name, &env_htab, env_flag)) |
9d8d661d JH |
902 | ret = 1; |
903 | } | |
904 | ||
905 | return ret; | |
ea882baf WD |
906 | } |
907 | ||
0c79cda0 | 908 | #ifdef CONFIG_CMD_EXPORTENV |
ea882baf | 909 | /* |
37f2fe74 | 910 | * env export [-t | -b | -c] [-s size] addr [var ...] |
ea882baf WD |
911 | * -t: export as text format; if size is given, data will be |
912 | * padded with '\0' bytes; if not, one terminating '\0' | |
913 | * will be added (which is included in the "filesize" | |
914 | * setting so you can for exmple copy this to flash and | |
915 | * keep the termination). | |
916 | * -b: export as binary format (name=value pairs separated by | |
917 | * '\0', list end marked by double "\0\0") | |
918 | * -c: export as checksum protected environment format as | |
919 | * used for example by "saveenv" command | |
37f2fe74 WD |
920 | * -s size: |
921 | * size of output buffer | |
ea882baf | 922 | * addr: memory address where environment gets stored |
37f2fe74 WD |
923 | * var... List of variable names that get included into the |
924 | * export. Without arguments, the whole environment gets | |
925 | * exported. | |
ea882baf WD |
926 | * |
927 | * With "-c" and size is NOT given, then the export command will | |
928 | * format the data as currently used for the persistent storage, | |
929 | * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and | |
fc0b5948 | 930 | * prepend a valid CRC32 checksum and, in case of redundant |
ea882baf WD |
931 | * environment, a "current" redundancy flag. If size is given, this |
932 | * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32 | |
933 | * checksum and redundancy flag will be inserted. | |
934 | * | |
935 | * With "-b" and "-t", always only the real data (including a | |
936 | * terminating '\0' byte) will be written; here the optional size | |
937 | * argument will be used to make sure not to overflow the user | |
938 | * provided buffer; the command will abort if the size is not | |
fc0b5948 | 939 | * sufficient. Any remaining space will be '\0' padded. |
ea882baf WD |
940 | * |
941 | * On successful return, the variable "filesize" will be set. | |
942 | * Note that filesize includes the trailing/terminating '\0' byte(s). | |
943 | * | |
fc0b5948 | 944 | * Usage scenario: create a text snapshot/backup of the current settings: |
ea882baf WD |
945 | * |
946 | * => env export -t 100000 | |
947 | * => era ${backup_addr} +${filesize} | |
948 | * => cp.b 100000 ${backup_addr} ${filesize} | |
949 | * | |
950 | * Re-import this snapshot, deleting all other settings: | |
951 | * | |
952 | * => env import -d -t ${backup_addr} | |
953 | */ | |
09140113 SG |
954 | static int do_env_export(struct cmd_tbl *cmdtp, int flag, |
955 | int argc, char *const argv[]) | |
ea882baf WD |
956 | { |
957 | char buf[32]; | |
fd37dac9 SG |
958 | ulong addr; |
959 | char *ptr, *cmd, *res; | |
37f2fe74 | 960 | size_t size = 0; |
ea882baf WD |
961 | ssize_t len; |
962 | env_t *envp; | |
963 | char sep = '\n'; | |
964 | int chk = 0; | |
965 | int fmt = 0; | |
966 | ||
967 | cmd = *argv; | |
968 | ||
969 | while (--argc > 0 && **++argv == '-') { | |
970 | char *arg = *argv; | |
971 | while (*++arg) { | |
972 | switch (*arg) { | |
973 | case 'b': /* raw binary format */ | |
974 | if (fmt++) | |
975 | goto sep_err; | |
976 | sep = '\0'; | |
977 | break; | |
978 | case 'c': /* external checksum format */ | |
979 | if (fmt++) | |
980 | goto sep_err; | |
981 | sep = '\0'; | |
982 | chk = 1; | |
983 | break; | |
37f2fe74 WD |
984 | case 's': /* size given */ |
985 | if (--argc <= 0) | |
986 | return cmd_usage(cmdtp); | |
987 | size = simple_strtoul(*++argv, NULL, 16); | |
988 | goto NXTARG; | |
ea882baf WD |
989 | case 't': /* text format */ |
990 | if (fmt++) | |
991 | goto sep_err; | |
992 | sep = '\n'; | |
993 | break; | |
994 | default: | |
4c12eeb8 | 995 | return CMD_RET_USAGE; |
ea882baf WD |
996 | } |
997 | } | |
37f2fe74 | 998 | NXTARG: ; |
ea882baf WD |
999 | } |
1000 | ||
f3c615b8 | 1001 | if (argc < 1) |
4c12eeb8 | 1002 | return CMD_RET_USAGE; |
8bde7f77 | 1003 | |
fd37dac9 SG |
1004 | addr = simple_strtoul(argv[0], NULL, 16); |
1005 | ptr = map_sysmem(addr, size); | |
ea882baf | 1006 | |
37f2fe74 | 1007 | if (size) |
fd37dac9 | 1008 | memset(ptr, '\0', size); |
37f2fe74 WD |
1009 | |
1010 | argc--; | |
1011 | argv++; | |
ea882baf WD |
1012 | |
1013 | if (sep) { /* export as text file */ | |
ea009d47 WD |
1014 | len = hexport_r(&env_htab, sep, |
1015 | H_MATCH_KEY | H_MATCH_IDENT, | |
fd37dac9 | 1016 | &ptr, size, argc, argv); |
ea882baf | 1017 | if (len < 0) { |
6c90f623 QS |
1018 | pr_err("## Error: Cannot export environment: errno = %d\n", |
1019 | errno); | |
ea882baf WD |
1020 | return 1; |
1021 | } | |
8c3aff52 | 1022 | sprintf(buf, "%zX", (size_t)len); |
382bee57 | 1023 | env_set("filesize", buf); |
ea882baf WD |
1024 | |
1025 | return 0; | |
1026 | } | |
1027 | ||
fd37dac9 | 1028 | envp = (env_t *)ptr; |
ea882baf WD |
1029 | |
1030 | if (chk) /* export as checksum protected block */ | |
1031 | res = (char *)envp->data; | |
1032 | else /* export as raw binary data */ | |
fd37dac9 | 1033 | res = ptr; |
ea882baf | 1034 | |
ea009d47 WD |
1035 | len = hexport_r(&env_htab, '\0', |
1036 | H_MATCH_KEY | H_MATCH_IDENT, | |
1037 | &res, ENV_SIZE, argc, argv); | |
ea882baf | 1038 | if (len < 0) { |
6c90f623 QS |
1039 | pr_err("## Error: Cannot export environment: errno = %d\n", |
1040 | errno); | |
ea882baf WD |
1041 | return 1; |
1042 | } | |
1043 | ||
1044 | if (chk) { | |
d71b029d NS |
1045 | envp->crc = crc32(0, envp->data, |
1046 | size ? size - offsetof(env_t, data) : ENV_SIZE); | |
ea882baf | 1047 | #ifdef CONFIG_ENV_ADDR_REDUND |
d3716dd6 | 1048 | envp->flags = ENV_REDUND_ACTIVE; |
ea882baf WD |
1049 | #endif |
1050 | } | |
018f5303 | 1051 | env_set_hex("filesize", len + offsetof(env_t, data)); |
ea882baf WD |
1052 | |
1053 | return 0; | |
1054 | ||
1055 | sep_err: | |
6c90f623 QS |
1056 | printf("## Error: %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", |
1057 | cmd); | |
ea882baf WD |
1058 | return 1; |
1059 | } | |
0c79cda0 | 1060 | #endif |
ea882baf | 1061 | |
0c79cda0 | 1062 | #ifdef CONFIG_CMD_IMPORTENV |
ea882baf | 1063 | /* |
eaf73472 QS |
1064 | * env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] |
1065 | * -d: delete existing environment before importing if no var is | |
1066 | * passed; if vars are passed, if one var is in the current | |
1067 | * environment but not in the environment at addr, delete var from | |
1068 | * current environment; | |
fc0b5948 | 1069 | * otherwise overwrite / append to existing definitions |
ea882baf WD |
1070 | * -t: assume text format; either "size" must be given or the |
1071 | * text data must be '\0' terminated | |
ecd1446f AH |
1072 | * -r: handle CRLF like LF, that means exported variables with |
1073 | * a content which ends with \r won't get imported. Used | |
1074 | * to import text files created with editors which are using CRLF | |
1075 | * for line endings. Only effective in addition to -t. | |
ea882baf WD |
1076 | * -b: assume binary format ('\0' separated, "\0\0" terminated) |
1077 | * -c: assume checksum protected environment format | |
1078 | * addr: memory address to read from | |
1079 | * size: length of input data; if missing, proper '\0' | |
1080 | * termination is mandatory | |
eaf73472 QS |
1081 | * if var is set and size should be missing (i.e. '\0' |
1082 | * termination), set size to '-' | |
1083 | * var... List of the names of the only variables that get imported from | |
1084 | * the environment at address 'addr'. Without arguments, the whole | |
1085 | * environment gets imported. | |
ea882baf | 1086 | */ |
09140113 SG |
1087 | static int do_env_import(struct cmd_tbl *cmdtp, int flag, |
1088 | int argc, char *const argv[]) | |
ea882baf | 1089 | { |
fd37dac9 SG |
1090 | ulong addr; |
1091 | char *cmd, *ptr; | |
ea882baf WD |
1092 | char sep = '\n'; |
1093 | int chk = 0; | |
1094 | int fmt = 0; | |
1095 | int del = 0; | |
ecd1446f | 1096 | int crlf_is_lf = 0; |
eaf73472 | 1097 | int wl = 0; |
ea882baf WD |
1098 | size_t size; |
1099 | ||
1100 | cmd = *argv; | |
1101 | ||
1102 | while (--argc > 0 && **++argv == '-') { | |
1103 | char *arg = *argv; | |
1104 | while (*++arg) { | |
1105 | switch (*arg) { | |
1106 | case 'b': /* raw binary format */ | |
1107 | if (fmt++) | |
1108 | goto sep_err; | |
1109 | sep = '\0'; | |
1110 | break; | |
1111 | case 'c': /* external checksum format */ | |
1112 | if (fmt++) | |
1113 | goto sep_err; | |
1114 | sep = '\0'; | |
1115 | chk = 1; | |
1116 | break; | |
1117 | case 't': /* text format */ | |
1118 | if (fmt++) | |
1119 | goto sep_err; | |
1120 | sep = '\n'; | |
1121 | break; | |
ecd1446f AH |
1122 | case 'r': /* handle CRLF like LF */ |
1123 | crlf_is_lf = 1; | |
1124 | break; | |
ea882baf WD |
1125 | case 'd': |
1126 | del = 1; | |
1127 | break; | |
1128 | default: | |
4c12eeb8 | 1129 | return CMD_RET_USAGE; |
ea882baf WD |
1130 | } |
1131 | } | |
1132 | } | |
1133 | ||
f3c615b8 | 1134 | if (argc < 1) |
4c12eeb8 | 1135 | return CMD_RET_USAGE; |
ea882baf WD |
1136 | |
1137 | if (!fmt) | |
1138 | printf("## Warning: defaulting to text format\n"); | |
1139 | ||
ecd1446f AH |
1140 | if (sep != '\n' && crlf_is_lf ) |
1141 | crlf_is_lf = 0; | |
1142 | ||
fd37dac9 SG |
1143 | addr = simple_strtoul(argv[0], NULL, 16); |
1144 | ptr = map_sysmem(addr, 0); | |
ea882baf | 1145 | |
eaf73472 | 1146 | if (argc >= 2 && strcmp(argv[1], "-")) { |
ea882baf | 1147 | size = simple_strtoul(argv[1], NULL, 16); |
eaf73472 | 1148 | } else if (chk) { |
3775dcd9 TR |
1149 | puts("## Error: external checksum format must pass size\n"); |
1150 | return CMD_RET_FAILURE; | |
ea882baf | 1151 | } else { |
fd37dac9 | 1152 | char *s = ptr; |
ea882baf WD |
1153 | |
1154 | size = 0; | |
1155 | ||
1156 | while (size < MAX_ENV_SIZE) { | |
1157 | if ((*s == sep) && (*(s+1) == '\0')) | |
1158 | break; | |
1159 | ++s; | |
1160 | ++size; | |
1161 | } | |
1162 | if (size == MAX_ENV_SIZE) { | |
1163 | printf("## Warning: Input data exceeds %d bytes" | |
1164 | " - truncated\n", MAX_ENV_SIZE); | |
1165 | } | |
d3f80c77 | 1166 | size += 2; |
79afc88d | 1167 | printf("## Info: input data size = %zu = 0x%zX\n", size, size); |
ea882baf WD |
1168 | } |
1169 | ||
eaf73472 QS |
1170 | if (argc > 2) |
1171 | wl = 1; | |
1172 | ||
ea882baf WD |
1173 | if (chk) { |
1174 | uint32_t crc; | |
fd37dac9 | 1175 | env_t *ep = (env_t *)ptr; |
ea882baf | 1176 | |
142775a5 PA |
1177 | if (size <= offsetof(env_t, data)) { |
1178 | printf("## Error: Invalid size 0x%zX\n", size); | |
1179 | return 1; | |
1180 | } | |
1181 | ||
ea882baf WD |
1182 | size -= offsetof(env_t, data); |
1183 | memcpy(&crc, &ep->crc, sizeof(crc)); | |
1184 | ||
1185 | if (crc32(0, ep->data, size) != crc) { | |
1186 | puts("## Error: bad CRC, import failed\n"); | |
1187 | return 1; | |
1188 | } | |
fd37dac9 | 1189 | ptr = (char *)ep->data; |
ea882baf WD |
1190 | } |
1191 | ||
eaf73472 QS |
1192 | if (!himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR, |
1193 | crlf_is_lf, wl ? argc - 2 : 0, wl ? &argv[2] : NULL)) { | |
6c90f623 QS |
1194 | pr_err("## Error: Environment import failed: errno = %d\n", |
1195 | errno); | |
ea882baf WD |
1196 | return 1; |
1197 | } | |
1198 | gd->flags |= GD_FLG_ENV_READY; | |
1199 | ||
1200 | return 0; | |
1201 | ||
1202 | sep_err: | |
1203 | printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", | |
1204 | cmd); | |
1205 | return 1; | |
1206 | } | |
0c79cda0 | 1207 | #endif |
ea882baf | 1208 | |
8e92120b LR |
1209 | #if defined(CONFIG_CMD_NVEDIT_INFO) |
1210 | /* | |
1211 | * print_env_info - print environment information | |
1212 | */ | |
1213 | static int print_env_info(void) | |
1214 | { | |
1215 | const char *value; | |
1216 | ||
1217 | /* print environment validity value */ | |
1218 | switch (gd->env_valid) { | |
1219 | case ENV_INVALID: | |
1220 | value = "invalid"; | |
1221 | break; | |
1222 | case ENV_VALID: | |
1223 | value = "valid"; | |
1224 | break; | |
1225 | case ENV_REDUND: | |
1226 | value = "redundant"; | |
1227 | break; | |
1228 | default: | |
1229 | value = "unknown"; | |
1230 | break; | |
1231 | } | |
1232 | printf("env_valid = %s\n", value); | |
1233 | ||
1234 | /* print environment ready flag */ | |
1235 | value = gd->flags & GD_FLG_ENV_READY ? "true" : "false"; | |
1236 | printf("env_ready = %s\n", value); | |
1237 | ||
1238 | /* print environment using default flag */ | |
1239 | value = gd->flags & GD_FLG_ENV_DEFAULT ? "true" : "false"; | |
1240 | printf("env_use_default = %s\n", value); | |
1241 | ||
1242 | return CMD_RET_SUCCESS; | |
1243 | } | |
1244 | ||
1245 | #define ENV_INFO_IS_DEFAULT BIT(0) /* default environment bit mask */ | |
1246 | #define ENV_INFO_IS_PERSISTED BIT(1) /* environment persistence bit mask */ | |
1247 | ||
1248 | /* | |
1249 | * env info - display environment information | |
1250 | * env info [-d] - evaluate whether default environment is used | |
1251 | * env info [-p] - evaluate whether environment can be persisted | |
6718ebd0 PD |
1252 | * Add [-q] - quiet mode, use only for command result, for test by example: |
1253 | * test env info -p -d -q | |
8e92120b | 1254 | */ |
09140113 SG |
1255 | static int do_env_info(struct cmd_tbl *cmdtp, int flag, |
1256 | int argc, char *const argv[]) | |
8e92120b LR |
1257 | { |
1258 | int eval_flags = 0; | |
1259 | int eval_results = 0; | |
6718ebd0 | 1260 | bool quiet = false; |
2f96b323 PD |
1261 | #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) |
1262 | enum env_location loc; | |
1263 | #endif | |
8e92120b LR |
1264 | |
1265 | /* display environment information */ | |
1266 | if (argc <= 1) | |
1267 | return print_env_info(); | |
1268 | ||
1269 | /* process options */ | |
1270 | while (--argc > 0 && **++argv == '-') { | |
1271 | char *arg = *argv; | |
1272 | ||
1273 | while (*++arg) { | |
1274 | switch (*arg) { | |
1275 | case 'd': | |
1276 | eval_flags |= ENV_INFO_IS_DEFAULT; | |
1277 | break; | |
1278 | case 'p': | |
1279 | eval_flags |= ENV_INFO_IS_PERSISTED; | |
1280 | break; | |
6718ebd0 PD |
1281 | case 'q': |
1282 | quiet = true; | |
1283 | break; | |
8e92120b LR |
1284 | default: |
1285 | return CMD_RET_USAGE; | |
1286 | } | |
1287 | } | |
1288 | } | |
1289 | ||
1290 | /* evaluate whether default environment is used */ | |
1291 | if (eval_flags & ENV_INFO_IS_DEFAULT) { | |
1292 | if (gd->flags & GD_FLG_ENV_DEFAULT) { | |
6718ebd0 PD |
1293 | if (!quiet) |
1294 | printf("Default environment is used\n"); | |
8e92120b LR |
1295 | eval_results |= ENV_INFO_IS_DEFAULT; |
1296 | } else { | |
6718ebd0 PD |
1297 | if (!quiet) |
1298 | printf("Environment was loaded from persistent storage\n"); | |
8e92120b LR |
1299 | } |
1300 | } | |
1301 | ||
1302 | /* evaluate whether environment can be persisted */ | |
1303 | if (eval_flags & ENV_INFO_IS_PERSISTED) { | |
8b5206d9 | 1304 | #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) |
2f96b323 PD |
1305 | loc = env_get_location(ENVOP_SAVE, gd->env_load_prio); |
1306 | if (ENVL_NOWHERE != loc && ENVL_UNKNOWN != loc) { | |
1307 | if (!quiet) | |
1308 | printf("Environment can be persisted\n"); | |
1309 | eval_results |= ENV_INFO_IS_PERSISTED; | |
1310 | } else { | |
1311 | if (!quiet) | |
1312 | printf("Environment cannot be persisted\n"); | |
1313 | } | |
8e92120b | 1314 | #else |
6718ebd0 PD |
1315 | if (!quiet) |
1316 | printf("Environment cannot be persisted\n"); | |
8e92120b LR |
1317 | #endif |
1318 | } | |
1319 | ||
1320 | /* The result of evaluations is combined with AND */ | |
1321 | if (eval_flags != eval_results) | |
1322 | return CMD_RET_FAILURE; | |
1323 | ||
1324 | return CMD_RET_SUCCESS; | |
1325 | } | |
1326 | #endif | |
1327 | ||
88733e2c | 1328 | #if defined(CONFIG_CMD_ENV_EXISTS) |
09140113 SG |
1329 | static int do_env_exists(struct cmd_tbl *cmdtp, int flag, int argc, |
1330 | char *const argv[]) | |
88733e2c | 1331 | { |
dd2408ca | 1332 | struct env_entry e, *ep; |
88733e2c AR |
1333 | |
1334 | if (argc < 2) | |
1335 | return CMD_RET_USAGE; | |
1336 | ||
1337 | e.key = argv[1]; | |
1338 | e.data = NULL; | |
3f0d6807 | 1339 | hsearch_r(e, ENV_FIND, &ep, &env_htab, 0); |
88733e2c AR |
1340 | |
1341 | return (ep == NULL) ? 1 : 0; | |
1342 | } | |
1343 | #endif | |
1344 | ||
ea882baf WD |
1345 | /* |
1346 | * New command line interface: "env" command with subcommands | |
1347 | */ | |
09140113 | 1348 | static struct cmd_tbl cmd_env_sub[] = { |
ea882baf WD |
1349 | #if defined(CONFIG_CMD_ASKENV) |
1350 | U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""), | |
1351 | #endif | |
1352 | U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""), | |
9d8d661d | 1353 | U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""), |
ea882baf WD |
1354 | #if defined(CONFIG_CMD_EDITENV) |
1355 | U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""), | |
1356 | #endif | |
5e2b3e0c JH |
1357 | #if defined(CONFIG_CMD_ENV_CALLBACK) |
1358 | U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""), | |
1359 | #endif | |
fffad71b JH |
1360 | #if defined(CONFIG_CMD_ENV_FLAGS) |
1361 | U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""), | |
1362 | #endif | |
0c79cda0 | 1363 | #if defined(CONFIG_CMD_EXPORTENV) |
ea882baf | 1364 | U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""), |
0c79cda0 | 1365 | #endif |
a000b795 KP |
1366 | #if defined(CONFIG_CMD_GREPENV) |
1367 | U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""), | |
1368 | #endif | |
0c79cda0 | 1369 | #if defined(CONFIG_CMD_IMPORTENV) |
ea882baf | 1370 | U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""), |
8e92120b LR |
1371 | #endif |
1372 | #if defined(CONFIG_CMD_NVEDIT_INFO) | |
6718ebd0 | 1373 | U_BOOT_CMD_MKENT(info, 3, 0, do_env_info, "", ""), |
0115dd3a PD |
1374 | #endif |
1375 | #if defined(CONFIG_CMD_NVEDIT_LOAD) | |
1376 | U_BOOT_CMD_MKENT(load, 1, 0, do_env_load, "", ""), | |
0c79cda0 | 1377 | #endif |
ea882baf WD |
1378 | U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""), |
1379 | #if defined(CONFIG_CMD_RUN) | |
1380 | U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""), | |
1381 | #endif | |
2643c85d | 1382 | #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) |
ea882baf | 1383 | U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""), |
cd121bdb FW |
1384 | #if defined(CONFIG_CMD_ERASEENV) |
1385 | U_BOOT_CMD_MKENT(erase, 1, 0, do_env_erase, "", ""), | |
1386 | #endif | |
a97d22eb PD |
1387 | #endif |
1388 | #if defined(CONFIG_CMD_NVEDIT_SELECT) | |
1389 | U_BOOT_CMD_MKENT(select, 2, 0, do_env_select, "", ""), | |
ea882baf WD |
1390 | #endif |
1391 | U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""), | |
88733e2c AR |
1392 | #if defined(CONFIG_CMD_ENV_EXISTS) |
1393 | U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""), | |
1394 | #endif | |
ea882baf WD |
1395 | }; |
1396 | ||
2e5167cc | 1397 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
60f7da1f HS |
1398 | void env_reloc(void) |
1399 | { | |
1400 | fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub)); | |
1401 | } | |
1402 | #endif | |
1403 | ||
09140113 | 1404 | static int do_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
ea882baf | 1405 | { |
09140113 | 1406 | struct cmd_tbl *cp; |
ea882baf | 1407 | |
5904da02 | 1408 | if (argc < 2) |
4c12eeb8 | 1409 | return CMD_RET_USAGE; |
5904da02 | 1410 | |
ea882baf WD |
1411 | /* drop initial "env" arg */ |
1412 | argc--; | |
1413 | argv++; | |
1414 | ||
1415 | cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub)); | |
1416 | ||
1417 | if (cp) | |
1418 | return cp->cmd(cmdtp, flag, argc, argv); | |
1419 | ||
4c12eeb8 | 1420 | return CMD_RET_USAGE; |
ea882baf WD |
1421 | } |
1422 | ||
088f1b19 KP |
1423 | #ifdef CONFIG_SYS_LONGHELP |
1424 | static char env_help_text[] = | |
ea882baf WD |
1425 | #if defined(CONFIG_CMD_ASKENV) |
1426 | "ask name [message] [size] - ask for environment variable\nenv " | |
5e2b3e0c JH |
1427 | #endif |
1428 | #if defined(CONFIG_CMD_ENV_CALLBACK) | |
1429 | "callbacks - print callbacks and their associated variables\nenv " | |
ea882baf | 1430 | #endif |
b64b7c3d GF |
1431 | "default [-f] -a - [forcibly] reset default environment\n" |
1432 | "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n" | |
9d8d661d | 1433 | "env delete [-f] var [...] - [forcibly] delete variable(s)\n" |
ea882baf WD |
1434 | #if defined(CONFIG_CMD_EDITENV) |
1435 | "env edit name - edit environment variable\n" | |
1436 | #endif | |
88733e2c AR |
1437 | #if defined(CONFIG_CMD_ENV_EXISTS) |
1438 | "env exists name - tests for existence of variable\n" | |
1439 | #endif | |
4796bc4b | 1440 | #if defined(CONFIG_CMD_EXPORTENV) |
37f2fe74 | 1441 | "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n" |
4796bc4b | 1442 | #endif |
fffad71b JH |
1443 | #if defined(CONFIG_CMD_ENV_FLAGS) |
1444 | "env flags - print variables that have non-default flags\n" | |
1445 | #endif | |
a000b795 | 1446 | #if defined(CONFIG_CMD_GREPENV) |
be29df6a WD |
1447 | #ifdef CONFIG_REGEX |
1448 | "env grep [-e] [-n | -v | -b] string [...] - search environment\n" | |
1449 | #else | |
d87244d5 | 1450 | "env grep [-n | -v | -b] string [...] - search environment\n" |
a000b795 | 1451 | #endif |
be29df6a | 1452 | #endif |
4796bc4b | 1453 | #if defined(CONFIG_CMD_IMPORTENV) |
eaf73472 | 1454 | "env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment\n" |
8e92120b LR |
1455 | #endif |
1456 | #if defined(CONFIG_CMD_NVEDIT_INFO) | |
1457 | "env info - display environment information\n" | |
6718ebd0 PD |
1458 | "env info [-d] [-p] [-q] - evaluate environment information\n" |
1459 | " \"-d\": default environment is used\n" | |
1460 | " \"-p\": environment can be persisted\n" | |
1461 | " \"-q\": quiet output\n" | |
4796bc4b | 1462 | #endif |
be11235a | 1463 | "env print [-a | name ...] - print environment\n" |
49d81fdf | 1464 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
c70f4481 | 1465 | "env print -e [-guid guid] [-n] [name ...] - print UEFI environment\n" |
49d81fdf | 1466 | #endif |
ea882baf WD |
1467 | #if defined(CONFIG_CMD_RUN) |
1468 | "env run var [...] - run commands in an environment variable\n" | |
1469 | #endif | |
2643c85d | 1470 | #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) |
ea882baf | 1471 | "env save - save environment\n" |
cd121bdb FW |
1472 | #if defined(CONFIG_CMD_ERASEENV) |
1473 | "env erase - erase environment\n" | |
1474 | #endif | |
49d81fdf | 1475 | #endif |
0115dd3a PD |
1476 | #if defined(CONFIG_CMD_NVEDIT_LOAD) |
1477 | "env load - load environment\n" | |
a97d22eb PD |
1478 | #endif |
1479 | #if defined(CONFIG_CMD_NVEDIT_SELECT) | |
1480 | "env select [target] - select environment target\n" | |
0115dd3a | 1481 | #endif |
49d81fdf | 1482 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
8f0ac536 | 1483 | "env set -e [-nv][-bs][-rt][-at][-a][-i addr:size][-v] name [arg ...]\n" |
051aa89f | 1484 | " - set UEFI variable; unset if '-i' or 'arg' not specified\n" |
d798a9b5 | 1485 | #endif |
088f1b19 KP |
1486 | "env set [-f] name [arg ...]\n"; |
1487 | #endif | |
1488 | ||
1489 | U_BOOT_CMD( | |
1490 | env, CONFIG_SYS_MAXARGS, 1, do_env, | |
1491 | "environment handling commands", env_help_text | |
ea882baf WD |
1492 | ); |
1493 | ||
1494 | /* | |
1495 | * Old command line interface, kept for compatibility | |
1496 | */ | |
8bde7f77 | 1497 | |
246c6922 | 1498 | #if defined(CONFIG_CMD_EDITENV) |
722b061b | 1499 | U_BOOT_CMD_COMPLETE( |
ea882baf | 1500 | editenv, 2, 0, do_env_edit, |
246c6922 PT |
1501 | "edit environment variable", |
1502 | "name\n" | |
722b061b MF |
1503 | " - edit environment variable 'name'", |
1504 | var_complete | |
246c6922 PT |
1505 | ); |
1506 | #endif | |
1507 | ||
722b061b | 1508 | U_BOOT_CMD_COMPLETE( |
ea882baf | 1509 | printenv, CONFIG_SYS_MAXARGS, 1, do_env_print, |
2fb2604d | 1510 | "print environment variables", |
be11235a | 1511 | "[-a]\n - print [all] values of all environment variables\n" |
49d81fdf | 1512 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
c70f4481 | 1513 | "printenv -e [-guid guid][-n] [name ...]\n" |
49d81fdf | 1514 | " - print UEFI variable 'name' or all the variables\n" |
c70f4481 | 1515 | " \"-guid\": GUID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n" |
051aa89f | 1516 | " \"-n\": suppress dumping variable's value\n" |
49d81fdf | 1517 | #endif |
8bde7f77 | 1518 | "printenv name ...\n" |
722b061b MF |
1519 | " - print value of environment variable 'name'", |
1520 | var_complete | |
8bde7f77 WD |
1521 | ); |
1522 | ||
a000b795 KP |
1523 | #ifdef CONFIG_CMD_GREPENV |
1524 | U_BOOT_CMD_COMPLETE( | |
1525 | grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep, | |
1526 | "search environment variables", | |
be29df6a WD |
1527 | #ifdef CONFIG_REGEX |
1528 | "[-e] [-n | -v | -b] string ...\n" | |
1529 | #else | |
d87244d5 | 1530 | "[-n | -v | -b] string ...\n" |
be29df6a | 1531 | #endif |
d87244d5 | 1532 | " - list environment name=value pairs matching 'string'\n" |
be29df6a WD |
1533 | #ifdef CONFIG_REGEX |
1534 | " \"-e\": enable regular expressions;\n" | |
1535 | #endif | |
d87244d5 WD |
1536 | " \"-n\": search variable names; \"-v\": search values;\n" |
1537 | " \"-b\": search both names and values (default)", | |
a000b795 KP |
1538 | var_complete |
1539 | ); | |
1540 | #endif | |
1541 | ||
722b061b | 1542 | U_BOOT_CMD_COMPLETE( |
ea882baf | 1543 | setenv, CONFIG_SYS_MAXARGS, 0, do_env_set, |
2fb2604d | 1544 | "set environment variables", |
49d81fdf | 1545 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
e50e2878 | 1546 | "-e [-guid guid][-nv][-bs][-rt][-at][-a][-v]\n" |
8f0ac536 | 1547 | " [-i addr:size name], or [name [value ...]]\n" |
49d81fdf | 1548 | " - set UEFI variable 'name' to 'value' ...'\n" |
c70f4481 | 1549 | " \"-guid\": GUID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n" |
051aa89f AT |
1550 | " \"-nv\": set non-volatile attribute\n" |
1551 | " \"-bs\": set boot-service attribute\n" | |
1552 | " \"-rt\": set runtime attribute\n" | |
e50e2878 | 1553 | " \"-at\": set time-based authentication attribute\n" |
051aa89f AT |
1554 | " \"-a\": append-write\n" |
1555 | " \"-i addr,size\": use <addr,size> as variable's value\n" | |
1556 | " \"-v\": verbose message\n" | |
49d81fdf AT |
1557 | " - delete UEFI variable 'name' if 'value' not specified\n" |
1558 | #endif | |
1559 | "setenv [-f] name value ...\n" | |
24ab5a19 JH |
1560 | " - [forcibly] set environment variable 'name' to 'value ...'\n" |
1561 | "setenv [-f] name\n" | |
1562 | " - [forcibly] delete environment variable 'name'", | |
722b061b | 1563 | var_complete |
8bde7f77 WD |
1564 | ); |
1565 | ||
c76fe474 | 1566 | #if defined(CONFIG_CMD_ASKENV) |
8bde7f77 | 1567 | |
0d498393 | 1568 | U_BOOT_CMD( |
ea882baf | 1569 | askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask, |
2fb2604d | 1570 | "get environment variables from stdin", |
8bde7f77 | 1571 | "name [message] [size]\n" |
7d85591d | 1572 | " - get environment variable 'name' from stdin (max 'size' chars)" |
8bde7f77 | 1573 | ); |
90253178 | 1574 | #endif |
8bde7f77 | 1575 | |
c76fe474 | 1576 | #if defined(CONFIG_CMD_RUN) |
722b061b | 1577 | U_BOOT_CMD_COMPLETE( |
6d0f6bcf | 1578 | run, CONFIG_SYS_MAXARGS, 1, do_run, |
2fb2604d | 1579 | "run commands in an environment variable", |
8bde7f77 | 1580 | "var [...]\n" |
722b061b MF |
1581 | " - run the commands in the environment variable(s) 'var'", |
1582 | var_complete | |
8bde7f77 | 1583 | ); |
90253178 | 1584 | #endif |
7ac2fe2d | 1585 | #endif /* CONFIG_SPL_BUILD */ |