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