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>
51 #include <linux/stddef.h>
52 #include <asm/byteorder.h>
54 DECLARE_GLOBAL_DATA_PTR;
56 #if !defined(CONFIG_ENV_IS_IN_EEPROM) && \
57 !defined(CONFIG_ENV_IS_IN_FLASH) && \
58 !defined(CONFIG_ENV_IS_IN_DATAFLASH) && \
59 !defined(CONFIG_ENV_IS_IN_MMC) && \
60 !defined(CONFIG_ENV_IS_IN_FAT) && \
61 !defined(CONFIG_ENV_IS_IN_NAND) && \
62 !defined(CONFIG_ENV_IS_IN_NVRAM) && \
63 !defined(CONFIG_ENV_IS_IN_ONENAND) && \
64 !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \
65 !defined(CONFIG_ENV_IS_IN_REMOTE) && \
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} or CONFIG_ENV_IS_NOWHERE
72 * Maximum expected input data size for import command
74 #define MAX_ENV_SIZE (1 << 20) /* 1 MiB */
76 ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
77 ulong save_addr; /* Default Save Address */
78 ulong save_size; /* Default Save Size (in bytes) */
81 * Table with supported baudrates (defined in config_xyz.h)
83 static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE;
84 #define N_BAUDRATES (sizeof(baudrate_table) / sizeof(baudrate_table[0]))
87 * This variable is incremented on each do_env_set(), so it can
88 * be used via get_env_id() as an indication, if the environment
89 * has changed or not. So it is possible to reread an environment
90 * variable only if the environment was changed ... done so for
91 * example in NetInitLoop()
93 static int env_id = 1;
100 #ifndef CONFIG_SPL_BUILD
102 * Command interface: print one or all environment variables
104 * Returns 0 in case of error, or length of printed string
106 static int env_print(char *name, int flag)
111 if (name) { /* print a single name */
116 hsearch_r(e, FIND, &ep, &env_htab, flag);
119 len = printf("%s=%s\n", ep->key, ep->data);
123 /* print whole list */
124 len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
132 /* should never happen */
136 static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
141 int env_flag = H_HIDE_DOT;
143 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
146 env_flag &= ~H_HIDE_DOT;
150 /* print all env vars */
151 rcode = env_print(NULL, env_flag);
154 printf("\nEnvironment size: %d/%ld bytes\n",
155 rcode, (ulong)ENV_SIZE);
159 /* print selected env vars */
160 env_flag &= ~H_HIDE_DOT;
161 for (i = 1; i < argc; ++i) {
162 int rc = env_print(argv[i], env_flag);
164 printf("## Error: \"%s\" not defined\n", argv[i]);
172 #ifdef CONFIG_CMD_GREPENV
173 static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
174 int argc, char * const argv[])
177 unsigned char matched[env_htab.size / 8];
178 int rcode = 1, arg = 1, idx;
181 return CMD_RET_USAGE;
183 memset(matched, 0, env_htab.size / 8);
185 while (arg <= argc) {
187 while ((idx = hstrstr_r(argv[arg], idx, &match, &env_htab))) {
188 if (!(matched[idx / 8] & (1 << (idx & 7)))) {
194 matched[idx / 8] |= 1 << (idx & 7);
203 #endif /* CONFIG_SPL_BUILD */
206 * Perform consistency checking before setting, replacing, or deleting an
207 * environment variable, then (if successful) apply the changes to internals so
208 * to make them effective. Code for this function was taken out of
209 * _do_env_set(), which now calls it instead.
210 * Also called as a callback function by himport_r().
211 * Returns 0 in case of success, 1 in case of failure.
212 * When (flag & H_FORCE) is set, do not print out any error message and force
213 * overwriting of write-once variables.
216 int env_change_ok(const ENTRY *item, const char *newval, enum env_op op,
221 #if !defined(CONFIG_ENV_OVERWRITE) && defined(CONFIG_OVERWRITE_ETHADDR_ONCE) \
222 && defined(CONFIG_ETHADDR)
223 const char *oldval = NULL;
225 if (op != env_op_create)
231 /* Default value for NULL to protect string-manipulating functions */
232 newval = newval ? : "";
234 /* Check for console redirection */
235 if (strcmp(name, "stdin") == 0)
237 else if (strcmp(name, "stdout") == 0)
239 else if (strcmp(name, "stderr") == 0)
242 if (console != -1 && (gd->flags & GD_FLG_DEVINIT) != 0) {
243 if ((newval == NULL) || (*newval == '\0')) {
244 /* We cannot delete stdin/stdout/stderr */
245 if ((flag & H_FORCE) == 0)
246 printf("Can't delete \"%s\"\n", name);
250 #ifdef CONFIG_CONSOLE_MUX
251 if (iomux_doenv(console, newval))
254 /* Try assigning specified device */
255 if (console_assign(console, newval) < 0)
257 #endif /* CONFIG_CONSOLE_MUX */
260 #ifndef CONFIG_ENV_OVERWRITE
262 * Some variables like "ethaddr" and "serial#" can be set only once and
263 * cannot be deleted, unless CONFIG_ENV_OVERWRITE is defined.
265 if (op != env_op_create && /* variable exists */
266 (flag & H_FORCE) == 0) { /* and we are not forced */
267 if (strcmp(name, "serial#") == 0 ||
268 (strcmp(name, "ethaddr") == 0
269 #if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
270 && strcmp(oldval, __stringify(CONFIG_ETHADDR)) != 0
271 #endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
273 printf("Can't overwrite \"%s\"\n", name);
279 * When we change baudrate, or we are doing an env default -a
280 * (which will erase all variables prior to calling this),
281 * we want the baudrate to actually change - for real.
283 if (op != env_op_create || /* variable exists */
284 (flag & H_NOCLEAR) == 0) { /* or env is clear */
286 * Switch to new baudrate if new baudrate is supported
288 if (strcmp(name, "baudrate") == 0) {
289 int baudrate = simple_strtoul(newval, NULL, 10);
291 for (i = 0; i < N_BAUDRATES; ++i) {
292 if (baudrate == baudrate_table[i])
295 if (i == N_BAUDRATES) {
296 if ((flag & H_FORCE) == 0)
297 printf("## Baudrate %d bps not "
298 "supported\n", baudrate);
301 if (gd->baudrate == baudrate) {
302 /* If unchanged, we just say it's OK */
305 printf("## Switch baudrate to %d bps and"
306 "press ENTER ...\n", baudrate);
308 gd->baudrate = baudrate;
309 #if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2)
310 gd->bd->bi_baudrate = baudrate;
315 while (getc() != '\r')
321 * Some variables should be updated when the corresponding
322 * entry in the environment is changed
324 if (strcmp(name, "loadaddr") == 0) {
325 load_addr = simple_strtoul(newval, NULL, 16);
332 * Set a new environment variable,
333 * or replace or delete an existing one.
335 static int _do_env_set(int flag, int argc, char * const argv[])
338 char *name, *value, *s;
344 if (strchr(name, '=')) {
345 printf("## Error: illegal character '='"
346 "in variable name \"%s\"\n", name);
353 if (argc < 3 || argv[2] == NULL) {
354 int rc = hdelete_r(name, &env_htab, H_INTERACTIVE);
359 * Insert / replace new value
361 for (i = 2, len = 0; i < argc; ++i)
362 len += strlen(argv[i]) + 1;
366 printf("## Can't malloc %d bytes\n", len);
369 for (i = 2, s = value; i < argc; ++i) {
372 while ((*s++ = *v++) != '\0')
381 hsearch_r(e, ENTER, &ep, &env_htab, H_INTERACTIVE);
384 printf("## Error inserting \"%s\" variable, errno=%d\n",
392 int setenv(const char *varname, const char *varvalue)
394 const char * const argv[4] = { "setenv", varname, varvalue, NULL };
396 if (varvalue == NULL || varvalue[0] == '\0')
397 return _do_env_set(0, 2, (char * const *)argv);
399 return _do_env_set(0, 3, (char * const *)argv);
403 * Set an environment variable to an integer value
405 * @param varname Environmet variable to set
406 * @param value Value to set it to
407 * @return 0 if ok, 1 on error
409 int setenv_ulong(const char *varname, ulong value)
411 /* TODO: this should be unsigned */
412 char *str = simple_itoa(value);
414 return setenv(varname, str);
418 * Set an environment variable to an address in hex
420 * @param varname Environmet variable to set
421 * @param addr Value to set it to
422 * @return 0 if ok, 1 on error
424 int setenv_addr(const char *varname, const void *addr)
428 sprintf(str, "%lx", (uintptr_t)addr);
429 return setenv(varname, str);
432 #ifndef CONFIG_SPL_BUILD
433 static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
436 return CMD_RET_USAGE;
438 return _do_env_set(flag, argc, argv);
442 * Prompt for environment variable
444 #if defined(CONFIG_CMD_ASKENV)
445 int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
447 char message[CONFIG_SYS_CBSIZE];
448 int size = CONFIG_SYS_CBSIZE - 1;
452 local_args[0] = argv[0];
453 local_args[1] = argv[1];
454 local_args[2] = NULL;
455 local_args[3] = NULL;
457 /* Check the syntax */
460 return CMD_RET_USAGE;
462 case 2: /* env_ask envname */
463 sprintf(message, "Please enter '%s':", argv[1]);
466 case 3: /* env_ask envname size */
467 sprintf(message, "Please enter '%s':", argv[1]);
468 size = simple_strtoul(argv[2], NULL, 10);
471 default: /* env_ask envname message1 ... messagen size */
472 for (i = 2, pos = 0; i < argc - 1; i++) {
474 message[pos++] = ' ';
476 strcpy(message + pos, argv[i]);
477 pos += strlen(argv[i]);
481 size = simple_strtoul(argv[argc - 1], NULL, 10);
485 if (size >= CONFIG_SYS_CBSIZE)
486 size = CONFIG_SYS_CBSIZE - 1;
491 /* prompt for input */
492 len = readline(message);
495 console_buffer[size] = '\0';
498 if (console_buffer[0] != '\0') {
499 local_args[2] = console_buffer;
503 /* Continue calling setenv code */
504 return _do_env_set(flag, len, local_args);
508 #if defined(CONFIG_CMD_ENV_CALLBACK)
509 static int print_static_binding(const char *var_name, const char *callback_name)
511 printf("\t%-20s %-20s\n", var_name, callback_name);
516 static int print_active_callback(ENTRY *entry)
518 struct env_clbk_tbl *clbkp;
522 if (entry->callback == NULL)
525 /* look up the callback in the linker-list */
526 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
527 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
530 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
531 if (entry->callback == clbkp->callback + gd->reloc_off)
533 if (entry->callback == clbkp->callback)
538 if (i == num_callbacks)
539 /* this should probably never happen, but just in case... */
540 printf("\t%-20s %p\n", entry->key, entry->callback);
542 printf("\t%-20s %-20s\n", entry->key, clbkp->name);
548 * Print the callbacks available and what they are bound to
550 int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
552 struct env_clbk_tbl *clbkp;
556 /* Print the available callbacks */
557 puts("Available callbacks:\n");
558 puts("\tCallback Name\n");
559 puts("\t-------------\n");
560 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
561 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
564 printf("\t%s\n", clbkp->name);
567 /* Print the static bindings that may exist */
568 puts("Static callback bindings:\n");
569 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
570 printf("\t%-20s %-20s\n", "-------------", "-------------");
571 env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
574 /* walk through each variable and print the callback if it has one */
575 puts("Active callback bindings:\n");
576 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
577 printf("\t%-20s %-20s\n", "-------------", "-------------");
578 hwalk_r(&env_htab, print_active_callback);
584 * Interactively edit an environment variable
586 #if defined(CONFIG_CMD_EDITENV)
587 static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
590 char buffer[CONFIG_SYS_CBSIZE];
594 return CMD_RET_USAGE;
596 /* Set read buffer to initial value or empty sting */
597 init_val = getenv(argv[1]);
599 sprintf(buffer, "%s", init_val);
603 readline_into_buffer("edit: ", buffer, 0);
605 return setenv(argv[1], buffer);
607 #endif /* CONFIG_CMD_EDITENV */
608 #endif /* CONFIG_SPL_BUILD */
611 * Look up variable from environment,
612 * return address of storage for that variable,
613 * or NULL if not found
615 char *getenv(const char *name)
617 if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
624 hsearch_r(e, FIND, &ep, &env_htab, 0);
626 return ep ? ep->data : NULL;
629 /* restricted capabilities before import */
630 if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
631 return (char *)(gd->env_buf);
637 * Look up variable from environment for restricted C runtime env.
639 int getenv_f(const char *name, char *buf, unsigned len)
643 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
646 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
647 if (nxt >= CONFIG_ENV_SIZE)
651 val = envmatch((uchar *)name, i);
655 /* found; copy out */
656 for (n = 0; n < len; ++n, ++buf) {
657 *buf = env_get_char(val++);
665 printf("env_buf [%d bytes] too small for value of \"%s\"\n",
675 * Decode the integer value of an environment variable and return it.
677 * @param name Name of environemnt variable
678 * @param base Number base to use (normally 10, or 16 for hex)
679 * @param default_val Default value to return if the variable is not
681 * @return the decoded value, or default_val if not found
683 ulong getenv_ulong(const char *name, int base, ulong default_val)
686 * We can use getenv() here, even before relocation, since the
687 * environment variable value is an integer and thus short.
689 const char *str = getenv(name);
691 return str ? simple_strtoul(str, NULL, base) : default_val;
694 #ifndef CONFIG_SPL_BUILD
695 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
696 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
699 printf("Saving Environment to %s...\n", env_name_spec);
701 return saveenv() ? 1 : 0;
705 saveenv, 1, 0, do_env_save,
706 "save environment variables to persistent storage",
710 #endif /* CONFIG_SPL_BUILD */
714 * Match a name / name=value pair
716 * s1 is either a simple 'name', or a 'name=value' pair.
717 * i2 is the environment index for a 'name2=value2' pair.
718 * If the names match, return the index for the value2, else -1.
720 int envmatch(uchar *s1, int i2)
725 while (*s1 == env_get_char(i2++))
729 if (*s1 == '\0' && env_get_char(i2-1) == '=')
735 #ifndef CONFIG_SPL_BUILD
736 static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
737 int argc, char * const argv[])
739 int all = 0, flag = 0;
741 debug("Initial value for argc=%d\n", argc);
742 while (--argc > 0 && **++argv == '-') {
747 case 'a': /* default all */
750 case 'f': /* force */
754 return cmd_usage(cmdtp);
758 debug("Final value for argc=%d\n", argc);
759 if (all && (argc == 0)) {
760 /* Reset the whole environment */
761 set_default_env("## Resetting to default environment\n");
764 if (!all && (argc > 0)) {
765 /* Reset individual variables */
766 set_default_vars(argc, argv);
770 return cmd_usage(cmdtp);
773 static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
774 int argc, char * const argv[])
776 printf("Not implemented yet\n");
780 #ifdef CONFIG_CMD_EXPORTENV
782 * env export [-t | -b | -c] [-s size] addr [var ...]
783 * -t: export as text format; if size is given, data will be
784 * padded with '\0' bytes; if not, one terminating '\0'
785 * will be added (which is included in the "filesize"
786 * setting so you can for exmple copy this to flash and
787 * keep the termination).
788 * -b: export as binary format (name=value pairs separated by
789 * '\0', list end marked by double "\0\0")
790 * -c: export as checksum protected environment format as
791 * used for example by "saveenv" command
793 * size of output buffer
794 * addr: memory address where environment gets stored
795 * var... List of variable names that get included into the
796 * export. Without arguments, the whole environment gets
799 * With "-c" and size is NOT given, then the export command will
800 * format the data as currently used for the persistent storage,
801 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
802 * prepend a valid CRC32 checksum and, in case of resundant
803 * environment, a "current" redundancy flag. If size is given, this
804 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
805 * checksum and redundancy flag will be inserted.
807 * With "-b" and "-t", always only the real data (including a
808 * terminating '\0' byte) will be written; here the optional size
809 * argument will be used to make sure not to overflow the user
810 * provided buffer; the command will abort if the size is not
811 * sufficient. Any remainign space will be '\0' padded.
813 * On successful return, the variable "filesize" will be set.
814 * Note that filesize includes the trailing/terminating '\0' byte(s).
816 * Usage szenario: create a text snapshot/backup of the current settings:
818 * => env export -t 100000
819 * => era ${backup_addr} +${filesize}
820 * => cp.b 100000 ${backup_addr} ${filesize}
822 * Re-import this snapshot, deleting all other settings:
824 * => env import -d -t ${backup_addr}
826 static int do_env_export(cmd_tbl_t *cmdtp, int flag,
827 int argc, char * const argv[])
830 char *addr, *cmd, *res;
840 while (--argc > 0 && **++argv == '-') {
844 case 'b': /* raw binary format */
849 case 'c': /* external checksum format */
855 case 's': /* size given */
857 return cmd_usage(cmdtp);
858 size = simple_strtoul(*++argv, NULL, 16);
860 case 't': /* text format */
866 return CMD_RET_USAGE;
873 return CMD_RET_USAGE;
875 addr = (char *)simple_strtoul(argv[0], NULL, 16);
878 memset(addr, '\0', size);
883 if (sep) { /* export as text file */
884 len = hexport_r(&env_htab, sep, 0, &addr, size, argc, argv);
886 error("Cannot export environment: errno = %d\n", errno);
889 sprintf(buf, "%zX", (size_t)len);
890 setenv("filesize", buf);
895 envp = (env_t *)addr;
897 if (chk) /* export as checksum protected block */
898 res = (char *)envp->data;
899 else /* export as raw binary data */
902 len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, argc, argv);
904 error("Cannot export environment: errno = %d\n", errno);
909 envp->crc = crc32(0, envp->data, ENV_SIZE);
910 #ifdef CONFIG_ENV_ADDR_REDUND
911 envp->flags = ACTIVE_FLAG;
914 sprintf(buf, "%zX", (size_t)(len + offsetof(env_t, data)));
915 setenv("filesize", buf);
920 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
925 #ifdef CONFIG_CMD_IMPORTENV
927 * env import [-d] [-t | -b | -c] addr [size]
928 * -d: delete existing environment before importing;
929 * otherwise overwrite / append to existion definitions
930 * -t: assume text format; either "size" must be given or the
931 * text data must be '\0' terminated
932 * -b: assume binary format ('\0' separated, "\0\0" terminated)
933 * -c: assume checksum protected environment format
934 * addr: memory address to read from
935 * size: length of input data; if missing, proper '\0'
936 * termination is mandatory
938 static int do_env_import(cmd_tbl_t *cmdtp, int flag,
939 int argc, char * const argv[])
950 while (--argc > 0 && **++argv == '-') {
954 case 'b': /* raw binary format */
959 case 'c': /* external checksum format */
965 case 't': /* text format */
974 return CMD_RET_USAGE;
980 return CMD_RET_USAGE;
983 printf("## Warning: defaulting to text format\n");
985 addr = (char *)simple_strtoul(argv[0], NULL, 16);
988 size = simple_strtoul(argv[1], NULL, 16);
994 while (size < MAX_ENV_SIZE) {
995 if ((*s == sep) && (*(s+1) == '\0'))
1000 if (size == MAX_ENV_SIZE) {
1001 printf("## Warning: Input data exceeds %d bytes"
1002 " - truncated\n", MAX_ENV_SIZE);
1005 printf("## Info: input data size = %zu = 0x%zX\n", size, size);
1010 env_t *ep = (env_t *)addr;
1012 size -= offsetof(env_t, data);
1013 memcpy(&crc, &ep->crc, sizeof(crc));
1015 if (crc32(0, ep->data, size) != crc) {
1016 puts("## Error: bad CRC, import failed\n");
1019 addr = (char *)ep->data;
1022 if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR,
1024 error("Environment import failed: errno = %d\n", errno);
1027 gd->flags |= GD_FLG_ENV_READY;
1032 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
1039 * New command line interface: "env" command with subcommands
1041 static cmd_tbl_t cmd_env_sub[] = {
1042 #if defined(CONFIG_CMD_ASKENV)
1043 U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
1045 U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
1046 U_BOOT_CMD_MKENT(delete, 2, 0, do_env_delete, "", ""),
1047 #if defined(CONFIG_CMD_EDITENV)
1048 U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
1050 #if defined(CONFIG_CMD_ENV_CALLBACK)
1051 U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
1053 #if defined(CONFIG_CMD_EXPORTENV)
1054 U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
1056 #if defined(CONFIG_CMD_GREPENV)
1057 U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
1059 #if defined(CONFIG_CMD_IMPORTENV)
1060 U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
1062 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
1063 #if defined(CONFIG_CMD_RUN)
1064 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
1066 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1067 U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
1069 U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
1072 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
1073 void env_reloc(void)
1075 fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1079 static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1084 return CMD_RET_USAGE;
1086 /* drop initial "env" arg */
1090 cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1093 return cp->cmd(cmdtp, flag, argc, argv);
1095 return CMD_RET_USAGE;
1098 #ifdef CONFIG_SYS_LONGHELP
1099 static char env_help_text[] =
1100 #if defined(CONFIG_CMD_ASKENV)
1101 "ask name [message] [size] - ask for environment variable\nenv "
1103 #if defined(CONFIG_CMD_ENV_CALLBACK)
1104 "callbacks - print callbacks and their associated variables\nenv "
1106 "default [-f] -a - [forcibly] reset default environment\n"
1107 "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
1108 #if defined(CONFIG_CMD_EDITENV)
1109 "env edit name - edit environment variable\n"
1111 #if defined(CONFIG_CMD_EXPORTENV)
1112 "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\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",
1172 " - set environment variable 'name' to 'value ...'\n"
1174 " - 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)\n"
1186 " - get environment variable 'name' from stdin\n"
1187 "askenv name size\n"
1188 " - get environment variable 'name' from stdin (max 'size' chars)\n"
1189 "askenv name [message] size\n"
1190 " - display 'message' string and get environment variable 'name'"
1191 "from stdin (max 'size' chars)"
1195 #if defined(CONFIG_CMD_RUN)
1196 U_BOOT_CMD_COMPLETE(
1197 run, CONFIG_SYS_MAXARGS, 1, do_run,
1198 "run commands in an environment variable",
1200 " - run the commands in the environment variable(s) 'var'",
1204 #endif /* CONFIG_SPL_BUILD */