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