2 * (C) Copyright 2000-2010
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6 * Andreas Heppel <aheppel@sysgo.de>
8 * Copyright 2011 Freescale Semiconductor, Inc.
10 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * Support for persistent environment data
32 * The "environment" is stored on external storage as a list of '\0'
33 * terminated "name=value" strings. The end of the list is marked by
34 * a double '\0'. The environment is preceeded by a 32 bit CRC over
35 * the data part and, in case of redundant environment, a byte of
38 * This linearized representation will also be used before
39 * relocation, i. e. as long as we don't have a full C runtime
40 * environment. After that, we use a hash table.
45 #include <environment.h>
50 #include <linux/stddef.h>
51 #include <asm/byteorder.h>
53 DECLARE_GLOBAL_DATA_PTR;
55 #if !defined(CONFIG_ENV_IS_IN_EEPROM) && \
56 !defined(CONFIG_ENV_IS_IN_FLASH) && \
57 !defined(CONFIG_ENV_IS_IN_DATAFLASH) && \
58 !defined(CONFIG_ENV_IS_IN_MMC) && \
59 !defined(CONFIG_ENV_IS_IN_FAT) && \
60 !defined(CONFIG_ENV_IS_IN_NAND) && \
61 !defined(CONFIG_ENV_IS_IN_NVRAM) && \
62 !defined(CONFIG_ENV_IS_IN_ONENAND) && \
63 !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \
64 !defined(CONFIG_ENV_IS_IN_REMOTE) && \
65 !defined(CONFIG_ENV_IS_IN_UBI) && \
66 !defined(CONFIG_ENV_IS_NOWHERE)
67 # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
68 SPI_FLASH|NVRAM|MMC|FAT|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
72 * Maximum expected input data size for import command
74 #define MAX_ENV_SIZE (1 << 20) /* 1 MiB */
77 * This variable is incremented on each do_env_set(), so it can
78 * be used via get_env_id() as an indication, if the environment
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()
83 static int env_id = 1;
90 #ifndef CONFIG_SPL_BUILD
92 * Command interface: print one or all environment variables
94 * Returns 0 in case of error, or length of printed string
96 static int env_print(char *name, int flag)
101 if (name) { /* print a single name */
106 hsearch_r(e, FIND, &ep, &env_htab, flag);
109 len = printf("%s=%s\n", ep->key, ep->data);
113 /* print whole list */
114 len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
122 /* should never happen */
123 printf("## Error: cannot export environment\n");
127 static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
132 int env_flag = H_HIDE_DOT;
134 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
137 env_flag &= ~H_HIDE_DOT;
141 /* print all env vars */
142 rcode = env_print(NULL, env_flag);
145 printf("\nEnvironment size: %d/%ld bytes\n",
146 rcode, (ulong)ENV_SIZE);
150 /* print selected env vars */
151 env_flag &= ~H_HIDE_DOT;
152 for (i = 1; i < argc; ++i) {
153 int rc = env_print(argv[i], env_flag);
155 printf("## Error: \"%s\" not defined\n", argv[i]);
163 #ifdef CONFIG_CMD_GREPENV
164 static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
165 int argc, char * const argv[])
168 unsigned char matched[env_htab.size / 8];
169 int rcode = 1, arg = 1, idx;
172 return CMD_RET_USAGE;
174 memset(matched, 0, env_htab.size / 8);
176 while (arg <= argc) {
178 while ((idx = hstrstr_r(argv[arg], idx, &match, &env_htab))) {
179 if (!(matched[idx / 8] & (1 << (idx & 7)))) {
185 matched[idx / 8] |= 1 << (idx & 7);
194 #endif /* CONFIG_SPL_BUILD */
197 * Set a new environment variable,
198 * or replace or delete an existing one.
200 static int _do_env_set(int flag, int argc, char * const argv[])
203 char *name, *value, *s;
205 int env_flag = H_INTERACTIVE;
207 debug("Initial value for argc=%d\n", argc);
208 while (argc > 1 && **(argv + 1) == '-') {
214 case 'f': /* force */
218 return CMD_RET_USAGE;
222 debug("Final value for argc=%d\n", argc);
226 if (strchr(name, '=')) {
227 printf("## Error: illegal character '='"
228 "in variable name \"%s\"\n", name);
235 if (argc < 3 || argv[2] == NULL) {
236 int rc = hdelete_r(name, &env_htab, env_flag);
241 * Insert / replace new value
243 for (i = 2, len = 0; i < argc; ++i)
244 len += strlen(argv[i]) + 1;
248 printf("## Can't malloc %d bytes\n", len);
251 for (i = 2, s = value; i < argc; ++i) {
254 while ((*s++ = *v++) != '\0')
263 hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
266 printf("## Error inserting \"%s\" variable, errno=%d\n",
274 int setenv(const char *varname, const char *varvalue)
276 const char * const argv[4] = { "setenv", varname, varvalue, NULL };
278 /* before import into hashtable */
279 if (!(gd->flags & GD_FLG_ENV_READY))
282 if (varvalue == NULL || varvalue[0] == '\0')
283 return _do_env_set(0, 2, (char * const *)argv);
285 return _do_env_set(0, 3, (char * const *)argv);
289 * Set an environment variable to an integer value
291 * @param varname Environmet variable to set
292 * @param value Value to set it to
293 * @return 0 if ok, 1 on error
295 int setenv_ulong(const char *varname, ulong value)
297 /* TODO: this should be unsigned */
298 char *str = simple_itoa(value);
300 return setenv(varname, str);
304 * Set an environment variable to an value in hex
306 * @param varname Environmet variable to set
307 * @param value Value to set it to
308 * @return 0 if ok, 1 on error
310 int setenv_hex(const char *varname, ulong value)
314 sprintf(str, "%lx", value);
315 return setenv(varname, str);
318 #ifndef CONFIG_SPL_BUILD
319 static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
322 return CMD_RET_USAGE;
324 return _do_env_set(flag, argc, argv);
328 * Prompt for environment variable
330 #if defined(CONFIG_CMD_ASKENV)
331 int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
333 char message[CONFIG_SYS_CBSIZE];
334 int i, len, pos, size;
338 local_args[0] = argv[0];
339 local_args[1] = argv[1];
340 local_args[2] = NULL;
341 local_args[3] = NULL;
346 * env_ask envname [message1 ...] [size]
349 return CMD_RET_USAGE;
352 * We test the last argument if it can be converted
353 * into a decimal number. If yes, we assume it's
354 * the size. Otherwise we echo it as part of the
357 i = simple_strtoul(argv[argc - 1], &endptr, 10);
358 if (*endptr != '\0') { /* no size */
359 size = CONFIG_SYS_CBSIZE - 1;
360 } else { /* size given */
366 sprintf(message, "Please enter '%s': ", argv[1]);
368 /* env_ask envname message1 ... messagen [size] */
369 for (i = 2, pos = 0; i < argc; i++) {
371 message[pos++] = ' ';
373 strcpy(message + pos, argv[i]);
374 pos += strlen(argv[i]);
376 message[pos++] = ' ';
380 if (size >= CONFIG_SYS_CBSIZE)
381 size = CONFIG_SYS_CBSIZE - 1;
386 /* prompt for input */
387 len = readline(message);
390 console_buffer[size] = '\0';
393 if (console_buffer[0] != '\0') {
394 local_args[2] = console_buffer;
398 /* Continue calling setenv code */
399 return _do_env_set(flag, len, local_args);
403 #if defined(CONFIG_CMD_ENV_CALLBACK)
404 static int print_static_binding(const char *var_name, const char *callback_name)
406 printf("\t%-20s %-20s\n", var_name, callback_name);
411 static int print_active_callback(ENTRY *entry)
413 struct env_clbk_tbl *clbkp;
417 if (entry->callback == NULL)
420 /* look up the callback in the linker-list */
421 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
422 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
425 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
426 if (entry->callback == clbkp->callback + gd->reloc_off)
428 if (entry->callback == clbkp->callback)
433 if (i == num_callbacks)
434 /* this should probably never happen, but just in case... */
435 printf("\t%-20s %p\n", entry->key, entry->callback);
437 printf("\t%-20s %-20s\n", entry->key, clbkp->name);
443 * Print the callbacks available and what they are bound to
445 int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
447 struct env_clbk_tbl *clbkp;
451 /* Print the available callbacks */
452 puts("Available callbacks:\n");
453 puts("\tCallback Name\n");
454 puts("\t-------------\n");
455 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
456 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
459 printf("\t%s\n", clbkp->name);
462 /* Print the static bindings that may exist */
463 puts("Static callback bindings:\n");
464 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
465 printf("\t%-20s %-20s\n", "-------------", "-------------");
466 env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
469 /* walk through each variable and print the callback if it has one */
470 puts("Active callback bindings:\n");
471 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
472 printf("\t%-20s %-20s\n", "-------------", "-------------");
473 hwalk_r(&env_htab, print_active_callback);
478 #if defined(CONFIG_CMD_ENV_FLAGS)
479 static int print_static_flags(const char *var_name, const char *flags)
481 enum env_flags_vartype type = env_flags_parse_vartype(flags);
482 enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
484 printf("\t%-20s %-20s %-20s\n", var_name,
485 env_flags_get_vartype_name(type),
486 env_flags_get_varaccess_name(access));
491 static int print_active_flags(ENTRY *entry)
493 enum env_flags_vartype type;
494 enum env_flags_varaccess access;
496 if (entry->flags == 0)
499 type = (enum env_flags_vartype)
500 (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
501 access = env_flags_parse_varaccess_from_binflags(entry->flags);
502 printf("\t%-20s %-20s %-20s\n", entry->key,
503 env_flags_get_vartype_name(type),
504 env_flags_get_varaccess_name(access));
510 * Print the flags available and what variables have flags
512 int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
514 /* Print the available variable types */
515 printf("Available variable type flags (position %d):\n",
516 ENV_FLAGS_VARTYPE_LOC);
517 puts("\tFlag\tVariable Type Name\n");
518 puts("\t----\t------------------\n");
519 env_flags_print_vartypes();
522 /* Print the available variable access types */
523 printf("Available variable access flags (position %d):\n",
524 ENV_FLAGS_VARACCESS_LOC);
525 puts("\tFlag\tVariable Access Name\n");
526 puts("\t----\t--------------------\n");
527 env_flags_print_varaccess();
530 /* Print the static flags that may exist */
531 puts("Static flags:\n");
532 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
534 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
536 env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
539 /* walk through each variable and print the flags if non-default */
540 puts("Active flags:\n");
541 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
543 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
545 hwalk_r(&env_htab, print_active_flags);
551 * Interactively edit an environment variable
553 #if defined(CONFIG_CMD_EDITENV)
554 static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
557 char buffer[CONFIG_SYS_CBSIZE];
561 return CMD_RET_USAGE;
563 /* Set read buffer to initial value or empty sting */
564 init_val = getenv(argv[1]);
566 sprintf(buffer, "%s", init_val);
570 if (readline_into_buffer("edit: ", buffer, 0) < 0)
573 return setenv(argv[1], buffer);
575 #endif /* CONFIG_CMD_EDITENV */
576 #endif /* CONFIG_SPL_BUILD */
579 * Look up variable from environment,
580 * return address of storage for that variable,
581 * or NULL if not found
583 char *getenv(const char *name)
585 if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
592 hsearch_r(e, FIND, &ep, &env_htab, 0);
594 return ep ? ep->data : NULL;
597 /* restricted capabilities before import */
598 if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
599 return (char *)(gd->env_buf);
605 * Look up variable from environment for restricted C runtime env.
607 int getenv_f(const char *name, char *buf, unsigned len)
611 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
614 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
615 if (nxt >= CONFIG_ENV_SIZE)
619 val = envmatch((uchar *)name, i);
623 /* found; copy out */
624 for (n = 0; n < len; ++n, ++buf) {
625 *buf = env_get_char(val++);
633 printf("env_buf [%d bytes] too small for value of \"%s\"\n",
643 * Decode the integer value of an environment variable and return it.
645 * @param name Name of environemnt variable
646 * @param base Number base to use (normally 10, or 16 for hex)
647 * @param default_val Default value to return if the variable is not
649 * @return the decoded value, or default_val if not found
651 ulong getenv_ulong(const char *name, int base, ulong default_val)
654 * We can use getenv() here, even before relocation, since the
655 * environment variable value is an integer and thus short.
657 const char *str = getenv(name);
659 return str ? simple_strtoul(str, NULL, base) : default_val;
662 #ifndef CONFIG_SPL_BUILD
663 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
664 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
667 printf("Saving Environment to %s...\n", env_name_spec);
669 return saveenv() ? 1 : 0;
673 saveenv, 1, 0, do_env_save,
674 "save environment variables to persistent storage",
678 #endif /* CONFIG_SPL_BUILD */
682 * Match a name / name=value pair
684 * s1 is either a simple 'name', or a 'name=value' pair.
685 * i2 is the environment index for a 'name2=value2' pair.
686 * If the names match, return the index for the value2, else -1.
688 int envmatch(uchar *s1, int i2)
693 while (*s1 == env_get_char(i2++))
697 if (*s1 == '\0' && env_get_char(i2-1) == '=')
703 #ifndef CONFIG_SPL_BUILD
704 static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
705 int argc, char * const argv[])
707 int all = 0, flag = 0;
709 debug("Initial value for argc=%d\n", argc);
710 while (--argc > 0 && **++argv == '-') {
715 case 'a': /* default all */
718 case 'f': /* force */
722 return cmd_usage(cmdtp);
726 debug("Final value for argc=%d\n", argc);
727 if (all && (argc == 0)) {
728 /* Reset the whole environment */
729 set_default_env("## Resetting to default environment\n");
732 if (!all && (argc > 0)) {
733 /* Reset individual variables */
734 set_default_vars(argc, argv);
738 return cmd_usage(cmdtp);
741 static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
742 int argc, char * const argv[])
744 int env_flag = H_INTERACTIVE;
747 debug("Initial value for argc=%d\n", argc);
748 while (argc > 1 && **(argv + 1) == '-') {
754 case 'f': /* force */
758 return CMD_RET_USAGE;
762 debug("Final value for argc=%d\n", argc);
767 char *name = *++argv;
769 if (!hdelete_r(name, &env_htab, env_flag))
776 #ifdef CONFIG_CMD_EXPORTENV
778 * env export [-t | -b | -c] [-s size] addr [var ...]
779 * -t: export as text format; if size is given, data will be
780 * padded with '\0' bytes; if not, one terminating '\0'
781 * will be added (which is included in the "filesize"
782 * setting so you can for exmple copy this to flash and
783 * keep the termination).
784 * -b: export as binary format (name=value pairs separated by
785 * '\0', list end marked by double "\0\0")
786 * -c: export as checksum protected environment format as
787 * used for example by "saveenv" command
789 * size of output buffer
790 * addr: memory address where environment gets stored
791 * var... List of variable names that get included into the
792 * export. Without arguments, the whole environment gets
795 * With "-c" and size is NOT given, then the export command will
796 * format the data as currently used for the persistent storage,
797 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
798 * prepend a valid CRC32 checksum and, in case of resundant
799 * environment, a "current" redundancy flag. If size is given, this
800 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
801 * checksum and redundancy flag will be inserted.
803 * With "-b" and "-t", always only the real data (including a
804 * terminating '\0' byte) will be written; here the optional size
805 * argument will be used to make sure not to overflow the user
806 * provided buffer; the command will abort if the size is not
807 * sufficient. Any remainign space will be '\0' padded.
809 * On successful return, the variable "filesize" will be set.
810 * Note that filesize includes the trailing/terminating '\0' byte(s).
812 * Usage szenario: create a text snapshot/backup of the current settings:
814 * => env export -t 100000
815 * => era ${backup_addr} +${filesize}
816 * => cp.b 100000 ${backup_addr} ${filesize}
818 * Re-import this snapshot, deleting all other settings:
820 * => env import -d -t ${backup_addr}
822 static int do_env_export(cmd_tbl_t *cmdtp, int flag,
823 int argc, char * const argv[])
826 char *addr, *cmd, *res;
836 while (--argc > 0 && **++argv == '-') {
840 case 'b': /* raw binary format */
845 case 'c': /* external checksum format */
851 case 's': /* size given */
853 return cmd_usage(cmdtp);
854 size = simple_strtoul(*++argv, NULL, 16);
856 case 't': /* text format */
862 return CMD_RET_USAGE;
869 return CMD_RET_USAGE;
871 addr = (char *)simple_strtoul(argv[0], NULL, 16);
874 memset(addr, '\0', size);
879 if (sep) { /* export as text file */
880 len = hexport_r(&env_htab, sep, 0, &addr, size, argc, argv);
882 error("Cannot export environment: errno = %d\n", errno);
885 sprintf(buf, "%zX", (size_t)len);
886 setenv("filesize", buf);
891 envp = (env_t *)addr;
893 if (chk) /* export as checksum protected block */
894 res = (char *)envp->data;
895 else /* export as raw binary data */
898 len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, argc, argv);
900 error("Cannot export environment: errno = %d\n", errno);
905 envp->crc = crc32(0, envp->data, ENV_SIZE);
906 #ifdef CONFIG_ENV_ADDR_REDUND
907 envp->flags = ACTIVE_FLAG;
910 setenv_hex("filesize", len + offsetof(env_t, data));
915 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
920 #ifdef CONFIG_CMD_IMPORTENV
922 * env import [-d] [-t | -b | -c] addr [size]
923 * -d: delete existing environment before importing;
924 * otherwise overwrite / append to existion definitions
925 * -t: assume text format; either "size" must be given or the
926 * text data must be '\0' terminated
927 * -b: assume binary format ('\0' separated, "\0\0" terminated)
928 * -c: assume checksum protected environment format
929 * addr: memory address to read from
930 * size: length of input data; if missing, proper '\0'
931 * termination is mandatory
933 static int do_env_import(cmd_tbl_t *cmdtp, int flag,
934 int argc, char * const argv[])
945 while (--argc > 0 && **++argv == '-') {
949 case 'b': /* raw binary format */
954 case 'c': /* external checksum format */
960 case 't': /* text format */
969 return CMD_RET_USAGE;
975 return CMD_RET_USAGE;
978 printf("## Warning: defaulting to text format\n");
980 addr = (char *)simple_strtoul(argv[0], NULL, 16);
983 size = simple_strtoul(argv[1], NULL, 16);
989 while (size < MAX_ENV_SIZE) {
990 if ((*s == sep) && (*(s+1) == '\0'))
995 if (size == MAX_ENV_SIZE) {
996 printf("## Warning: Input data exceeds %d bytes"
997 " - truncated\n", MAX_ENV_SIZE);
1000 printf("## Info: input data size = %zu = 0x%zX\n", size, size);
1005 env_t *ep = (env_t *)addr;
1007 size -= offsetof(env_t, data);
1008 memcpy(&crc, &ep->crc, sizeof(crc));
1010 if (crc32(0, ep->data, size) != crc) {
1011 puts("## Error: bad CRC, import failed\n");
1014 addr = (char *)ep->data;
1017 if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
1019 error("Environment import failed: errno = %d\n", errno);
1022 gd->flags |= GD_FLG_ENV_READY;
1027 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
1034 * New command line interface: "env" command with subcommands
1036 static cmd_tbl_t cmd_env_sub[] = {
1037 #if defined(CONFIG_CMD_ASKENV)
1038 U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
1040 U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
1041 U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
1042 #if defined(CONFIG_CMD_EDITENV)
1043 U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
1045 #if defined(CONFIG_CMD_ENV_CALLBACK)
1046 U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
1048 #if defined(CONFIG_CMD_ENV_FLAGS)
1049 U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
1051 #if defined(CONFIG_CMD_EXPORTENV)
1052 U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
1054 #if defined(CONFIG_CMD_GREPENV)
1055 U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
1057 #if defined(CONFIG_CMD_IMPORTENV)
1058 U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
1060 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
1061 #if defined(CONFIG_CMD_RUN)
1062 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
1064 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1065 U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
1067 U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
1070 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
1071 void env_reloc(void)
1073 fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1077 static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1082 return CMD_RET_USAGE;
1084 /* drop initial "env" arg */
1088 cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1091 return cp->cmd(cmdtp, flag, argc, argv);
1093 return CMD_RET_USAGE;
1096 #ifdef CONFIG_SYS_LONGHELP
1097 static char env_help_text[] =
1098 #if defined(CONFIG_CMD_ASKENV)
1099 "ask name [message] [size] - ask for environment variable\nenv "
1101 #if defined(CONFIG_CMD_ENV_CALLBACK)
1102 "callbacks - print callbacks and their associated variables\nenv "
1104 "default [-f] -a - [forcibly] reset default environment\n"
1105 "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
1106 "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
1107 #if defined(CONFIG_CMD_EDITENV)
1108 "env edit name - edit environment variable\n"
1110 #if defined(CONFIG_CMD_EXPORTENV)
1111 "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
1113 #if defined(CONFIG_CMD_ENV_FLAGS)
1114 "env flags - print variables that have non-default flags\n"
1116 #if defined(CONFIG_CMD_GREPENV)
1117 "env grep string [...] - search environment\n"
1119 #if defined(CONFIG_CMD_IMPORTENV)
1120 "env import [-d] [-t | -b | -c] addr [size] - import environment\n"
1122 "env print [-a | name ...] - print environment\n"
1123 #if defined(CONFIG_CMD_RUN)
1124 "env run var [...] - run commands in an environment variable\n"
1126 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1127 "env save - save environment\n"
1129 "env set [-f] name [arg ...]\n";
1133 env, CONFIG_SYS_MAXARGS, 1, do_env,
1134 "environment handling commands", env_help_text
1138 * Old command line interface, kept for compatibility
1141 #if defined(CONFIG_CMD_EDITENV)
1142 U_BOOT_CMD_COMPLETE(
1143 editenv, 2, 0, do_env_edit,
1144 "edit environment variable",
1146 " - edit environment variable 'name'",
1151 U_BOOT_CMD_COMPLETE(
1152 printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
1153 "print environment variables",
1154 "[-a]\n - print [all] values of all environment variables\n"
1155 "printenv name ...\n"
1156 " - print value of environment variable 'name'",
1160 #ifdef CONFIG_CMD_GREPENV
1161 U_BOOT_CMD_COMPLETE(
1162 grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
1163 "search environment variables",
1165 " - list environment name=value pairs matching 'string'",
1170 U_BOOT_CMD_COMPLETE(
1171 setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
1172 "set environment variables",
1173 "[-f] name value ...\n"
1174 " - [forcibly] set environment variable 'name' to 'value ...'\n"
1175 "setenv [-f] name\n"
1176 " - [forcibly] delete environment variable 'name'",
1180 #if defined(CONFIG_CMD_ASKENV)
1183 askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask,
1184 "get environment variables from stdin",
1185 "name [message] [size]\n"
1186 " - get environment variable 'name' from stdin (max 'size' chars)"
1190 #if defined(CONFIG_CMD_RUN)
1191 U_BOOT_CMD_COMPLETE(
1192 run, CONFIG_SYS_MAXARGS, 1, do_run,
1193 "run commands in an environment variable",
1195 " - run the commands in the environment variable(s) 'var'",
1199 #endif /* CONFIG_SPL_BUILD */