Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 2 | /* |
Wolfgang Denk | ea009d4 | 2013-03-23 23:50:28 +0000 | [diff] [blame] | 3 | * (C) Copyright 2000-2013 |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
| 6 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Andreas Heppel <aheppel@sysgo.de> |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 8 | * |
| 9 | * Copyright 2011 Freescale Semiconductor, Inc. |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 12 | /* |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 13 | * Support for persistent environment data |
| 14 | * |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 15 | * The "environment" is stored on external storage as a list of '\0' |
| 16 | * terminated "name=value" strings. The end of the list is marked by |
Robert P. J. Day | fc0b594 | 2016-09-07 14:27:59 -0400 | [diff] [blame] | 17 | * a double '\0'. The environment is preceded by a 32 bit CRC over |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 18 | * the data part and, in case of redundant environment, a byte of |
| 19 | * flags. |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 20 | * |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 21 | * This linearized representation will also be used before |
| 22 | * relocation, i. e. as long as we don't have a full C runtime |
| 23 | * environment. After that, we use a hash table. |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <common.h> |
Simon Glass | 18d6653 | 2014-04-10 20:01:25 -0600 | [diff] [blame] | 27 | #include <cli.h> |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 28 | #include <command.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 29 | #include <console.h> |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 30 | #include <environment.h> |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 31 | #include <search.h> |
| 32 | #include <errno.h> |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 33 | #include <malloc.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 34 | #include <mapmem.h> |
wdenk | 2a3cb02 | 2002-11-05 21:01:48 +0000 | [diff] [blame] | 35 | #include <watchdog.h> |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 36 | #include <linux/stddef.h> |
| 37 | #include <asm/byteorder.h> |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 38 | #include <asm/io.h> |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 39 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
Patrick Delaunay | 2643c85 | 2019-02-18 10:58:16 +0100 | [diff] [blame] | 42 | #if defined(CONFIG_ENV_IS_IN_EEPROM) || \ |
| 43 | defined(CONFIG_ENV_IS_IN_FLASH) || \ |
| 44 | defined(CONFIG_ENV_IS_IN_MMC) || \ |
| 45 | defined(CONFIG_ENV_IS_IN_FAT) || \ |
| 46 | defined(CONFIG_ENV_IS_IN_EXT4) || \ |
| 47 | defined(CONFIG_ENV_IS_IN_NAND) || \ |
| 48 | defined(CONFIG_ENV_IS_IN_NVRAM) || \ |
| 49 | defined(CONFIG_ENV_IS_IN_ONENAND) || \ |
| 50 | defined(CONFIG_ENV_IS_IN_SATA) || \ |
| 51 | defined(CONFIG_ENV_IS_IN_SPI_FLASH) || \ |
| 52 | defined(CONFIG_ENV_IS_IN_REMOTE) || \ |
| 53 | defined(CONFIG_ENV_IS_IN_UBI) |
| 54 | |
| 55 | #define ENV_IS_IN_DEVICE |
| 56 | |
| 57 | #endif |
| 58 | |
| 59 | #if !defined(ENV_IS_IN_DEVICE) && \ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 60 | !defined(CONFIG_ENV_IS_NOWHERE) |
Tuomas Tynkkynen | 7b7341d | 2017-10-10 21:59:40 +0300 | [diff] [blame] | 61 | # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|MMC|FAT|EXT4|\ |
Lothar Waßmann | d1b88cd | 2017-06-08 14:16:14 +0200 | [diff] [blame] | 62 | NAND|NVRAM|ONENAND|SATA|SPI_FLASH|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 63 | #endif |
| 64 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 65 | /* |
| 66 | * Maximum expected input data size for import command |
| 67 | */ |
| 68 | #define MAX_ENV_SIZE (1 << 20) /* 1 MiB */ |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 69 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 70 | /* |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 71 | * This variable is incremented on each do_env_set(), so it can |
Heiko Schocher | da95427 | 2009-04-28 08:36:11 +0200 | [diff] [blame] | 72 | * be used via get_env_id() as an indication, if the environment |
| 73 | * has changed or not. So it is possible to reread an environment |
| 74 | * variable only if the environment was changed ... done so for |
| 75 | * example in NetInitLoop() |
| 76 | */ |
Heiko Schocher | 2f70c49 | 2009-02-10 09:38:52 +0100 | [diff] [blame] | 77 | static int env_id = 1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 78 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 79 | int get_env_id(void) |
Heiko Schocher | 2f70c49 | 2009-02-10 09:38:52 +0100 | [diff] [blame] | 80 | { |
| 81 | return env_id; |
| 82 | } |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 83 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 84 | #ifndef CONFIG_SPL_BUILD |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 85 | /* |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 86 | * Command interface: print one or all environment variables |
| 87 | * |
| 88 | * Returns 0 in case of error, or length of printed string |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 89 | */ |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 90 | static int env_print(char *name, int flag) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 91 | { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 92 | char *res = NULL; |
Maxime Larocque | 22a4a6c | 2012-09-28 05:00:13 +0000 | [diff] [blame] | 93 | ssize_t len; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 94 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 95 | if (name) { /* print a single name */ |
| 96 | ENTRY e, *ep; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 97 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 98 | e.key = name; |
| 99 | e.data = NULL; |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 100 | hsearch_r(e, FIND, &ep, &env_htab, flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 101 | if (ep == NULL) |
| 102 | return 0; |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 103 | len = printf("%s=%s\n", ep->key, ep->data); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 104 | return len; |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 105 | } |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 106 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 107 | /* print whole list */ |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 108 | len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 109 | |
| 110 | if (len > 0) { |
| 111 | puts(res); |
| 112 | free(res); |
| 113 | return len; |
| 114 | } |
| 115 | |
| 116 | /* should never happen */ |
Maxime Larocque | 22a4a6c | 2012-09-28 05:00:13 +0000 | [diff] [blame] | 117 | printf("## Error: cannot export environment\n"); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 118 | return 0; |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 119 | } |
| 120 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 121 | static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc, |
| 122 | char * const argv[]) |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 123 | { |
| 124 | int i; |
| 125 | int rcode = 0; |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 126 | int env_flag = H_HIDE_DOT; |
| 127 | |
AKASHI Takahiro | 49d81fd | 2019-02-25 15:54:36 +0900 | [diff] [blame] | 128 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
| 129 | if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') |
| 130 | return do_env_print_efi(cmdtp, flag, --argc, ++argv); |
| 131 | #endif |
| 132 | |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 133 | if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') { |
| 134 | argc--; |
| 135 | argv++; |
| 136 | env_flag &= ~H_HIDE_DOT; |
| 137 | } |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 138 | |
| 139 | if (argc == 1) { |
| 140 | /* print all env vars */ |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 141 | rcode = env_print(NULL, env_flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 142 | if (!rcode) |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 143 | return 1; |
| 144 | printf("\nEnvironment size: %d/%ld bytes\n", |
| 145 | rcode, (ulong)ENV_SIZE); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 149 | /* print selected env vars */ |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 150 | env_flag &= ~H_HIDE_DOT; |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 151 | for (i = 1; i < argc; ++i) { |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 152 | int rc = env_print(argv[i], env_flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 153 | if (!rc) { |
| 154 | printf("## Error: \"%s\" not defined\n", argv[i]); |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 155 | ++rcode; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 156 | } |
| 157 | } |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 158 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 159 | return rcode; |
| 160 | } |
| 161 | |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 162 | #ifdef CONFIG_CMD_GREPENV |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 163 | static int do_env_grep(cmd_tbl_t *cmdtp, int flag, |
| 164 | int argc, char * const argv[]) |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 165 | { |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 166 | char *res = NULL; |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 167 | int len, grep_how, grep_what; |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 168 | |
| 169 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 170 | return CMD_RET_USAGE; |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 171 | |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 172 | grep_how = H_MATCH_SUBSTR; /* default: substring search */ |
| 173 | grep_what = H_MATCH_BOTH; /* default: grep names and values */ |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 174 | |
Pierre Aubert | 9a83233 | 2013-10-08 14:20:27 +0200 | [diff] [blame] | 175 | while (--argc > 0 && **++argv == '-') { |
| 176 | char *arg = *argv; |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 177 | while (*++arg) { |
| 178 | switch (*arg) { |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 179 | #ifdef CONFIG_REGEX |
| 180 | case 'e': /* use regex matching */ |
| 181 | grep_how = H_MATCH_REGEX; |
| 182 | break; |
| 183 | #endif |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 184 | case 'n': /* grep for name */ |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 185 | grep_what = H_MATCH_KEY; |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 186 | break; |
| 187 | case 'v': /* grep for value */ |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 188 | grep_what = H_MATCH_DATA; |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 189 | break; |
| 190 | case 'b': /* grep for both */ |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 191 | grep_what = H_MATCH_BOTH; |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 192 | break; |
| 193 | case '-': |
| 194 | goto DONE; |
| 195 | default: |
| 196 | return CMD_RET_USAGE; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | DONE: |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 202 | len = hexport_r(&env_htab, '\n', |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 203 | flag | grep_what | grep_how, |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 204 | &res, 0, argc, argv); |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 205 | |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 206 | if (len > 0) { |
| 207 | puts(res); |
| 208 | free(res); |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 211 | if (len < 2) |
| 212 | return 1; |
| 213 | |
| 214 | return 0; |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 215 | } |
| 216 | #endif |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 217 | #endif /* CONFIG_SPL_BUILD */ |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 218 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 219 | /* |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 220 | * Set a new environment variable, |
| 221 | * or replace or delete an existing one. |
Joe Hershberger | 2598090 | 2012-12-11 22:16:31 -0600 | [diff] [blame] | 222 | */ |
Joe Hershberger | 94b467b | 2015-05-20 14:27:21 -0500 | [diff] [blame] | 223 | static int _do_env_set(int flag, int argc, char * const argv[], int env_flag) |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 224 | { |
| 225 | int i, len; |
| 226 | char *name, *value, *s; |
| 227 | ENTRY e, *ep; |
| 228 | |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 229 | debug("Initial value for argc=%d\n", argc); |
AKASHI Takahiro | 49d81fd | 2019-02-25 15:54:36 +0900 | [diff] [blame] | 230 | |
| 231 | #if CONFIG_IS_ENABLED(CMD_NVEDIT_EFI) |
| 232 | if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') |
| 233 | return do_env_set_efi(NULL, flag, --argc, ++argv); |
| 234 | #endif |
| 235 | |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 236 | while (argc > 1 && **(argv + 1) == '-') { |
| 237 | char *arg = *++argv; |
| 238 | |
| 239 | --argc; |
| 240 | while (*++arg) { |
| 241 | switch (*arg) { |
| 242 | case 'f': /* force */ |
| 243 | env_flag |= H_FORCE; |
| 244 | break; |
| 245 | default: |
| 246 | return CMD_RET_USAGE; |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | debug("Final value for argc=%d\n", argc); |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 251 | name = argv[1]; |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 252 | |
| 253 | if (strchr(name, '=')) { |
| 254 | printf("## Error: illegal character '='" |
| 255 | "in variable name \"%s\"\n", name); |
| 256 | return 1; |
| 257 | } |
| 258 | |
| 259 | env_id++; |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 260 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 261 | /* Delete only ? */ |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 262 | if (argc < 3 || argv[2] == NULL) { |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 263 | int rc = hdelete_r(name, &env_htab, env_flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 264 | return !rc; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 268 | * Insert / replace new value |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 269 | */ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 270 | for (i = 2, len = 0; i < argc; ++i) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 271 | len += strlen(argv[i]) + 1; |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 272 | |
| 273 | value = malloc(len); |
| 274 | if (value == NULL) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 275 | printf("## Can't malloc %d bytes\n", len); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 276 | return 1; |
| 277 | } |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 278 | for (i = 2, s = value; i < argc; ++i) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 279 | char *v = argv[i]; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 280 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 281 | while ((*s++ = *v++) != '\0') |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 282 | ; |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 283 | *(s - 1) = ' '; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 284 | } |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 285 | if (s != value) |
| 286 | *--s = '\0'; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 287 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 288 | e.key = name; |
| 289 | e.data = value; |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 290 | hsearch_r(e, ENTER, &ep, &env_htab, env_flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 291 | free(value); |
| 292 | if (!ep) { |
| 293 | printf("## Error inserting \"%s\" variable, errno=%d\n", |
| 294 | name, errno); |
| 295 | return 1; |
| 296 | } |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 297 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 301 | int env_set(const char *varname, const char *varvalue) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 302 | { |
Wolfgang Denk | 84b5e80 | 2011-07-29 14:42:18 +0200 | [diff] [blame] | 303 | const char * const argv[4] = { "setenv", varname, varvalue, NULL }; |
| 304 | |
Joe Hershberger | a7eb1d6 | 2013-04-08 10:32:50 +0000 | [diff] [blame] | 305 | /* before import into hashtable */ |
| 306 | if (!(gd->flags & GD_FLG_ENV_READY)) |
| 307 | return 1; |
| 308 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 309 | if (varvalue == NULL || varvalue[0] == '\0') |
Joe Hershberger | 94b467b | 2015-05-20 14:27:21 -0500 | [diff] [blame] | 310 | return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC); |
Jeffrey Mann | 9ffd451 | 2007-04-23 14:00:11 +0200 | [diff] [blame] | 311 | else |
Joe Hershberger | 94b467b | 2015-05-20 14:27:21 -0500 | [diff] [blame] | 312 | return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 315 | /** |
| 316 | * Set an environment variable to an integer value |
| 317 | * |
Simon Glass | 9602286 | 2013-05-07 06:11:45 +0000 | [diff] [blame] | 318 | * @param varname Environment variable to set |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 319 | * @param value Value to set it to |
| 320 | * @return 0 if ok, 1 on error |
| 321 | */ |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 322 | int env_set_ulong(const char *varname, ulong value) |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 323 | { |
| 324 | /* TODO: this should be unsigned */ |
| 325 | char *str = simple_itoa(value); |
| 326 | |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 327 | return env_set(varname, str); |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /** |
Simon Glass | bfc5996 | 2013-02-24 17:33:21 +0000 | [diff] [blame] | 331 | * Set an environment variable to an value in hex |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 332 | * |
Simon Glass | 9602286 | 2013-05-07 06:11:45 +0000 | [diff] [blame] | 333 | * @param varname Environment variable to set |
Simon Glass | bfc5996 | 2013-02-24 17:33:21 +0000 | [diff] [blame] | 334 | * @param value Value to set it to |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 335 | * @return 0 if ok, 1 on error |
| 336 | */ |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 337 | int env_set_hex(const char *varname, ulong value) |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 338 | { |
| 339 | char str[17]; |
| 340 | |
Simon Glass | bfc5996 | 2013-02-24 17:33:21 +0000 | [diff] [blame] | 341 | sprintf(str, "%lx", value); |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 342 | return env_set(varname, str); |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Simon Glass | bfebc8c | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 345 | ulong env_get_hex(const char *varname, ulong default_val) |
Simon Glass | 76b8f79 | 2013-04-20 08:42:43 +0000 | [diff] [blame] | 346 | { |
| 347 | const char *s; |
| 348 | ulong value; |
| 349 | char *endp; |
| 350 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 351 | s = env_get(varname); |
Simon Glass | 76b8f79 | 2013-04-20 08:42:43 +0000 | [diff] [blame] | 352 | if (s) |
| 353 | value = simple_strtoul(s, &endp, 16); |
| 354 | if (!s || endp == s) |
| 355 | return default_val; |
| 356 | |
| 357 | return value; |
| 358 | } |
| 359 | |
Alex Kiernan | 9925f1d | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 360 | void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr) |
| 361 | { |
| 362 | char *end; |
| 363 | int i; |
| 364 | |
| 365 | for (i = 0; i < 6; ++i) { |
| 366 | enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; |
| 367 | if (addr) |
| 368 | addr = (*end) ? end + 1 : end; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | int eth_env_get_enetaddr(const char *name, uint8_t *enetaddr) |
| 373 | { |
| 374 | eth_parse_enetaddr(env_get(name), enetaddr); |
| 375 | return is_valid_ethaddr(enetaddr); |
| 376 | } |
| 377 | |
| 378 | int eth_env_set_enetaddr(const char *name, const uint8_t *enetaddr) |
| 379 | { |
| 380 | char buf[ARP_HLEN_ASCII + 1]; |
| 381 | |
| 382 | if (eth_env_get_enetaddr(name, (uint8_t *)buf)) |
| 383 | return -EEXIST; |
| 384 | |
| 385 | sprintf(buf, "%pM", enetaddr); |
| 386 | |
| 387 | return env_set(name, buf); |
| 388 | } |
| 389 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 390 | #ifndef CONFIG_SPL_BUILD |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 391 | static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 392 | { |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 393 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 394 | return CMD_RET_USAGE; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 395 | |
Joe Hershberger | 94b467b | 2015-05-20 14:27:21 -0500 | [diff] [blame] | 396 | return _do_env_set(flag, argc, argv, H_INTERACTIVE); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 399 | /* |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 400 | * Prompt for environment variable |
| 401 | */ |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 402 | #if defined(CONFIG_CMD_ASKENV) |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 403 | int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 404 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 405 | char message[CONFIG_SYS_CBSIZE]; |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 406 | int i, len, pos, size; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 407 | char *local_args[4]; |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 408 | char *endptr; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 409 | |
| 410 | local_args[0] = argv[0]; |
| 411 | local_args[1] = argv[1]; |
| 412 | local_args[2] = NULL; |
| 413 | local_args[3] = NULL; |
| 414 | |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 415 | /* |
| 416 | * Check the syntax: |
| 417 | * |
| 418 | * env_ask envname [message1 ...] [size] |
| 419 | */ |
| 420 | if (argc == 1) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 421 | return CMD_RET_USAGE; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 422 | |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 423 | /* |
| 424 | * We test the last argument if it can be converted |
| 425 | * into a decimal number. If yes, we assume it's |
| 426 | * the size. Otherwise we echo it as part of the |
| 427 | * message. |
| 428 | */ |
| 429 | i = simple_strtoul(argv[argc - 1], &endptr, 10); |
| 430 | if (*endptr != '\0') { /* no size */ |
| 431 | size = CONFIG_SYS_CBSIZE - 1; |
| 432 | } else { /* size given */ |
| 433 | size = i; |
| 434 | --argc; |
| 435 | } |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 436 | |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 437 | if (argc <= 2) { |
| 438 | sprintf(message, "Please enter '%s': ", argv[1]); |
| 439 | } else { |
| 440 | /* env_ask envname message1 ... messagen [size] */ |
Tom Rini | bf52fcd | 2017-10-07 11:27:59 -0400 | [diff] [blame] | 441 | for (i = 2, pos = 0; i < argc && pos+1 < sizeof(message); i++) { |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 442 | if (pos) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 443 | message[pos++] = ' '; |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 444 | |
Tom Rini | c667723 | 2017-09-26 19:37:11 -0400 | [diff] [blame] | 445 | strncpy(message + pos, argv[i], sizeof(message) - pos); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 446 | pos += strlen(argv[i]); |
| 447 | } |
Tom Rini | c667723 | 2017-09-26 19:37:11 -0400 | [diff] [blame] | 448 | if (pos < sizeof(message) - 1) { |
| 449 | message[pos++] = ' '; |
| 450 | message[pos] = '\0'; |
| 451 | } else |
| 452 | message[CONFIG_SYS_CBSIZE - 1] = '\0'; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 455 | if (size >= CONFIG_SYS_CBSIZE) |
| 456 | size = CONFIG_SYS_CBSIZE - 1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 457 | |
| 458 | if (size <= 0) |
| 459 | return 1; |
| 460 | |
| 461 | /* prompt for input */ |
Simon Glass | e1bf824 | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 462 | len = cli_readline(message); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 463 | |
| 464 | if (size < len) |
| 465 | console_buffer[size] = '\0'; |
| 466 | |
| 467 | len = 2; |
| 468 | if (console_buffer[0] != '\0') { |
| 469 | local_args[2] = console_buffer; |
| 470 | len = 3; |
| 471 | } |
| 472 | |
| 473 | /* Continue calling setenv code */ |
Joe Hershberger | 94b467b | 2015-05-20 14:27:21 -0500 | [diff] [blame] | 474 | return _do_env_set(flag, len, local_args, H_INTERACTIVE); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 475 | } |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 476 | #endif |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 477 | |
Joe Hershberger | 5e2b3e0 | 2012-12-11 22:16:25 -0600 | [diff] [blame] | 478 | #if defined(CONFIG_CMD_ENV_CALLBACK) |
Joe Hershberger | cca98fd | 2015-05-20 14:27:19 -0500 | [diff] [blame] | 479 | static int print_static_binding(const char *var_name, const char *callback_name, |
| 480 | void *priv) |
Joe Hershberger | 5e2b3e0 | 2012-12-11 22:16:25 -0600 | [diff] [blame] | 481 | { |
| 482 | printf("\t%-20s %-20s\n", var_name, callback_name); |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static int print_active_callback(ENTRY *entry) |
| 488 | { |
| 489 | struct env_clbk_tbl *clbkp; |
| 490 | int i; |
| 491 | int num_callbacks; |
| 492 | |
| 493 | if (entry->callback == NULL) |
| 494 | return 0; |
| 495 | |
| 496 | /* look up the callback in the linker-list */ |
| 497 | num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk); |
| 498 | for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk); |
| 499 | i < num_callbacks; |
| 500 | i++, clbkp++) { |
| 501 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
| 502 | if (entry->callback == clbkp->callback + gd->reloc_off) |
| 503 | #else |
| 504 | if (entry->callback == clbkp->callback) |
| 505 | #endif |
| 506 | break; |
| 507 | } |
| 508 | |
| 509 | if (i == num_callbacks) |
| 510 | /* this should probably never happen, but just in case... */ |
| 511 | printf("\t%-20s %p\n", entry->key, entry->callback); |
| 512 | else |
| 513 | printf("\t%-20s %-20s\n", entry->key, clbkp->name); |
| 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * Print the callbacks available and what they are bound to |
| 520 | */ |
| 521 | int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 522 | { |
| 523 | struct env_clbk_tbl *clbkp; |
| 524 | int i; |
| 525 | int num_callbacks; |
| 526 | |
| 527 | /* Print the available callbacks */ |
| 528 | puts("Available callbacks:\n"); |
| 529 | puts("\tCallback Name\n"); |
| 530 | puts("\t-------------\n"); |
| 531 | num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk); |
| 532 | for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk); |
| 533 | i < num_callbacks; |
| 534 | i++, clbkp++) |
| 535 | printf("\t%s\n", clbkp->name); |
| 536 | puts("\n"); |
| 537 | |
| 538 | /* Print the static bindings that may exist */ |
| 539 | puts("Static callback bindings:\n"); |
| 540 | printf("\t%-20s %-20s\n", "Variable Name", "Callback Name"); |
| 541 | printf("\t%-20s %-20s\n", "-------------", "-------------"); |
Joe Hershberger | cca98fd | 2015-05-20 14:27:19 -0500 | [diff] [blame] | 542 | env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding, NULL); |
Joe Hershberger | 5e2b3e0 | 2012-12-11 22:16:25 -0600 | [diff] [blame] | 543 | puts("\n"); |
| 544 | |
| 545 | /* walk through each variable and print the callback if it has one */ |
| 546 | puts("Active callback bindings:\n"); |
| 547 | printf("\t%-20s %-20s\n", "Variable Name", "Callback Name"); |
| 548 | printf("\t%-20s %-20s\n", "-------------", "-------------"); |
| 549 | hwalk_r(&env_htab, print_active_callback); |
| 550 | return 0; |
| 551 | } |
| 552 | #endif |
| 553 | |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 554 | #if defined(CONFIG_CMD_ENV_FLAGS) |
Joe Hershberger | cca98fd | 2015-05-20 14:27:19 -0500 | [diff] [blame] | 555 | static int print_static_flags(const char *var_name, const char *flags, |
| 556 | void *priv) |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 557 | { |
| 558 | enum env_flags_vartype type = env_flags_parse_vartype(flags); |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 559 | enum env_flags_varaccess access = env_flags_parse_varaccess(flags); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 560 | |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 561 | printf("\t%-20s %-20s %-20s\n", var_name, |
| 562 | env_flags_get_vartype_name(type), |
| 563 | env_flags_get_varaccess_name(access)); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | static int print_active_flags(ENTRY *entry) |
| 569 | { |
| 570 | enum env_flags_vartype type; |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 571 | enum env_flags_varaccess access; |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 572 | |
| 573 | if (entry->flags == 0) |
| 574 | return 0; |
| 575 | |
| 576 | type = (enum env_flags_vartype) |
| 577 | (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK); |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 578 | access = env_flags_parse_varaccess_from_binflags(entry->flags); |
| 579 | printf("\t%-20s %-20s %-20s\n", entry->key, |
| 580 | env_flags_get_vartype_name(type), |
| 581 | env_flags_get_varaccess_name(access)); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 582 | |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * Print the flags available and what variables have flags |
| 588 | */ |
| 589 | int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 590 | { |
| 591 | /* Print the available variable types */ |
| 592 | printf("Available variable type flags (position %d):\n", |
| 593 | ENV_FLAGS_VARTYPE_LOC); |
| 594 | puts("\tFlag\tVariable Type Name\n"); |
| 595 | puts("\t----\t------------------\n"); |
| 596 | env_flags_print_vartypes(); |
| 597 | puts("\n"); |
| 598 | |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 599 | /* Print the available variable access types */ |
| 600 | printf("Available variable access flags (position %d):\n", |
| 601 | ENV_FLAGS_VARACCESS_LOC); |
| 602 | puts("\tFlag\tVariable Access Name\n"); |
| 603 | puts("\t----\t--------------------\n"); |
| 604 | env_flags_print_varaccess(); |
| 605 | puts("\n"); |
| 606 | |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 607 | /* Print the static flags that may exist */ |
| 608 | puts("Static flags:\n"); |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 609 | printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type", |
| 610 | "Variable Access"); |
| 611 | printf("\t%-20s %-20s %-20s\n", "-------------", "-------------", |
| 612 | "---------------"); |
Joe Hershberger | cca98fd | 2015-05-20 14:27:19 -0500 | [diff] [blame] | 613 | env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags, NULL); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 614 | puts("\n"); |
| 615 | |
| 616 | /* walk through each variable and print the flags if non-default */ |
| 617 | puts("Active flags:\n"); |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 618 | printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type", |
| 619 | "Variable Access"); |
| 620 | printf("\t%-20s %-20s %-20s\n", "-------------", "-------------", |
| 621 | "---------------"); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 622 | hwalk_r(&env_htab, print_active_flags); |
| 623 | return 0; |
| 624 | } |
| 625 | #endif |
| 626 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 627 | /* |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 628 | * Interactively edit an environment variable |
| 629 | */ |
| 630 | #if defined(CONFIG_CMD_EDITENV) |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 631 | static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, |
| 632 | char * const argv[]) |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 633 | { |
| 634 | char buffer[CONFIG_SYS_CBSIZE]; |
| 635 | char *init_val; |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 636 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 637 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 638 | return CMD_RET_USAGE; |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 639 | |
Joe Hershberger | 94b467b | 2015-05-20 14:27:21 -0500 | [diff] [blame] | 640 | /* before import into hashtable */ |
| 641 | if (!(gd->flags & GD_FLG_ENV_READY)) |
| 642 | return 1; |
| 643 | |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 644 | /* Set read buffer to initial value or empty sting */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 645 | init_val = env_get(argv[1]); |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 646 | if (init_val) |
Peng Fan | 5d49b4c | 2015-12-23 12:08:09 +0800 | [diff] [blame] | 647 | snprintf(buffer, CONFIG_SYS_CBSIZE, "%s", init_val); |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 648 | else |
| 649 | buffer[0] = '\0'; |
| 650 | |
Simon Glass | e1bf824 | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 651 | if (cli_readline_into_buffer("edit: ", buffer, 0) < 0) |
Joe Hershberger | 18a3cce | 2013-02-08 10:12:34 +0000 | [diff] [blame] | 652 | return 1; |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 653 | |
Joe Hershberger | 94b467b | 2015-05-20 14:27:21 -0500 | [diff] [blame] | 654 | if (buffer[0] == '\0') { |
| 655 | const char * const _argv[3] = { "setenv", argv[1], NULL }; |
| 656 | |
| 657 | return _do_env_set(0, 2, (char * const *)_argv, H_INTERACTIVE); |
| 658 | } else { |
| 659 | const char * const _argv[4] = { "setenv", argv[1], buffer, |
| 660 | NULL }; |
| 661 | |
| 662 | return _do_env_set(0, 3, (char * const *)_argv, H_INTERACTIVE); |
| 663 | } |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 664 | } |
| 665 | #endif /* CONFIG_CMD_EDITENV */ |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 666 | #endif /* CONFIG_SPL_BUILD */ |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 667 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 668 | /* |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 669 | * Look up variable from environment, |
| 670 | * return address of storage for that variable, |
| 671 | * or NULL if not found |
| 672 | */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 673 | char *env_get(const char *name) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 674 | { |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 675 | if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 676 | ENTRY e, *ep; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 677 | |
Wolfgang Denk | 91a7675 | 2010-07-24 20:22:02 +0200 | [diff] [blame] | 678 | WATCHDOG_RESET(); |
wdenk | 2a3cb02 | 2002-11-05 21:01:48 +0000 | [diff] [blame] | 679 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 680 | e.key = name; |
| 681 | e.data = NULL; |
Joe Hershberger | c4e0057 | 2012-12-11 22:16:19 -0600 | [diff] [blame] | 682 | hsearch_r(e, FIND, &ep, &env_htab, 0); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 683 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 684 | return ep ? ep->data : NULL; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 687 | /* restricted capabilities before import */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 688 | if (env_get_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 689 | return (char *)(gd->env_buf); |
| 690 | |
| 691 | return NULL; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 692 | } |
| 693 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 694 | /* |
| 695 | * Look up variable from environment for restricted C runtime env. |
| 696 | */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 697 | int env_get_f(const char *name, char *buf, unsigned len) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 698 | { |
Simon Goldschmidt | 87c7fb3 | 2018-01-31 07:56:48 +0100 | [diff] [blame] | 699 | int i, nxt, c; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 700 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 701 | for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) { |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 702 | int val, n; |
| 703 | |
Simon Goldschmidt | 87c7fb3 | 2018-01-31 07:56:48 +0100 | [diff] [blame] | 704 | for (nxt = i; (c = env_get_char(nxt)) != '\0'; ++nxt) { |
| 705 | if (c < 0) |
| 706 | return c; |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 707 | if (nxt >= CONFIG_ENV_SIZE) |
| 708 | return -1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 709 | } |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 710 | |
| 711 | val = envmatch((uchar *)name, i); |
| 712 | if (val < 0) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 713 | continue; |
Wolfgang Denk | 9ed4a95 | 2010-07-24 22:16:20 +0200 | [diff] [blame] | 714 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 715 | /* found; copy out */ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 716 | for (n = 0; n < len; ++n, ++buf) { |
Simon Goldschmidt | 87c7fb3 | 2018-01-31 07:56:48 +0100 | [diff] [blame] | 717 | c = env_get_char(val++); |
| 718 | if (c < 0) |
| 719 | return c; |
| 720 | *buf = c; |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 721 | if (*buf == '\0') |
Wolfgang Denk | 9ed4a95 | 2010-07-24 22:16:20 +0200 | [diff] [blame] | 722 | return n; |
| 723 | } |
| 724 | |
| 725 | if (n) |
| 726 | *--buf = '\0'; |
| 727 | |
Heinrich Schuchardt | 8291951 | 2019-01-06 11:52:06 +0100 | [diff] [blame] | 728 | printf("env_buf [%u bytes] too small for value of \"%s\"\n", |
| 729 | len, name); |
Wolfgang Denk | 9ed4a95 | 2010-07-24 22:16:20 +0200 | [diff] [blame] | 730 | |
| 731 | return n; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 732 | } |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 733 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 734 | return -1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Simon Glass | 4a9b413 | 2011-10-14 13:25:18 +0000 | [diff] [blame] | 737 | /** |
| 738 | * Decode the integer value of an environment variable and return it. |
| 739 | * |
Shyam Saini | 919d25c | 2018-06-07 19:47:19 +0530 | [diff] [blame] | 740 | * @param name Name of environment variable |
Simon Glass | 4a9b413 | 2011-10-14 13:25:18 +0000 | [diff] [blame] | 741 | * @param base Number base to use (normally 10, or 16 for hex) |
| 742 | * @param default_val Default value to return if the variable is not |
| 743 | * found |
| 744 | * @return the decoded value, or default_val if not found |
| 745 | */ |
Simon Glass | bfebc8c | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 746 | ulong env_get_ulong(const char *name, int base, ulong default_val) |
Simon Glass | 4a9b413 | 2011-10-14 13:25:18 +0000 | [diff] [blame] | 747 | { |
| 748 | /* |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 749 | * We can use env_get() here, even before relocation, since the |
Simon Glass | 4a9b413 | 2011-10-14 13:25:18 +0000 | [diff] [blame] | 750 | * environment variable value is an integer and thus short. |
| 751 | */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 752 | const char *str = env_get(name); |
Simon Glass | 4a9b413 | 2011-10-14 13:25:18 +0000 | [diff] [blame] | 753 | |
| 754 | return str ? simple_strtoul(str, NULL, base) : default_val; |
| 755 | } |
| 756 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 757 | #ifndef CONFIG_SPL_BUILD |
Patrick Delaunay | 2643c85 | 2019-02-18 10:58:16 +0100 | [diff] [blame] | 758 | #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 759 | static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, |
| 760 | char * const argv[]) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 761 | { |
Simon Glass | 0151009 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 762 | return env_save() ? 1 : 0; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 763 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 764 | |
Mike Frysinger | ba69dc2 | 2008-12-30 02:59:25 -0500 | [diff] [blame] | 765 | U_BOOT_CMD( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 766 | saveenv, 1, 0, do_env_save, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 767 | "save environment variables to persistent storage", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 768 | "" |
Mike Frysinger | ba69dc2 | 2008-12-30 02:59:25 -0500 | [diff] [blame] | 769 | ); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 770 | #endif |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 771 | #endif /* CONFIG_SPL_BUILD */ |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 772 | |
| 773 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 774 | /* |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 775 | * Match a name / name=value pair |
| 776 | * |
| 777 | * s1 is either a simple 'name', or a 'name=value' pair. |
| 778 | * i2 is the environment index for a 'name2=value2' pair. |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 779 | * If the names match, return the index for the value2, else -1. |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 780 | */ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 781 | int envmatch(uchar *s1, int i2) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 782 | { |
Joe Hershberger | 586197d | 2012-10-03 09:38:50 +0000 | [diff] [blame] | 783 | if (s1 == NULL) |
| 784 | return -1; |
| 785 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 786 | while (*s1 == env_get_char(i2++)) |
| 787 | if (*s1++ == '=') |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 788 | return i2; |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 789 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 790 | if (*s1 == '\0' && env_get_char(i2-1) == '=') |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 791 | return i2; |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 792 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 793 | return -1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 794 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 795 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 796 | #ifndef CONFIG_SPL_BUILD |
Yaniv Levinsky | 3009149 | 2018-06-24 19:16:54 +0300 | [diff] [blame] | 797 | static int do_env_default(cmd_tbl_t *cmdtp, int flag, |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 798 | int argc, char * const argv[]) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 799 | { |
Yaniv Levinsky | 5a04264 | 2018-06-24 19:16:56 +0300 | [diff] [blame] | 800 | int all = 0, env_flag = H_INTERACTIVE; |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 801 | |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 802 | debug("Initial value for argc=%d\n", argc); |
| 803 | while (--argc > 0 && **++argv == '-') { |
| 804 | char *arg = *argv; |
| 805 | |
| 806 | while (*++arg) { |
| 807 | switch (*arg) { |
| 808 | case 'a': /* default all */ |
| 809 | all = 1; |
| 810 | break; |
| 811 | case 'f': /* force */ |
Yaniv Levinsky | 3009149 | 2018-06-24 19:16:54 +0300 | [diff] [blame] | 812 | env_flag |= H_FORCE; |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 813 | break; |
| 814 | default: |
| 815 | return cmd_usage(cmdtp); |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | debug("Final value for argc=%d\n", argc); |
| 820 | if (all && (argc == 0)) { |
| 821 | /* Reset the whole environment */ |
Yaniv Levinsky | c5d548a | 2018-06-24 19:16:57 +0300 | [diff] [blame] | 822 | set_default_env("## Resetting to default environment\n", |
| 823 | env_flag); |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 824 | return 0; |
| 825 | } |
| 826 | if (!all && (argc > 0)) { |
| 827 | /* Reset individual variables */ |
Yaniv Levinsky | 477f811 | 2018-06-24 19:16:55 +0300 | [diff] [blame] | 828 | set_default_vars(argc, argv, env_flag); |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | return cmd_usage(cmdtp); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 833 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 834 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 835 | static int do_env_delete(cmd_tbl_t *cmdtp, int flag, |
| 836 | int argc, char * const argv[]) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 837 | { |
Joe Hershberger | 9d8d661 | 2012-12-11 22:16:36 -0600 | [diff] [blame] | 838 | int env_flag = H_INTERACTIVE; |
| 839 | int ret = 0; |
| 840 | |
| 841 | debug("Initial value for argc=%d\n", argc); |
| 842 | while (argc > 1 && **(argv + 1) == '-') { |
| 843 | char *arg = *++argv; |
| 844 | |
| 845 | --argc; |
| 846 | while (*++arg) { |
| 847 | switch (*arg) { |
| 848 | case 'f': /* force */ |
| 849 | env_flag |= H_FORCE; |
| 850 | break; |
| 851 | default: |
| 852 | return CMD_RET_USAGE; |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | debug("Final value for argc=%d\n", argc); |
| 857 | |
| 858 | env_id++; |
| 859 | |
| 860 | while (--argc > 0) { |
| 861 | char *name = *++argv; |
| 862 | |
| 863 | if (!hdelete_r(name, &env_htab, env_flag)) |
| 864 | ret = 1; |
| 865 | } |
| 866 | |
| 867 | return ret; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 868 | } |
| 869 | |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 870 | #ifdef CONFIG_CMD_EXPORTENV |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 871 | /* |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 872 | * env export [-t | -b | -c] [-s size] addr [var ...] |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 873 | * -t: export as text format; if size is given, data will be |
| 874 | * padded with '\0' bytes; if not, one terminating '\0' |
| 875 | * will be added (which is included in the "filesize" |
| 876 | * setting so you can for exmple copy this to flash and |
| 877 | * keep the termination). |
| 878 | * -b: export as binary format (name=value pairs separated by |
| 879 | * '\0', list end marked by double "\0\0") |
| 880 | * -c: export as checksum protected environment format as |
| 881 | * used for example by "saveenv" command |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 882 | * -s size: |
| 883 | * size of output buffer |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 884 | * addr: memory address where environment gets stored |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 885 | * var... List of variable names that get included into the |
| 886 | * export. Without arguments, the whole environment gets |
| 887 | * exported. |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 888 | * |
| 889 | * With "-c" and size is NOT given, then the export command will |
| 890 | * format the data as currently used for the persistent storage, |
| 891 | * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and |
Robert P. J. Day | fc0b594 | 2016-09-07 14:27:59 -0400 | [diff] [blame] | 892 | * prepend a valid CRC32 checksum and, in case of redundant |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 893 | * environment, a "current" redundancy flag. If size is given, this |
| 894 | * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32 |
| 895 | * checksum and redundancy flag will be inserted. |
| 896 | * |
| 897 | * With "-b" and "-t", always only the real data (including a |
| 898 | * terminating '\0' byte) will be written; here the optional size |
| 899 | * argument will be used to make sure not to overflow the user |
| 900 | * provided buffer; the command will abort if the size is not |
Robert P. J. Day | fc0b594 | 2016-09-07 14:27:59 -0400 | [diff] [blame] | 901 | * sufficient. Any remaining space will be '\0' padded. |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 902 | * |
| 903 | * On successful return, the variable "filesize" will be set. |
| 904 | * Note that filesize includes the trailing/terminating '\0' byte(s). |
| 905 | * |
Robert P. J. Day | fc0b594 | 2016-09-07 14:27:59 -0400 | [diff] [blame] | 906 | * Usage scenario: create a text snapshot/backup of the current settings: |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 907 | * |
| 908 | * => env export -t 100000 |
| 909 | * => era ${backup_addr} +${filesize} |
| 910 | * => cp.b 100000 ${backup_addr} ${filesize} |
| 911 | * |
| 912 | * Re-import this snapshot, deleting all other settings: |
| 913 | * |
| 914 | * => env import -d -t ${backup_addr} |
| 915 | */ |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 916 | static int do_env_export(cmd_tbl_t *cmdtp, int flag, |
| 917 | int argc, char * const argv[]) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 918 | { |
| 919 | char buf[32]; |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 920 | ulong addr; |
| 921 | char *ptr, *cmd, *res; |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 922 | size_t size = 0; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 923 | ssize_t len; |
| 924 | env_t *envp; |
| 925 | char sep = '\n'; |
| 926 | int chk = 0; |
| 927 | int fmt = 0; |
| 928 | |
| 929 | cmd = *argv; |
| 930 | |
| 931 | while (--argc > 0 && **++argv == '-') { |
| 932 | char *arg = *argv; |
| 933 | while (*++arg) { |
| 934 | switch (*arg) { |
| 935 | case 'b': /* raw binary format */ |
| 936 | if (fmt++) |
| 937 | goto sep_err; |
| 938 | sep = '\0'; |
| 939 | break; |
| 940 | case 'c': /* external checksum format */ |
| 941 | if (fmt++) |
| 942 | goto sep_err; |
| 943 | sep = '\0'; |
| 944 | chk = 1; |
| 945 | break; |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 946 | case 's': /* size given */ |
| 947 | if (--argc <= 0) |
| 948 | return cmd_usage(cmdtp); |
| 949 | size = simple_strtoul(*++argv, NULL, 16); |
| 950 | goto NXTARG; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 951 | case 't': /* text format */ |
| 952 | if (fmt++) |
| 953 | goto sep_err; |
| 954 | sep = '\n'; |
| 955 | break; |
| 956 | default: |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 957 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 958 | } |
| 959 | } |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 960 | NXTARG: ; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 961 | } |
| 962 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 963 | if (argc < 1) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 964 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 965 | |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 966 | addr = simple_strtoul(argv[0], NULL, 16); |
| 967 | ptr = map_sysmem(addr, size); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 968 | |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 969 | if (size) |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 970 | memset(ptr, '\0', size); |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 971 | |
| 972 | argc--; |
| 973 | argv++; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 974 | |
| 975 | if (sep) { /* export as text file */ |
Wolfgang Denk | ea009d4 | 2013-03-23 23:50:28 +0000 | [diff] [blame] | 976 | len = hexport_r(&env_htab, sep, |
| 977 | H_MATCH_KEY | H_MATCH_IDENT, |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 978 | &ptr, size, argc, argv); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 979 | if (len < 0) { |
Quentin Schulz | 6c90f62 | 2018-07-09 19:16:25 +0200 | [diff] [blame] | 980 | pr_err("## Error: Cannot export environment: errno = %d\n", |
| 981 | errno); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 982 | return 1; |
| 983 | } |
Andreas Bießmann | 8c3aff5 | 2011-02-09 15:10:29 +0100 | [diff] [blame] | 984 | sprintf(buf, "%zX", (size_t)len); |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 985 | env_set("filesize", buf); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 986 | |
| 987 | return 0; |
| 988 | } |
| 989 | |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 990 | envp = (env_t *)ptr; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 991 | |
| 992 | if (chk) /* export as checksum protected block */ |
| 993 | res = (char *)envp->data; |
| 994 | else /* export as raw binary data */ |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 995 | res = ptr; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 996 | |
Wolfgang Denk | ea009d4 | 2013-03-23 23:50:28 +0000 | [diff] [blame] | 997 | len = hexport_r(&env_htab, '\0', |
| 998 | H_MATCH_KEY | H_MATCH_IDENT, |
| 999 | &res, ENV_SIZE, argc, argv); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1000 | if (len < 0) { |
Quentin Schulz | 6c90f62 | 2018-07-09 19:16:25 +0200 | [diff] [blame] | 1001 | pr_err("## Error: Cannot export environment: errno = %d\n", |
| 1002 | errno); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1003 | return 1; |
| 1004 | } |
| 1005 | |
| 1006 | if (chk) { |
Neil Stainton | d71b029 | 2018-09-12 11:02:51 +0000 | [diff] [blame] | 1007 | envp->crc = crc32(0, envp->data, |
| 1008 | size ? size - offsetof(env_t, data) : ENV_SIZE); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1009 | #ifdef CONFIG_ENV_ADDR_REDUND |
| 1010 | envp->flags = ACTIVE_FLAG; |
| 1011 | #endif |
| 1012 | } |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 1013 | env_set_hex("filesize", len + offsetof(env_t, data)); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1014 | |
| 1015 | return 0; |
| 1016 | |
| 1017 | sep_err: |
Quentin Schulz | 6c90f62 | 2018-07-09 19:16:25 +0200 | [diff] [blame] | 1018 | printf("## Error: %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", |
| 1019 | cmd); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1020 | return 1; |
| 1021 | } |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1022 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1023 | |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1024 | #ifdef CONFIG_CMD_IMPORTENV |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1025 | /* |
Quentin Schulz | eaf7347 | 2018-07-09 19:16:29 +0200 | [diff] [blame] | 1026 | * env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] |
| 1027 | * -d: delete existing environment before importing if no var is |
| 1028 | * passed; if vars are passed, if one var is in the current |
| 1029 | * environment but not in the environment at addr, delete var from |
| 1030 | * current environment; |
Robert P. J. Day | fc0b594 | 2016-09-07 14:27:59 -0400 | [diff] [blame] | 1031 | * otherwise overwrite / append to existing definitions |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1032 | * -t: assume text format; either "size" must be given or the |
| 1033 | * text data must be '\0' terminated |
Alexander Holler | ecd1446 | 2014-07-14 17:49:55 +0200 | [diff] [blame] | 1034 | * -r: handle CRLF like LF, that means exported variables with |
| 1035 | * a content which ends with \r won't get imported. Used |
| 1036 | * to import text files created with editors which are using CRLF |
| 1037 | * for line endings. Only effective in addition to -t. |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1038 | * -b: assume binary format ('\0' separated, "\0\0" terminated) |
| 1039 | * -c: assume checksum protected environment format |
| 1040 | * addr: memory address to read from |
| 1041 | * size: length of input data; if missing, proper '\0' |
| 1042 | * termination is mandatory |
Quentin Schulz | eaf7347 | 2018-07-09 19:16:29 +0200 | [diff] [blame] | 1043 | * if var is set and size should be missing (i.e. '\0' |
| 1044 | * termination), set size to '-' |
| 1045 | * var... List of the names of the only variables that get imported from |
| 1046 | * the environment at address 'addr'. Without arguments, the whole |
| 1047 | * environment gets imported. |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1048 | */ |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 1049 | static int do_env_import(cmd_tbl_t *cmdtp, int flag, |
| 1050 | int argc, char * const argv[]) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1051 | { |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 1052 | ulong addr; |
| 1053 | char *cmd, *ptr; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1054 | char sep = '\n'; |
| 1055 | int chk = 0; |
| 1056 | int fmt = 0; |
| 1057 | int del = 0; |
Alexander Holler | ecd1446 | 2014-07-14 17:49:55 +0200 | [diff] [blame] | 1058 | int crlf_is_lf = 0; |
Quentin Schulz | eaf7347 | 2018-07-09 19:16:29 +0200 | [diff] [blame] | 1059 | int wl = 0; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1060 | size_t size; |
| 1061 | |
| 1062 | cmd = *argv; |
| 1063 | |
| 1064 | while (--argc > 0 && **++argv == '-') { |
| 1065 | char *arg = *argv; |
| 1066 | while (*++arg) { |
| 1067 | switch (*arg) { |
| 1068 | case 'b': /* raw binary format */ |
| 1069 | if (fmt++) |
| 1070 | goto sep_err; |
| 1071 | sep = '\0'; |
| 1072 | break; |
| 1073 | case 'c': /* external checksum format */ |
| 1074 | if (fmt++) |
| 1075 | goto sep_err; |
| 1076 | sep = '\0'; |
| 1077 | chk = 1; |
| 1078 | break; |
| 1079 | case 't': /* text format */ |
| 1080 | if (fmt++) |
| 1081 | goto sep_err; |
| 1082 | sep = '\n'; |
| 1083 | break; |
Alexander Holler | ecd1446 | 2014-07-14 17:49:55 +0200 | [diff] [blame] | 1084 | case 'r': /* handle CRLF like LF */ |
| 1085 | crlf_is_lf = 1; |
| 1086 | break; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1087 | case 'd': |
| 1088 | del = 1; |
| 1089 | break; |
| 1090 | default: |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1091 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 1096 | if (argc < 1) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1097 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1098 | |
| 1099 | if (!fmt) |
| 1100 | printf("## Warning: defaulting to text format\n"); |
| 1101 | |
Alexander Holler | ecd1446 | 2014-07-14 17:49:55 +0200 | [diff] [blame] | 1102 | if (sep != '\n' && crlf_is_lf ) |
| 1103 | crlf_is_lf = 0; |
| 1104 | |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 1105 | addr = simple_strtoul(argv[0], NULL, 16); |
| 1106 | ptr = map_sysmem(addr, 0); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1107 | |
Quentin Schulz | eaf7347 | 2018-07-09 19:16:29 +0200 | [diff] [blame] | 1108 | if (argc >= 2 && strcmp(argv[1], "-")) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1109 | size = simple_strtoul(argv[1], NULL, 16); |
Quentin Schulz | eaf7347 | 2018-07-09 19:16:29 +0200 | [diff] [blame] | 1110 | } else if (chk) { |
Tom Rini | 3775dcd | 2014-03-04 15:52:35 -0500 | [diff] [blame] | 1111 | puts("## Error: external checksum format must pass size\n"); |
| 1112 | return CMD_RET_FAILURE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1113 | } else { |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 1114 | char *s = ptr; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1115 | |
| 1116 | size = 0; |
| 1117 | |
| 1118 | while (size < MAX_ENV_SIZE) { |
| 1119 | if ((*s == sep) && (*(s+1) == '\0')) |
| 1120 | break; |
| 1121 | ++s; |
| 1122 | ++size; |
| 1123 | } |
| 1124 | if (size == MAX_ENV_SIZE) { |
| 1125 | printf("## Warning: Input data exceeds %d bytes" |
| 1126 | " - truncated\n", MAX_ENV_SIZE); |
| 1127 | } |
Horst Kronstorfer | d3f80c7 | 2011-12-16 23:33:10 +0000 | [diff] [blame] | 1128 | size += 2; |
Simon Glass | 79afc88 | 2011-11-04 06:42:36 +0000 | [diff] [blame] | 1129 | printf("## Info: input data size = %zu = 0x%zX\n", size, size); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
Quentin Schulz | eaf7347 | 2018-07-09 19:16:29 +0200 | [diff] [blame] | 1132 | if (argc > 2) |
| 1133 | wl = 1; |
| 1134 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1135 | if (chk) { |
| 1136 | uint32_t crc; |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 1137 | env_t *ep = (env_t *)ptr; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1138 | |
| 1139 | size -= offsetof(env_t, data); |
| 1140 | memcpy(&crc, &ep->crc, sizeof(crc)); |
| 1141 | |
| 1142 | if (crc32(0, ep->data, size) != crc) { |
| 1143 | puts("## Error: bad CRC, import failed\n"); |
| 1144 | return 1; |
| 1145 | } |
Simon Glass | fd37dac | 2013-10-25 23:01:31 -0600 | [diff] [blame] | 1146 | ptr = (char *)ep->data; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1147 | } |
| 1148 | |
Quentin Schulz | eaf7347 | 2018-07-09 19:16:29 +0200 | [diff] [blame] | 1149 | if (!himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR, |
| 1150 | crlf_is_lf, wl ? argc - 2 : 0, wl ? &argv[2] : NULL)) { |
Quentin Schulz | 6c90f62 | 2018-07-09 19:16:25 +0200 | [diff] [blame] | 1151 | pr_err("## Error: Environment import failed: errno = %d\n", |
| 1152 | errno); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1153 | return 1; |
| 1154 | } |
| 1155 | gd->flags |= GD_FLG_ENV_READY; |
| 1156 | |
| 1157 | return 0; |
| 1158 | |
| 1159 | sep_err: |
| 1160 | printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", |
| 1161 | cmd); |
| 1162 | return 1; |
| 1163 | } |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1164 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1165 | |
Leo Ruan | 8e92120 | 2019-05-24 17:20:19 +0200 | [diff] [blame] | 1166 | #if defined(CONFIG_CMD_NVEDIT_INFO) |
| 1167 | /* |
| 1168 | * print_env_info - print environment information |
| 1169 | */ |
| 1170 | static int print_env_info(void) |
| 1171 | { |
| 1172 | const char *value; |
| 1173 | |
| 1174 | /* print environment validity value */ |
| 1175 | switch (gd->env_valid) { |
| 1176 | case ENV_INVALID: |
| 1177 | value = "invalid"; |
| 1178 | break; |
| 1179 | case ENV_VALID: |
| 1180 | value = "valid"; |
| 1181 | break; |
| 1182 | case ENV_REDUND: |
| 1183 | value = "redundant"; |
| 1184 | break; |
| 1185 | default: |
| 1186 | value = "unknown"; |
| 1187 | break; |
| 1188 | } |
| 1189 | printf("env_valid = %s\n", value); |
| 1190 | |
| 1191 | /* print environment ready flag */ |
| 1192 | value = gd->flags & GD_FLG_ENV_READY ? "true" : "false"; |
| 1193 | printf("env_ready = %s\n", value); |
| 1194 | |
| 1195 | /* print environment using default flag */ |
| 1196 | value = gd->flags & GD_FLG_ENV_DEFAULT ? "true" : "false"; |
| 1197 | printf("env_use_default = %s\n", value); |
| 1198 | |
| 1199 | return CMD_RET_SUCCESS; |
| 1200 | } |
| 1201 | |
| 1202 | #define ENV_INFO_IS_DEFAULT BIT(0) /* default environment bit mask */ |
| 1203 | #define ENV_INFO_IS_PERSISTED BIT(1) /* environment persistence bit mask */ |
| 1204 | |
| 1205 | /* |
| 1206 | * env info - display environment information |
| 1207 | * env info [-d] - evaluate whether default environment is used |
| 1208 | * env info [-p] - evaluate whether environment can be persisted |
| 1209 | */ |
| 1210 | static int do_env_info(cmd_tbl_t *cmdtp, int flag, |
| 1211 | int argc, char * const argv[]) |
| 1212 | { |
| 1213 | int eval_flags = 0; |
| 1214 | int eval_results = 0; |
| 1215 | |
| 1216 | /* display environment information */ |
| 1217 | if (argc <= 1) |
| 1218 | return print_env_info(); |
| 1219 | |
| 1220 | /* process options */ |
| 1221 | while (--argc > 0 && **++argv == '-') { |
| 1222 | char *arg = *argv; |
| 1223 | |
| 1224 | while (*++arg) { |
| 1225 | switch (*arg) { |
| 1226 | case 'd': |
| 1227 | eval_flags |= ENV_INFO_IS_DEFAULT; |
| 1228 | break; |
| 1229 | case 'p': |
| 1230 | eval_flags |= ENV_INFO_IS_PERSISTED; |
| 1231 | break; |
| 1232 | default: |
| 1233 | return CMD_RET_USAGE; |
| 1234 | } |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | /* evaluate whether default environment is used */ |
| 1239 | if (eval_flags & ENV_INFO_IS_DEFAULT) { |
| 1240 | if (gd->flags & GD_FLG_ENV_DEFAULT) { |
| 1241 | printf("Default environment is used\n"); |
| 1242 | eval_results |= ENV_INFO_IS_DEFAULT; |
| 1243 | } else { |
| 1244 | printf("Environment was loaded from persistent storage\n"); |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | /* evaluate whether environment can be persisted */ |
| 1249 | if (eval_flags & ENV_INFO_IS_PERSISTED) { |
| 1250 | #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) |
| 1251 | printf("Environment can be persisted\n"); |
| 1252 | eval_results |= ENV_INFO_IS_PERSISTED; |
| 1253 | #else |
| 1254 | printf("Environment cannot be persisted\n"); |
| 1255 | #endif |
| 1256 | } |
| 1257 | |
| 1258 | /* The result of evaluations is combined with AND */ |
| 1259 | if (eval_flags != eval_results) |
| 1260 | return CMD_RET_FAILURE; |
| 1261 | |
| 1262 | return CMD_RET_SUCCESS; |
| 1263 | } |
| 1264 | #endif |
| 1265 | |
Andrew Ruder | 88733e2 | 2013-10-22 19:07:34 -0500 | [diff] [blame] | 1266 | #if defined(CONFIG_CMD_ENV_EXISTS) |
| 1267 | static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc, |
| 1268 | char * const argv[]) |
| 1269 | { |
| 1270 | ENTRY e, *ep; |
| 1271 | |
| 1272 | if (argc < 2) |
| 1273 | return CMD_RET_USAGE; |
| 1274 | |
| 1275 | e.key = argv[1]; |
| 1276 | e.data = NULL; |
| 1277 | hsearch_r(e, FIND, &ep, &env_htab, 0); |
| 1278 | |
| 1279 | return (ep == NULL) ? 1 : 0; |
| 1280 | } |
| 1281 | #endif |
| 1282 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1283 | /* |
| 1284 | * New command line interface: "env" command with subcommands |
| 1285 | */ |
| 1286 | static cmd_tbl_t cmd_env_sub[] = { |
| 1287 | #if defined(CONFIG_CMD_ASKENV) |
| 1288 | U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""), |
| 1289 | #endif |
| 1290 | U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""), |
Joe Hershberger | 9d8d661 | 2012-12-11 22:16:36 -0600 | [diff] [blame] | 1291 | U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""), |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1292 | #if defined(CONFIG_CMD_EDITENV) |
| 1293 | U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""), |
| 1294 | #endif |
Joe Hershberger | 5e2b3e0 | 2012-12-11 22:16:25 -0600 | [diff] [blame] | 1295 | #if defined(CONFIG_CMD_ENV_CALLBACK) |
| 1296 | U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""), |
| 1297 | #endif |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 1298 | #if defined(CONFIG_CMD_ENV_FLAGS) |
| 1299 | U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""), |
| 1300 | #endif |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1301 | #if defined(CONFIG_CMD_EXPORTENV) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1302 | U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""), |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1303 | #endif |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1304 | #if defined(CONFIG_CMD_GREPENV) |
| 1305 | U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""), |
| 1306 | #endif |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1307 | #if defined(CONFIG_CMD_IMPORTENV) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1308 | U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""), |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1309 | #endif |
Leo Ruan | 8e92120 | 2019-05-24 17:20:19 +0200 | [diff] [blame] | 1310 | #if defined(CONFIG_CMD_NVEDIT_INFO) |
| 1311 | U_BOOT_CMD_MKENT(info, 2, 0, do_env_info, "", ""), |
| 1312 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1313 | U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""), |
| 1314 | #if defined(CONFIG_CMD_RUN) |
| 1315 | U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""), |
| 1316 | #endif |
Patrick Delaunay | 2643c85 | 2019-02-18 10:58:16 +0100 | [diff] [blame] | 1317 | #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1318 | U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""), |
| 1319 | #endif |
| 1320 | U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""), |
Andrew Ruder | 88733e2 | 2013-10-22 19:07:34 -0500 | [diff] [blame] | 1321 | #if defined(CONFIG_CMD_ENV_EXISTS) |
| 1322 | U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""), |
| 1323 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1324 | }; |
| 1325 | |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 1326 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
Heiko Schocher | 60f7da1 | 2010-10-05 14:17:00 +0200 | [diff] [blame] | 1327 | void env_reloc(void) |
| 1328 | { |
| 1329 | fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub)); |
| 1330 | } |
| 1331 | #endif |
| 1332 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 1333 | static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1334 | { |
| 1335 | cmd_tbl_t *cp; |
| 1336 | |
Thomas Weber | 5904da0 | 2010-11-24 13:07:52 +0100 | [diff] [blame] | 1337 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1338 | return CMD_RET_USAGE; |
Thomas Weber | 5904da0 | 2010-11-24 13:07:52 +0100 | [diff] [blame] | 1339 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1340 | /* drop initial "env" arg */ |
| 1341 | argc--; |
| 1342 | argv++; |
| 1343 | |
| 1344 | cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub)); |
| 1345 | |
| 1346 | if (cp) |
| 1347 | return cp->cmd(cmdtp, flag, argc, argv); |
| 1348 | |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1349 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1350 | } |
| 1351 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1352 | #ifdef CONFIG_SYS_LONGHELP |
| 1353 | static char env_help_text[] = |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1354 | #if defined(CONFIG_CMD_ASKENV) |
| 1355 | "ask name [message] [size] - ask for environment variable\nenv " |
| 1356 | #endif |
Joe Hershberger | 5e2b3e0 | 2012-12-11 22:16:25 -0600 | [diff] [blame] | 1357 | #if defined(CONFIG_CMD_ENV_CALLBACK) |
| 1358 | "callbacks - print callbacks and their associated variables\nenv " |
| 1359 | #endif |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 1360 | "default [-f] -a - [forcibly] reset default environment\n" |
| 1361 | "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n" |
Joe Hershberger | 9d8d661 | 2012-12-11 22:16:36 -0600 | [diff] [blame] | 1362 | "env delete [-f] var [...] - [forcibly] delete variable(s)\n" |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1363 | #if defined(CONFIG_CMD_EDITENV) |
| 1364 | "env edit name - edit environment variable\n" |
| 1365 | #endif |
Andrew Ruder | 88733e2 | 2013-10-22 19:07:34 -0500 | [diff] [blame] | 1366 | #if defined(CONFIG_CMD_ENV_EXISTS) |
| 1367 | "env exists name - tests for existence of variable\n" |
| 1368 | #endif |
Benoît Thébaudeau | 4796bc4 | 2012-08-10 07:45:44 +0000 | [diff] [blame] | 1369 | #if defined(CONFIG_CMD_EXPORTENV) |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 1370 | "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n" |
Benoît Thébaudeau | 4796bc4 | 2012-08-10 07:45:44 +0000 | [diff] [blame] | 1371 | #endif |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 1372 | #if defined(CONFIG_CMD_ENV_FLAGS) |
| 1373 | "env flags - print variables that have non-default flags\n" |
| 1374 | #endif |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1375 | #if defined(CONFIG_CMD_GREPENV) |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1376 | #ifdef CONFIG_REGEX |
| 1377 | "env grep [-e] [-n | -v | -b] string [...] - search environment\n" |
| 1378 | #else |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 1379 | "env grep [-n | -v | -b] string [...] - search environment\n" |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1380 | #endif |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1381 | #endif |
Benoît Thébaudeau | 4796bc4 | 2012-08-10 07:45:44 +0000 | [diff] [blame] | 1382 | #if defined(CONFIG_CMD_IMPORTENV) |
Quentin Schulz | eaf7347 | 2018-07-09 19:16:29 +0200 | [diff] [blame] | 1383 | "env import [-d] [-t [-r] | -b | -c] addr [size] [var ...] - import environment\n" |
Benoît Thébaudeau | 4796bc4 | 2012-08-10 07:45:44 +0000 | [diff] [blame] | 1384 | #endif |
Leo Ruan | 8e92120 | 2019-05-24 17:20:19 +0200 | [diff] [blame] | 1385 | #if defined(CONFIG_CMD_NVEDIT_INFO) |
| 1386 | "env info - display environment information\n" |
| 1387 | "env info [-d] - whether default environment is used\n" |
| 1388 | "env info [-p] - whether environment can be persisted\n" |
| 1389 | #endif |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 1390 | "env print [-a | name ...] - print environment\n" |
AKASHI Takahiro | 49d81fd | 2019-02-25 15:54:36 +0900 | [diff] [blame] | 1391 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
| 1392 | "env print -e [name ...] - print UEFI environment\n" |
| 1393 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1394 | #if defined(CONFIG_CMD_RUN) |
| 1395 | "env run var [...] - run commands in an environment variable\n" |
| 1396 | #endif |
Patrick Delaunay | 2643c85 | 2019-02-18 10:58:16 +0100 | [diff] [blame] | 1397 | #if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1398 | "env save - save environment\n" |
Horst Kronstorfer | d798a9b | 2011-12-10 02:25:19 +0000 | [diff] [blame] | 1399 | #endif |
AKASHI Takahiro | 49d81fd | 2019-02-25 15:54:36 +0900 | [diff] [blame] | 1400 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
| 1401 | "env set -e name [arg ...] - set UEFI variable; unset if 'arg' not specified\n" |
| 1402 | #endif |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1403 | "env set [-f] name [arg ...]\n"; |
| 1404 | #endif |
| 1405 | |
| 1406 | U_BOOT_CMD( |
| 1407 | env, CONFIG_SYS_MAXARGS, 1, do_env, |
| 1408 | "environment handling commands", env_help_text |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1409 | ); |
| 1410 | |
| 1411 | /* |
| 1412 | * Old command line interface, kept for compatibility |
| 1413 | */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1414 | |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 1415 | #if defined(CONFIG_CMD_EDITENV) |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1416 | U_BOOT_CMD_COMPLETE( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1417 | editenv, 2, 0, do_env_edit, |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 1418 | "edit environment variable", |
| 1419 | "name\n" |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1420 | " - edit environment variable 'name'", |
| 1421 | var_complete |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 1422 | ); |
| 1423 | #endif |
| 1424 | |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1425 | U_BOOT_CMD_COMPLETE( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1426 | printenv, CONFIG_SYS_MAXARGS, 1, do_env_print, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1427 | "print environment variables", |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 1428 | "[-a]\n - print [all] values of all environment variables\n" |
AKASHI Takahiro | 49d81fd | 2019-02-25 15:54:36 +0900 | [diff] [blame] | 1429 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
| 1430 | "printenv -e [name ...]\n" |
| 1431 | " - print UEFI variable 'name' or all the variables\n" |
| 1432 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1433 | "printenv name ...\n" |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1434 | " - print value of environment variable 'name'", |
| 1435 | var_complete |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1436 | ); |
| 1437 | |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1438 | #ifdef CONFIG_CMD_GREPENV |
| 1439 | U_BOOT_CMD_COMPLETE( |
| 1440 | grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep, |
| 1441 | "search environment variables", |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1442 | #ifdef CONFIG_REGEX |
| 1443 | "[-e] [-n | -v | -b] string ...\n" |
| 1444 | #else |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 1445 | "[-n | -v | -b] string ...\n" |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1446 | #endif |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 1447 | " - list environment name=value pairs matching 'string'\n" |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1448 | #ifdef CONFIG_REGEX |
| 1449 | " \"-e\": enable regular expressions;\n" |
| 1450 | #endif |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 1451 | " \"-n\": search variable names; \"-v\": search values;\n" |
| 1452 | " \"-b\": search both names and values (default)", |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1453 | var_complete |
| 1454 | ); |
| 1455 | #endif |
| 1456 | |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1457 | U_BOOT_CMD_COMPLETE( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1458 | setenv, CONFIG_SYS_MAXARGS, 0, do_env_set, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1459 | "set environment variables", |
AKASHI Takahiro | 49d81fd | 2019-02-25 15:54:36 +0900 | [diff] [blame] | 1460 | #if defined(CONFIG_CMD_NVEDIT_EFI) |
AKASHI Takahiro | 4b27a76 | 2019-06-04 15:52:11 +0900 | [diff] [blame] | 1461 | "-e [-nv] name [value ...]\n" |
AKASHI Takahiro | 49d81fd | 2019-02-25 15:54:36 +0900 | [diff] [blame] | 1462 | " - set UEFI variable 'name' to 'value' ...'\n" |
AKASHI Takahiro | 4b27a76 | 2019-06-04 15:52:11 +0900 | [diff] [blame] | 1463 | " 'nv' option makes the variable non-volatile\n" |
AKASHI Takahiro | 49d81fd | 2019-02-25 15:54:36 +0900 | [diff] [blame] | 1464 | " - delete UEFI variable 'name' if 'value' not specified\n" |
| 1465 | #endif |
| 1466 | "setenv [-f] name value ...\n" |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 1467 | " - [forcibly] set environment variable 'name' to 'value ...'\n" |
| 1468 | "setenv [-f] name\n" |
| 1469 | " - [forcibly] delete environment variable 'name'", |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1470 | var_complete |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1471 | ); |
| 1472 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 1473 | #if defined(CONFIG_CMD_ASKENV) |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1474 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1475 | U_BOOT_CMD( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1476 | askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1477 | "get environment variables from stdin", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1478 | "name [message] [size]\n" |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 1479 | " - get environment variable 'name' from stdin (max 'size' chars)" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1480 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1481 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1482 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 1483 | #if defined(CONFIG_CMD_RUN) |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1484 | U_BOOT_CMD_COMPLETE( |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1485 | run, CONFIG_SYS_MAXARGS, 1, do_run, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1486 | "run commands in an environment variable", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1487 | "var [...]\n" |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1488 | " - run the commands in the environment variable(s) 'var'", |
| 1489 | var_complete |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1490 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1491 | #endif |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 1492 | #endif /* CONFIG_SPL_BUILD */ |