2 * (C) Copyright 2000-2013
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[])
171 return CMD_RET_USAGE;
173 grep_flags = H_MATCH_BOTH;
175 while (argc > 1 && **(argv + 1) == '-') {
181 case 'n': /* grep for name */
182 grep_flags = H_MATCH_KEY;
184 case 'v': /* grep for value */
185 grep_flags = H_MATCH_DATA;
187 case 'b': /* grep for both */
188 grep_flags = H_MATCH_BOTH;
193 return CMD_RET_USAGE;
199 len = hexport_r(&env_htab, '\n',
200 flag | grep_flags | H_MATCH_SUBSTR,
201 &res, 0, argc, argv);
214 #endif /* CONFIG_SPL_BUILD */
217 * Set a new environment variable,
218 * or replace or delete an existing one.
220 static int _do_env_set(int flag, int argc, char * const argv[])
223 char *name, *value, *s;
225 int env_flag = H_INTERACTIVE;
227 debug("Initial value for argc=%d\n", argc);
228 while (argc > 1 && **(argv + 1) == '-') {
234 case 'f': /* force */
238 return CMD_RET_USAGE;
242 debug("Final value for argc=%d\n", argc);
246 if (strchr(name, '=')) {
247 printf("## Error: illegal character '='"
248 "in variable name \"%s\"\n", name);
255 if (argc < 3 || argv[2] == NULL) {
256 int rc = hdelete_r(name, &env_htab, env_flag);
261 * Insert / replace new value
263 for (i = 2, len = 0; i < argc; ++i)
264 len += strlen(argv[i]) + 1;
268 printf("## Can't malloc %d bytes\n", len);
271 for (i = 2, s = value; i < argc; ++i) {
274 while ((*s++ = *v++) != '\0')
283 hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
286 printf("## Error inserting \"%s\" variable, errno=%d\n",
294 int setenv(const char *varname, const char *varvalue)
296 const char * const argv[4] = { "setenv", varname, varvalue, NULL };
298 /* before import into hashtable */
299 if (!(gd->flags & GD_FLG_ENV_READY))
302 if (varvalue == NULL || varvalue[0] == '\0')
303 return _do_env_set(0, 2, (char * const *)argv);
305 return _do_env_set(0, 3, (char * const *)argv);
309 * Set an environment variable to an integer value
311 * @param varname Environmet variable to set
312 * @param value Value to set it to
313 * @return 0 if ok, 1 on error
315 int setenv_ulong(const char *varname, ulong value)
317 /* TODO: this should be unsigned */
318 char *str = simple_itoa(value);
320 return setenv(varname, str);
324 * Set an environment variable to an value in hex
326 * @param varname Environmet variable to set
327 * @param value Value to set it to
328 * @return 0 if ok, 1 on error
330 int setenv_hex(const char *varname, ulong value)
334 sprintf(str, "%lx", value);
335 return setenv(varname, str);
338 ulong getenv_hex(const char *varname, ulong default_val)
346 value = simple_strtoul(s, &endp, 16);
353 #ifndef CONFIG_SPL_BUILD
354 static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
357 return CMD_RET_USAGE;
359 return _do_env_set(flag, argc, argv);
363 * Prompt for environment variable
365 #if defined(CONFIG_CMD_ASKENV)
366 int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
368 char message[CONFIG_SYS_CBSIZE];
369 int i, len, pos, size;
373 local_args[0] = argv[0];
374 local_args[1] = argv[1];
375 local_args[2] = NULL;
376 local_args[3] = NULL;
381 * env_ask envname [message1 ...] [size]
384 return CMD_RET_USAGE;
387 * We test the last argument if it can be converted
388 * into a decimal number. If yes, we assume it's
389 * the size. Otherwise we echo it as part of the
392 i = simple_strtoul(argv[argc - 1], &endptr, 10);
393 if (*endptr != '\0') { /* no size */
394 size = CONFIG_SYS_CBSIZE - 1;
395 } else { /* size given */
401 sprintf(message, "Please enter '%s': ", argv[1]);
403 /* env_ask envname message1 ... messagen [size] */
404 for (i = 2, pos = 0; i < argc; i++) {
406 message[pos++] = ' ';
408 strcpy(message + pos, argv[i]);
409 pos += strlen(argv[i]);
411 message[pos++] = ' ';
415 if (size >= CONFIG_SYS_CBSIZE)
416 size = CONFIG_SYS_CBSIZE - 1;
421 /* prompt for input */
422 len = readline(message);
425 console_buffer[size] = '\0';
428 if (console_buffer[0] != '\0') {
429 local_args[2] = console_buffer;
433 /* Continue calling setenv code */
434 return _do_env_set(flag, len, local_args);
438 #if defined(CONFIG_CMD_ENV_CALLBACK)
439 static int print_static_binding(const char *var_name, const char *callback_name)
441 printf("\t%-20s %-20s\n", var_name, callback_name);
446 static int print_active_callback(ENTRY *entry)
448 struct env_clbk_tbl *clbkp;
452 if (entry->callback == NULL)
455 /* look up the callback in the linker-list */
456 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
457 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
460 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
461 if (entry->callback == clbkp->callback + gd->reloc_off)
463 if (entry->callback == clbkp->callback)
468 if (i == num_callbacks)
469 /* this should probably never happen, but just in case... */
470 printf("\t%-20s %p\n", entry->key, entry->callback);
472 printf("\t%-20s %-20s\n", entry->key, clbkp->name);
478 * Print the callbacks available and what they are bound to
480 int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
482 struct env_clbk_tbl *clbkp;
486 /* Print the available callbacks */
487 puts("Available callbacks:\n");
488 puts("\tCallback Name\n");
489 puts("\t-------------\n");
490 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
491 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
494 printf("\t%s\n", clbkp->name);
497 /* Print the static bindings that may exist */
498 puts("Static callback bindings:\n");
499 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
500 printf("\t%-20s %-20s\n", "-------------", "-------------");
501 env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
504 /* walk through each variable and print the callback if it has one */
505 puts("Active callback bindings:\n");
506 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
507 printf("\t%-20s %-20s\n", "-------------", "-------------");
508 hwalk_r(&env_htab, print_active_callback);
513 #if defined(CONFIG_CMD_ENV_FLAGS)
514 static int print_static_flags(const char *var_name, const char *flags)
516 enum env_flags_vartype type = env_flags_parse_vartype(flags);
517 enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
519 printf("\t%-20s %-20s %-20s\n", var_name,
520 env_flags_get_vartype_name(type),
521 env_flags_get_varaccess_name(access));
526 static int print_active_flags(ENTRY *entry)
528 enum env_flags_vartype type;
529 enum env_flags_varaccess access;
531 if (entry->flags == 0)
534 type = (enum env_flags_vartype)
535 (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
536 access = env_flags_parse_varaccess_from_binflags(entry->flags);
537 printf("\t%-20s %-20s %-20s\n", entry->key,
538 env_flags_get_vartype_name(type),
539 env_flags_get_varaccess_name(access));
545 * Print the flags available and what variables have flags
547 int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
549 /* Print the available variable types */
550 printf("Available variable type flags (position %d):\n",
551 ENV_FLAGS_VARTYPE_LOC);
552 puts("\tFlag\tVariable Type Name\n");
553 puts("\t----\t------------------\n");
554 env_flags_print_vartypes();
557 /* Print the available variable access types */
558 printf("Available variable access flags (position %d):\n",
559 ENV_FLAGS_VARACCESS_LOC);
560 puts("\tFlag\tVariable Access Name\n");
561 puts("\t----\t--------------------\n");
562 env_flags_print_varaccess();
565 /* Print the static flags that may exist */
566 puts("Static flags:\n");
567 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
569 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
571 env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
574 /* walk through each variable and print the flags if non-default */
575 puts("Active flags:\n");
576 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
578 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
580 hwalk_r(&env_htab, print_active_flags);
586 * Interactively edit an environment variable
588 #if defined(CONFIG_CMD_EDITENV)
589 static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
592 char buffer[CONFIG_SYS_CBSIZE];
596 return CMD_RET_USAGE;
598 /* Set read buffer to initial value or empty sting */
599 init_val = getenv(argv[1]);
601 sprintf(buffer, "%s", init_val);
605 if (readline_into_buffer("edit: ", buffer, 0) < 0)
608 return setenv(argv[1], buffer);
610 #endif /* CONFIG_CMD_EDITENV */
611 #endif /* CONFIG_SPL_BUILD */
614 * Look up variable from environment,
615 * return address of storage for that variable,
616 * or NULL if not found
618 char *getenv(const char *name)
620 if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
627 hsearch_r(e, FIND, &ep, &env_htab, 0);
629 return ep ? ep->data : NULL;
632 /* restricted capabilities before import */
633 if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
634 return (char *)(gd->env_buf);
640 * Look up variable from environment for restricted C runtime env.
642 int getenv_f(const char *name, char *buf, unsigned len)
646 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
649 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
650 if (nxt >= CONFIG_ENV_SIZE)
654 val = envmatch((uchar *)name, i);
658 /* found; copy out */
659 for (n = 0; n < len; ++n, ++buf) {
660 *buf = env_get_char(val++);
668 printf("env_buf [%d bytes] too small for value of \"%s\"\n",
678 * Decode the integer value of an environment variable and return it.
680 * @param name Name of environemnt variable
681 * @param base Number base to use (normally 10, or 16 for hex)
682 * @param default_val Default value to return if the variable is not
684 * @return the decoded value, or default_val if not found
686 ulong getenv_ulong(const char *name, int base, ulong default_val)
689 * We can use getenv() here, even before relocation, since the
690 * environment variable value is an integer and thus short.
692 const char *str = getenv(name);
694 return str ? simple_strtoul(str, NULL, base) : default_val;
697 #ifndef CONFIG_SPL_BUILD
698 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
699 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
702 printf("Saving Environment to %s...\n", env_name_spec);
704 return saveenv() ? 1 : 0;
708 saveenv, 1, 0, do_env_save,
709 "save environment variables to persistent storage",
713 #endif /* CONFIG_SPL_BUILD */
717 * Match a name / name=value pair
719 * s1 is either a simple 'name', or a 'name=value' pair.
720 * i2 is the environment index for a 'name2=value2' pair.
721 * If the names match, return the index for the value2, else -1.
723 int envmatch(uchar *s1, int i2)
728 while (*s1 == env_get_char(i2++))
732 if (*s1 == '\0' && env_get_char(i2-1) == '=')
738 #ifndef CONFIG_SPL_BUILD
739 static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
740 int argc, char * const argv[])
742 int all = 0, flag = 0;
744 debug("Initial value for argc=%d\n", argc);
745 while (--argc > 0 && **++argv == '-') {
750 case 'a': /* default all */
753 case 'f': /* force */
757 return cmd_usage(cmdtp);
761 debug("Final value for argc=%d\n", argc);
762 if (all && (argc == 0)) {
763 /* Reset the whole environment */
764 set_default_env("## Resetting to default environment\n");
767 if (!all && (argc > 0)) {
768 /* Reset individual variables */
769 set_default_vars(argc, argv);
773 return cmd_usage(cmdtp);
776 static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
777 int argc, char * const argv[])
779 int env_flag = H_INTERACTIVE;
782 debug("Initial value for argc=%d\n", argc);
783 while (argc > 1 && **(argv + 1) == '-') {
789 case 'f': /* force */
793 return CMD_RET_USAGE;
797 debug("Final value for argc=%d\n", argc);
802 char *name = *++argv;
804 if (!hdelete_r(name, &env_htab, env_flag))
811 #ifdef CONFIG_CMD_EXPORTENV
813 * env export [-t | -b | -c] [-s size] addr [var ...]
814 * -t: export as text format; if size is given, data will be
815 * padded with '\0' bytes; if not, one terminating '\0'
816 * will be added (which is included in the "filesize"
817 * setting so you can for exmple copy this to flash and
818 * keep the termination).
819 * -b: export as binary format (name=value pairs separated by
820 * '\0', list end marked by double "\0\0")
821 * -c: export as checksum protected environment format as
822 * used for example by "saveenv" command
824 * size of output buffer
825 * addr: memory address where environment gets stored
826 * var... List of variable names that get included into the
827 * export. Without arguments, the whole environment gets
830 * With "-c" and size is NOT given, then the export command will
831 * format the data as currently used for the persistent storage,
832 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
833 * prepend a valid CRC32 checksum and, in case of resundant
834 * environment, a "current" redundancy flag. If size is given, this
835 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
836 * checksum and redundancy flag will be inserted.
838 * With "-b" and "-t", always only the real data (including a
839 * terminating '\0' byte) will be written; here the optional size
840 * argument will be used to make sure not to overflow the user
841 * provided buffer; the command will abort if the size is not
842 * sufficient. Any remainign space will be '\0' padded.
844 * On successful return, the variable "filesize" will be set.
845 * Note that filesize includes the trailing/terminating '\0' byte(s).
847 * Usage szenario: create a text snapshot/backup of the current settings:
849 * => env export -t 100000
850 * => era ${backup_addr} +${filesize}
851 * => cp.b 100000 ${backup_addr} ${filesize}
853 * Re-import this snapshot, deleting all other settings:
855 * => env import -d -t ${backup_addr}
857 static int do_env_export(cmd_tbl_t *cmdtp, int flag,
858 int argc, char * const argv[])
861 char *addr, *cmd, *res;
871 while (--argc > 0 && **++argv == '-') {
875 case 'b': /* raw binary format */
880 case 'c': /* external checksum format */
886 case 's': /* size given */
888 return cmd_usage(cmdtp);
889 size = simple_strtoul(*++argv, NULL, 16);
891 case 't': /* text format */
897 return CMD_RET_USAGE;
904 return CMD_RET_USAGE;
906 addr = (char *)simple_strtoul(argv[0], NULL, 16);
909 memset(addr, '\0', size);
914 if (sep) { /* export as text file */
915 len = hexport_r(&env_htab, sep,
916 H_MATCH_KEY | H_MATCH_IDENT,
917 &addr, size, argc, argv);
919 error("Cannot export environment: errno = %d\n", errno);
922 sprintf(buf, "%zX", (size_t)len);
923 setenv("filesize", buf);
928 envp = (env_t *)addr;
930 if (chk) /* export as checksum protected block */
931 res = (char *)envp->data;
932 else /* export as raw binary data */
935 len = hexport_r(&env_htab, '\0',
936 H_MATCH_KEY | H_MATCH_IDENT,
937 &res, ENV_SIZE, argc, argv);
939 error("Cannot export environment: errno = %d\n", errno);
944 envp->crc = crc32(0, envp->data, ENV_SIZE);
945 #ifdef CONFIG_ENV_ADDR_REDUND
946 envp->flags = ACTIVE_FLAG;
949 setenv_hex("filesize", len + offsetof(env_t, data));
954 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
959 #ifdef CONFIG_CMD_IMPORTENV
961 * env import [-d] [-t | -b | -c] addr [size]
962 * -d: delete existing environment before importing;
963 * otherwise overwrite / append to existion definitions
964 * -t: assume text format; either "size" must be given or the
965 * text data must be '\0' terminated
966 * -b: assume binary format ('\0' separated, "\0\0" terminated)
967 * -c: assume checksum protected environment format
968 * addr: memory address to read from
969 * size: length of input data; if missing, proper '\0'
970 * termination is mandatory
972 static int do_env_import(cmd_tbl_t *cmdtp, int flag,
973 int argc, char * const argv[])
984 while (--argc > 0 && **++argv == '-') {
988 case 'b': /* raw binary format */
993 case 'c': /* external checksum format */
999 case 't': /* text format */
1008 return CMD_RET_USAGE;
1014 return CMD_RET_USAGE;
1017 printf("## Warning: defaulting to text format\n");
1019 addr = (char *)simple_strtoul(argv[0], NULL, 16);
1022 size = simple_strtoul(argv[1], NULL, 16);
1028 while (size < MAX_ENV_SIZE) {
1029 if ((*s == sep) && (*(s+1) == '\0'))
1034 if (size == MAX_ENV_SIZE) {
1035 printf("## Warning: Input data exceeds %d bytes"
1036 " - truncated\n", MAX_ENV_SIZE);
1039 printf("## Info: input data size = %zu = 0x%zX\n", size, size);
1044 env_t *ep = (env_t *)addr;
1046 size -= offsetof(env_t, data);
1047 memcpy(&crc, &ep->crc, sizeof(crc));
1049 if (crc32(0, ep->data, size) != crc) {
1050 puts("## Error: bad CRC, import failed\n");
1053 addr = (char *)ep->data;
1056 if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
1058 error("Environment import failed: errno = %d\n", errno);
1061 gd->flags |= GD_FLG_ENV_READY;
1066 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
1073 * New command line interface: "env" command with subcommands
1075 static cmd_tbl_t cmd_env_sub[] = {
1076 #if defined(CONFIG_CMD_ASKENV)
1077 U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
1079 U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
1080 U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
1081 #if defined(CONFIG_CMD_EDITENV)
1082 U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
1084 #if defined(CONFIG_CMD_ENV_CALLBACK)
1085 U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
1087 #if defined(CONFIG_CMD_ENV_FLAGS)
1088 U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
1090 #if defined(CONFIG_CMD_EXPORTENV)
1091 U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
1093 #if defined(CONFIG_CMD_GREPENV)
1094 U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
1096 #if defined(CONFIG_CMD_IMPORTENV)
1097 U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
1099 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
1100 #if defined(CONFIG_CMD_RUN)
1101 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
1103 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1104 U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
1106 U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
1109 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
1110 void env_reloc(void)
1112 fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1116 static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1121 return CMD_RET_USAGE;
1123 /* drop initial "env" arg */
1127 cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1130 return cp->cmd(cmdtp, flag, argc, argv);
1132 return CMD_RET_USAGE;
1135 #ifdef CONFIG_SYS_LONGHELP
1136 static char env_help_text[] =
1137 #if defined(CONFIG_CMD_ASKENV)
1138 "ask name [message] [size] - ask for environment variable\nenv "
1140 #if defined(CONFIG_CMD_ENV_CALLBACK)
1141 "callbacks - print callbacks and their associated variables\nenv "
1143 "default [-f] -a - [forcibly] reset default environment\n"
1144 "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
1145 "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
1146 #if defined(CONFIG_CMD_EDITENV)
1147 "env edit name - edit environment variable\n"
1149 #if defined(CONFIG_CMD_EXPORTENV)
1150 "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
1152 #if defined(CONFIG_CMD_ENV_FLAGS)
1153 "env flags - print variables that have non-default flags\n"
1155 #if defined(CONFIG_CMD_GREPENV)
1156 "env grep [-n | -v | -b] string [...] - search environment\n"
1158 #if defined(CONFIG_CMD_IMPORTENV)
1159 "env import [-d] [-t | -b | -c] addr [size] - import environment\n"
1161 "env print [-a | name ...] - print environment\n"
1162 #if defined(CONFIG_CMD_RUN)
1163 "env run var [...] - run commands in an environment variable\n"
1165 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1166 "env save - save environment\n"
1168 "env set [-f] name [arg ...]\n";
1172 env, CONFIG_SYS_MAXARGS, 1, do_env,
1173 "environment handling commands", env_help_text
1177 * Old command line interface, kept for compatibility
1180 #if defined(CONFIG_CMD_EDITENV)
1181 U_BOOT_CMD_COMPLETE(
1182 editenv, 2, 0, do_env_edit,
1183 "edit environment variable",
1185 " - edit environment variable 'name'",
1190 U_BOOT_CMD_COMPLETE(
1191 printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
1192 "print environment variables",
1193 "[-a]\n - print [all] values of all environment variables\n"
1194 "printenv name ...\n"
1195 " - print value of environment variable 'name'",
1199 #ifdef CONFIG_CMD_GREPENV
1200 U_BOOT_CMD_COMPLETE(
1201 grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
1202 "search environment variables",
1203 "[-n | -v | -b] string ...\n"
1204 " - list environment name=value pairs matching 'string'\n"
1205 " \"-n\": search variable names; \"-v\": search values;\n"
1206 " \"-b\": search both names and values (default)",
1211 U_BOOT_CMD_COMPLETE(
1212 setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
1213 "set environment variables",
1214 "[-f] name value ...\n"
1215 " - [forcibly] set environment variable 'name' to 'value ...'\n"
1216 "setenv [-f] name\n"
1217 " - [forcibly] delete environment variable 'name'",
1221 #if defined(CONFIG_CMD_ASKENV)
1224 askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask,
1225 "get environment variables from stdin",
1226 "name [message] [size]\n"
1227 " - get environment variable 'name' from stdin (max 'size' chars)"
1231 #if defined(CONFIG_CMD_RUN)
1232 U_BOOT_CMD_COMPLETE(
1233 run, CONFIG_SYS_MAXARGS, 1, do_run,
1234 "run commands in an environment variable",
1236 " - run the commands in the environment variable(s) 'var'",
1240 #endif /* CONFIG_SPL_BUILD */