2 * (C) Copyright 2000-2010
5 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
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 if (varvalue == NULL || varvalue[0] == '\0')
277 return _do_env_set(0, 2, (char * const *)argv);
279 return _do_env_set(0, 3, (char * const *)argv);
283 * Set an environment variable to an integer value
285 * @param varname Environmet variable to set
286 * @param value Value to set it to
287 * @return 0 if ok, 1 on error
289 int setenv_ulong(const char *varname, ulong value)
291 /* TODO: this should be unsigned */
292 char *str = simple_itoa(value);
294 return setenv(varname, str);
298 * Set an environment variable to an value in hex
300 * @param varname Environmet variable to set
301 * @param value Value to set it to
302 * @return 0 if ok, 1 on error
304 int setenv_hex(const char *varname, ulong value)
308 sprintf(str, "%lx", value);
309 return setenv(varname, str);
312 #ifndef CONFIG_SPL_BUILD
313 static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
316 return CMD_RET_USAGE;
318 return _do_env_set(flag, argc, argv);
322 * Prompt for environment variable
324 #if defined(CONFIG_CMD_ASKENV)
325 int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
327 char message[CONFIG_SYS_CBSIZE];
328 int size = CONFIG_SYS_CBSIZE - 1;
332 local_args[0] = argv[0];
333 local_args[1] = argv[1];
334 local_args[2] = NULL;
335 local_args[3] = NULL;
337 /* Check the syntax */
340 return CMD_RET_USAGE;
342 case 2: /* env_ask envname */
343 sprintf(message, "Please enter '%s':", argv[1]);
346 case 3: /* env_ask envname size */
347 sprintf(message, "Please enter '%s':", argv[1]);
348 size = simple_strtoul(argv[2], NULL, 10);
351 default: /* env_ask envname message1 ... messagen size */
352 for (i = 2, pos = 0; i < argc - 1; i++) {
354 message[pos++] = ' ';
356 strcpy(message + pos, argv[i]);
357 pos += strlen(argv[i]);
361 size = simple_strtoul(argv[argc - 1], NULL, 10);
365 if (size >= CONFIG_SYS_CBSIZE)
366 size = CONFIG_SYS_CBSIZE - 1;
371 /* prompt for input */
372 len = readline(message);
375 console_buffer[size] = '\0';
378 if (console_buffer[0] != '\0') {
379 local_args[2] = console_buffer;
383 /* Continue calling setenv code */
384 return _do_env_set(flag, len, local_args);
388 #if defined(CONFIG_CMD_ENV_CALLBACK)
389 static int print_static_binding(const char *var_name, const char *callback_name)
391 printf("\t%-20s %-20s\n", var_name, callback_name);
396 static int print_active_callback(ENTRY *entry)
398 struct env_clbk_tbl *clbkp;
402 if (entry->callback == NULL)
405 /* look up the callback in the linker-list */
406 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
407 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
410 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
411 if (entry->callback == clbkp->callback + gd->reloc_off)
413 if (entry->callback == clbkp->callback)
418 if (i == num_callbacks)
419 /* this should probably never happen, but just in case... */
420 printf("\t%-20s %p\n", entry->key, entry->callback);
422 printf("\t%-20s %-20s\n", entry->key, clbkp->name);
428 * Print the callbacks available and what they are bound to
430 int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
432 struct env_clbk_tbl *clbkp;
436 /* Print the available callbacks */
437 puts("Available callbacks:\n");
438 puts("\tCallback Name\n");
439 puts("\t-------------\n");
440 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
441 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
444 printf("\t%s\n", clbkp->name);
447 /* Print the static bindings that may exist */
448 puts("Static callback bindings:\n");
449 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
450 printf("\t%-20s %-20s\n", "-------------", "-------------");
451 env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
454 /* walk through each variable and print the callback if it has one */
455 puts("Active callback bindings:\n");
456 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
457 printf("\t%-20s %-20s\n", "-------------", "-------------");
458 hwalk_r(&env_htab, print_active_callback);
463 #if defined(CONFIG_CMD_ENV_FLAGS)
464 static int print_static_flags(const char *var_name, const char *flags)
466 enum env_flags_vartype type = env_flags_parse_vartype(flags);
467 enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
469 printf("\t%-20s %-20s %-20s\n", var_name,
470 env_flags_get_vartype_name(type),
471 env_flags_get_varaccess_name(access));
476 static int print_active_flags(ENTRY *entry)
478 enum env_flags_vartype type;
479 enum env_flags_varaccess access;
481 if (entry->flags == 0)
484 type = (enum env_flags_vartype)
485 (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
486 access = env_flags_parse_varaccess_from_binflags(entry->flags);
487 printf("\t%-20s %-20s %-20s\n", entry->key,
488 env_flags_get_vartype_name(type),
489 env_flags_get_varaccess_name(access));
495 * Print the flags available and what variables have flags
497 int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
499 /* Print the available variable types */
500 printf("Available variable type flags (position %d):\n",
501 ENV_FLAGS_VARTYPE_LOC);
502 puts("\tFlag\tVariable Type Name\n");
503 puts("\t----\t------------------\n");
504 env_flags_print_vartypes();
507 /* Print the available variable access types */
508 printf("Available variable access flags (position %d):\n",
509 ENV_FLAGS_VARACCESS_LOC);
510 puts("\tFlag\tVariable Access Name\n");
511 puts("\t----\t--------------------\n");
512 env_flags_print_varaccess();
515 /* Print the static flags that may exist */
516 puts("Static flags:\n");
517 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
519 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
521 env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
524 /* walk through each variable and print the flags if non-default */
525 puts("Active flags:\n");
526 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
528 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
530 hwalk_r(&env_htab, print_active_flags);
536 * Interactively edit an environment variable
538 #if defined(CONFIG_CMD_EDITENV)
539 static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
542 char buffer[CONFIG_SYS_CBSIZE];
546 return CMD_RET_USAGE;
548 /* Set read buffer to initial value or empty sting */
549 init_val = getenv(argv[1]);
551 sprintf(buffer, "%s", init_val);
555 if (readline_into_buffer("edit: ", buffer, 0) < 0)
558 return setenv(argv[1], buffer);
560 #endif /* CONFIG_CMD_EDITENV */
561 #endif /* CONFIG_SPL_BUILD */
564 * Look up variable from environment,
565 * return address of storage for that variable,
566 * or NULL if not found
568 char *getenv(const char *name)
570 if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
577 hsearch_r(e, FIND, &ep, &env_htab, 0);
579 return ep ? ep->data : NULL;
582 /* restricted capabilities before import */
583 if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
584 return (char *)(gd->env_buf);
590 * Look up variable from environment for restricted C runtime env.
592 int getenv_f(const char *name, char *buf, unsigned len)
596 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
599 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
600 if (nxt >= CONFIG_ENV_SIZE)
604 val = envmatch((uchar *)name, i);
608 /* found; copy out */
609 for (n = 0; n < len; ++n, ++buf) {
610 *buf = env_get_char(val++);
618 printf("env_buf [%d bytes] too small for value of \"%s\"\n",
628 * Decode the integer value of an environment variable and return it.
630 * @param name Name of environemnt variable
631 * @param base Number base to use (normally 10, or 16 for hex)
632 * @param default_val Default value to return if the variable is not
634 * @return the decoded value, or default_val if not found
636 ulong getenv_ulong(const char *name, int base, ulong default_val)
639 * We can use getenv() here, even before relocation, since the
640 * environment variable value is an integer and thus short.
642 const char *str = getenv(name);
644 return str ? simple_strtoul(str, NULL, base) : default_val;
647 #ifndef CONFIG_SPL_BUILD
648 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
649 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
652 printf("Saving Environment to %s...\n", env_name_spec);
654 return saveenv() ? 1 : 0;
658 saveenv, 1, 0, do_env_save,
659 "save environment variables to persistent storage",
663 #endif /* CONFIG_SPL_BUILD */
667 * Match a name / name=value pair
669 * s1 is either a simple 'name', or a 'name=value' pair.
670 * i2 is the environment index for a 'name2=value2' pair.
671 * If the names match, return the index for the value2, else -1.
673 int envmatch(uchar *s1, int i2)
678 while (*s1 == env_get_char(i2++))
682 if (*s1 == '\0' && env_get_char(i2-1) == '=')
688 #ifndef CONFIG_SPL_BUILD
689 static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
690 int argc, char * const argv[])
692 int all = 0, flag = 0;
694 debug("Initial value for argc=%d\n", argc);
695 while (--argc > 0 && **++argv == '-') {
700 case 'a': /* default all */
703 case 'f': /* force */
707 return cmd_usage(cmdtp);
711 debug("Final value for argc=%d\n", argc);
712 if (all && (argc == 0)) {
713 /* Reset the whole environment */
714 set_default_env("## Resetting to default environment\n");
717 if (!all && (argc > 0)) {
718 /* Reset individual variables */
719 set_default_vars(argc, argv);
723 return cmd_usage(cmdtp);
726 static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
727 int argc, char * const argv[])
729 int env_flag = H_INTERACTIVE;
732 debug("Initial value for argc=%d\n", argc);
733 while (argc > 1 && **(argv + 1) == '-') {
739 case 'f': /* force */
743 return CMD_RET_USAGE;
747 debug("Final value for argc=%d\n", argc);
752 char *name = *++argv;
754 if (!hdelete_r(name, &env_htab, env_flag))
761 #ifdef CONFIG_CMD_EXPORTENV
763 * env export [-t | -b | -c] [-s size] addr [var ...]
764 * -t: export as text format; if size is given, data will be
765 * padded with '\0' bytes; if not, one terminating '\0'
766 * will be added (which is included in the "filesize"
767 * setting so you can for exmple copy this to flash and
768 * keep the termination).
769 * -b: export as binary format (name=value pairs separated by
770 * '\0', list end marked by double "\0\0")
771 * -c: export as checksum protected environment format as
772 * used for example by "saveenv" command
774 * size of output buffer
775 * addr: memory address where environment gets stored
776 * var... List of variable names that get included into the
777 * export. Without arguments, the whole environment gets
780 * With "-c" and size is NOT given, then the export command will
781 * format the data as currently used for the persistent storage,
782 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
783 * prepend a valid CRC32 checksum and, in case of resundant
784 * environment, a "current" redundancy flag. If size is given, this
785 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
786 * checksum and redundancy flag will be inserted.
788 * With "-b" and "-t", always only the real data (including a
789 * terminating '\0' byte) will be written; here the optional size
790 * argument will be used to make sure not to overflow the user
791 * provided buffer; the command will abort if the size is not
792 * sufficient. Any remainign space will be '\0' padded.
794 * On successful return, the variable "filesize" will be set.
795 * Note that filesize includes the trailing/terminating '\0' byte(s).
797 * Usage szenario: create a text snapshot/backup of the current settings:
799 * => env export -t 100000
800 * => era ${backup_addr} +${filesize}
801 * => cp.b 100000 ${backup_addr} ${filesize}
803 * Re-import this snapshot, deleting all other settings:
805 * => env import -d -t ${backup_addr}
807 static int do_env_export(cmd_tbl_t *cmdtp, int flag,
808 int argc, char * const argv[])
811 char *addr, *cmd, *res;
821 while (--argc > 0 && **++argv == '-') {
825 case 'b': /* raw binary format */
830 case 'c': /* external checksum format */
836 case 's': /* size given */
838 return cmd_usage(cmdtp);
839 size = simple_strtoul(*++argv, NULL, 16);
841 case 't': /* text format */
847 return CMD_RET_USAGE;
854 return CMD_RET_USAGE;
856 addr = (char *)simple_strtoul(argv[0], NULL, 16);
859 memset(addr, '\0', size);
864 if (sep) { /* export as text file */
865 len = hexport_r(&env_htab, sep, 0, &addr, size, argc, argv);
867 error("Cannot export environment: errno = %d\n", errno);
870 sprintf(buf, "%zX", (size_t)len);
871 setenv("filesize", buf);
876 envp = (env_t *)addr;
878 if (chk) /* export as checksum protected block */
879 res = (char *)envp->data;
880 else /* export as raw binary data */
883 len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, argc, argv);
885 error("Cannot export environment: errno = %d\n", errno);
890 envp->crc = crc32(0, envp->data, ENV_SIZE);
891 #ifdef CONFIG_ENV_ADDR_REDUND
892 envp->flags = ACTIVE_FLAG;
895 setenv_hex("filesize", len + offsetof(env_t, data));
900 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
905 #ifdef CONFIG_CMD_IMPORTENV
907 * env import [-d] [-t | -b | -c] addr [size]
908 * -d: delete existing environment before importing;
909 * otherwise overwrite / append to existion definitions
910 * -t: assume text format; either "size" must be given or the
911 * text data must be '\0' terminated
912 * -b: assume binary format ('\0' separated, "\0\0" terminated)
913 * -c: assume checksum protected environment format
914 * addr: memory address to read from
915 * size: length of input data; if missing, proper '\0'
916 * termination is mandatory
918 static int do_env_import(cmd_tbl_t *cmdtp, int flag,
919 int argc, char * const argv[])
930 while (--argc > 0 && **++argv == '-') {
934 case 'b': /* raw binary format */
939 case 'c': /* external checksum format */
945 case 't': /* text format */
954 return CMD_RET_USAGE;
960 return CMD_RET_USAGE;
963 printf("## Warning: defaulting to text format\n");
965 addr = (char *)simple_strtoul(argv[0], NULL, 16);
968 size = simple_strtoul(argv[1], NULL, 16);
974 while (size < MAX_ENV_SIZE) {
975 if ((*s == sep) && (*(s+1) == '\0'))
980 if (size == MAX_ENV_SIZE) {
981 printf("## Warning: Input data exceeds %d bytes"
982 " - truncated\n", MAX_ENV_SIZE);
985 printf("## Info: input data size = %zu = 0x%zX\n", size, size);
990 env_t *ep = (env_t *)addr;
992 size -= offsetof(env_t, data);
993 memcpy(&crc, &ep->crc, sizeof(crc));
995 if (crc32(0, ep->data, size) != crc) {
996 puts("## Error: bad CRC, import failed\n");
999 addr = (char *)ep->data;
1002 if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
1004 error("Environment import failed: errno = %d\n", errno);
1007 gd->flags |= GD_FLG_ENV_READY;
1012 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
1019 * New command line interface: "env" command with subcommands
1021 static cmd_tbl_t cmd_env_sub[] = {
1022 #if defined(CONFIG_CMD_ASKENV)
1023 U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
1025 U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
1026 U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
1027 #if defined(CONFIG_CMD_EDITENV)
1028 U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
1030 #if defined(CONFIG_CMD_ENV_CALLBACK)
1031 U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
1033 #if defined(CONFIG_CMD_ENV_FLAGS)
1034 U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
1036 #if defined(CONFIG_CMD_EXPORTENV)
1037 U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
1039 #if defined(CONFIG_CMD_GREPENV)
1040 U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
1042 #if defined(CONFIG_CMD_IMPORTENV)
1043 U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
1045 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
1046 #if defined(CONFIG_CMD_RUN)
1047 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
1049 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1050 U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
1052 U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
1055 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
1056 void env_reloc(void)
1058 fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1062 static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1067 return CMD_RET_USAGE;
1069 /* drop initial "env" arg */
1073 cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1076 return cp->cmd(cmdtp, flag, argc, argv);
1078 return CMD_RET_USAGE;
1081 #ifdef CONFIG_SYS_LONGHELP
1082 static char env_help_text[] =
1083 #if defined(CONFIG_CMD_ASKENV)
1084 "ask name [message] [size] - ask for environment variable\nenv "
1086 #if defined(CONFIG_CMD_ENV_CALLBACK)
1087 "callbacks - print callbacks and their associated variables\nenv "
1089 "default [-f] -a - [forcibly] reset default environment\n"
1090 "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
1091 "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
1092 #if defined(CONFIG_CMD_EDITENV)
1093 "env edit name - edit environment variable\n"
1095 #if defined(CONFIG_CMD_EXPORTENV)
1096 "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
1098 #if defined(CONFIG_CMD_ENV_FLAGS)
1099 "env flags - print variables that have non-default flags\n"
1101 #if defined(CONFIG_CMD_GREPENV)
1102 "env grep string [...] - search environment\n"
1104 #if defined(CONFIG_CMD_IMPORTENV)
1105 "env import [-d] [-t | -b | -c] addr [size] - import environment\n"
1107 "env print [-a | name ...] - print environment\n"
1108 #if defined(CONFIG_CMD_RUN)
1109 "env run var [...] - run commands in an environment variable\n"
1111 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1112 "env save - save environment\n"
1114 "env set [-f] name [arg ...]\n";
1118 env, CONFIG_SYS_MAXARGS, 1, do_env,
1119 "environment handling commands", env_help_text
1123 * Old command line interface, kept for compatibility
1126 #if defined(CONFIG_CMD_EDITENV)
1127 U_BOOT_CMD_COMPLETE(
1128 editenv, 2, 0, do_env_edit,
1129 "edit environment variable",
1131 " - edit environment variable 'name'",
1136 U_BOOT_CMD_COMPLETE(
1137 printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
1138 "print environment variables",
1139 "[-a]\n - print [all] values of all environment variables\n"
1140 "printenv name ...\n"
1141 " - print value of environment variable 'name'",
1145 #ifdef CONFIG_CMD_GREPENV
1146 U_BOOT_CMD_COMPLETE(
1147 grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
1148 "search environment variables",
1150 " - list environment name=value pairs matching 'string'",
1155 U_BOOT_CMD_COMPLETE(
1156 setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
1157 "set environment variables",
1158 "[-f] name value ...\n"
1159 " - [forcibly] set environment variable 'name' to 'value ...'\n"
1160 "setenv [-f] name\n"
1161 " - [forcibly] delete environment variable 'name'",
1165 #if defined(CONFIG_CMD_ASKENV)
1168 askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask,
1169 "get environment variables from stdin",
1170 "name [message] [size]\n"
1171 " - get environment variable 'name' from stdin (max 'size' chars)\n"
1173 " - get environment variable 'name' from stdin\n"
1174 "askenv name size\n"
1175 " - get environment variable 'name' from stdin (max 'size' chars)\n"
1176 "askenv name [message] size\n"
1177 " - display 'message' string and get environment variable 'name'"
1178 "from stdin (max 'size' chars)"
1182 #if defined(CONFIG_CMD_RUN)
1183 U_BOOT_CMD_COMPLETE(
1184 run, CONFIG_SYS_MAXARGS, 1, do_run,
1185 "run commands in an environment variable",
1187 " - run the commands in the environment variable(s) 'var'",
1191 #endif /* CONFIG_SPL_BUILD */