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