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