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_NOWHERE)
66 # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
67 SPI_FLASH|NVRAM|MMC|FAT|REMOTE} or CONFIG_ENV_IS_NOWHERE
71 * Maximum expected input data size for import command
73 #define MAX_ENV_SIZE (1 << 20) /* 1 MiB */
76 * This variable is incremented on each do_env_set(), so it can
77 * be used via get_env_id() as an indication, if the environment
78 * has changed or not. So it is possible to reread an environment
79 * variable only if the environment was changed ... done so for
80 * example in NetInitLoop()
82 static int env_id = 1;
89 #ifndef CONFIG_SPL_BUILD
91 * Command interface: print one or all environment variables
93 * Returns 0 in case of error, or length of printed string
95 static int env_print(char *name, int flag)
100 if (name) { /* print a single name */
105 hsearch_r(e, FIND, &ep, &env_htab, flag);
108 len = printf("%s=%s\n", ep->key, ep->data);
112 /* print whole list */
113 len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
121 /* should never happen */
125 static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
130 int env_flag = H_HIDE_DOT;
132 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
135 env_flag &= ~H_HIDE_DOT;
139 /* print all env vars */
140 rcode = env_print(NULL, env_flag);
143 printf("\nEnvironment size: %d/%ld bytes\n",
144 rcode, (ulong)ENV_SIZE);
148 /* print selected env vars */
149 env_flag &= ~H_HIDE_DOT;
150 for (i = 1; i < argc; ++i) {
151 int rc = env_print(argv[i], env_flag);
153 printf("## Error: \"%s\" not defined\n", argv[i]);
161 #ifdef CONFIG_CMD_GREPENV
162 static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
163 int argc, char * const argv[])
166 unsigned char matched[env_htab.size / 8];
167 int rcode = 1, arg = 1, idx;
170 return CMD_RET_USAGE;
172 memset(matched, 0, env_htab.size / 8);
174 while (arg <= argc) {
176 while ((idx = hstrstr_r(argv[arg], idx, &match, &env_htab))) {
177 if (!(matched[idx / 8] & (1 << (idx & 7)))) {
183 matched[idx / 8] |= 1 << (idx & 7);
192 #endif /* CONFIG_SPL_BUILD */
195 * Set a new environment variable,
196 * or replace or delete an existing one.
198 static int _do_env_set(int flag, int argc, char * const argv[])
201 char *name, *value, *s;
203 int env_flag = H_INTERACTIVE;
205 debug("Initial value for argc=%d\n", argc);
206 while (argc > 1 && **(argv + 1) == '-') {
212 case 'f': /* force */
216 return CMD_RET_USAGE;
220 debug("Final value for argc=%d\n", argc);
224 if (strchr(name, '=')) {
225 printf("## Error: illegal character '='"
226 "in variable name \"%s\"\n", name);
233 if (argc < 3 || argv[2] == NULL) {
234 int rc = hdelete_r(name, &env_htab, env_flag);
239 * Insert / replace new value
241 for (i = 2, len = 0; i < argc; ++i)
242 len += strlen(argv[i]) + 1;
246 printf("## Can't malloc %d bytes\n", len);
249 for (i = 2, s = value; i < argc; ++i) {
252 while ((*s++ = *v++) != '\0')
261 hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
264 printf("## Error inserting \"%s\" variable, errno=%d\n",
272 int setenv(const char *varname, const char *varvalue)
274 const char * const argv[4] = { "setenv", varname, varvalue, NULL };
276 /* before import into hashtable */
277 if (!(gd->flags & GD_FLG_ENV_READY))
280 if (varvalue == NULL || varvalue[0] == '\0')
281 return _do_env_set(0, 2, (char * const *)argv);
283 return _do_env_set(0, 3, (char * const *)argv);
287 * Set an environment variable to an integer value
289 * @param varname Environmet variable to set
290 * @param value Value to set it to
291 * @return 0 if ok, 1 on error
293 int setenv_ulong(const char *varname, ulong value)
295 /* TODO: this should be unsigned */
296 char *str = simple_itoa(value);
298 return setenv(varname, str);
302 * Set an environment variable to an value in hex
304 * @param varname Environmet variable to set
305 * @param value Value to set it to
306 * @return 0 if ok, 1 on error
308 int setenv_hex(const char *varname, ulong value)
312 sprintf(str, "%lx", value);
313 return setenv(varname, str);
316 #ifndef CONFIG_SPL_BUILD
317 static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
320 return CMD_RET_USAGE;
322 return _do_env_set(flag, argc, argv);
326 * Prompt for environment variable
328 #if defined(CONFIG_CMD_ASKENV)
329 int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
331 char message[CONFIG_SYS_CBSIZE];
332 int i, len, pos, size;
336 local_args[0] = argv[0];
337 local_args[1] = argv[1];
338 local_args[2] = NULL;
339 local_args[3] = NULL;
344 * env_ask envname [message1 ...] [size]
347 return CMD_RET_USAGE;
350 * We test the last argument if it can be converted
351 * into a decimal number. If yes, we assume it's
352 * the size. Otherwise we echo it as part of the
355 i = simple_strtoul(argv[argc - 1], &endptr, 10);
356 if (*endptr != '\0') { /* no size */
357 size = CONFIG_SYS_CBSIZE - 1;
358 } else { /* size given */
364 sprintf(message, "Please enter '%s': ", argv[1]);
366 /* env_ask envname message1 ... messagen [size] */
367 for (i = 2, pos = 0; i < argc; i++) {
369 message[pos++] = ' ';
371 strcpy(message + pos, argv[i]);
372 pos += strlen(argv[i]);
374 message[pos++] = ' ';
378 if (size >= CONFIG_SYS_CBSIZE)
379 size = CONFIG_SYS_CBSIZE - 1;
384 /* prompt for input */
385 len = readline(message);
388 console_buffer[size] = '\0';
391 if (console_buffer[0] != '\0') {
392 local_args[2] = console_buffer;
396 /* Continue calling setenv code */
397 return _do_env_set(flag, len, local_args);
401 #if defined(CONFIG_CMD_ENV_CALLBACK)
402 static int print_static_binding(const char *var_name, const char *callback_name)
404 printf("\t%-20s %-20s\n", var_name, callback_name);
409 static int print_active_callback(ENTRY *entry)
411 struct env_clbk_tbl *clbkp;
415 if (entry->callback == NULL)
418 /* look up the callback in the linker-list */
419 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
420 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
423 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
424 if (entry->callback == clbkp->callback + gd->reloc_off)
426 if (entry->callback == clbkp->callback)
431 if (i == num_callbacks)
432 /* this should probably never happen, but just in case... */
433 printf("\t%-20s %p\n", entry->key, entry->callback);
435 printf("\t%-20s %-20s\n", entry->key, clbkp->name);
441 * Print the callbacks available and what they are bound to
443 int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
445 struct env_clbk_tbl *clbkp;
449 /* Print the available callbacks */
450 puts("Available callbacks:\n");
451 puts("\tCallback Name\n");
452 puts("\t-------------\n");
453 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
454 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
457 printf("\t%s\n", clbkp->name);
460 /* Print the static bindings that may exist */
461 puts("Static callback bindings:\n");
462 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
463 printf("\t%-20s %-20s\n", "-------------", "-------------");
464 env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
467 /* walk through each variable and print the callback if it has one */
468 puts("Active callback bindings:\n");
469 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
470 printf("\t%-20s %-20s\n", "-------------", "-------------");
471 hwalk_r(&env_htab, print_active_callback);
476 #if defined(CONFIG_CMD_ENV_FLAGS)
477 static int print_static_flags(const char *var_name, const char *flags)
479 enum env_flags_vartype type = env_flags_parse_vartype(flags);
480 enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
482 printf("\t%-20s %-20s %-20s\n", var_name,
483 env_flags_get_vartype_name(type),
484 env_flags_get_varaccess_name(access));
489 static int print_active_flags(ENTRY *entry)
491 enum env_flags_vartype type;
492 enum env_flags_varaccess access;
494 if (entry->flags == 0)
497 type = (enum env_flags_vartype)
498 (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
499 access = env_flags_parse_varaccess_from_binflags(entry->flags);
500 printf("\t%-20s %-20s %-20s\n", entry->key,
501 env_flags_get_vartype_name(type),
502 env_flags_get_varaccess_name(access));
508 * Print the flags available and what variables have flags
510 int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
512 /* Print the available variable types */
513 printf("Available variable type flags (position %d):\n",
514 ENV_FLAGS_VARTYPE_LOC);
515 puts("\tFlag\tVariable Type Name\n");
516 puts("\t----\t------------------\n");
517 env_flags_print_vartypes();
520 /* Print the available variable access types */
521 printf("Available variable access flags (position %d):\n",
522 ENV_FLAGS_VARACCESS_LOC);
523 puts("\tFlag\tVariable Access Name\n");
524 puts("\t----\t--------------------\n");
525 env_flags_print_varaccess();
528 /* Print the static flags that may exist */
529 puts("Static flags:\n");
530 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
532 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
534 env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
537 /* walk through each variable and print the flags if non-default */
538 puts("Active flags:\n");
539 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
541 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
543 hwalk_r(&env_htab, print_active_flags);
549 * Interactively edit an environment variable
551 #if defined(CONFIG_CMD_EDITENV)
552 static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
555 char buffer[CONFIG_SYS_CBSIZE];
559 return CMD_RET_USAGE;
561 /* Set read buffer to initial value or empty sting */
562 init_val = getenv(argv[1]);
564 sprintf(buffer, "%s", init_val);
568 if (readline_into_buffer("edit: ", buffer, 0) < 0)
571 return setenv(argv[1], buffer);
573 #endif /* CONFIG_CMD_EDITENV */
574 #endif /* CONFIG_SPL_BUILD */
577 * Look up variable from environment,
578 * return address of storage for that variable,
579 * or NULL if not found
581 char *getenv(const char *name)
583 if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
590 hsearch_r(e, FIND, &ep, &env_htab, 0);
592 return ep ? ep->data : NULL;
595 /* restricted capabilities before import */
596 if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
597 return (char *)(gd->env_buf);
603 * Look up variable from environment for restricted C runtime env.
605 int getenv_f(const char *name, char *buf, unsigned len)
609 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
612 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
613 if (nxt >= CONFIG_ENV_SIZE)
617 val = envmatch((uchar *)name, i);
621 /* found; copy out */
622 for (n = 0; n < len; ++n, ++buf) {
623 *buf = env_get_char(val++);
631 printf("env_buf [%d bytes] too small for value of \"%s\"\n",
641 * Decode the integer value of an environment variable and return it.
643 * @param name Name of environemnt variable
644 * @param base Number base to use (normally 10, or 16 for hex)
645 * @param default_val Default value to return if the variable is not
647 * @return the decoded value, or default_val if not found
649 ulong getenv_ulong(const char *name, int base, ulong default_val)
652 * We can use getenv() here, even before relocation, since the
653 * environment variable value is an integer and thus short.
655 const char *str = getenv(name);
657 return str ? simple_strtoul(str, NULL, base) : default_val;
660 #ifndef CONFIG_SPL_BUILD
661 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
662 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
665 printf("Saving Environment to %s...\n", env_name_spec);
667 return saveenv() ? 1 : 0;
671 saveenv, 1, 0, do_env_save,
672 "save environment variables to persistent storage",
676 #endif /* CONFIG_SPL_BUILD */
680 * Match a name / name=value pair
682 * s1 is either a simple 'name', or a 'name=value' pair.
683 * i2 is the environment index for a 'name2=value2' pair.
684 * If the names match, return the index for the value2, else -1.
686 int envmatch(uchar *s1, int i2)
691 while (*s1 == env_get_char(i2++))
695 if (*s1 == '\0' && env_get_char(i2-1) == '=')
701 #ifndef CONFIG_SPL_BUILD
702 static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
703 int argc, char * const argv[])
705 int all = 0, flag = 0;
707 debug("Initial value for argc=%d\n", argc);
708 while (--argc > 0 && **++argv == '-') {
713 case 'a': /* default all */
716 case 'f': /* force */
720 return cmd_usage(cmdtp);
724 debug("Final value for argc=%d\n", argc);
725 if (all && (argc == 0)) {
726 /* Reset the whole environment */
727 set_default_env("## Resetting to default environment\n");
730 if (!all && (argc > 0)) {
731 /* Reset individual variables */
732 set_default_vars(argc, argv);
736 return cmd_usage(cmdtp);
739 static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
740 int argc, char * const argv[])
742 int env_flag = H_INTERACTIVE;
745 debug("Initial value for argc=%d\n", argc);
746 while (argc > 1 && **(argv + 1) == '-') {
752 case 'f': /* force */
756 return CMD_RET_USAGE;
760 debug("Final value for argc=%d\n", argc);
765 char *name = *++argv;
767 if (!hdelete_r(name, &env_htab, env_flag))
774 #ifdef CONFIG_CMD_EXPORTENV
776 * env export [-t | -b | -c] [-s size] addr [var ...]
777 * -t: export as text format; if size is given, data will be
778 * padded with '\0' bytes; if not, one terminating '\0'
779 * will be added (which is included in the "filesize"
780 * setting so you can for exmple copy this to flash and
781 * keep the termination).
782 * -b: export as binary format (name=value pairs separated by
783 * '\0', list end marked by double "\0\0")
784 * -c: export as checksum protected environment format as
785 * used for example by "saveenv" command
787 * size of output buffer
788 * addr: memory address where environment gets stored
789 * var... List of variable names that get included into the
790 * export. Without arguments, the whole environment gets
793 * With "-c" and size is NOT given, then the export command will
794 * format the data as currently used for the persistent storage,
795 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
796 * prepend a valid CRC32 checksum and, in case of resundant
797 * environment, a "current" redundancy flag. If size is given, this
798 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
799 * checksum and redundancy flag will be inserted.
801 * With "-b" and "-t", always only the real data (including a
802 * terminating '\0' byte) will be written; here the optional size
803 * argument will be used to make sure not to overflow the user
804 * provided buffer; the command will abort if the size is not
805 * sufficient. Any remainign space will be '\0' padded.
807 * On successful return, the variable "filesize" will be set.
808 * Note that filesize includes the trailing/terminating '\0' byte(s).
810 * Usage szenario: create a text snapshot/backup of the current settings:
812 * => env export -t 100000
813 * => era ${backup_addr} +${filesize}
814 * => cp.b 100000 ${backup_addr} ${filesize}
816 * Re-import this snapshot, deleting all other settings:
818 * => env import -d -t ${backup_addr}
820 static int do_env_export(cmd_tbl_t *cmdtp, int flag,
821 int argc, char * const argv[])
824 char *addr, *cmd, *res;
834 while (--argc > 0 && **++argv == '-') {
838 case 'b': /* raw binary format */
843 case 'c': /* external checksum format */
849 case 's': /* size given */
851 return cmd_usage(cmdtp);
852 size = simple_strtoul(*++argv, NULL, 16);
854 case 't': /* text format */
860 return CMD_RET_USAGE;
867 return CMD_RET_USAGE;
869 addr = (char *)simple_strtoul(argv[0], NULL, 16);
872 memset(addr, '\0', size);
877 if (sep) { /* export as text file */
878 len = hexport_r(&env_htab, sep, 0, &addr, size, argc, argv);
880 error("Cannot export environment: errno = %d\n", errno);
883 sprintf(buf, "%zX", (size_t)len);
884 setenv("filesize", buf);
889 envp = (env_t *)addr;
891 if (chk) /* export as checksum protected block */
892 res = (char *)envp->data;
893 else /* export as raw binary data */
896 len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, argc, argv);
898 error("Cannot export environment: errno = %d\n", errno);
903 envp->crc = crc32(0, envp->data, ENV_SIZE);
904 #ifdef CONFIG_ENV_ADDR_REDUND
905 envp->flags = ACTIVE_FLAG;
908 setenv_hex("filesize", len + offsetof(env_t, data));
913 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
918 #ifdef CONFIG_CMD_IMPORTENV
920 * env import [-d] [-t | -b | -c] addr [size]
921 * -d: delete existing environment before importing;
922 * otherwise overwrite / append to existion definitions
923 * -t: assume text format; either "size" must be given or the
924 * text data must be '\0' terminated
925 * -b: assume binary format ('\0' separated, "\0\0" terminated)
926 * -c: assume checksum protected environment format
927 * addr: memory address to read from
928 * size: length of input data; if missing, proper '\0'
929 * termination is mandatory
931 static int do_env_import(cmd_tbl_t *cmdtp, int flag,
932 int argc, char * const argv[])
943 while (--argc > 0 && **++argv == '-') {
947 case 'b': /* raw binary format */
952 case 'c': /* external checksum format */
958 case 't': /* text format */
967 return CMD_RET_USAGE;
973 return CMD_RET_USAGE;
976 printf("## Warning: defaulting to text format\n");
978 addr = (char *)simple_strtoul(argv[0], NULL, 16);
981 size = simple_strtoul(argv[1], NULL, 16);
987 while (size < MAX_ENV_SIZE) {
988 if ((*s == sep) && (*(s+1) == '\0'))
993 if (size == MAX_ENV_SIZE) {
994 printf("## Warning: Input data exceeds %d bytes"
995 " - truncated\n", MAX_ENV_SIZE);
998 printf("## Info: input data size = %zu = 0x%zX\n", size, size);
1003 env_t *ep = (env_t *)addr;
1005 size -= offsetof(env_t, data);
1006 memcpy(&crc, &ep->crc, sizeof(crc));
1008 if (crc32(0, ep->data, size) != crc) {
1009 puts("## Error: bad CRC, import failed\n");
1012 addr = (char *)ep->data;
1015 if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
1017 error("Environment import failed: errno = %d\n", errno);
1020 gd->flags |= GD_FLG_ENV_READY;
1025 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
1032 * New command line interface: "env" command with subcommands
1034 static cmd_tbl_t cmd_env_sub[] = {
1035 #if defined(CONFIG_CMD_ASKENV)
1036 U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
1038 U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
1039 U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
1040 #if defined(CONFIG_CMD_EDITENV)
1041 U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
1043 #if defined(CONFIG_CMD_ENV_CALLBACK)
1044 U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
1046 #if defined(CONFIG_CMD_ENV_FLAGS)
1047 U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
1049 #if defined(CONFIG_CMD_EXPORTENV)
1050 U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
1052 #if defined(CONFIG_CMD_GREPENV)
1053 U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
1055 #if defined(CONFIG_CMD_IMPORTENV)
1056 U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
1058 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
1059 #if defined(CONFIG_CMD_RUN)
1060 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
1062 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1063 U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
1065 U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
1068 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
1069 void env_reloc(void)
1071 fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1075 static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1080 return CMD_RET_USAGE;
1082 /* drop initial "env" arg */
1086 cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1089 return cp->cmd(cmdtp, flag, argc, argv);
1091 return CMD_RET_USAGE;
1094 #ifdef CONFIG_SYS_LONGHELP
1095 static char env_help_text[] =
1096 #if defined(CONFIG_CMD_ASKENV)
1097 "ask name [message] [size] - ask for environment variable\nenv "
1099 #if defined(CONFIG_CMD_ENV_CALLBACK)
1100 "callbacks - print callbacks and their associated variables\nenv "
1102 "default [-f] -a - [forcibly] reset default environment\n"
1103 "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
1104 "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
1105 #if defined(CONFIG_CMD_EDITENV)
1106 "env edit name - edit environment variable\n"
1108 #if defined(CONFIG_CMD_EXPORTENV)
1109 "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
1111 #if defined(CONFIG_CMD_ENV_FLAGS)
1112 "env flags - print variables that have non-default flags\n"
1114 #if defined(CONFIG_CMD_GREPENV)
1115 "env grep string [...] - search environment\n"
1117 #if defined(CONFIG_CMD_IMPORTENV)
1118 "env import [-d] [-t | -b | -c] addr [size] - import environment\n"
1120 "env print [-a | name ...] - print environment\n"
1121 #if defined(CONFIG_CMD_RUN)
1122 "env run var [...] - run commands in an environment variable\n"
1124 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1125 "env save - save environment\n"
1127 "env set [-f] name [arg ...]\n";
1131 env, CONFIG_SYS_MAXARGS, 1, do_env,
1132 "environment handling commands", env_help_text
1136 * Old command line interface, kept for compatibility
1139 #if defined(CONFIG_CMD_EDITENV)
1140 U_BOOT_CMD_COMPLETE(
1141 editenv, 2, 0, do_env_edit,
1142 "edit environment variable",
1144 " - edit environment variable 'name'",
1149 U_BOOT_CMD_COMPLETE(
1150 printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
1151 "print environment variables",
1152 "[-a]\n - print [all] values of all environment variables\n"
1153 "printenv name ...\n"
1154 " - print value of environment variable 'name'",
1158 #ifdef CONFIG_CMD_GREPENV
1159 U_BOOT_CMD_COMPLETE(
1160 grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
1161 "search environment variables",
1163 " - list environment name=value pairs matching 'string'",
1168 U_BOOT_CMD_COMPLETE(
1169 setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
1170 "set environment variables",
1171 "[-f] name value ...\n"
1172 " - [forcibly] set environment variable 'name' to 'value ...'\n"
1173 "setenv [-f] name\n"
1174 " - [forcibly] delete environment variable 'name'",
1178 #if defined(CONFIG_CMD_ASKENV)
1181 askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask,
1182 "get environment variables from stdin",
1183 "name [message] [size]\n"
1184 " - get environment variable 'name' from stdin (max 'size' chars)"
1188 #if defined(CONFIG_CMD_RUN)
1189 U_BOOT_CMD_COMPLETE(
1190 run, CONFIG_SYS_MAXARGS, 1, do_run,
1191 "run commands in an environment variable",
1193 " - run the commands in the environment variable(s) 'var'",
1197 #endif /* CONFIG_SPL_BUILD */