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 */
126 static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
131 int env_flag = H_HIDE_DOT;
133 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
136 env_flag &= ~H_HIDE_DOT;
140 /* print all env vars */
141 rcode = env_print(NULL, env_flag);
144 printf("\nEnvironment size: %d/%ld bytes\n",
145 rcode, (ulong)ENV_SIZE);
149 /* print selected env vars */
150 env_flag &= ~H_HIDE_DOT;
151 for (i = 1; i < argc; ++i) {
152 int rc = env_print(argv[i], env_flag);
154 printf("## Error: \"%s\" not defined\n", argv[i]);
162 #ifdef CONFIG_CMD_GREPENV
163 static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
164 int argc, char * const argv[])
167 unsigned char matched[env_htab.size / 8];
168 int rcode = 1, arg = 1, idx;
171 return CMD_RET_USAGE;
173 memset(matched, 0, env_htab.size / 8);
175 while (arg <= argc) {
177 while ((idx = hstrstr_r(argv[arg], idx, &match, &env_htab))) {
178 if (!(matched[idx / 8] & (1 << (idx & 7)))) {
184 matched[idx / 8] |= 1 << (idx & 7);
193 #endif /* CONFIG_SPL_BUILD */
196 * Set a new environment variable,
197 * or replace or delete an existing one.
199 static int _do_env_set(int flag, int argc, char * const argv[])
202 char *name, *value, *s;
204 int env_flag = H_INTERACTIVE;
206 debug("Initial value for argc=%d\n", argc);
207 while (argc > 1 && **(argv + 1) == '-') {
213 case 'f': /* force */
217 return CMD_RET_USAGE;
221 debug("Final value for argc=%d\n", argc);
225 if (strchr(name, '=')) {
226 printf("## Error: illegal character '='"
227 "in variable name \"%s\"\n", name);
234 if (argc < 3 || argv[2] == NULL) {
235 int rc = hdelete_r(name, &env_htab, env_flag);
240 * Insert / replace new value
242 for (i = 2, len = 0; i < argc; ++i)
243 len += strlen(argv[i]) + 1;
247 printf("## Can't malloc %d bytes\n", len);
250 for (i = 2, s = value; i < argc; ++i) {
253 while ((*s++ = *v++) != '\0')
262 hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
265 printf("## Error inserting \"%s\" variable, errno=%d\n",
273 int setenv(const char *varname, const char *varvalue)
275 const char * const argv[4] = { "setenv", varname, varvalue, NULL };
277 /* before import into hashtable */
278 if (!(gd->flags & GD_FLG_ENV_READY))
281 if (varvalue == NULL || varvalue[0] == '\0')
282 return _do_env_set(0, 2, (char * const *)argv);
284 return _do_env_set(0, 3, (char * const *)argv);
288 * Set an environment variable to an integer value
290 * @param varname Environmet variable to set
291 * @param value Value to set it to
292 * @return 0 if ok, 1 on error
294 int setenv_ulong(const char *varname, ulong value)
296 /* TODO: this should be unsigned */
297 char *str = simple_itoa(value);
299 return setenv(varname, str);
303 * Set an environment variable to an value in hex
305 * @param varname Environmet variable to set
306 * @param value Value to set it to
307 * @return 0 if ok, 1 on error
309 int setenv_hex(const char *varname, ulong value)
313 sprintf(str, "%lx", value);
314 return setenv(varname, str);
317 #ifndef CONFIG_SPL_BUILD
318 static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
321 return CMD_RET_USAGE;
323 return _do_env_set(flag, argc, argv);
327 * Prompt for environment variable
329 #if defined(CONFIG_CMD_ASKENV)
330 int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
332 char message[CONFIG_SYS_CBSIZE];
333 int i, len, pos, size;
337 local_args[0] = argv[0];
338 local_args[1] = argv[1];
339 local_args[2] = NULL;
340 local_args[3] = NULL;
345 * env_ask envname [message1 ...] [size]
348 return CMD_RET_USAGE;
351 * We test the last argument if it can be converted
352 * into a decimal number. If yes, we assume it's
353 * the size. Otherwise we echo it as part of the
356 i = simple_strtoul(argv[argc - 1], &endptr, 10);
357 if (*endptr != '\0') { /* no size */
358 size = CONFIG_SYS_CBSIZE - 1;
359 } else { /* size given */
365 sprintf(message, "Please enter '%s': ", argv[1]);
367 /* env_ask envname message1 ... messagen [size] */
368 for (i = 2, pos = 0; i < argc; i++) {
370 message[pos++] = ' ';
372 strcpy(message + pos, argv[i]);
373 pos += strlen(argv[i]);
375 message[pos++] = ' ';
379 if (size >= CONFIG_SYS_CBSIZE)
380 size = CONFIG_SYS_CBSIZE - 1;
385 /* prompt for input */
386 len = readline(message);
389 console_buffer[size] = '\0';
392 if (console_buffer[0] != '\0') {
393 local_args[2] = console_buffer;
397 /* Continue calling setenv code */
398 return _do_env_set(flag, len, local_args);
402 #if defined(CONFIG_CMD_ENV_CALLBACK)
403 static int print_static_binding(const char *var_name, const char *callback_name)
405 printf("\t%-20s %-20s\n", var_name, callback_name);
410 static int print_active_callback(ENTRY *entry)
412 struct env_clbk_tbl *clbkp;
416 if (entry->callback == NULL)
419 /* look up the callback in the linker-list */
420 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
421 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
424 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
425 if (entry->callback == clbkp->callback + gd->reloc_off)
427 if (entry->callback == clbkp->callback)
432 if (i == num_callbacks)
433 /* this should probably never happen, but just in case... */
434 printf("\t%-20s %p\n", entry->key, entry->callback);
436 printf("\t%-20s %-20s\n", entry->key, clbkp->name);
442 * Print the callbacks available and what they are bound to
444 int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
446 struct env_clbk_tbl *clbkp;
450 /* Print the available callbacks */
451 puts("Available callbacks:\n");
452 puts("\tCallback Name\n");
453 puts("\t-------------\n");
454 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
455 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
458 printf("\t%s\n", clbkp->name);
461 /* Print the static bindings that may exist */
462 puts("Static callback bindings:\n");
463 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
464 printf("\t%-20s %-20s\n", "-------------", "-------------");
465 env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
468 /* walk through each variable and print the callback if it has one */
469 puts("Active callback bindings:\n");
470 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
471 printf("\t%-20s %-20s\n", "-------------", "-------------");
472 hwalk_r(&env_htab, print_active_callback);
477 #if defined(CONFIG_CMD_ENV_FLAGS)
478 static int print_static_flags(const char *var_name, const char *flags)
480 enum env_flags_vartype type = env_flags_parse_vartype(flags);
481 enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
483 printf("\t%-20s %-20s %-20s\n", var_name,
484 env_flags_get_vartype_name(type),
485 env_flags_get_varaccess_name(access));
490 static int print_active_flags(ENTRY *entry)
492 enum env_flags_vartype type;
493 enum env_flags_varaccess access;
495 if (entry->flags == 0)
498 type = (enum env_flags_vartype)
499 (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
500 access = env_flags_parse_varaccess_from_binflags(entry->flags);
501 printf("\t%-20s %-20s %-20s\n", entry->key,
502 env_flags_get_vartype_name(type),
503 env_flags_get_varaccess_name(access));
509 * Print the flags available and what variables have flags
511 int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
513 /* Print the available variable types */
514 printf("Available variable type flags (position %d):\n",
515 ENV_FLAGS_VARTYPE_LOC);
516 puts("\tFlag\tVariable Type Name\n");
517 puts("\t----\t------------------\n");
518 env_flags_print_vartypes();
521 /* Print the available variable access types */
522 printf("Available variable access flags (position %d):\n",
523 ENV_FLAGS_VARACCESS_LOC);
524 puts("\tFlag\tVariable Access Name\n");
525 puts("\t----\t--------------------\n");
526 env_flags_print_varaccess();
529 /* Print the static flags that may exist */
530 puts("Static flags:\n");
531 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
533 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
535 env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
538 /* walk through each variable and print the flags if non-default */
539 puts("Active flags:\n");
540 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
542 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
544 hwalk_r(&env_htab, print_active_flags);
550 * Interactively edit an environment variable
552 #if defined(CONFIG_CMD_EDITENV)
553 static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
556 char buffer[CONFIG_SYS_CBSIZE];
560 return CMD_RET_USAGE;
562 /* Set read buffer to initial value or empty sting */
563 init_val = getenv(argv[1]);
565 sprintf(buffer, "%s", init_val);
569 if (readline_into_buffer("edit: ", buffer, 0) < 0)
572 return setenv(argv[1], buffer);
574 #endif /* CONFIG_CMD_EDITENV */
575 #endif /* CONFIG_SPL_BUILD */
578 * Look up variable from environment,
579 * return address of storage for that variable,
580 * or NULL if not found
582 char *getenv(const char *name)
584 if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
591 hsearch_r(e, FIND, &ep, &env_htab, 0);
593 return ep ? ep->data : NULL;
596 /* restricted capabilities before import */
597 if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
598 return (char *)(gd->env_buf);
604 * Look up variable from environment for restricted C runtime env.
606 int getenv_f(const char *name, char *buf, unsigned len)
610 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
613 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
614 if (nxt >= CONFIG_ENV_SIZE)
618 val = envmatch((uchar *)name, i);
622 /* found; copy out */
623 for (n = 0; n < len; ++n, ++buf) {
624 *buf = env_get_char(val++);
632 printf("env_buf [%d bytes] too small for value of \"%s\"\n",
642 * Decode the integer value of an environment variable and return it.
644 * @param name Name of environemnt variable
645 * @param base Number base to use (normally 10, or 16 for hex)
646 * @param default_val Default value to return if the variable is not
648 * @return the decoded value, or default_val if not found
650 ulong getenv_ulong(const char *name, int base, ulong default_val)
653 * We can use getenv() here, even before relocation, since the
654 * environment variable value is an integer and thus short.
656 const char *str = getenv(name);
658 return str ? simple_strtoul(str, NULL, base) : default_val;
661 #ifndef CONFIG_SPL_BUILD
662 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
663 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
666 printf("Saving Environment to %s...\n", env_name_spec);
668 return saveenv() ? 1 : 0;
672 saveenv, 1, 0, do_env_save,
673 "save environment variables to persistent storage",
677 #endif /* CONFIG_SPL_BUILD */
681 * Match a name / name=value pair
683 * s1 is either a simple 'name', or a 'name=value' pair.
684 * i2 is the environment index for a 'name2=value2' pair.
685 * If the names match, return the index for the value2, else -1.
687 int envmatch(uchar *s1, int i2)
692 while (*s1 == env_get_char(i2++))
696 if (*s1 == '\0' && env_get_char(i2-1) == '=')
702 #ifndef CONFIG_SPL_BUILD
703 static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
704 int argc, char * const argv[])
706 int all = 0, flag = 0;
708 debug("Initial value for argc=%d\n", argc);
709 while (--argc > 0 && **++argv == '-') {
714 case 'a': /* default all */
717 case 'f': /* force */
721 return cmd_usage(cmdtp);
725 debug("Final value for argc=%d\n", argc);
726 if (all && (argc == 0)) {
727 /* Reset the whole environment */
728 set_default_env("## Resetting to default environment\n");
731 if (!all && (argc > 0)) {
732 /* Reset individual variables */
733 set_default_vars(argc, argv);
737 return cmd_usage(cmdtp);
740 static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
741 int argc, char * const argv[])
743 int env_flag = H_INTERACTIVE;
746 debug("Initial value for argc=%d\n", argc);
747 while (argc > 1 && **(argv + 1) == '-') {
753 case 'f': /* force */
757 return CMD_RET_USAGE;
761 debug("Final value for argc=%d\n", argc);
766 char *name = *++argv;
768 if (!hdelete_r(name, &env_htab, env_flag))
775 #ifdef CONFIG_CMD_EXPORTENV
777 * env export [-t | -b | -c] [-s size] addr [var ...]
778 * -t: export as text format; if size is given, data will be
779 * padded with '\0' bytes; if not, one terminating '\0'
780 * will be added (which is included in the "filesize"
781 * setting so you can for exmple copy this to flash and
782 * keep the termination).
783 * -b: export as binary format (name=value pairs separated by
784 * '\0', list end marked by double "\0\0")
785 * -c: export as checksum protected environment format as
786 * used for example by "saveenv" command
788 * size of output buffer
789 * addr: memory address where environment gets stored
790 * var... List of variable names that get included into the
791 * export. Without arguments, the whole environment gets
794 * With "-c" and size is NOT given, then the export command will
795 * format the data as currently used for the persistent storage,
796 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
797 * prepend a valid CRC32 checksum and, in case of resundant
798 * environment, a "current" redundancy flag. If size is given, this
799 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
800 * checksum and redundancy flag will be inserted.
802 * With "-b" and "-t", always only the real data (including a
803 * terminating '\0' byte) will be written; here the optional size
804 * argument will be used to make sure not to overflow the user
805 * provided buffer; the command will abort if the size is not
806 * sufficient. Any remainign space will be '\0' padded.
808 * On successful return, the variable "filesize" will be set.
809 * Note that filesize includes the trailing/terminating '\0' byte(s).
811 * Usage szenario: create a text snapshot/backup of the current settings:
813 * => env export -t 100000
814 * => era ${backup_addr} +${filesize}
815 * => cp.b 100000 ${backup_addr} ${filesize}
817 * Re-import this snapshot, deleting all other settings:
819 * => env import -d -t ${backup_addr}
821 static int do_env_export(cmd_tbl_t *cmdtp, int flag,
822 int argc, char * const argv[])
825 char *addr, *cmd, *res;
835 while (--argc > 0 && **++argv == '-') {
839 case 'b': /* raw binary format */
844 case 'c': /* external checksum format */
850 case 's': /* size given */
852 return cmd_usage(cmdtp);
853 size = simple_strtoul(*++argv, NULL, 16);
855 case 't': /* text format */
861 return CMD_RET_USAGE;
868 return CMD_RET_USAGE;
870 addr = (char *)simple_strtoul(argv[0], NULL, 16);
873 memset(addr, '\0', size);
878 if (sep) { /* export as text file */
879 len = hexport_r(&env_htab, sep, 0, &addr, size, argc, argv);
881 error("Cannot export environment: errno = %d\n", errno);
884 sprintf(buf, "%zX", (size_t)len);
885 setenv("filesize", buf);
890 envp = (env_t *)addr;
892 if (chk) /* export as checksum protected block */
893 res = (char *)envp->data;
894 else /* export as raw binary data */
897 len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, argc, argv);
899 error("Cannot export environment: errno = %d\n", errno);
904 envp->crc = crc32(0, envp->data, ENV_SIZE);
905 #ifdef CONFIG_ENV_ADDR_REDUND
906 envp->flags = ACTIVE_FLAG;
909 setenv_hex("filesize", len + offsetof(env_t, data));
914 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
919 #ifdef CONFIG_CMD_IMPORTENV
921 * env import [-d] [-t | -b | -c] addr [size]
922 * -d: delete existing environment before importing;
923 * otherwise overwrite / append to existion definitions
924 * -t: assume text format; either "size" must be given or the
925 * text data must be '\0' terminated
926 * -b: assume binary format ('\0' separated, "\0\0" terminated)
927 * -c: assume checksum protected environment format
928 * addr: memory address to read from
929 * size: length of input data; if missing, proper '\0'
930 * termination is mandatory
932 static int do_env_import(cmd_tbl_t *cmdtp, int flag,
933 int argc, char * const argv[])
944 while (--argc > 0 && **++argv == '-') {
948 case 'b': /* raw binary format */
953 case 'c': /* external checksum format */
959 case 't': /* text format */
968 return CMD_RET_USAGE;
974 return CMD_RET_USAGE;
977 printf("## Warning: defaulting to text format\n");
979 addr = (char *)simple_strtoul(argv[0], NULL, 16);
982 size = simple_strtoul(argv[1], NULL, 16);
988 while (size < MAX_ENV_SIZE) {
989 if ((*s == sep) && (*(s+1) == '\0'))
994 if (size == MAX_ENV_SIZE) {
995 printf("## Warning: Input data exceeds %d bytes"
996 " - truncated\n", MAX_ENV_SIZE);
999 printf("## Info: input data size = %zu = 0x%zX\n", size, size);
1004 env_t *ep = (env_t *)addr;
1006 size -= offsetof(env_t, data);
1007 memcpy(&crc, &ep->crc, sizeof(crc));
1009 if (crc32(0, ep->data, size) != crc) {
1010 puts("## Error: bad CRC, import failed\n");
1013 addr = (char *)ep->data;
1016 if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
1018 error("Environment import failed: errno = %d\n", errno);
1021 gd->flags |= GD_FLG_ENV_READY;
1026 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
1033 * New command line interface: "env" command with subcommands
1035 static cmd_tbl_t cmd_env_sub[] = {
1036 #if defined(CONFIG_CMD_ASKENV)
1037 U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
1039 U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
1040 U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
1041 #if defined(CONFIG_CMD_EDITENV)
1042 U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
1044 #if defined(CONFIG_CMD_ENV_CALLBACK)
1045 U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
1047 #if defined(CONFIG_CMD_ENV_FLAGS)
1048 U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
1050 #if defined(CONFIG_CMD_EXPORTENV)
1051 U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
1053 #if defined(CONFIG_CMD_GREPENV)
1054 U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
1056 #if defined(CONFIG_CMD_IMPORTENV)
1057 U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
1059 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
1060 #if defined(CONFIG_CMD_RUN)
1061 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
1063 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1064 U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
1066 U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
1069 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
1070 void env_reloc(void)
1072 fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1076 static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1081 return CMD_RET_USAGE;
1083 /* drop initial "env" arg */
1087 cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1090 return cp->cmd(cmdtp, flag, argc, argv);
1092 return CMD_RET_USAGE;
1095 #ifdef CONFIG_SYS_LONGHELP
1096 static char env_help_text[] =
1097 #if defined(CONFIG_CMD_ASKENV)
1098 "ask name [message] [size] - ask for environment variable\nenv "
1100 #if defined(CONFIG_CMD_ENV_CALLBACK)
1101 "callbacks - print callbacks and their associated variables\nenv "
1103 "default [-f] -a - [forcibly] reset default environment\n"
1104 "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
1105 "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
1106 #if defined(CONFIG_CMD_EDITENV)
1107 "env edit name - edit environment variable\n"
1109 #if defined(CONFIG_CMD_EXPORTENV)
1110 "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
1112 #if defined(CONFIG_CMD_ENV_FLAGS)
1113 "env flags - print variables that have non-default flags\n"
1115 #if defined(CONFIG_CMD_GREPENV)
1116 "env grep string [...] - search environment\n"
1118 #if defined(CONFIG_CMD_IMPORTENV)
1119 "env import [-d] [-t | -b | -c] addr [size] - import environment\n"
1121 "env print [-a | name ...] - print environment\n"
1122 #if defined(CONFIG_CMD_RUN)
1123 "env run var [...] - run commands in an environment variable\n"
1125 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1126 "env save - save environment\n"
1128 "env set [-f] name [arg ...]\n";
1132 env, CONFIG_SYS_MAXARGS, 1, do_env,
1133 "environment handling commands", env_help_text
1137 * Old command line interface, kept for compatibility
1140 #if defined(CONFIG_CMD_EDITENV)
1141 U_BOOT_CMD_COMPLETE(
1142 editenv, 2, 0, do_env_edit,
1143 "edit environment variable",
1145 " - edit environment variable 'name'",
1150 U_BOOT_CMD_COMPLETE(
1151 printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
1152 "print environment variables",
1153 "[-a]\n - print [all] values of all environment variables\n"
1154 "printenv name ...\n"
1155 " - print value of environment variable 'name'",
1159 #ifdef CONFIG_CMD_GREPENV
1160 U_BOOT_CMD_COMPLETE(
1161 grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
1162 "search environment variables",
1164 " - list environment name=value pairs matching 'string'",
1169 U_BOOT_CMD_COMPLETE(
1170 setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
1171 "set environment variables",
1172 "[-f] name value ...\n"
1173 " - [forcibly] set environment variable 'name' to 'value ...'\n"
1174 "setenv [-f] name\n"
1175 " - [forcibly] delete environment variable 'name'",
1179 #if defined(CONFIG_CMD_ASKENV)
1182 askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask,
1183 "get environment variables from stdin",
1184 "name [message] [size]\n"
1185 " - get environment variable 'name' from stdin (max 'size' chars)"
1189 #if defined(CONFIG_CMD_RUN)
1190 U_BOOT_CMD_COMPLETE(
1191 run, CONFIG_SYS_MAXARGS, 1, do_run,
1192 "run commands in an environment variable",
1194 " - run the commands in the environment variable(s) 'var'",
1198 #endif /* CONFIG_SPL_BUILD */