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