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