2 * (C) Copyright 2000-2013
5 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Copyright 2011 Freescale Semiconductor, Inc.
10 * SPDX-License-Identifier: GPL-2.0+
14 * Support for persistent environment data
16 * The "environment" is stored on external storage as a list of '\0'
17 * terminated "name=value" strings. The end of the list is marked by
18 * a double '\0'. The environment is preceeded by a 32 bit CRC over
19 * the data part and, in case of redundant environment, a byte of
22 * This linearized representation will also be used before
23 * relocation, i. e. as long as we don't have a full C runtime
24 * environment. After that, we use a hash table.
29 #include <environment.h>
34 #include <linux/stddef.h>
35 #include <asm/byteorder.h>
37 DECLARE_GLOBAL_DATA_PTR;
39 #if !defined(CONFIG_ENV_IS_IN_EEPROM) && \
40 !defined(CONFIG_ENV_IS_IN_FLASH) && \
41 !defined(CONFIG_ENV_IS_IN_DATAFLASH) && \
42 !defined(CONFIG_ENV_IS_IN_MMC) && \
43 !defined(CONFIG_ENV_IS_IN_FAT) && \
44 !defined(CONFIG_ENV_IS_IN_NAND) && \
45 !defined(CONFIG_ENV_IS_IN_NVRAM) && \
46 !defined(CONFIG_ENV_IS_IN_ONENAND) && \
47 !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \
48 !defined(CONFIG_ENV_IS_IN_REMOTE) && \
49 !defined(CONFIG_ENV_IS_IN_UBI) && \
50 !defined(CONFIG_ENV_IS_NOWHERE)
51 # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
52 SPI_FLASH|NVRAM|MMC|FAT|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
56 * Maximum expected input data size for import command
58 #define MAX_ENV_SIZE (1 << 20) /* 1 MiB */
61 * This variable is incremented on each do_env_set(), so it can
62 * be used via get_env_id() as an indication, if the environment
63 * has changed or not. So it is possible to reread an environment
64 * variable only if the environment was changed ... done so for
65 * example in NetInitLoop()
67 static int env_id = 1;
74 #ifndef CONFIG_SPL_BUILD
76 * Command interface: print one or all environment variables
78 * Returns 0 in case of error, or length of printed string
80 static int env_print(char *name, int flag)
85 if (name) { /* print a single name */
90 hsearch_r(e, FIND, &ep, &env_htab, flag);
93 len = printf("%s=%s\n", ep->key, ep->data);
97 /* print whole list */
98 len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
106 /* should never happen */
107 printf("## Error: cannot export environment\n");
111 static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
116 int env_flag = H_HIDE_DOT;
118 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
121 env_flag &= ~H_HIDE_DOT;
125 /* print all env vars */
126 rcode = env_print(NULL, env_flag);
129 printf("\nEnvironment size: %d/%ld bytes\n",
130 rcode, (ulong)ENV_SIZE);
134 /* print selected env vars */
135 env_flag &= ~H_HIDE_DOT;
136 for (i = 1; i < argc; ++i) {
137 int rc = env_print(argv[i], env_flag);
139 printf("## Error: \"%s\" not defined\n", argv[i]);
147 #ifdef CONFIG_CMD_GREPENV
148 static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
149 int argc, char * const argv[])
152 int len, grep_how, grep_what;
155 return CMD_RET_USAGE;
157 grep_how = H_MATCH_SUBSTR; /* default: substring search */
158 grep_what = H_MATCH_BOTH; /* default: grep names and values */
160 while (--argc > 0 && **++argv == '-') {
165 case 'e': /* use regex matching */
166 grep_how = H_MATCH_REGEX;
169 case 'n': /* grep for name */
170 grep_what = H_MATCH_KEY;
172 case 'v': /* grep for value */
173 grep_what = H_MATCH_DATA;
175 case 'b': /* grep for both */
176 grep_what = H_MATCH_BOTH;
181 return CMD_RET_USAGE;
187 len = hexport_r(&env_htab, '\n',
188 flag | grep_what | grep_how,
189 &res, 0, argc, argv);
202 #endif /* CONFIG_SPL_BUILD */
205 * Set a new environment variable,
206 * or replace or delete an existing one.
208 static int _do_env_set(int flag, int argc, char * const argv[])
211 char *name, *value, *s;
213 int env_flag = H_INTERACTIVE;
215 debug("Initial value for argc=%d\n", argc);
216 while (argc > 1 && **(argv + 1) == '-') {
222 case 'f': /* force */
226 return CMD_RET_USAGE;
230 debug("Final value for argc=%d\n", argc);
234 if (strchr(name, '=')) {
235 printf("## Error: illegal character '='"
236 "in variable name \"%s\"\n", name);
243 if (argc < 3 || argv[2] == NULL) {
244 int rc = hdelete_r(name, &env_htab, env_flag);
249 * Insert / replace new value
251 for (i = 2, len = 0; i < argc; ++i)
252 len += strlen(argv[i]) + 1;
256 printf("## Can't malloc %d bytes\n", len);
259 for (i = 2, s = value; i < argc; ++i) {
262 while ((*s++ = *v++) != '\0')
271 hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
274 printf("## Error inserting \"%s\" variable, errno=%d\n",
282 int setenv(const char *varname, const char *varvalue)
284 const char * const argv[4] = { "setenv", varname, varvalue, NULL };
286 /* before import into hashtable */
287 if (!(gd->flags & GD_FLG_ENV_READY))
290 if (varvalue == NULL || varvalue[0] == '\0')
291 return _do_env_set(0, 2, (char * const *)argv);
293 return _do_env_set(0, 3, (char * const *)argv);
297 * Set an environment variable to an integer value
299 * @param varname Environment variable to set
300 * @param value Value to set it to
301 * @return 0 if ok, 1 on error
303 int setenv_ulong(const char *varname, ulong value)
305 /* TODO: this should be unsigned */
306 char *str = simple_itoa(value);
308 return setenv(varname, str);
312 * Set an environment variable to an value in hex
314 * @param varname Environment variable to set
315 * @param value Value to set it to
316 * @return 0 if ok, 1 on error
318 int setenv_hex(const char *varname, ulong value)
322 sprintf(str, "%lx", value);
323 return setenv(varname, str);
326 ulong getenv_hex(const char *varname, ulong default_val)
334 value = simple_strtoul(s, &endp, 16);
341 #ifndef CONFIG_SPL_BUILD
342 static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
345 return CMD_RET_USAGE;
347 return _do_env_set(flag, argc, argv);
351 * Prompt for environment variable
353 #if defined(CONFIG_CMD_ASKENV)
354 int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
356 char message[CONFIG_SYS_CBSIZE];
357 int i, len, pos, size;
361 local_args[0] = argv[0];
362 local_args[1] = argv[1];
363 local_args[2] = NULL;
364 local_args[3] = NULL;
369 * env_ask envname [message1 ...] [size]
372 return CMD_RET_USAGE;
375 * We test the last argument if it can be converted
376 * into a decimal number. If yes, we assume it's
377 * the size. Otherwise we echo it as part of the
380 i = simple_strtoul(argv[argc - 1], &endptr, 10);
381 if (*endptr != '\0') { /* no size */
382 size = CONFIG_SYS_CBSIZE - 1;
383 } else { /* size given */
389 sprintf(message, "Please enter '%s': ", argv[1]);
391 /* env_ask envname message1 ... messagen [size] */
392 for (i = 2, pos = 0; i < argc; i++) {
394 message[pos++] = ' ';
396 strcpy(message + pos, argv[i]);
397 pos += strlen(argv[i]);
399 message[pos++] = ' ';
403 if (size >= CONFIG_SYS_CBSIZE)
404 size = CONFIG_SYS_CBSIZE - 1;
409 /* prompt for input */
410 len = readline(message);
413 console_buffer[size] = '\0';
416 if (console_buffer[0] != '\0') {
417 local_args[2] = console_buffer;
421 /* Continue calling setenv code */
422 return _do_env_set(flag, len, local_args);
426 #if defined(CONFIG_CMD_ENV_CALLBACK)
427 static int print_static_binding(const char *var_name, const char *callback_name)
429 printf("\t%-20s %-20s\n", var_name, callback_name);
434 static int print_active_callback(ENTRY *entry)
436 struct env_clbk_tbl *clbkp;
440 if (entry->callback == NULL)
443 /* look up the callback in the linker-list */
444 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
445 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
448 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
449 if (entry->callback == clbkp->callback + gd->reloc_off)
451 if (entry->callback == clbkp->callback)
456 if (i == num_callbacks)
457 /* this should probably never happen, but just in case... */
458 printf("\t%-20s %p\n", entry->key, entry->callback);
460 printf("\t%-20s %-20s\n", entry->key, clbkp->name);
466 * Print the callbacks available and what they are bound to
468 int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
470 struct env_clbk_tbl *clbkp;
474 /* Print the available callbacks */
475 puts("Available callbacks:\n");
476 puts("\tCallback Name\n");
477 puts("\t-------------\n");
478 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
479 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
482 printf("\t%s\n", clbkp->name);
485 /* Print the static bindings that may exist */
486 puts("Static callback bindings:\n");
487 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
488 printf("\t%-20s %-20s\n", "-------------", "-------------");
489 env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
492 /* walk through each variable and print the callback if it has one */
493 puts("Active callback bindings:\n");
494 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
495 printf("\t%-20s %-20s\n", "-------------", "-------------");
496 hwalk_r(&env_htab, print_active_callback);
501 #if defined(CONFIG_CMD_ENV_FLAGS)
502 static int print_static_flags(const char *var_name, const char *flags)
504 enum env_flags_vartype type = env_flags_parse_vartype(flags);
505 enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
507 printf("\t%-20s %-20s %-20s\n", var_name,
508 env_flags_get_vartype_name(type),
509 env_flags_get_varaccess_name(access));
514 static int print_active_flags(ENTRY *entry)
516 enum env_flags_vartype type;
517 enum env_flags_varaccess access;
519 if (entry->flags == 0)
522 type = (enum env_flags_vartype)
523 (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
524 access = env_flags_parse_varaccess_from_binflags(entry->flags);
525 printf("\t%-20s %-20s %-20s\n", entry->key,
526 env_flags_get_vartype_name(type),
527 env_flags_get_varaccess_name(access));
533 * Print the flags available and what variables have flags
535 int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
537 /* Print the available variable types */
538 printf("Available variable type flags (position %d):\n",
539 ENV_FLAGS_VARTYPE_LOC);
540 puts("\tFlag\tVariable Type Name\n");
541 puts("\t----\t------------------\n");
542 env_flags_print_vartypes();
545 /* Print the available variable access types */
546 printf("Available variable access flags (position %d):\n",
547 ENV_FLAGS_VARACCESS_LOC);
548 puts("\tFlag\tVariable Access Name\n");
549 puts("\t----\t--------------------\n");
550 env_flags_print_varaccess();
553 /* Print the static flags that may exist */
554 puts("Static flags:\n");
555 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
557 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
559 env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
562 /* walk through each variable and print the flags if non-default */
563 puts("Active flags:\n");
564 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
566 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
568 hwalk_r(&env_htab, print_active_flags);
574 * Interactively edit an environment variable
576 #if defined(CONFIG_CMD_EDITENV)
577 static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
580 char buffer[CONFIG_SYS_CBSIZE];
584 return CMD_RET_USAGE;
586 /* Set read buffer to initial value or empty sting */
587 init_val = getenv(argv[1]);
589 sprintf(buffer, "%s", init_val);
593 if (readline_into_buffer("edit: ", buffer, 0) < 0)
596 return setenv(argv[1], buffer);
598 #endif /* CONFIG_CMD_EDITENV */
599 #endif /* CONFIG_SPL_BUILD */
602 * Look up variable from environment,
603 * return address of storage for that variable,
604 * or NULL if not found
606 char *getenv(const char *name)
608 if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
615 hsearch_r(e, FIND, &ep, &env_htab, 0);
617 return ep ? ep->data : NULL;
620 /* restricted capabilities before import */
621 if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
622 return (char *)(gd->env_buf);
628 * Look up variable from environment for restricted C runtime env.
630 int getenv_f(const char *name, char *buf, unsigned len)
634 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
637 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
638 if (nxt >= CONFIG_ENV_SIZE)
642 val = envmatch((uchar *)name, i);
646 /* found; copy out */
647 for (n = 0; n < len; ++n, ++buf) {
648 *buf = env_get_char(val++);
656 printf("env_buf [%d bytes] too small for value of \"%s\"\n",
666 * Decode the integer value of an environment variable and return it.
668 * @param name Name of environemnt variable
669 * @param base Number base to use (normally 10, or 16 for hex)
670 * @param default_val Default value to return if the variable is not
672 * @return the decoded value, or default_val if not found
674 ulong getenv_ulong(const char *name, int base, ulong default_val)
677 * We can use getenv() here, even before relocation, since the
678 * environment variable value is an integer and thus short.
680 const char *str = getenv(name);
682 return str ? simple_strtoul(str, NULL, base) : default_val;
685 #ifndef CONFIG_SPL_BUILD
686 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
687 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
690 printf("Saving Environment to %s...\n", env_name_spec);
692 return saveenv() ? 1 : 0;
696 saveenv, 1, 0, do_env_save,
697 "save environment variables to persistent storage",
701 #endif /* CONFIG_SPL_BUILD */
705 * Match a name / name=value pair
707 * s1 is either a simple 'name', or a 'name=value' pair.
708 * i2 is the environment index for a 'name2=value2' pair.
709 * If the names match, return the index for the value2, else -1.
711 int envmatch(uchar *s1, int i2)
716 while (*s1 == env_get_char(i2++))
720 if (*s1 == '\0' && env_get_char(i2-1) == '=')
726 #ifndef CONFIG_SPL_BUILD
727 static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
728 int argc, char * const argv[])
730 int all = 0, flag = 0;
732 debug("Initial value for argc=%d\n", argc);
733 while (--argc > 0 && **++argv == '-') {
738 case 'a': /* default all */
741 case 'f': /* force */
745 return cmd_usage(cmdtp);
749 debug("Final value for argc=%d\n", argc);
750 if (all && (argc == 0)) {
751 /* Reset the whole environment */
752 set_default_env("## Resetting to default environment\n");
755 if (!all && (argc > 0)) {
756 /* Reset individual variables */
757 set_default_vars(argc, argv);
761 return cmd_usage(cmdtp);
764 static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
765 int argc, char * const argv[])
767 int env_flag = H_INTERACTIVE;
770 debug("Initial value for argc=%d\n", argc);
771 while (argc > 1 && **(argv + 1) == '-') {
777 case 'f': /* force */
781 return CMD_RET_USAGE;
785 debug("Final value for argc=%d\n", argc);
790 char *name = *++argv;
792 if (!hdelete_r(name, &env_htab, env_flag))
799 #ifdef CONFIG_CMD_EXPORTENV
801 * env export [-t | -b | -c] [-s size] addr [var ...]
802 * -t: export as text format; if size is given, data will be
803 * padded with '\0' bytes; if not, one terminating '\0'
804 * will be added (which is included in the "filesize"
805 * setting so you can for exmple copy this to flash and
806 * keep the termination).
807 * -b: export as binary format (name=value pairs separated by
808 * '\0', list end marked by double "\0\0")
809 * -c: export as checksum protected environment format as
810 * used for example by "saveenv" command
812 * size of output buffer
813 * addr: memory address where environment gets stored
814 * var... List of variable names that get included into the
815 * export. Without arguments, the whole environment gets
818 * With "-c" and size is NOT given, then the export command will
819 * format the data as currently used for the persistent storage,
820 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
821 * prepend a valid CRC32 checksum and, in case of resundant
822 * environment, a "current" redundancy flag. If size is given, this
823 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
824 * checksum and redundancy flag will be inserted.
826 * With "-b" and "-t", always only the real data (including a
827 * terminating '\0' byte) will be written; here the optional size
828 * argument will be used to make sure not to overflow the user
829 * provided buffer; the command will abort if the size is not
830 * sufficient. Any remainign space will be '\0' padded.
832 * On successful return, the variable "filesize" will be set.
833 * Note that filesize includes the trailing/terminating '\0' byte(s).
835 * Usage szenario: create a text snapshot/backup of the current settings:
837 * => env export -t 100000
838 * => era ${backup_addr} +${filesize}
839 * => cp.b 100000 ${backup_addr} ${filesize}
841 * Re-import this snapshot, deleting all other settings:
843 * => env import -d -t ${backup_addr}
845 static int do_env_export(cmd_tbl_t *cmdtp, int flag,
846 int argc, char * const argv[])
849 char *addr, *cmd, *res;
859 while (--argc > 0 && **++argv == '-') {
863 case 'b': /* raw binary format */
868 case 'c': /* external checksum format */
874 case 's': /* size given */
876 return cmd_usage(cmdtp);
877 size = simple_strtoul(*++argv, NULL, 16);
879 case 't': /* text format */
885 return CMD_RET_USAGE;
892 return CMD_RET_USAGE;
894 addr = (char *)simple_strtoul(argv[0], NULL, 16);
897 memset(addr, '\0', size);
902 if (sep) { /* export as text file */
903 len = hexport_r(&env_htab, sep,
904 H_MATCH_KEY | H_MATCH_IDENT,
905 &addr, size, argc, argv);
907 error("Cannot export environment: errno = %d\n", errno);
910 sprintf(buf, "%zX", (size_t)len);
911 setenv("filesize", buf);
916 envp = (env_t *)addr;
918 if (chk) /* export as checksum protected block */
919 res = (char *)envp->data;
920 else /* export as raw binary data */
923 len = hexport_r(&env_htab, '\0',
924 H_MATCH_KEY | H_MATCH_IDENT,
925 &res, ENV_SIZE, argc, argv);
927 error("Cannot export environment: errno = %d\n", errno);
932 envp->crc = crc32(0, envp->data, ENV_SIZE);
933 #ifdef CONFIG_ENV_ADDR_REDUND
934 envp->flags = ACTIVE_FLAG;
937 setenv_hex("filesize", len + offsetof(env_t, data));
942 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
947 #ifdef CONFIG_CMD_IMPORTENV
949 * env import [-d] [-t | -b | -c] addr [size]
950 * -d: delete existing environment before importing;
951 * otherwise overwrite / append to existion definitions
952 * -t: assume text format; either "size" must be given or the
953 * text data must be '\0' terminated
954 * -b: assume binary format ('\0' separated, "\0\0" terminated)
955 * -c: assume checksum protected environment format
956 * addr: memory address to read from
957 * size: length of input data; if missing, proper '\0'
958 * termination is mandatory
960 static int do_env_import(cmd_tbl_t *cmdtp, int flag,
961 int argc, char * const argv[])
972 while (--argc > 0 && **++argv == '-') {
976 case 'b': /* raw binary format */
981 case 'c': /* external checksum format */
987 case 't': /* text format */
996 return CMD_RET_USAGE;
1002 return CMD_RET_USAGE;
1005 printf("## Warning: defaulting to text format\n");
1007 addr = (char *)simple_strtoul(argv[0], NULL, 16);
1010 size = simple_strtoul(argv[1], NULL, 16);
1016 while (size < MAX_ENV_SIZE) {
1017 if ((*s == sep) && (*(s+1) == '\0'))
1022 if (size == MAX_ENV_SIZE) {
1023 printf("## Warning: Input data exceeds %d bytes"
1024 " - truncated\n", MAX_ENV_SIZE);
1027 printf("## Info: input data size = %zu = 0x%zX\n", size, size);
1032 env_t *ep = (env_t *)addr;
1034 size -= offsetof(env_t, data);
1035 memcpy(&crc, &ep->crc, sizeof(crc));
1037 if (crc32(0, ep->data, size) != crc) {
1038 puts("## Error: bad CRC, import failed\n");
1041 addr = (char *)ep->data;
1044 if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
1046 error("Environment import failed: errno = %d\n", errno);
1049 gd->flags |= GD_FLG_ENV_READY;
1054 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
1060 #if defined(CONFIG_CMD_ENV_EXISTS)
1061 static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
1062 char * const argv[])
1067 return CMD_RET_USAGE;
1071 hsearch_r(e, FIND, &ep, &env_htab, 0);
1073 return (ep == NULL) ? 1 : 0;
1078 * New command line interface: "env" command with subcommands
1080 static cmd_tbl_t cmd_env_sub[] = {
1081 #if defined(CONFIG_CMD_ASKENV)
1082 U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
1084 U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
1085 U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
1086 #if defined(CONFIG_CMD_EDITENV)
1087 U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
1089 #if defined(CONFIG_CMD_ENV_CALLBACK)
1090 U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
1092 #if defined(CONFIG_CMD_ENV_FLAGS)
1093 U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
1095 #if defined(CONFIG_CMD_EXPORTENV)
1096 U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
1098 #if defined(CONFIG_CMD_GREPENV)
1099 U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
1101 #if defined(CONFIG_CMD_IMPORTENV)
1102 U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
1104 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
1105 #if defined(CONFIG_CMD_RUN)
1106 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
1108 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1109 U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
1111 U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
1112 #if defined(CONFIG_CMD_ENV_EXISTS)
1113 U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""),
1117 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
1118 void env_reloc(void)
1120 fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1124 static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1129 return CMD_RET_USAGE;
1131 /* drop initial "env" arg */
1135 cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1138 return cp->cmd(cmdtp, flag, argc, argv);
1140 return CMD_RET_USAGE;
1143 #ifdef CONFIG_SYS_LONGHELP
1144 static char env_help_text[] =
1145 #if defined(CONFIG_CMD_ASKENV)
1146 "ask name [message] [size] - ask for environment variable\nenv "
1148 #if defined(CONFIG_CMD_ENV_CALLBACK)
1149 "callbacks - print callbacks and their associated variables\nenv "
1151 "default [-f] -a - [forcibly] reset default environment\n"
1152 "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
1153 "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
1154 #if defined(CONFIG_CMD_EDITENV)
1155 "env edit name - edit environment variable\n"
1157 #if defined(CONFIG_CMD_ENV_EXISTS)
1158 "env exists name - tests for existence of variable\n"
1160 #if defined(CONFIG_CMD_EXPORTENV)
1161 "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
1163 #if defined(CONFIG_CMD_ENV_FLAGS)
1164 "env flags - print variables that have non-default flags\n"
1166 #if defined(CONFIG_CMD_GREPENV)
1168 "env grep [-e] [-n | -v | -b] string [...] - search environment\n"
1170 "env grep [-n | -v | -b] string [...] - search environment\n"
1173 #if defined(CONFIG_CMD_IMPORTENV)
1174 "env import [-d] [-t | -b | -c] addr [size] - import environment\n"
1176 "env print [-a | name ...] - print environment\n"
1177 #if defined(CONFIG_CMD_RUN)
1178 "env run var [...] - run commands in an environment variable\n"
1180 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1181 "env save - save environment\n"
1183 "env set [-f] name [arg ...]\n";
1187 env, CONFIG_SYS_MAXARGS, 1, do_env,
1188 "environment handling commands", env_help_text
1192 * Old command line interface, kept for compatibility
1195 #if defined(CONFIG_CMD_EDITENV)
1196 U_BOOT_CMD_COMPLETE(
1197 editenv, 2, 0, do_env_edit,
1198 "edit environment variable",
1200 " - edit environment variable 'name'",
1205 U_BOOT_CMD_COMPLETE(
1206 printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
1207 "print environment variables",
1208 "[-a]\n - print [all] values of all environment variables\n"
1209 "printenv name ...\n"
1210 " - print value of environment variable 'name'",
1214 #ifdef CONFIG_CMD_GREPENV
1215 U_BOOT_CMD_COMPLETE(
1216 grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
1217 "search environment variables",
1219 "[-e] [-n | -v | -b] string ...\n"
1221 "[-n | -v | -b] string ...\n"
1223 " - list environment name=value pairs matching 'string'\n"
1225 " \"-e\": enable regular expressions;\n"
1227 " \"-n\": search variable names; \"-v\": search values;\n"
1228 " \"-b\": search both names and values (default)",
1233 U_BOOT_CMD_COMPLETE(
1234 setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
1235 "set environment variables",
1236 "[-f] name value ...\n"
1237 " - [forcibly] set environment variable 'name' to 'value ...'\n"
1238 "setenv [-f] name\n"
1239 " - [forcibly] delete environment variable 'name'",
1243 #if defined(CONFIG_CMD_ASKENV)
1246 askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask,
1247 "get environment variables from stdin",
1248 "name [message] [size]\n"
1249 " - get environment variable 'name' from stdin (max 'size' chars)"
1253 #if defined(CONFIG_CMD_RUN)
1254 U_BOOT_CMD_COMPLETE(
1255 run, CONFIG_SYS_MAXARGS, 1, do_run,
1256 "run commands in an environment variable",
1258 " - run the commands in the environment variable(s) 'var'",
1262 #endif /* CONFIG_SPL_BUILD */