wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | ea009d4 | 2013-03-23 23:50:28 +0000 | [diff] [blame] | 2 | * (C) Copyright 2000-2013 |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 6 | * Andreas Heppel <aheppel@sysgo.de> |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 7 | * |
| 8 | * Copyright 2011 Freescale Semiconductor, Inc. |
| 9 | * |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 10 | * See file CREDITS for list of people who contributed to this |
| 11 | * project. |
| 12 | * |
| 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. |
| 17 | * |
| 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. |
| 22 | * |
| 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, |
| 26 | * MA 02111-1307 USA |
| 27 | */ |
| 28 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 29 | /* |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 30 | * Support for persistent environment data |
| 31 | * |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 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 |
| 36 | * flags. |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 37 | * |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 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. |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 41 | */ |
| 42 | |
| 43 | #include <common.h> |
| 44 | #include <command.h> |
| 45 | #include <environment.h> |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 46 | #include <search.h> |
| 47 | #include <errno.h> |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 48 | #include <malloc.h> |
wdenk | 2a3cb02 | 2002-11-05 21:01:48 +0000 | [diff] [blame] | 49 | #include <watchdog.h> |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 50 | #include <linux/stddef.h> |
| 51 | #include <asm/byteorder.h> |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 52 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 53 | DECLARE_GLOBAL_DATA_PTR; |
| 54 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 55 | #if !defined(CONFIG_ENV_IS_IN_EEPROM) && \ |
| 56 | !defined(CONFIG_ENV_IS_IN_FLASH) && \ |
| 57 | !defined(CONFIG_ENV_IS_IN_DATAFLASH) && \ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 58 | !defined(CONFIG_ENV_IS_IN_MMC) && \ |
Maximilian Schwerin | 57210c7 | 2012-03-12 23:57:50 +0000 | [diff] [blame] | 59 | !defined(CONFIG_ENV_IS_IN_FAT) && \ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 60 | !defined(CONFIG_ENV_IS_IN_NAND) && \ |
| 61 | !defined(CONFIG_ENV_IS_IN_NVRAM) && \ |
| 62 | !defined(CONFIG_ENV_IS_IN_ONENAND) && \ |
| 63 | !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \ |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 64 | !defined(CONFIG_ENV_IS_IN_REMOTE) && \ |
Joe Hershberger | 2b74433 | 2013-04-08 10:32:51 +0000 | [diff] [blame] | 65 | !defined(CONFIG_ENV_IS_IN_UBI) && \ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 66 | !defined(CONFIG_ENV_IS_NOWHERE) |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 67 | # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\ |
Joe Hershberger | 2b74433 | 2013-04-08 10:32:51 +0000 | [diff] [blame] | 68 | SPI_FLASH|NVRAM|MMC|FAT|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 71 | /* |
| 72 | * Maximum expected input data size for import command |
| 73 | */ |
| 74 | #define MAX_ENV_SIZE (1 << 20) /* 1 MiB */ |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 75 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 76 | /* |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 77 | * This variable is incremented on each do_env_set(), so it can |
Heiko Schocher | da95427 | 2009-04-28 08:36:11 +0200 | [diff] [blame] | 78 | * be used via get_env_id() as an indication, if the environment |
| 79 | * has changed or not. So it is possible to reread an environment |
| 80 | * variable only if the environment was changed ... done so for |
| 81 | * example in NetInitLoop() |
| 82 | */ |
Heiko Schocher | 2f70c49 | 2009-02-10 09:38:52 +0100 | [diff] [blame] | 83 | static int env_id = 1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 84 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 85 | int get_env_id(void) |
Heiko Schocher | 2f70c49 | 2009-02-10 09:38:52 +0100 | [diff] [blame] | 86 | { |
| 87 | return env_id; |
| 88 | } |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 89 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 90 | #ifndef CONFIG_SPL_BUILD |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 91 | /* |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 92 | * Command interface: print one or all environment variables |
| 93 | * |
| 94 | * Returns 0 in case of error, or length of printed string |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 95 | */ |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 96 | static int env_print(char *name, int flag) |
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 | char *res = NULL; |
Maxime Larocque | 22a4a6c | 2012-09-28 05:00:13 +0000 | [diff] [blame] | 99 | ssize_t len; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 100 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 101 | if (name) { /* print a single name */ |
| 102 | ENTRY e, *ep; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 103 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 104 | e.key = name; |
| 105 | e.data = NULL; |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 106 | hsearch_r(e, FIND, &ep, &env_htab, flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 107 | if (ep == NULL) |
| 108 | return 0; |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 109 | len = printf("%s=%s\n", ep->key, ep->data); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 110 | return len; |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 111 | } |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 112 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 113 | /* print whole list */ |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 114 | len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 115 | |
| 116 | if (len > 0) { |
| 117 | puts(res); |
| 118 | free(res); |
| 119 | return len; |
| 120 | } |
| 121 | |
| 122 | /* should never happen */ |
Maxime Larocque | 22a4a6c | 2012-09-28 05:00:13 +0000 | [diff] [blame] | 123 | printf("## Error: cannot export environment\n"); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 124 | return 0; |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 127 | static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc, |
| 128 | char * const argv[]) |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 129 | { |
| 130 | int i; |
| 131 | int rcode = 0; |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 132 | int env_flag = H_HIDE_DOT; |
| 133 | |
| 134 | if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') { |
| 135 | argc--; |
| 136 | argv++; |
| 137 | env_flag &= ~H_HIDE_DOT; |
| 138 | } |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 139 | |
| 140 | if (argc == 1) { |
| 141 | /* print all env vars */ |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 142 | rcode = env_print(NULL, env_flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 143 | if (!rcode) |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 144 | return 1; |
| 145 | printf("\nEnvironment size: %d/%ld bytes\n", |
| 146 | rcode, (ulong)ENV_SIZE); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 147 | return 0; |
| 148 | } |
| 149 | |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 150 | /* print selected env vars */ |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 151 | env_flag &= ~H_HIDE_DOT; |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 152 | for (i = 1; i < argc; ++i) { |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 153 | int rc = env_print(argv[i], env_flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 154 | if (!rc) { |
| 155 | printf("## Error: \"%s\" not defined\n", argv[i]); |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 156 | ++rcode; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 157 | } |
| 158 | } |
Mike Frysinger | 4c94f6c | 2009-05-24 02:26:19 -0400 | [diff] [blame] | 159 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 160 | return rcode; |
| 161 | } |
| 162 | |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 163 | #ifdef CONFIG_CMD_GREPENV |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 164 | static int do_env_grep(cmd_tbl_t *cmdtp, int flag, |
| 165 | int argc, char * const argv[]) |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 166 | { |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 167 | char *res = NULL; |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 168 | int len, grep_how, grep_what; |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 169 | |
| 170 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 171 | return CMD_RET_USAGE; |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 172 | |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 173 | grep_how = H_MATCH_SUBSTR; /* default: substring search */ |
| 174 | grep_what = H_MATCH_BOTH; /* default: grep names and values */ |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 175 | |
| 176 | while (argc > 1 && **(argv + 1) == '-') { |
| 177 | char *arg = *++argv; |
| 178 | |
| 179 | --argc; |
| 180 | while (*++arg) { |
| 181 | switch (*arg) { |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 182 | #ifdef CONFIG_REGEX |
| 183 | case 'e': /* use regex matching */ |
| 184 | grep_how = H_MATCH_REGEX; |
| 185 | break; |
| 186 | #endif |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 187 | case 'n': /* grep for name */ |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 188 | grep_what = H_MATCH_KEY; |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 189 | break; |
| 190 | case 'v': /* grep for value */ |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 191 | grep_what = H_MATCH_DATA; |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 192 | break; |
| 193 | case 'b': /* grep for both */ |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 194 | grep_what = H_MATCH_BOTH; |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 195 | break; |
| 196 | case '-': |
| 197 | goto DONE; |
| 198 | default: |
| 199 | return CMD_RET_USAGE; |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | DONE: |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 205 | len = hexport_r(&env_htab, '\n', |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 206 | flag | grep_what | grep_how, |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 207 | &res, 0, argc, argv); |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 208 | |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 209 | if (len > 0) { |
| 210 | puts(res); |
| 211 | free(res); |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Wolfgang Denk | 5a31ea0 | 2013-03-23 23:50:29 +0000 | [diff] [blame] | 214 | if (len < 2) |
| 215 | return 1; |
| 216 | |
| 217 | return 0; |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 218 | } |
| 219 | #endif |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 220 | #endif /* CONFIG_SPL_BUILD */ |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 221 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 222 | /* |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 223 | * Set a new environment variable, |
| 224 | * or replace or delete an existing one. |
Joe Hershberger | 2598090 | 2012-12-11 22:16:31 -0600 | [diff] [blame] | 225 | */ |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 226 | static int _do_env_set(int flag, int argc, char * const argv[]) |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 227 | { |
| 228 | int i, len; |
| 229 | char *name, *value, *s; |
| 230 | ENTRY e, *ep; |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 231 | int env_flag = H_INTERACTIVE; |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 232 | |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 233 | debug("Initial value for argc=%d\n", argc); |
| 234 | while (argc > 1 && **(argv + 1) == '-') { |
| 235 | char *arg = *++argv; |
| 236 | |
| 237 | --argc; |
| 238 | while (*++arg) { |
| 239 | switch (*arg) { |
| 240 | case 'f': /* force */ |
| 241 | env_flag |= H_FORCE; |
| 242 | break; |
| 243 | default: |
| 244 | return CMD_RET_USAGE; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | debug("Final value for argc=%d\n", argc); |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 249 | name = argv[1]; |
| 250 | value = argv[2]; |
| 251 | |
| 252 | if (strchr(name, '=')) { |
| 253 | printf("## Error: illegal character '='" |
| 254 | "in variable name \"%s\"\n", name); |
| 255 | return 1; |
| 256 | } |
| 257 | |
| 258 | env_id++; |
Gerlando Falauto | c3f6525 | 2012-08-24 00:11:37 +0000 | [diff] [blame] | 259 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 260 | /* Delete only ? */ |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 261 | if (argc < 3 || argv[2] == NULL) { |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 262 | int rc = hdelete_r(name, &env_htab, env_flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 263 | return !rc; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /* |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 267 | * Insert / replace new value |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 268 | */ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 269 | for (i = 2, len = 0; i < argc; ++i) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 270 | len += strlen(argv[i]) + 1; |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 271 | |
| 272 | value = malloc(len); |
| 273 | if (value == NULL) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 274 | printf("## Can't malloc %d bytes\n", len); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 275 | return 1; |
| 276 | } |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 277 | for (i = 2, s = value; i < argc; ++i) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 278 | char *v = argv[i]; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 279 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 280 | while ((*s++ = *v++) != '\0') |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 281 | ; |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 282 | *(s - 1) = ' '; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 283 | } |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 284 | if (s != value) |
| 285 | *--s = '\0'; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 286 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 287 | e.key = name; |
| 288 | e.data = value; |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 289 | hsearch_r(e, ENTER, &ep, &env_htab, env_flag); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 290 | free(value); |
| 291 | if (!ep) { |
| 292 | printf("## Error inserting \"%s\" variable, errno=%d\n", |
| 293 | name, errno); |
| 294 | return 1; |
| 295 | } |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 296 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
Wolfgang Denk | 84b5e80 | 2011-07-29 14:42:18 +0200 | [diff] [blame] | 300 | int setenv(const char *varname, const char *varvalue) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 301 | { |
Wolfgang Denk | 84b5e80 | 2011-07-29 14:42:18 +0200 | [diff] [blame] | 302 | const char * const argv[4] = { "setenv", varname, varvalue, NULL }; |
| 303 | |
Joe Hershberger | a7eb1d6 | 2013-04-08 10:32:50 +0000 | [diff] [blame] | 304 | /* before import into hashtable */ |
| 305 | if (!(gd->flags & GD_FLG_ENV_READY)) |
| 306 | return 1; |
| 307 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 308 | if (varvalue == NULL || varvalue[0] == '\0') |
Wolfgang Denk | 84b5e80 | 2011-07-29 14:42:18 +0200 | [diff] [blame] | 309 | return _do_env_set(0, 2, (char * const *)argv); |
Jeffrey Mann | 9ffd451 | 2007-04-23 14:00:11 +0200 | [diff] [blame] | 310 | else |
Wolfgang Denk | 84b5e80 | 2011-07-29 14:42:18 +0200 | [diff] [blame] | 311 | return _do_env_set(0, 3, (char * const *)argv); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 314 | /** |
| 315 | * Set an environment variable to an integer value |
| 316 | * |
Simon Glass | 9602286 | 2013-05-07 06:11:45 +0000 | [diff] [blame] | 317 | * @param varname Environment variable to set |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 318 | * @param value Value to set it to |
| 319 | * @return 0 if ok, 1 on error |
| 320 | */ |
| 321 | int setenv_ulong(const char *varname, ulong value) |
| 322 | { |
| 323 | /* TODO: this should be unsigned */ |
| 324 | char *str = simple_itoa(value); |
| 325 | |
| 326 | return setenv(varname, str); |
| 327 | } |
| 328 | |
| 329 | /** |
Simon Glass | bfc5996 | 2013-02-24 17:33:21 +0000 | [diff] [blame] | 330 | * Set an environment variable to an value in hex |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 331 | * |
Simon Glass | 9602286 | 2013-05-07 06:11:45 +0000 | [diff] [blame] | 332 | * @param varname Environment variable to set |
Simon Glass | bfc5996 | 2013-02-24 17:33:21 +0000 | [diff] [blame] | 333 | * @param value Value to set it to |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 334 | * @return 0 if ok, 1 on error |
| 335 | */ |
Simon Glass | bfc5996 | 2013-02-24 17:33:21 +0000 | [diff] [blame] | 336 | int setenv_hex(const char *varname, ulong value) |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 337 | { |
| 338 | char str[17]; |
| 339 | |
Simon Glass | bfc5996 | 2013-02-24 17:33:21 +0000 | [diff] [blame] | 340 | sprintf(str, "%lx", value); |
Simon Glass | d67f10c | 2011-10-24 17:59:59 +0000 | [diff] [blame] | 341 | return setenv(varname, str); |
| 342 | } |
| 343 | |
Simon Glass | 76b8f79 | 2013-04-20 08:42:43 +0000 | [diff] [blame] | 344 | ulong getenv_hex(const char *varname, ulong default_val) |
| 345 | { |
| 346 | const char *s; |
| 347 | ulong value; |
| 348 | char *endp; |
| 349 | |
| 350 | s = getenv(varname); |
| 351 | if (s) |
| 352 | value = simple_strtoul(s, &endp, 16); |
| 353 | if (!s || endp == s) |
| 354 | return default_val; |
| 355 | |
| 356 | return value; |
| 357 | } |
| 358 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 359 | #ifndef CONFIG_SPL_BUILD |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 360 | 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] | 361 | { |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 362 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 363 | return CMD_RET_USAGE; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 364 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 365 | return _do_env_set(flag, argc, argv); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 368 | /* |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 369 | * Prompt for environment variable |
| 370 | */ |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 371 | #if defined(CONFIG_CMD_ASKENV) |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 372 | 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] | 373 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 374 | char message[CONFIG_SYS_CBSIZE]; |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 375 | int i, len, pos, size; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 376 | char *local_args[4]; |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 377 | char *endptr; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 378 | |
| 379 | local_args[0] = argv[0]; |
| 380 | local_args[1] = argv[1]; |
| 381 | local_args[2] = NULL; |
| 382 | local_args[3] = NULL; |
| 383 | |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 384 | /* |
| 385 | * Check the syntax: |
| 386 | * |
| 387 | * env_ask envname [message1 ...] [size] |
| 388 | */ |
| 389 | if (argc == 1) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 390 | return CMD_RET_USAGE; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 391 | |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 392 | /* |
| 393 | * We test the last argument if it can be converted |
| 394 | * into a decimal number. If yes, we assume it's |
| 395 | * the size. Otherwise we echo it as part of the |
| 396 | * message. |
| 397 | */ |
| 398 | i = simple_strtoul(argv[argc - 1], &endptr, 10); |
| 399 | if (*endptr != '\0') { /* no size */ |
| 400 | size = CONFIG_SYS_CBSIZE - 1; |
| 401 | } else { /* size given */ |
| 402 | size = i; |
| 403 | --argc; |
| 404 | } |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 405 | |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 406 | if (argc <= 2) { |
| 407 | sprintf(message, "Please enter '%s': ", argv[1]); |
| 408 | } else { |
| 409 | /* env_ask envname message1 ... messagen [size] */ |
| 410 | for (i = 2, pos = 0; i < argc; i++) { |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 411 | if (pos) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 412 | message[pos++] = ' '; |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 413 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 414 | strcpy(message + pos, argv[i]); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 415 | pos += strlen(argv[i]); |
| 416 | } |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 417 | message[pos++] = ' '; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 418 | message[pos] = '\0'; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 421 | if (size >= CONFIG_SYS_CBSIZE) |
| 422 | size = CONFIG_SYS_CBSIZE - 1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 423 | |
| 424 | if (size <= 0) |
| 425 | return 1; |
| 426 | |
| 427 | /* prompt for input */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 428 | len = readline(message); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 429 | |
| 430 | if (size < len) |
| 431 | console_buffer[size] = '\0'; |
| 432 | |
| 433 | len = 2; |
| 434 | if (console_buffer[0] != '\0') { |
| 435 | local_args[2] = console_buffer; |
| 436 | len = 3; |
| 437 | } |
| 438 | |
| 439 | /* Continue calling setenv code */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 440 | return _do_env_set(flag, len, local_args); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 441 | } |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 442 | #endif |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 443 | |
Joe Hershberger | 5e2b3e0 | 2012-12-11 22:16:25 -0600 | [diff] [blame] | 444 | #if defined(CONFIG_CMD_ENV_CALLBACK) |
| 445 | static int print_static_binding(const char *var_name, const char *callback_name) |
| 446 | { |
| 447 | printf("\t%-20s %-20s\n", var_name, callback_name); |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static int print_active_callback(ENTRY *entry) |
| 453 | { |
| 454 | struct env_clbk_tbl *clbkp; |
| 455 | int i; |
| 456 | int num_callbacks; |
| 457 | |
| 458 | if (entry->callback == NULL) |
| 459 | return 0; |
| 460 | |
| 461 | /* look up the callback in the linker-list */ |
| 462 | num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk); |
| 463 | for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk); |
| 464 | i < num_callbacks; |
| 465 | i++, clbkp++) { |
| 466 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
| 467 | if (entry->callback == clbkp->callback + gd->reloc_off) |
| 468 | #else |
| 469 | if (entry->callback == clbkp->callback) |
| 470 | #endif |
| 471 | break; |
| 472 | } |
| 473 | |
| 474 | if (i == num_callbacks) |
| 475 | /* this should probably never happen, but just in case... */ |
| 476 | printf("\t%-20s %p\n", entry->key, entry->callback); |
| 477 | else |
| 478 | printf("\t%-20s %-20s\n", entry->key, clbkp->name); |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | * Print the callbacks available and what they are bound to |
| 485 | */ |
| 486 | int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 487 | { |
| 488 | struct env_clbk_tbl *clbkp; |
| 489 | int i; |
| 490 | int num_callbacks; |
| 491 | |
| 492 | /* Print the available callbacks */ |
| 493 | puts("Available callbacks:\n"); |
| 494 | puts("\tCallback Name\n"); |
| 495 | puts("\t-------------\n"); |
| 496 | num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk); |
| 497 | for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk); |
| 498 | i < num_callbacks; |
| 499 | i++, clbkp++) |
| 500 | printf("\t%s\n", clbkp->name); |
| 501 | puts("\n"); |
| 502 | |
| 503 | /* Print the static bindings that may exist */ |
| 504 | puts("Static callback bindings:\n"); |
| 505 | printf("\t%-20s %-20s\n", "Variable Name", "Callback Name"); |
| 506 | printf("\t%-20s %-20s\n", "-------------", "-------------"); |
| 507 | env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding); |
| 508 | puts("\n"); |
| 509 | |
| 510 | /* walk through each variable and print the callback if it has one */ |
| 511 | puts("Active callback bindings:\n"); |
| 512 | printf("\t%-20s %-20s\n", "Variable Name", "Callback Name"); |
| 513 | printf("\t%-20s %-20s\n", "-------------", "-------------"); |
| 514 | hwalk_r(&env_htab, print_active_callback); |
| 515 | return 0; |
| 516 | } |
| 517 | #endif |
| 518 | |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 519 | #if defined(CONFIG_CMD_ENV_FLAGS) |
| 520 | static int print_static_flags(const char *var_name, const char *flags) |
| 521 | { |
| 522 | enum env_flags_vartype type = env_flags_parse_vartype(flags); |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 523 | enum env_flags_varaccess access = env_flags_parse_varaccess(flags); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 524 | |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 525 | printf("\t%-20s %-20s %-20s\n", var_name, |
| 526 | env_flags_get_vartype_name(type), |
| 527 | env_flags_get_varaccess_name(access)); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static int print_active_flags(ENTRY *entry) |
| 533 | { |
| 534 | enum env_flags_vartype type; |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 535 | enum env_flags_varaccess access; |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 536 | |
| 537 | if (entry->flags == 0) |
| 538 | return 0; |
| 539 | |
| 540 | type = (enum env_flags_vartype) |
| 541 | (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK); |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 542 | access = env_flags_parse_varaccess_from_binflags(entry->flags); |
| 543 | printf("\t%-20s %-20s %-20s\n", entry->key, |
| 544 | env_flags_get_vartype_name(type), |
| 545 | env_flags_get_varaccess_name(access)); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * Print the flags available and what variables have flags |
| 552 | */ |
| 553 | int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 554 | { |
| 555 | /* Print the available variable types */ |
| 556 | printf("Available variable type flags (position %d):\n", |
| 557 | ENV_FLAGS_VARTYPE_LOC); |
| 558 | puts("\tFlag\tVariable Type Name\n"); |
| 559 | puts("\t----\t------------------\n"); |
| 560 | env_flags_print_vartypes(); |
| 561 | puts("\n"); |
| 562 | |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 563 | /* Print the available variable access types */ |
| 564 | printf("Available variable access flags (position %d):\n", |
| 565 | ENV_FLAGS_VARACCESS_LOC); |
| 566 | puts("\tFlag\tVariable Access Name\n"); |
| 567 | puts("\t----\t--------------------\n"); |
| 568 | env_flags_print_varaccess(); |
| 569 | puts("\n"); |
| 570 | |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 571 | /* Print the static flags that may exist */ |
| 572 | puts("Static flags:\n"); |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 573 | printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type", |
| 574 | "Variable Access"); |
| 575 | printf("\t%-20s %-20s %-20s\n", "-------------", "-------------", |
| 576 | "---------------"); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 577 | env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags); |
| 578 | puts("\n"); |
| 579 | |
| 580 | /* walk through each variable and print the flags if non-default */ |
| 581 | puts("Active flags:\n"); |
Joe Hershberger | 267541f | 2012-12-11 22:16:34 -0600 | [diff] [blame] | 582 | printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type", |
| 583 | "Variable Access"); |
| 584 | printf("\t%-20s %-20s %-20s\n", "-------------", "-------------", |
| 585 | "---------------"); |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 586 | hwalk_r(&env_htab, print_active_flags); |
| 587 | return 0; |
| 588 | } |
| 589 | #endif |
| 590 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 591 | /* |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 592 | * Interactively edit an environment variable |
| 593 | */ |
| 594 | #if defined(CONFIG_CMD_EDITENV) |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 595 | static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, |
| 596 | char * const argv[]) |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 597 | { |
| 598 | char buffer[CONFIG_SYS_CBSIZE]; |
| 599 | char *init_val; |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 600 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 601 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 602 | return CMD_RET_USAGE; |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 603 | |
| 604 | /* Set read buffer to initial value or empty sting */ |
| 605 | init_val = getenv(argv[1]); |
| 606 | if (init_val) |
Marek Vasut | 7fcd9bb | 2011-09-26 02:26:03 +0200 | [diff] [blame] | 607 | sprintf(buffer, "%s", init_val); |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 608 | else |
| 609 | buffer[0] = '\0'; |
| 610 | |
Joe Hershberger | 18a3cce | 2013-02-08 10:12:34 +0000 | [diff] [blame] | 611 | if (readline_into_buffer("edit: ", buffer, 0) < 0) |
| 612 | return 1; |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 613 | |
| 614 | return setenv(argv[1], buffer); |
| 615 | } |
| 616 | #endif /* CONFIG_CMD_EDITENV */ |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 617 | #endif /* CONFIG_SPL_BUILD */ |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 618 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 619 | /* |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 620 | * Look up variable from environment, |
| 621 | * return address of storage for that variable, |
| 622 | * or NULL if not found |
| 623 | */ |
Wolfgang Denk | 84b5e80 | 2011-07-29 14:42:18 +0200 | [diff] [blame] | 624 | char *getenv(const char *name) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 625 | { |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 626 | if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 627 | ENTRY e, *ep; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 628 | |
Wolfgang Denk | 91a7675 | 2010-07-24 20:22:02 +0200 | [diff] [blame] | 629 | WATCHDOG_RESET(); |
wdenk | 2a3cb02 | 2002-11-05 21:01:48 +0000 | [diff] [blame] | 630 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 631 | e.key = name; |
| 632 | e.data = NULL; |
Joe Hershberger | c4e0057 | 2012-12-11 22:16:19 -0600 | [diff] [blame] | 633 | hsearch_r(e, FIND, &ep, &env_htab, 0); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 634 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 635 | return ep ? ep->data : NULL; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 638 | /* restricted capabilities before import */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 639 | if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0) |
| 640 | return (char *)(gd->env_buf); |
| 641 | |
| 642 | return NULL; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 645 | /* |
| 646 | * Look up variable from environment for restricted C runtime env. |
| 647 | */ |
Wolfgang Denk | 84b5e80 | 2011-07-29 14:42:18 +0200 | [diff] [blame] | 648 | int getenv_f(const char *name, char *buf, unsigned len) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 649 | { |
| 650 | int i, nxt; |
| 651 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 652 | for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) { |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 653 | int val, n; |
| 654 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 655 | for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) { |
| 656 | if (nxt >= CONFIG_ENV_SIZE) |
| 657 | return -1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 658 | } |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 659 | |
| 660 | val = envmatch((uchar *)name, i); |
| 661 | if (val < 0) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 662 | continue; |
Wolfgang Denk | 9ed4a95 | 2010-07-24 22:16:20 +0200 | [diff] [blame] | 663 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 664 | /* found; copy out */ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 665 | for (n = 0; n < len; ++n, ++buf) { |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 666 | *buf = env_get_char(val++); |
| 667 | if (*buf == '\0') |
Wolfgang Denk | 9ed4a95 | 2010-07-24 22:16:20 +0200 | [diff] [blame] | 668 | return n; |
| 669 | } |
| 670 | |
| 671 | if (n) |
| 672 | *--buf = '\0'; |
| 673 | |
Wolfgang Denk | a02a884 | 2011-05-04 10:29:49 +0000 | [diff] [blame] | 674 | printf("env_buf [%d bytes] too small for value of \"%s\"\n", |
| 675 | len, name); |
Wolfgang Denk | 9ed4a95 | 2010-07-24 22:16:20 +0200 | [diff] [blame] | 676 | |
| 677 | return n; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 678 | } |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 679 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 680 | return -1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 681 | } |
| 682 | |
Simon Glass | 4a9b413 | 2011-10-14 13:25:18 +0000 | [diff] [blame] | 683 | /** |
| 684 | * Decode the integer value of an environment variable and return it. |
| 685 | * |
| 686 | * @param name Name of environemnt variable |
| 687 | * @param base Number base to use (normally 10, or 16 for hex) |
| 688 | * @param default_val Default value to return if the variable is not |
| 689 | * found |
| 690 | * @return the decoded value, or default_val if not found |
| 691 | */ |
| 692 | ulong getenv_ulong(const char *name, int base, ulong default_val) |
| 693 | { |
| 694 | /* |
| 695 | * We can use getenv() here, even before relocation, since the |
| 696 | * environment variable value is an integer and thus short. |
| 697 | */ |
| 698 | const char *str = getenv(name); |
| 699 | |
| 700 | return str ? simple_strtoul(str, NULL, base) : default_val; |
| 701 | } |
| 702 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 703 | #ifndef CONFIG_SPL_BUILD |
Mike Frysinger | bdab39d | 2009-01-28 19:08:14 -0500 | [diff] [blame] | 704 | #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 705 | static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, |
| 706 | char * const argv[]) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 707 | { |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 708 | printf("Saving Environment to %s...\n", env_name_spec); |
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 | return saveenv() ? 1 : 0; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 711 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 712 | |
Mike Frysinger | ba69dc2 | 2008-12-30 02:59:25 -0500 | [diff] [blame] | 713 | U_BOOT_CMD( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 714 | saveenv, 1, 0, do_env_save, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 715 | "save environment variables to persistent storage", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 716 | "" |
Mike Frysinger | ba69dc2 | 2008-12-30 02:59:25 -0500 | [diff] [blame] | 717 | ); |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 718 | #endif |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 719 | #endif /* CONFIG_SPL_BUILD */ |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 720 | |
| 721 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 722 | /* |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 723 | * Match a name / name=value pair |
| 724 | * |
| 725 | * s1 is either a simple 'name', or a 'name=value' pair. |
| 726 | * i2 is the environment index for a 'name2=value2' pair. |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 727 | * If the names match, return the index for the value2, else -1. |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 728 | */ |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 729 | int envmatch(uchar *s1, int i2) |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 730 | { |
Joe Hershberger | 586197d | 2012-10-03 09:38:50 +0000 | [diff] [blame] | 731 | if (s1 == NULL) |
| 732 | return -1; |
| 733 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 734 | while (*s1 == env_get_char(i2++)) |
| 735 | if (*s1++ == '=') |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 736 | return i2; |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 737 | |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 738 | if (*s1 == '\0' && env_get_char(i2-1) == '=') |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 739 | return i2; |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 740 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 741 | return -1; |
wdenk | a68d3ed | 2002-10-11 08:38:32 +0000 | [diff] [blame] | 742 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 743 | |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 744 | #ifndef CONFIG_SPL_BUILD |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 745 | static int do_env_default(cmd_tbl_t *cmdtp, int __flag, |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 746 | int argc, char * const argv[]) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 747 | { |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 748 | int all = 0, flag = 0; |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 749 | |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 750 | debug("Initial value for argc=%d\n", argc); |
| 751 | while (--argc > 0 && **++argv == '-') { |
| 752 | char *arg = *argv; |
| 753 | |
| 754 | while (*++arg) { |
| 755 | switch (*arg) { |
| 756 | case 'a': /* default all */ |
| 757 | all = 1; |
| 758 | break; |
| 759 | case 'f': /* force */ |
| 760 | flag |= H_FORCE; |
| 761 | break; |
| 762 | default: |
| 763 | return cmd_usage(cmdtp); |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | debug("Final value for argc=%d\n", argc); |
| 768 | if (all && (argc == 0)) { |
| 769 | /* Reset the whole environment */ |
| 770 | set_default_env("## Resetting to default environment\n"); |
| 771 | return 0; |
| 772 | } |
| 773 | if (!all && (argc > 0)) { |
| 774 | /* Reset individual variables */ |
| 775 | set_default_vars(argc, argv); |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | return cmd_usage(cmdtp); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 780 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 781 | |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 782 | static int do_env_delete(cmd_tbl_t *cmdtp, int flag, |
| 783 | int argc, char * const argv[]) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 784 | { |
Joe Hershberger | 9d8d661 | 2012-12-11 22:16:36 -0600 | [diff] [blame] | 785 | int env_flag = H_INTERACTIVE; |
| 786 | int ret = 0; |
| 787 | |
| 788 | debug("Initial value for argc=%d\n", argc); |
| 789 | while (argc > 1 && **(argv + 1) == '-') { |
| 790 | char *arg = *++argv; |
| 791 | |
| 792 | --argc; |
| 793 | while (*++arg) { |
| 794 | switch (*arg) { |
| 795 | case 'f': /* force */ |
| 796 | env_flag |= H_FORCE; |
| 797 | break; |
| 798 | default: |
| 799 | return CMD_RET_USAGE; |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | debug("Final value for argc=%d\n", argc); |
| 804 | |
| 805 | env_id++; |
| 806 | |
| 807 | while (--argc > 0) { |
| 808 | char *name = *++argv; |
| 809 | |
| 810 | if (!hdelete_r(name, &env_htab, env_flag)) |
| 811 | ret = 1; |
| 812 | } |
| 813 | |
| 814 | return ret; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 815 | } |
| 816 | |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 817 | #ifdef CONFIG_CMD_EXPORTENV |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 818 | /* |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 819 | * env export [-t | -b | -c] [-s size] addr [var ...] |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 820 | * -t: export as text format; if size is given, data will be |
| 821 | * padded with '\0' bytes; if not, one terminating '\0' |
| 822 | * will be added (which is included in the "filesize" |
| 823 | * setting so you can for exmple copy this to flash and |
| 824 | * keep the termination). |
| 825 | * -b: export as binary format (name=value pairs separated by |
| 826 | * '\0', list end marked by double "\0\0") |
| 827 | * -c: export as checksum protected environment format as |
| 828 | * used for example by "saveenv" command |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 829 | * -s size: |
| 830 | * size of output buffer |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 831 | * addr: memory address where environment gets stored |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 832 | * var... List of variable names that get included into the |
| 833 | * export. Without arguments, the whole environment gets |
| 834 | * exported. |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 835 | * |
| 836 | * With "-c" and size is NOT given, then the export command will |
| 837 | * format the data as currently used for the persistent storage, |
| 838 | * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and |
| 839 | * prepend a valid CRC32 checksum and, in case of resundant |
| 840 | * environment, a "current" redundancy flag. If size is given, this |
| 841 | * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32 |
| 842 | * checksum and redundancy flag will be inserted. |
| 843 | * |
| 844 | * With "-b" and "-t", always only the real data (including a |
| 845 | * terminating '\0' byte) will be written; here the optional size |
| 846 | * argument will be used to make sure not to overflow the user |
| 847 | * provided buffer; the command will abort if the size is not |
| 848 | * sufficient. Any remainign space will be '\0' padded. |
| 849 | * |
| 850 | * On successful return, the variable "filesize" will be set. |
| 851 | * Note that filesize includes the trailing/terminating '\0' byte(s). |
| 852 | * |
| 853 | * Usage szenario: create a text snapshot/backup of the current settings: |
| 854 | * |
| 855 | * => env export -t 100000 |
| 856 | * => era ${backup_addr} +${filesize} |
| 857 | * => cp.b 100000 ${backup_addr} ${filesize} |
| 858 | * |
| 859 | * Re-import this snapshot, deleting all other settings: |
| 860 | * |
| 861 | * => env import -d -t ${backup_addr} |
| 862 | */ |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 863 | static int do_env_export(cmd_tbl_t *cmdtp, int flag, |
| 864 | int argc, char * const argv[]) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 865 | { |
| 866 | char buf[32]; |
| 867 | char *addr, *cmd, *res; |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 868 | size_t size = 0; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 869 | ssize_t len; |
| 870 | env_t *envp; |
| 871 | char sep = '\n'; |
| 872 | int chk = 0; |
| 873 | int fmt = 0; |
| 874 | |
| 875 | cmd = *argv; |
| 876 | |
| 877 | while (--argc > 0 && **++argv == '-') { |
| 878 | char *arg = *argv; |
| 879 | while (*++arg) { |
| 880 | switch (*arg) { |
| 881 | case 'b': /* raw binary format */ |
| 882 | if (fmt++) |
| 883 | goto sep_err; |
| 884 | sep = '\0'; |
| 885 | break; |
| 886 | case 'c': /* external checksum format */ |
| 887 | if (fmt++) |
| 888 | goto sep_err; |
| 889 | sep = '\0'; |
| 890 | chk = 1; |
| 891 | break; |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 892 | case 's': /* size given */ |
| 893 | if (--argc <= 0) |
| 894 | return cmd_usage(cmdtp); |
| 895 | size = simple_strtoul(*++argv, NULL, 16); |
| 896 | goto NXTARG; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 897 | case 't': /* text format */ |
| 898 | if (fmt++) |
| 899 | goto sep_err; |
| 900 | sep = '\n'; |
| 901 | break; |
| 902 | default: |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 903 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 904 | } |
| 905 | } |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 906 | NXTARG: ; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 907 | } |
| 908 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 909 | if (argc < 1) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 910 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 911 | |
| 912 | addr = (char *)simple_strtoul(argv[0], NULL, 16); |
| 913 | |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 914 | if (size) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 915 | memset(addr, '\0', size); |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 916 | |
| 917 | argc--; |
| 918 | argv++; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 919 | |
| 920 | if (sep) { /* export as text file */ |
Wolfgang Denk | ea009d4 | 2013-03-23 23:50:28 +0000 | [diff] [blame] | 921 | len = hexport_r(&env_htab, sep, |
| 922 | H_MATCH_KEY | H_MATCH_IDENT, |
| 923 | &addr, size, argc, argv); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 924 | if (len < 0) { |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 925 | error("Cannot export environment: errno = %d\n", errno); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 926 | return 1; |
| 927 | } |
Andreas Bießmann | 8c3aff5 | 2011-02-09 15:10:29 +0100 | [diff] [blame] | 928 | sprintf(buf, "%zX", (size_t)len); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 929 | setenv("filesize", buf); |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | envp = (env_t *)addr; |
| 935 | |
| 936 | if (chk) /* export as checksum protected block */ |
| 937 | res = (char *)envp->data; |
| 938 | else /* export as raw binary data */ |
| 939 | res = addr; |
| 940 | |
Wolfgang Denk | ea009d4 | 2013-03-23 23:50:28 +0000 | [diff] [blame] | 941 | len = hexport_r(&env_htab, '\0', |
| 942 | H_MATCH_KEY | H_MATCH_IDENT, |
| 943 | &res, ENV_SIZE, argc, argv); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 944 | if (len < 0) { |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 945 | error("Cannot export environment: errno = %d\n", errno); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 946 | return 1; |
| 947 | } |
| 948 | |
| 949 | if (chk) { |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 950 | envp->crc = crc32(0, envp->data, ENV_SIZE); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 951 | #ifdef CONFIG_ENV_ADDR_REDUND |
| 952 | envp->flags = ACTIVE_FLAG; |
| 953 | #endif |
| 954 | } |
Simon Glass | 41ef372 | 2013-02-24 17:33:22 +0000 | [diff] [blame] | 955 | setenv_hex("filesize", len + offsetof(env_t, data)); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 956 | |
| 957 | return 0; |
| 958 | |
| 959 | sep_err: |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 960 | printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 961 | return 1; |
| 962 | } |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 963 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 964 | |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 965 | #ifdef CONFIG_CMD_IMPORTENV |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 966 | /* |
| 967 | * env import [-d] [-t | -b | -c] addr [size] |
| 968 | * -d: delete existing environment before importing; |
| 969 | * otherwise overwrite / append to existion definitions |
| 970 | * -t: assume text format; either "size" must be given or the |
| 971 | * text data must be '\0' terminated |
| 972 | * -b: assume binary format ('\0' separated, "\0\0" terminated) |
| 973 | * -c: assume checksum protected environment format |
| 974 | * addr: memory address to read from |
| 975 | * size: length of input data; if missing, proper '\0' |
| 976 | * termination is mandatory |
| 977 | */ |
Igor Grinberg | d09b178 | 2011-11-07 01:13:59 +0000 | [diff] [blame] | 978 | static int do_env_import(cmd_tbl_t *cmdtp, int flag, |
| 979 | int argc, char * const argv[]) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 980 | { |
| 981 | char *cmd, *addr; |
| 982 | char sep = '\n'; |
| 983 | int chk = 0; |
| 984 | int fmt = 0; |
| 985 | int del = 0; |
| 986 | size_t size; |
| 987 | |
| 988 | cmd = *argv; |
| 989 | |
| 990 | while (--argc > 0 && **++argv == '-') { |
| 991 | char *arg = *argv; |
| 992 | while (*++arg) { |
| 993 | switch (*arg) { |
| 994 | case 'b': /* raw binary format */ |
| 995 | if (fmt++) |
| 996 | goto sep_err; |
| 997 | sep = '\0'; |
| 998 | break; |
| 999 | case 'c': /* external checksum format */ |
| 1000 | if (fmt++) |
| 1001 | goto sep_err; |
| 1002 | sep = '\0'; |
| 1003 | chk = 1; |
| 1004 | break; |
| 1005 | case 't': /* text format */ |
| 1006 | if (fmt++) |
| 1007 | goto sep_err; |
| 1008 | sep = '\n'; |
| 1009 | break; |
| 1010 | case 'd': |
| 1011 | del = 1; |
| 1012 | break; |
| 1013 | default: |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1014 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | } |
| 1018 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 1019 | if (argc < 1) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1020 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1021 | |
| 1022 | if (!fmt) |
| 1023 | printf("## Warning: defaulting to text format\n"); |
| 1024 | |
| 1025 | addr = (char *)simple_strtoul(argv[0], NULL, 16); |
| 1026 | |
| 1027 | if (argc == 2) { |
| 1028 | size = simple_strtoul(argv[1], NULL, 16); |
| 1029 | } else { |
| 1030 | char *s = addr; |
| 1031 | |
| 1032 | size = 0; |
| 1033 | |
| 1034 | while (size < MAX_ENV_SIZE) { |
| 1035 | if ((*s == sep) && (*(s+1) == '\0')) |
| 1036 | break; |
| 1037 | ++s; |
| 1038 | ++size; |
| 1039 | } |
| 1040 | if (size == MAX_ENV_SIZE) { |
| 1041 | printf("## Warning: Input data exceeds %d bytes" |
| 1042 | " - truncated\n", MAX_ENV_SIZE); |
| 1043 | } |
Horst Kronstorfer | d3f80c7 | 2011-12-16 23:33:10 +0000 | [diff] [blame] | 1044 | size += 2; |
Simon Glass | 79afc88 | 2011-11-04 06:42:36 +0000 | [diff] [blame] | 1045 | printf("## Info: input data size = %zu = 0x%zX\n", size, size); |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | if (chk) { |
| 1049 | uint32_t crc; |
| 1050 | env_t *ep = (env_t *)addr; |
| 1051 | |
| 1052 | size -= offsetof(env_t, data); |
| 1053 | memcpy(&crc, &ep->crc, sizeof(crc)); |
| 1054 | |
| 1055 | if (crc32(0, ep->data, size) != crc) { |
| 1056 | puts("## Error: bad CRC, import failed\n"); |
| 1057 | return 1; |
| 1058 | } |
| 1059 | addr = (char *)ep->data; |
| 1060 | } |
| 1061 | |
Gerlando Falauto | 348b1f1 | 2012-08-24 00:11:38 +0000 | [diff] [blame] | 1062 | if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR, |
Joe Hershberger | c4e0057 | 2012-12-11 22:16:19 -0600 | [diff] [blame] | 1063 | 0, NULL) == 0) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1064 | error("Environment import failed: errno = %d\n", errno); |
| 1065 | return 1; |
| 1066 | } |
| 1067 | gd->flags |= GD_FLG_ENV_READY; |
| 1068 | |
| 1069 | return 0; |
| 1070 | |
| 1071 | sep_err: |
| 1072 | printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", |
| 1073 | cmd); |
| 1074 | return 1; |
| 1075 | } |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1076 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1077 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1078 | /* |
| 1079 | * New command line interface: "env" command with subcommands |
| 1080 | */ |
| 1081 | static cmd_tbl_t cmd_env_sub[] = { |
| 1082 | #if defined(CONFIG_CMD_ASKENV) |
| 1083 | U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""), |
| 1084 | #endif |
| 1085 | U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""), |
Joe Hershberger | 9d8d661 | 2012-12-11 22:16:36 -0600 | [diff] [blame] | 1086 | U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""), |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1087 | #if defined(CONFIG_CMD_EDITENV) |
| 1088 | U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""), |
| 1089 | #endif |
Joe Hershberger | 5e2b3e0 | 2012-12-11 22:16:25 -0600 | [diff] [blame] | 1090 | #if defined(CONFIG_CMD_ENV_CALLBACK) |
| 1091 | U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""), |
| 1092 | #endif |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 1093 | #if defined(CONFIG_CMD_ENV_FLAGS) |
| 1094 | U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""), |
| 1095 | #endif |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1096 | #if defined(CONFIG_CMD_EXPORTENV) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1097 | U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""), |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1098 | #endif |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1099 | #if defined(CONFIG_CMD_GREPENV) |
| 1100 | U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""), |
| 1101 | #endif |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1102 | #if defined(CONFIG_CMD_IMPORTENV) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1103 | U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""), |
Mike Frysinger | 0c79cda | 2010-12-26 23:09:45 -0500 | [diff] [blame] | 1104 | #endif |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1105 | U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""), |
| 1106 | #if defined(CONFIG_CMD_RUN) |
| 1107 | U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""), |
| 1108 | #endif |
| 1109 | #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) |
| 1110 | U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""), |
| 1111 | #endif |
| 1112 | U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""), |
| 1113 | }; |
| 1114 | |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 1115 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
Heiko Schocher | 60f7da1 | 2010-10-05 14:17:00 +0200 | [diff] [blame] | 1116 | void env_reloc(void) |
| 1117 | { |
| 1118 | fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub)); |
| 1119 | } |
| 1120 | #endif |
| 1121 | |
Macpaul Lin | f3c615b | 2011-04-26 16:16:45 +0000 | [diff] [blame] | 1122 | 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] | 1123 | { |
| 1124 | cmd_tbl_t *cp; |
| 1125 | |
Thomas Weber | 5904da0 | 2010-11-24 13:07:52 +0100 | [diff] [blame] | 1126 | if (argc < 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1127 | return CMD_RET_USAGE; |
Thomas Weber | 5904da0 | 2010-11-24 13:07:52 +0100 | [diff] [blame] | 1128 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1129 | /* drop initial "env" arg */ |
| 1130 | argc--; |
| 1131 | argv++; |
| 1132 | |
| 1133 | cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub)); |
| 1134 | |
| 1135 | if (cp) |
| 1136 | return cp->cmd(cmdtp, flag, argc, argv); |
| 1137 | |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 1138 | return CMD_RET_USAGE; |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1139 | } |
| 1140 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1141 | #ifdef CONFIG_SYS_LONGHELP |
| 1142 | static char env_help_text[] = |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1143 | #if defined(CONFIG_CMD_ASKENV) |
| 1144 | "ask name [message] [size] - ask for environment variable\nenv " |
| 1145 | #endif |
Joe Hershberger | 5e2b3e0 | 2012-12-11 22:16:25 -0600 | [diff] [blame] | 1146 | #if defined(CONFIG_CMD_ENV_CALLBACK) |
| 1147 | "callbacks - print callbacks and their associated variables\nenv " |
| 1148 | #endif |
Gerlando Falauto | b64b7c3 | 2012-08-24 00:11:41 +0000 | [diff] [blame] | 1149 | "default [-f] -a - [forcibly] reset default environment\n" |
| 1150 | "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] | 1151 | "env delete [-f] var [...] - [forcibly] delete variable(s)\n" |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1152 | #if defined(CONFIG_CMD_EDITENV) |
| 1153 | "env edit name - edit environment variable\n" |
| 1154 | #endif |
Benoît Thébaudeau | 4796bc4 | 2012-08-10 07:45:44 +0000 | [diff] [blame] | 1155 | #if defined(CONFIG_CMD_EXPORTENV) |
Wolfgang Denk | 37f2fe7 | 2011-11-06 22:49:44 +0100 | [diff] [blame] | 1156 | "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] | 1157 | #endif |
Joe Hershberger | fffad71 | 2012-12-11 22:16:33 -0600 | [diff] [blame] | 1158 | #if defined(CONFIG_CMD_ENV_FLAGS) |
| 1159 | "env flags - print variables that have non-default flags\n" |
| 1160 | #endif |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1161 | #if defined(CONFIG_CMD_GREPENV) |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1162 | #ifdef CONFIG_REGEX |
| 1163 | "env grep [-e] [-n | -v | -b] string [...] - search environment\n" |
| 1164 | #else |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 1165 | "env grep [-n | -v | -b] string [...] - search environment\n" |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1166 | #endif |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1167 | #endif |
Benoît Thébaudeau | 4796bc4 | 2012-08-10 07:45:44 +0000 | [diff] [blame] | 1168 | #if defined(CONFIG_CMD_IMPORTENV) |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1169 | "env import [-d] [-t | -b | -c] addr [size] - import environment\n" |
Benoît Thébaudeau | 4796bc4 | 2012-08-10 07:45:44 +0000 | [diff] [blame] | 1170 | #endif |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 1171 | "env print [-a | name ...] - print environment\n" |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1172 | #if defined(CONFIG_CMD_RUN) |
| 1173 | "env run var [...] - run commands in an environment variable\n" |
| 1174 | #endif |
Horst Kronstorfer | d798a9b | 2011-12-10 02:25:19 +0000 | [diff] [blame] | 1175 | #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1176 | "env save - save environment\n" |
Horst Kronstorfer | d798a9b | 2011-12-10 02:25:19 +0000 | [diff] [blame] | 1177 | #endif |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1178 | "env set [-f] name [arg ...]\n"; |
| 1179 | #endif |
| 1180 | |
| 1181 | U_BOOT_CMD( |
| 1182 | env, CONFIG_SYS_MAXARGS, 1, do_env, |
| 1183 | "environment handling commands", env_help_text |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1184 | ); |
| 1185 | |
| 1186 | /* |
| 1187 | * Old command line interface, kept for compatibility |
| 1188 | */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1189 | |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 1190 | #if defined(CONFIG_CMD_EDITENV) |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1191 | U_BOOT_CMD_COMPLETE( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1192 | editenv, 2, 0, do_env_edit, |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 1193 | "edit environment variable", |
| 1194 | "name\n" |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1195 | " - edit environment variable 'name'", |
| 1196 | var_complete |
Peter Tyser | 246c692 | 2009-10-25 15:12:56 -0500 | [diff] [blame] | 1197 | ); |
| 1198 | #endif |
| 1199 | |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1200 | U_BOOT_CMD_COMPLETE( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1201 | printenv, CONFIG_SYS_MAXARGS, 1, do_env_print, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1202 | "print environment variables", |
Joe Hershberger | be11235 | 2012-12-11 22:16:23 -0600 | [diff] [blame] | 1203 | "[-a]\n - print [all] values of all environment variables\n" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1204 | "printenv name ...\n" |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1205 | " - print value of environment variable 'name'", |
| 1206 | var_complete |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1207 | ); |
| 1208 | |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1209 | #ifdef CONFIG_CMD_GREPENV |
| 1210 | U_BOOT_CMD_COMPLETE( |
| 1211 | grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep, |
| 1212 | "search environment variables", |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1213 | #ifdef CONFIG_REGEX |
| 1214 | "[-e] [-n | -v | -b] string ...\n" |
| 1215 | #else |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 1216 | "[-n | -v | -b] string ...\n" |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1217 | #endif |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 1218 | " - list environment name=value pairs matching 'string'\n" |
Wolfgang Denk | be29df6 | 2013-03-23 23:50:32 +0000 | [diff] [blame] | 1219 | #ifdef CONFIG_REGEX |
| 1220 | " \"-e\": enable regular expressions;\n" |
| 1221 | #endif |
Wolfgang Denk | d87244d | 2013-03-23 23:50:30 +0000 | [diff] [blame] | 1222 | " \"-n\": search variable names; \"-v\": search values;\n" |
| 1223 | " \"-b\": search both names and values (default)", |
Kim Phillips | a000b79 | 2011-04-05 07:15:14 +0000 | [diff] [blame] | 1224 | var_complete |
| 1225 | ); |
| 1226 | #endif |
| 1227 | |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1228 | U_BOOT_CMD_COMPLETE( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1229 | setenv, CONFIG_SYS_MAXARGS, 0, do_env_set, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1230 | "set environment variables", |
Joe Hershberger | 24ab5a1 | 2012-12-11 22:16:35 -0600 | [diff] [blame] | 1231 | "[-f] name value ...\n" |
| 1232 | " - [forcibly] set environment variable 'name' to 'value ...'\n" |
| 1233 | "setenv [-f] name\n" |
| 1234 | " - [forcibly] delete environment variable 'name'", |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1235 | var_complete |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1236 | ); |
| 1237 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 1238 | #if defined(CONFIG_CMD_ASKENV) |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1239 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1240 | U_BOOT_CMD( |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 1241 | askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1242 | "get environment variables from stdin", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1243 | "name [message] [size]\n" |
Wolfgang Denk | 7d85591 | 2013-02-20 04:53:16 +0000 | [diff] [blame] | 1244 | " - get environment variable 'name' from stdin (max 'size' chars)" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1245 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1246 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1247 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 1248 | #if defined(CONFIG_CMD_RUN) |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1249 | U_BOOT_CMD_COMPLETE( |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1250 | run, CONFIG_SYS_MAXARGS, 1, do_run, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1251 | "run commands in an environment variable", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1252 | "var [...]\n" |
Mike Frysinger | 722b061 | 2010-10-20 03:52:39 -0400 | [diff] [blame] | 1253 | " - run the commands in the environment variable(s) 'var'", |
| 1254 | var_complete |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1255 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1256 | #endif |
Ilya Yanok | 7ac2fe2 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 1257 | #endif /* CONFIG_SPL_BUILD */ |