blob: 6ca5a2e5a90f700ae9e0e31f8b96edd683c54465 [file] [log] [blame]
wdenka68d3ed2002-10-11 08:38:32 +00001/*
Wolfgang Denkea009d42013-03-23 23:50:28 +00002 * (C) Copyright 2000-2013
wdenka68d3ed2002-10-11 08:38:32 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6 * Andreas Heppel <aheppel@sysgo.de>
Kim Phillipsa000b792011-04-05 07:15:14 +00007 *
8 * Copyright 2011 Freescale Semiconductor, Inc.
9 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +020010 * SPDX-License-Identifier: GPL-2.0+
wdenka68d3ed2002-10-11 08:38:32 +000011 */
12
Wolfgang Denkea882ba2010-06-20 23:33:59 +020013/*
wdenka68d3ed2002-10-11 08:38:32 +000014 * Support for persistent environment data
15 *
Wolfgang Denkea882ba2010-06-20 23:33:59 +020016 * The "environment" is stored on external storage as a list of '\0'
17 * terminated "name=value" strings. The end of the list is marked by
18 * a double '\0'. The environment is preceeded by a 32 bit CRC over
19 * the data part and, in case of redundant environment, a byte of
20 * flags.
wdenka68d3ed2002-10-11 08:38:32 +000021 *
Wolfgang Denkea882ba2010-06-20 23:33:59 +020022 * This linearized representation will also be used before
23 * relocation, i. e. as long as we don't have a full C runtime
24 * environment. After that, we use a hash table.
wdenka68d3ed2002-10-11 08:38:32 +000025 */
26
27#include <common.h>
Simon Glass18d66532014-04-10 20:01:25 -060028#include <cli.h>
wdenka68d3ed2002-10-11 08:38:32 +000029#include <command.h>
30#include <environment.h>
Wolfgang Denkea882ba2010-06-20 23:33:59 +020031#include <search.h>
32#include <errno.h>
Peter Tyser246c6922009-10-25 15:12:56 -050033#include <malloc.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050034#include <mapmem.h>
wdenk2a3cb022002-11-05 21:01:48 +000035#include <watchdog.h>
wdenka68d3ed2002-10-11 08:38:32 +000036#include <linux/stddef.h>
37#include <asm/byteorder.h>
Simon Glassfd37dac2013-10-25 23:01:31 -060038#include <asm/io.h>
wdenka68d3ed2002-10-11 08:38:32 +000039
Wolfgang Denkd87080b2006-03-31 18:32:53 +020040DECLARE_GLOBAL_DATA_PTR;
41
Macpaul Linf3c615b2011-04-26 16:16:45 +000042#if !defined(CONFIG_ENV_IS_IN_EEPROM) && \
43 !defined(CONFIG_ENV_IS_IN_FLASH) && \
44 !defined(CONFIG_ENV_IS_IN_DATAFLASH) && \
Macpaul Linf3c615b2011-04-26 16:16:45 +000045 !defined(CONFIG_ENV_IS_IN_MMC) && \
Maximilian Schwerin57210c72012-03-12 23:57:50 +000046 !defined(CONFIG_ENV_IS_IN_FAT) && \
Macpaul Linf3c615b2011-04-26 16:16:45 +000047 !defined(CONFIG_ENV_IS_IN_NAND) && \
48 !defined(CONFIG_ENV_IS_IN_NVRAM) && \
49 !defined(CONFIG_ENV_IS_IN_ONENAND) && \
50 !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \
Liu Gang0a85a9e2012-03-08 00:33:20 +000051 !defined(CONFIG_ENV_IS_IN_REMOTE) && \
Joe Hershberger2b744332013-04-08 10:32:51 +000052 !defined(CONFIG_ENV_IS_IN_UBI) && \
Macpaul Linf3c615b2011-04-26 16:16:45 +000053 !defined(CONFIG_ENV_IS_NOWHERE)
unsik Kim75eb82e2009-02-25 11:31:24 +090054# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
Joe Hershberger2b744332013-04-08 10:32:51 +000055SPI_FLASH|NVRAM|MMC|FAT|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
wdenka68d3ed2002-10-11 08:38:32 +000056#endif
57
Wolfgang Denkea882ba2010-06-20 23:33:59 +020058/*
59 * Maximum expected input data size for import command
60 */
61#define MAX_ENV_SIZE (1 << 20) /* 1 MiB */
wdenka68d3ed2002-10-11 08:38:32 +000062
wdenka68d3ed2002-10-11 08:38:32 +000063/*
Wolfgang Denkea882ba2010-06-20 23:33:59 +020064 * This variable is incremented on each do_env_set(), so it can
Heiko Schocherda954272009-04-28 08:36:11 +020065 * be used via get_env_id() as an indication, if the environment
66 * has changed or not. So it is possible to reread an environment
67 * variable only if the environment was changed ... done so for
68 * example in NetInitLoop()
69 */
Heiko Schocher2f70c492009-02-10 09:38:52 +010070static int env_id = 1;
wdenka68d3ed2002-10-11 08:38:32 +000071
Macpaul Linf3c615b2011-04-26 16:16:45 +000072int get_env_id(void)
Heiko Schocher2f70c492009-02-10 09:38:52 +010073{
74 return env_id;
75}
wdenka68d3ed2002-10-11 08:38:32 +000076
Ilya Yanok7ac2fe22012-09-18 00:22:50 +000077#ifndef CONFIG_SPL_BUILD
Mike Frysinger4c94f6c2009-05-24 02:26:19 -040078/*
Wolfgang Denkea882ba2010-06-20 23:33:59 +020079 * Command interface: print one or all environment variables
80 *
81 * Returns 0 in case of error, or length of printed string
Mike Frysinger4c94f6c2009-05-24 02:26:19 -040082 */
Joe Hershbergerbe112352012-12-11 22:16:23 -060083static int env_print(char *name, int flag)
wdenka68d3ed2002-10-11 08:38:32 +000084{
Wolfgang Denkea882ba2010-06-20 23:33:59 +020085 char *res = NULL;
Maxime Larocque22a4a6c2012-09-28 05:00:13 +000086 ssize_t len;
wdenka68d3ed2002-10-11 08:38:32 +000087
Wolfgang Denkea882ba2010-06-20 23:33:59 +020088 if (name) { /* print a single name */
89 ENTRY e, *ep;
wdenka68d3ed2002-10-11 08:38:32 +000090
Wolfgang Denkea882ba2010-06-20 23:33:59 +020091 e.key = name;
92 e.data = NULL;
Joe Hershbergerbe112352012-12-11 22:16:23 -060093 hsearch_r(e, FIND, &ep, &env_htab, flag);
Wolfgang Denkea882ba2010-06-20 23:33:59 +020094 if (ep == NULL)
95 return 0;
Macpaul Linf3c615b2011-04-26 16:16:45 +000096 len = printf("%s=%s\n", ep->key, ep->data);
Wolfgang Denkea882ba2010-06-20 23:33:59 +020097 return len;
Mike Frysinger4c94f6c2009-05-24 02:26:19 -040098 }
wdenka68d3ed2002-10-11 08:38:32 +000099
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200100 /* print whole list */
Joe Hershbergerbe112352012-12-11 22:16:23 -0600101 len = hexport_r(&env_htab, '\n', flag, &res, 0, 0, NULL);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200102
103 if (len > 0) {
104 puts(res);
105 free(res);
106 return len;
107 }
108
109 /* should never happen */
Maxime Larocque22a4a6c2012-09-28 05:00:13 +0000110 printf("## Error: cannot export environment\n");
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200111 return 0;
Mike Frysinger4c94f6c2009-05-24 02:26:19 -0400112}
113
Kim Phillips088f1b12012-10-29 13:34:31 +0000114static int do_env_print(cmd_tbl_t *cmdtp, int flag, int argc,
115 char * const argv[])
Mike Frysinger4c94f6c2009-05-24 02:26:19 -0400116{
117 int i;
118 int rcode = 0;
Joe Hershbergerbe112352012-12-11 22:16:23 -0600119 int env_flag = H_HIDE_DOT;
120
121 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'a') {
122 argc--;
123 argv++;
124 env_flag &= ~H_HIDE_DOT;
125 }
Mike Frysinger4c94f6c2009-05-24 02:26:19 -0400126
127 if (argc == 1) {
128 /* print all env vars */
Joe Hershbergerbe112352012-12-11 22:16:23 -0600129 rcode = env_print(NULL, env_flag);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200130 if (!rcode)
Mike Frysinger4c94f6c2009-05-24 02:26:19 -0400131 return 1;
132 printf("\nEnvironment size: %d/%ld bytes\n",
133 rcode, (ulong)ENV_SIZE);
wdenka68d3ed2002-10-11 08:38:32 +0000134 return 0;
135 }
136
Mike Frysinger4c94f6c2009-05-24 02:26:19 -0400137 /* print selected env vars */
Joe Hershbergerbe112352012-12-11 22:16:23 -0600138 env_flag &= ~H_HIDE_DOT;
Mike Frysinger4c94f6c2009-05-24 02:26:19 -0400139 for (i = 1; i < argc; ++i) {
Joe Hershbergerbe112352012-12-11 22:16:23 -0600140 int rc = env_print(argv[i], env_flag);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200141 if (!rc) {
142 printf("## Error: \"%s\" not defined\n", argv[i]);
Mike Frysinger4c94f6c2009-05-24 02:26:19 -0400143 ++rcode;
wdenka68d3ed2002-10-11 08:38:32 +0000144 }
145 }
Mike Frysinger4c94f6c2009-05-24 02:26:19 -0400146
wdenka68d3ed2002-10-11 08:38:32 +0000147 return rcode;
148}
149
Kim Phillipsa000b792011-04-05 07:15:14 +0000150#ifdef CONFIG_CMD_GREPENV
Igor Grinbergd09b1782011-11-07 01:13:59 +0000151static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
152 int argc, char * const argv[])
Kim Phillipsa000b792011-04-05 07:15:14 +0000153{
Wolfgang Denk5a31ea02013-03-23 23:50:29 +0000154 char *res = NULL;
Wolfgang Denkbe29df62013-03-23 23:50:32 +0000155 int len, grep_how, grep_what;
Kim Phillipsa000b792011-04-05 07:15:14 +0000156
157 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000158 return CMD_RET_USAGE;
Kim Phillipsa000b792011-04-05 07:15:14 +0000159
Wolfgang Denkbe29df62013-03-23 23:50:32 +0000160 grep_how = H_MATCH_SUBSTR; /* default: substring search */
161 grep_what = H_MATCH_BOTH; /* default: grep names and values */
Wolfgang Denkd87244d2013-03-23 23:50:30 +0000162
Pierre Aubert9a832332013-10-08 14:20:27 +0200163 while (--argc > 0 && **++argv == '-') {
164 char *arg = *argv;
Wolfgang Denkd87244d2013-03-23 23:50:30 +0000165 while (*++arg) {
166 switch (*arg) {
Wolfgang Denkbe29df62013-03-23 23:50:32 +0000167#ifdef CONFIG_REGEX
168 case 'e': /* use regex matching */
169 grep_how = H_MATCH_REGEX;
170 break;
171#endif
Wolfgang Denkd87244d2013-03-23 23:50:30 +0000172 case 'n': /* grep for name */
Wolfgang Denkbe29df62013-03-23 23:50:32 +0000173 grep_what = H_MATCH_KEY;
Wolfgang Denkd87244d2013-03-23 23:50:30 +0000174 break;
175 case 'v': /* grep for value */
Wolfgang Denkbe29df62013-03-23 23:50:32 +0000176 grep_what = H_MATCH_DATA;
Wolfgang Denkd87244d2013-03-23 23:50:30 +0000177 break;
178 case 'b': /* grep for both */
Wolfgang Denkbe29df62013-03-23 23:50:32 +0000179 grep_what = H_MATCH_BOTH;
Wolfgang Denkd87244d2013-03-23 23:50:30 +0000180 break;
181 case '-':
182 goto DONE;
183 default:
184 return CMD_RET_USAGE;
185 }
186 }
187 }
188
189DONE:
Wolfgang Denk5a31ea02013-03-23 23:50:29 +0000190 len = hexport_r(&env_htab, '\n',
Wolfgang Denkbe29df62013-03-23 23:50:32 +0000191 flag | grep_what | grep_how,
Wolfgang Denk5a31ea02013-03-23 23:50:29 +0000192 &res, 0, argc, argv);
Kim Phillipsa000b792011-04-05 07:15:14 +0000193
Wolfgang Denk5a31ea02013-03-23 23:50:29 +0000194 if (len > 0) {
195 puts(res);
196 free(res);
Kim Phillipsa000b792011-04-05 07:15:14 +0000197 }
198
Wolfgang Denk5a31ea02013-03-23 23:50:29 +0000199 if (len < 2)
200 return 1;
201
202 return 0;
Kim Phillipsa000b792011-04-05 07:15:14 +0000203}
204#endif
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000205#endif /* CONFIG_SPL_BUILD */
Kim Phillipsa000b792011-04-05 07:15:14 +0000206
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200207/*
Gerlando Falautoc3f65252012-08-24 00:11:37 +0000208 * Set a new environment variable,
209 * or replace or delete an existing one.
Joe Hershberger25980902012-12-11 22:16:31 -0600210 */
Kim Phillips088f1b12012-10-29 13:34:31 +0000211static int _do_env_set(int flag, int argc, char * const argv[])
Gerlando Falautoc3f65252012-08-24 00:11:37 +0000212{
213 int i, len;
214 char *name, *value, *s;
215 ENTRY e, *ep;
Joe Hershberger24ab5a12012-12-11 22:16:35 -0600216 int env_flag = H_INTERACTIVE;
Gerlando Falautoc3f65252012-08-24 00:11:37 +0000217
Joe Hershberger24ab5a12012-12-11 22:16:35 -0600218 debug("Initial value for argc=%d\n", argc);
219 while (argc > 1 && **(argv + 1) == '-') {
220 char *arg = *++argv;
221
222 --argc;
223 while (*++arg) {
224 switch (*arg) {
225 case 'f': /* force */
226 env_flag |= H_FORCE;
227 break;
228 default:
229 return CMD_RET_USAGE;
230 }
231 }
232 }
233 debug("Final value for argc=%d\n", argc);
Gerlando Falautoc3f65252012-08-24 00:11:37 +0000234 name = argv[1];
235 value = argv[2];
236
237 if (strchr(name, '=')) {
238 printf("## Error: illegal character '='"
239 "in variable name \"%s\"\n", name);
240 return 1;
241 }
242
243 env_id++;
Gerlando Falautoc3f65252012-08-24 00:11:37 +0000244
wdenka68d3ed2002-10-11 08:38:32 +0000245 /* Delete only ? */
Igor Grinbergd09b1782011-11-07 01:13:59 +0000246 if (argc < 3 || argv[2] == NULL) {
Joe Hershberger24ab5a12012-12-11 22:16:35 -0600247 int rc = hdelete_r(name, &env_htab, env_flag);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200248 return !rc;
wdenka68d3ed2002-10-11 08:38:32 +0000249 }
250
251 /*
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200252 * Insert / replace new value
wdenka68d3ed2002-10-11 08:38:32 +0000253 */
Macpaul Linf3c615b2011-04-26 16:16:45 +0000254 for (i = 2, len = 0; i < argc; ++i)
wdenka68d3ed2002-10-11 08:38:32 +0000255 len += strlen(argv[i]) + 1;
Macpaul Linf3c615b2011-04-26 16:16:45 +0000256
257 value = malloc(len);
258 if (value == NULL) {
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200259 printf("## Can't malloc %d bytes\n", len);
wdenka68d3ed2002-10-11 08:38:32 +0000260 return 1;
261 }
Macpaul Linf3c615b2011-04-26 16:16:45 +0000262 for (i = 2, s = value; i < argc; ++i) {
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200263 char *v = argv[i];
wdenka68d3ed2002-10-11 08:38:32 +0000264
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200265 while ((*s++ = *v++) != '\0')
wdenka68d3ed2002-10-11 08:38:32 +0000266 ;
Igor Grinbergd09b1782011-11-07 01:13:59 +0000267 *(s - 1) = ' ';
wdenka68d3ed2002-10-11 08:38:32 +0000268 }
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200269 if (s != value)
270 *--s = '\0';
wdenka68d3ed2002-10-11 08:38:32 +0000271
Igor Grinbergd09b1782011-11-07 01:13:59 +0000272 e.key = name;
273 e.data = value;
Joe Hershberger24ab5a12012-12-11 22:16:35 -0600274 hsearch_r(e, ENTER, &ep, &env_htab, env_flag);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200275 free(value);
276 if (!ep) {
277 printf("## Error inserting \"%s\" variable, errno=%d\n",
278 name, errno);
279 return 1;
280 }
wdenka68d3ed2002-10-11 08:38:32 +0000281
wdenka68d3ed2002-10-11 08:38:32 +0000282 return 0;
283}
284
Wolfgang Denk84b5e802011-07-29 14:42:18 +0200285int setenv(const char *varname, const char *varvalue)
wdenka68d3ed2002-10-11 08:38:32 +0000286{
Wolfgang Denk84b5e802011-07-29 14:42:18 +0200287 const char * const argv[4] = { "setenv", varname, varvalue, NULL };
288
Joe Hershbergera7eb1d62013-04-08 10:32:50 +0000289 /* before import into hashtable */
290 if (!(gd->flags & GD_FLG_ENV_READY))
291 return 1;
292
Igor Grinbergd09b1782011-11-07 01:13:59 +0000293 if (varvalue == NULL || varvalue[0] == '\0')
Wolfgang Denk84b5e802011-07-29 14:42:18 +0200294 return _do_env_set(0, 2, (char * const *)argv);
Jeffrey Mann9ffd4512007-04-23 14:00:11 +0200295 else
Wolfgang Denk84b5e802011-07-29 14:42:18 +0200296 return _do_env_set(0, 3, (char * const *)argv);
wdenka68d3ed2002-10-11 08:38:32 +0000297}
298
Simon Glassd67f10c2011-10-24 17:59:59 +0000299/**
300 * Set an environment variable to an integer value
301 *
Simon Glass96022862013-05-07 06:11:45 +0000302 * @param varname Environment variable to set
Simon Glassd67f10c2011-10-24 17:59:59 +0000303 * @param value Value to set it to
304 * @return 0 if ok, 1 on error
305 */
306int setenv_ulong(const char *varname, ulong value)
307{
308 /* TODO: this should be unsigned */
309 char *str = simple_itoa(value);
310
311 return setenv(varname, str);
312}
313
314/**
Simon Glassbfc59962013-02-24 17:33:21 +0000315 * Set an environment variable to an value in hex
Simon Glassd67f10c2011-10-24 17:59:59 +0000316 *
Simon Glass96022862013-05-07 06:11:45 +0000317 * @param varname Environment variable to set
Simon Glassbfc59962013-02-24 17:33:21 +0000318 * @param value Value to set it to
Simon Glassd67f10c2011-10-24 17:59:59 +0000319 * @return 0 if ok, 1 on error
320 */
Simon Glassbfc59962013-02-24 17:33:21 +0000321int setenv_hex(const char *varname, ulong value)
Simon Glassd67f10c2011-10-24 17:59:59 +0000322{
323 char str[17];
324
Simon Glassbfc59962013-02-24 17:33:21 +0000325 sprintf(str, "%lx", value);
Simon Glassd67f10c2011-10-24 17:59:59 +0000326 return setenv(varname, str);
327}
328
Simon Glass76b8f792013-04-20 08:42:43 +0000329ulong getenv_hex(const char *varname, ulong default_val)
330{
331 const char *s;
332 ulong value;
333 char *endp;
334
335 s = getenv(varname);
336 if (s)
337 value = simple_strtoul(s, &endp, 16);
338 if (!s || endp == s)
339 return default_val;
340
341 return value;
342}
343
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000344#ifndef CONFIG_SPL_BUILD
Kim Phillips088f1b12012-10-29 13:34:31 +0000345static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenka68d3ed2002-10-11 08:38:32 +0000346{
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200347 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000348 return CMD_RET_USAGE;
wdenka68d3ed2002-10-11 08:38:32 +0000349
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200350 return _do_env_set(flag, argc, argv);
wdenka68d3ed2002-10-11 08:38:32 +0000351}
352
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200353/*
wdenka68d3ed2002-10-11 08:38:32 +0000354 * Prompt for environment variable
355 */
Jon Loeligerc76fe472007-07-08 18:02:23 -0500356#if defined(CONFIG_CMD_ASKENV)
Macpaul Linf3c615b2011-04-26 16:16:45 +0000357int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenka68d3ed2002-10-11 08:38:32 +0000358{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200359 char message[CONFIG_SYS_CBSIZE];
Wolfgang Denk7d855912013-02-20 04:53:16 +0000360 int i, len, pos, size;
wdenka68d3ed2002-10-11 08:38:32 +0000361 char *local_args[4];
Wolfgang Denk7d855912013-02-20 04:53:16 +0000362 char *endptr;
wdenka68d3ed2002-10-11 08:38:32 +0000363
364 local_args[0] = argv[0];
365 local_args[1] = argv[1];
366 local_args[2] = NULL;
367 local_args[3] = NULL;
368
Wolfgang Denk7d855912013-02-20 04:53:16 +0000369 /*
370 * Check the syntax:
371 *
372 * env_ask envname [message1 ...] [size]
373 */
374 if (argc == 1)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000375 return CMD_RET_USAGE;
wdenka68d3ed2002-10-11 08:38:32 +0000376
Wolfgang Denk7d855912013-02-20 04:53:16 +0000377 /*
378 * We test the last argument if it can be converted
379 * into a decimal number. If yes, we assume it's
380 * the size. Otherwise we echo it as part of the
381 * message.
382 */
383 i = simple_strtoul(argv[argc - 1], &endptr, 10);
384 if (*endptr != '\0') { /* no size */
385 size = CONFIG_SYS_CBSIZE - 1;
386 } else { /* size given */
387 size = i;
388 --argc;
389 }
wdenka68d3ed2002-10-11 08:38:32 +0000390
Wolfgang Denk7d855912013-02-20 04:53:16 +0000391 if (argc <= 2) {
392 sprintf(message, "Please enter '%s': ", argv[1]);
393 } else {
394 /* env_ask envname message1 ... messagen [size] */
395 for (i = 2, pos = 0; i < argc; i++) {
Macpaul Linf3c615b2011-04-26 16:16:45 +0000396 if (pos)
wdenka68d3ed2002-10-11 08:38:32 +0000397 message[pos++] = ' ';
Macpaul Linf3c615b2011-04-26 16:16:45 +0000398
Igor Grinbergd09b1782011-11-07 01:13:59 +0000399 strcpy(message + pos, argv[i]);
wdenka68d3ed2002-10-11 08:38:32 +0000400 pos += strlen(argv[i]);
401 }
Wolfgang Denk7d855912013-02-20 04:53:16 +0000402 message[pos++] = ' ';
wdenka68d3ed2002-10-11 08:38:32 +0000403 message[pos] = '\0';
wdenka68d3ed2002-10-11 08:38:32 +0000404 }
405
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200406 if (size >= CONFIG_SYS_CBSIZE)
407 size = CONFIG_SYS_CBSIZE - 1;
wdenka68d3ed2002-10-11 08:38:32 +0000408
409 if (size <= 0)
410 return 1;
411
412 /* prompt for input */
Simon Glasse1bf8242014-04-10 20:01:27 -0600413 len = cli_readline(message);
wdenka68d3ed2002-10-11 08:38:32 +0000414
415 if (size < len)
416 console_buffer[size] = '\0';
417
418 len = 2;
419 if (console_buffer[0] != '\0') {
420 local_args[2] = console_buffer;
421 len = 3;
422 }
423
424 /* Continue calling setenv code */
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200425 return _do_env_set(flag, len, local_args);
wdenka68d3ed2002-10-11 08:38:32 +0000426}
Jon Loeliger90253172007-07-10 11:02:44 -0500427#endif
wdenka68d3ed2002-10-11 08:38:32 +0000428
Joe Hershberger5e2b3e02012-12-11 22:16:25 -0600429#if defined(CONFIG_CMD_ENV_CALLBACK)
Joe Hershbergercca98fd2015-05-20 14:27:19 -0500430static int print_static_binding(const char *var_name, const char *callback_name,
431 void *priv)
Joe Hershberger5e2b3e02012-12-11 22:16:25 -0600432{
433 printf("\t%-20s %-20s\n", var_name, callback_name);
434
435 return 0;
436}
437
438static int print_active_callback(ENTRY *entry)
439{
440 struct env_clbk_tbl *clbkp;
441 int i;
442 int num_callbacks;
443
444 if (entry->callback == NULL)
445 return 0;
446
447 /* look up the callback in the linker-list */
448 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
449 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
450 i < num_callbacks;
451 i++, clbkp++) {
452#if defined(CONFIG_NEEDS_MANUAL_RELOC)
453 if (entry->callback == clbkp->callback + gd->reloc_off)
454#else
455 if (entry->callback == clbkp->callback)
456#endif
457 break;
458 }
459
460 if (i == num_callbacks)
461 /* this should probably never happen, but just in case... */
462 printf("\t%-20s %p\n", entry->key, entry->callback);
463 else
464 printf("\t%-20s %-20s\n", entry->key, clbkp->name);
465
466 return 0;
467}
468
469/*
470 * Print the callbacks available and what they are bound to
471 */
472int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
473{
474 struct env_clbk_tbl *clbkp;
475 int i;
476 int num_callbacks;
477
478 /* Print the available callbacks */
479 puts("Available callbacks:\n");
480 puts("\tCallback Name\n");
481 puts("\t-------------\n");
482 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
483 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
484 i < num_callbacks;
485 i++, clbkp++)
486 printf("\t%s\n", clbkp->name);
487 puts("\n");
488
489 /* Print the static bindings that may exist */
490 puts("Static callback bindings:\n");
491 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
492 printf("\t%-20s %-20s\n", "-------------", "-------------");
Joe Hershbergercca98fd2015-05-20 14:27:19 -0500493 env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding, NULL);
Joe Hershberger5e2b3e02012-12-11 22:16:25 -0600494 puts("\n");
495
496 /* walk through each variable and print the callback if it has one */
497 puts("Active callback bindings:\n");
498 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
499 printf("\t%-20s %-20s\n", "-------------", "-------------");
500 hwalk_r(&env_htab, print_active_callback);
501 return 0;
502}
503#endif
504
Joe Hershbergerfffad712012-12-11 22:16:33 -0600505#if defined(CONFIG_CMD_ENV_FLAGS)
Joe Hershbergercca98fd2015-05-20 14:27:19 -0500506static int print_static_flags(const char *var_name, const char *flags,
507 void *priv)
Joe Hershbergerfffad712012-12-11 22:16:33 -0600508{
509 enum env_flags_vartype type = env_flags_parse_vartype(flags);
Joe Hershberger267541f2012-12-11 22:16:34 -0600510 enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
Joe Hershbergerfffad712012-12-11 22:16:33 -0600511
Joe Hershberger267541f2012-12-11 22:16:34 -0600512 printf("\t%-20s %-20s %-20s\n", var_name,
513 env_flags_get_vartype_name(type),
514 env_flags_get_varaccess_name(access));
Joe Hershbergerfffad712012-12-11 22:16:33 -0600515
516 return 0;
517}
518
519static int print_active_flags(ENTRY *entry)
520{
521 enum env_flags_vartype type;
Joe Hershberger267541f2012-12-11 22:16:34 -0600522 enum env_flags_varaccess access;
Joe Hershbergerfffad712012-12-11 22:16:33 -0600523
524 if (entry->flags == 0)
525 return 0;
526
527 type = (enum env_flags_vartype)
528 (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
Joe Hershberger267541f2012-12-11 22:16:34 -0600529 access = env_flags_parse_varaccess_from_binflags(entry->flags);
530 printf("\t%-20s %-20s %-20s\n", entry->key,
531 env_flags_get_vartype_name(type),
532 env_flags_get_varaccess_name(access));
Joe Hershbergerfffad712012-12-11 22:16:33 -0600533
534 return 0;
535}
536
537/*
538 * Print the flags available and what variables have flags
539 */
540int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
541{
542 /* Print the available variable types */
543 printf("Available variable type flags (position %d):\n",
544 ENV_FLAGS_VARTYPE_LOC);
545 puts("\tFlag\tVariable Type Name\n");
546 puts("\t----\t------------------\n");
547 env_flags_print_vartypes();
548 puts("\n");
549
Joe Hershberger267541f2012-12-11 22:16:34 -0600550 /* Print the available variable access types */
551 printf("Available variable access flags (position %d):\n",
552 ENV_FLAGS_VARACCESS_LOC);
553 puts("\tFlag\tVariable Access Name\n");
554 puts("\t----\t--------------------\n");
555 env_flags_print_varaccess();
556 puts("\n");
557
Joe Hershbergerfffad712012-12-11 22:16:33 -0600558 /* Print the static flags that may exist */
559 puts("Static flags:\n");
Joe Hershberger267541f2012-12-11 22:16:34 -0600560 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
561 "Variable Access");
562 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
563 "---------------");
Joe Hershbergercca98fd2015-05-20 14:27:19 -0500564 env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags, NULL);
Joe Hershbergerfffad712012-12-11 22:16:33 -0600565 puts("\n");
566
567 /* walk through each variable and print the flags if non-default */
568 puts("Active flags:\n");
Joe Hershberger267541f2012-12-11 22:16:34 -0600569 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
570 "Variable Access");
571 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
572 "---------------");
Joe Hershbergerfffad712012-12-11 22:16:33 -0600573 hwalk_r(&env_htab, print_active_flags);
574 return 0;
575}
576#endif
577
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200578/*
Peter Tyser246c6922009-10-25 15:12:56 -0500579 * Interactively edit an environment variable
580 */
581#if defined(CONFIG_CMD_EDITENV)
Kim Phillips088f1b12012-10-29 13:34:31 +0000582static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
583 char * const argv[])
Peter Tyser246c6922009-10-25 15:12:56 -0500584{
585 char buffer[CONFIG_SYS_CBSIZE];
586 char *init_val;
Peter Tyser246c6922009-10-25 15:12:56 -0500587
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200588 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000589 return CMD_RET_USAGE;
Peter Tyser246c6922009-10-25 15:12:56 -0500590
591 /* Set read buffer to initial value or empty sting */
592 init_val = getenv(argv[1]);
593 if (init_val)
Marek Vasut7fcd9bb2011-09-26 02:26:03 +0200594 sprintf(buffer, "%s", init_val);
Peter Tyser246c6922009-10-25 15:12:56 -0500595 else
596 buffer[0] = '\0';
597
Simon Glasse1bf8242014-04-10 20:01:27 -0600598 if (cli_readline_into_buffer("edit: ", buffer, 0) < 0)
Joe Hershberger18a3cce2013-02-08 10:12:34 +0000599 return 1;
Peter Tyser246c6922009-10-25 15:12:56 -0500600
601 return setenv(argv[1], buffer);
602}
603#endif /* CONFIG_CMD_EDITENV */
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000604#endif /* CONFIG_SPL_BUILD */
Peter Tyser246c6922009-10-25 15:12:56 -0500605
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200606/*
wdenka68d3ed2002-10-11 08:38:32 +0000607 * Look up variable from environment,
608 * return address of storage for that variable,
609 * or NULL if not found
610 */
Wolfgang Denk84b5e802011-07-29 14:42:18 +0200611char *getenv(const char *name)
wdenka68d3ed2002-10-11 08:38:32 +0000612{
Igor Grinbergd09b1782011-11-07 01:13:59 +0000613 if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200614 ENTRY e, *ep;
wdenka68d3ed2002-10-11 08:38:32 +0000615
Wolfgang Denk91a76752010-07-24 20:22:02 +0200616 WATCHDOG_RESET();
wdenk2a3cb022002-11-05 21:01:48 +0000617
Igor Grinbergd09b1782011-11-07 01:13:59 +0000618 e.key = name;
619 e.data = NULL;
Joe Hershbergerc4e00572012-12-11 22:16:19 -0600620 hsearch_r(e, FIND, &ep, &env_htab, 0);
wdenka68d3ed2002-10-11 08:38:32 +0000621
Macpaul Linf3c615b2011-04-26 16:16:45 +0000622 return ep ? ep->data : NULL;
wdenka68d3ed2002-10-11 08:38:32 +0000623 }
624
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200625 /* restricted capabilities before import */
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200626 if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
627 return (char *)(gd->env_buf);
628
629 return NULL;
wdenka68d3ed2002-10-11 08:38:32 +0000630}
631
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200632/*
633 * Look up variable from environment for restricted C runtime env.
634 */
Wolfgang Denk84b5e802011-07-29 14:42:18 +0200635int getenv_f(const char *name, char *buf, unsigned len)
wdenka68d3ed2002-10-11 08:38:32 +0000636{
637 int i, nxt;
638
Igor Grinbergd09b1782011-11-07 01:13:59 +0000639 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
wdenka68d3ed2002-10-11 08:38:32 +0000640 int val, n;
641
Macpaul Linf3c615b2011-04-26 16:16:45 +0000642 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
643 if (nxt >= CONFIG_ENV_SIZE)
644 return -1;
wdenka68d3ed2002-10-11 08:38:32 +0000645 }
Macpaul Linf3c615b2011-04-26 16:16:45 +0000646
647 val = envmatch((uchar *)name, i);
648 if (val < 0)
wdenka68d3ed2002-10-11 08:38:32 +0000649 continue;
Wolfgang Denk9ed4a952010-07-24 22:16:20 +0200650
wdenka68d3ed2002-10-11 08:38:32 +0000651 /* found; copy out */
Macpaul Linf3c615b2011-04-26 16:16:45 +0000652 for (n = 0; n < len; ++n, ++buf) {
Igor Grinbergd09b1782011-11-07 01:13:59 +0000653 *buf = env_get_char(val++);
654 if (*buf == '\0')
Wolfgang Denk9ed4a952010-07-24 22:16:20 +0200655 return n;
656 }
657
658 if (n)
659 *--buf = '\0';
660
Wolfgang Denka02a8842011-05-04 10:29:49 +0000661 printf("env_buf [%d bytes] too small for value of \"%s\"\n",
662 len, name);
Wolfgang Denk9ed4a952010-07-24 22:16:20 +0200663
664 return n;
wdenka68d3ed2002-10-11 08:38:32 +0000665 }
Igor Grinbergd09b1782011-11-07 01:13:59 +0000666
Macpaul Linf3c615b2011-04-26 16:16:45 +0000667 return -1;
wdenka68d3ed2002-10-11 08:38:32 +0000668}
669
Simon Glass4a9b4132011-10-14 13:25:18 +0000670/**
671 * Decode the integer value of an environment variable and return it.
672 *
673 * @param name Name of environemnt variable
674 * @param base Number base to use (normally 10, or 16 for hex)
675 * @param default_val Default value to return if the variable is not
676 * found
677 * @return the decoded value, or default_val if not found
678 */
679ulong getenv_ulong(const char *name, int base, ulong default_val)
680{
681 /*
682 * We can use getenv() here, even before relocation, since the
683 * environment variable value is an integer and thus short.
684 */
685 const char *str = getenv(name);
686
687 return str ? simple_strtoul(str, NULL, base) : default_val;
688}
689
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000690#ifndef CONFIG_SPL_BUILD
Mike Frysingerbdab39d2009-01-28 19:08:14 -0500691#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Kim Phillips088f1b12012-10-29 13:34:31 +0000692static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
693 char * const argv[])
wdenka68d3ed2002-10-11 08:38:32 +0000694{
Macpaul Linf3c615b2011-04-26 16:16:45 +0000695 printf("Saving Environment to %s...\n", env_name_spec);
wdenka68d3ed2002-10-11 08:38:32 +0000696
Macpaul Linf3c615b2011-04-26 16:16:45 +0000697 return saveenv() ? 1 : 0;
wdenka68d3ed2002-10-11 08:38:32 +0000698}
wdenk8bde7f72003-06-27 21:31:46 +0000699
Mike Frysingerba69dc22008-12-30 02:59:25 -0500700U_BOOT_CMD(
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200701 saveenv, 1, 0, do_env_save,
Peter Tyser2fb26042009-01-27 18:03:12 -0600702 "save environment variables to persistent storage",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200703 ""
Mike Frysingerba69dc22008-12-30 02:59:25 -0500704);
wdenka68d3ed2002-10-11 08:38:32 +0000705#endif
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000706#endif /* CONFIG_SPL_BUILD */
wdenka68d3ed2002-10-11 08:38:32 +0000707
708
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200709/*
wdenka68d3ed2002-10-11 08:38:32 +0000710 * Match a name / name=value pair
711 *
712 * s1 is either a simple 'name', or a 'name=value' pair.
713 * i2 is the environment index for a 'name2=value2' pair.
Igor Grinbergd09b1782011-11-07 01:13:59 +0000714 * If the names match, return the index for the value2, else -1.
wdenka68d3ed2002-10-11 08:38:32 +0000715 */
Macpaul Linf3c615b2011-04-26 16:16:45 +0000716int envmatch(uchar *s1, int i2)
wdenka68d3ed2002-10-11 08:38:32 +0000717{
Joe Hershberger586197d2012-10-03 09:38:50 +0000718 if (s1 == NULL)
719 return -1;
720
wdenka68d3ed2002-10-11 08:38:32 +0000721 while (*s1 == env_get_char(i2++))
722 if (*s1++ == '=')
Macpaul Linf3c615b2011-04-26 16:16:45 +0000723 return i2;
Igor Grinbergd09b1782011-11-07 01:13:59 +0000724
wdenka68d3ed2002-10-11 08:38:32 +0000725 if (*s1 == '\0' && env_get_char(i2-1) == '=')
Macpaul Linf3c615b2011-04-26 16:16:45 +0000726 return i2;
Igor Grinbergd09b1782011-11-07 01:13:59 +0000727
Macpaul Linf3c615b2011-04-26 16:16:45 +0000728 return -1;
wdenka68d3ed2002-10-11 08:38:32 +0000729}
wdenk8bde7f72003-06-27 21:31:46 +0000730
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000731#ifndef CONFIG_SPL_BUILD
Gerlando Falautob64b7c32012-08-24 00:11:41 +0000732static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
Igor Grinbergd09b1782011-11-07 01:13:59 +0000733 int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200734{
Gerlando Falautob64b7c32012-08-24 00:11:41 +0000735 int all = 0, flag = 0;
Macpaul Linf3c615b2011-04-26 16:16:45 +0000736
Gerlando Falautob64b7c32012-08-24 00:11:41 +0000737 debug("Initial value for argc=%d\n", argc);
738 while (--argc > 0 && **++argv == '-') {
739 char *arg = *argv;
740
741 while (*++arg) {
742 switch (*arg) {
743 case 'a': /* default all */
744 all = 1;
745 break;
746 case 'f': /* force */
747 flag |= H_FORCE;
748 break;
749 default:
750 return cmd_usage(cmdtp);
751 }
752 }
753 }
754 debug("Final value for argc=%d\n", argc);
755 if (all && (argc == 0)) {
756 /* Reset the whole environment */
757 set_default_env("## Resetting to default environment\n");
758 return 0;
759 }
760 if (!all && (argc > 0)) {
761 /* Reset individual variables */
762 set_default_vars(argc, argv);
763 return 0;
764 }
765
766 return cmd_usage(cmdtp);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200767}
wdenk8bde7f72003-06-27 21:31:46 +0000768
Igor Grinbergd09b1782011-11-07 01:13:59 +0000769static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
770 int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200771{
Joe Hershberger9d8d6612012-12-11 22:16:36 -0600772 int env_flag = H_INTERACTIVE;
773 int ret = 0;
774
775 debug("Initial value for argc=%d\n", argc);
776 while (argc > 1 && **(argv + 1) == '-') {
777 char *arg = *++argv;
778
779 --argc;
780 while (*++arg) {
781 switch (*arg) {
782 case 'f': /* force */
783 env_flag |= H_FORCE;
784 break;
785 default:
786 return CMD_RET_USAGE;
787 }
788 }
789 }
790 debug("Final value for argc=%d\n", argc);
791
792 env_id++;
793
794 while (--argc > 0) {
795 char *name = *++argv;
796
797 if (!hdelete_r(name, &env_htab, env_flag))
798 ret = 1;
799 }
800
801 return ret;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200802}
803
Mike Frysinger0c79cda2010-12-26 23:09:45 -0500804#ifdef CONFIG_CMD_EXPORTENV
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200805/*
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100806 * env export [-t | -b | -c] [-s size] addr [var ...]
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200807 * -t: export as text format; if size is given, data will be
808 * padded with '\0' bytes; if not, one terminating '\0'
809 * will be added (which is included in the "filesize"
810 * setting so you can for exmple copy this to flash and
811 * keep the termination).
812 * -b: export as binary format (name=value pairs separated by
813 * '\0', list end marked by double "\0\0")
814 * -c: export as checksum protected environment format as
815 * used for example by "saveenv" command
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100816 * -s size:
817 * size of output buffer
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200818 * addr: memory address where environment gets stored
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100819 * var... List of variable names that get included into the
820 * export. Without arguments, the whole environment gets
821 * exported.
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200822 *
823 * With "-c" and size is NOT given, then the export command will
824 * format the data as currently used for the persistent storage,
825 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
826 * prepend a valid CRC32 checksum and, in case of resundant
827 * environment, a "current" redundancy flag. If size is given, this
828 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
829 * checksum and redundancy flag will be inserted.
830 *
831 * With "-b" and "-t", always only the real data (including a
832 * terminating '\0' byte) will be written; here the optional size
833 * argument will be used to make sure not to overflow the user
834 * provided buffer; the command will abort if the size is not
835 * sufficient. Any remainign space will be '\0' padded.
836 *
837 * On successful return, the variable "filesize" will be set.
838 * Note that filesize includes the trailing/terminating '\0' byte(s).
839 *
840 * Usage szenario: create a text snapshot/backup of the current settings:
841 *
842 * => env export -t 100000
843 * => era ${backup_addr} +${filesize}
844 * => cp.b 100000 ${backup_addr} ${filesize}
845 *
846 * Re-import this snapshot, deleting all other settings:
847 *
848 * => env import -d -t ${backup_addr}
849 */
Igor Grinbergd09b1782011-11-07 01:13:59 +0000850static int do_env_export(cmd_tbl_t *cmdtp, int flag,
851 int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200852{
853 char buf[32];
Simon Glassfd37dac2013-10-25 23:01:31 -0600854 ulong addr;
855 char *ptr, *cmd, *res;
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100856 size_t size = 0;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200857 ssize_t len;
858 env_t *envp;
859 char sep = '\n';
860 int chk = 0;
861 int fmt = 0;
862
863 cmd = *argv;
864
865 while (--argc > 0 && **++argv == '-') {
866 char *arg = *argv;
867 while (*++arg) {
868 switch (*arg) {
869 case 'b': /* raw binary format */
870 if (fmt++)
871 goto sep_err;
872 sep = '\0';
873 break;
874 case 'c': /* external checksum format */
875 if (fmt++)
876 goto sep_err;
877 sep = '\0';
878 chk = 1;
879 break;
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100880 case 's': /* size given */
881 if (--argc <= 0)
882 return cmd_usage(cmdtp);
883 size = simple_strtoul(*++argv, NULL, 16);
884 goto NXTARG;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200885 case 't': /* text format */
886 if (fmt++)
887 goto sep_err;
888 sep = '\n';
889 break;
890 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +0000891 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200892 }
893 }
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100894NXTARG: ;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200895 }
896
Macpaul Linf3c615b2011-04-26 16:16:45 +0000897 if (argc < 1)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000898 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200899
Simon Glassfd37dac2013-10-25 23:01:31 -0600900 addr = simple_strtoul(argv[0], NULL, 16);
901 ptr = map_sysmem(addr, size);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200902
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100903 if (size)
Simon Glassfd37dac2013-10-25 23:01:31 -0600904 memset(ptr, '\0', size);
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100905
906 argc--;
907 argv++;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200908
909 if (sep) { /* export as text file */
Wolfgang Denkea009d42013-03-23 23:50:28 +0000910 len = hexport_r(&env_htab, sep,
911 H_MATCH_KEY | H_MATCH_IDENT,
Simon Glassfd37dac2013-10-25 23:01:31 -0600912 &ptr, size, argc, argv);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200913 if (len < 0) {
Igor Grinbergd09b1782011-11-07 01:13:59 +0000914 error("Cannot export environment: errno = %d\n", errno);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200915 return 1;
916 }
Andreas Bießmann8c3aff52011-02-09 15:10:29 +0100917 sprintf(buf, "%zX", (size_t)len);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200918 setenv("filesize", buf);
919
920 return 0;
921 }
922
Simon Glassfd37dac2013-10-25 23:01:31 -0600923 envp = (env_t *)ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200924
925 if (chk) /* export as checksum protected block */
926 res = (char *)envp->data;
927 else /* export as raw binary data */
Simon Glassfd37dac2013-10-25 23:01:31 -0600928 res = ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200929
Wolfgang Denkea009d42013-03-23 23:50:28 +0000930 len = hexport_r(&env_htab, '\0',
931 H_MATCH_KEY | H_MATCH_IDENT,
932 &res, ENV_SIZE, argc, argv);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200933 if (len < 0) {
Igor Grinbergd09b1782011-11-07 01:13:59 +0000934 error("Cannot export environment: errno = %d\n", errno);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200935 return 1;
936 }
937
938 if (chk) {
Igor Grinbergd09b1782011-11-07 01:13:59 +0000939 envp->crc = crc32(0, envp->data, ENV_SIZE);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200940#ifdef CONFIG_ENV_ADDR_REDUND
941 envp->flags = ACTIVE_FLAG;
942#endif
943 }
Simon Glass41ef3722013-02-24 17:33:22 +0000944 setenv_hex("filesize", len + offsetof(env_t, data));
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200945
946 return 0;
947
948sep_err:
Igor Grinbergd09b1782011-11-07 01:13:59 +0000949 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200950 return 1;
951}
Mike Frysinger0c79cda2010-12-26 23:09:45 -0500952#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200953
Mike Frysinger0c79cda2010-12-26 23:09:45 -0500954#ifdef CONFIG_CMD_IMPORTENV
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200955/*
Alexander Hollerecd14462014-07-14 17:49:55 +0200956 * env import [-d] [-t [-r] | -b | -c] addr [size]
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200957 * -d: delete existing environment before importing;
958 * otherwise overwrite / append to existion definitions
959 * -t: assume text format; either "size" must be given or the
960 * text data must be '\0' terminated
Alexander Hollerecd14462014-07-14 17:49:55 +0200961 * -r: handle CRLF like LF, that means exported variables with
962 * a content which ends with \r won't get imported. Used
963 * to import text files created with editors which are using CRLF
964 * for line endings. Only effective in addition to -t.
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200965 * -b: assume binary format ('\0' separated, "\0\0" terminated)
966 * -c: assume checksum protected environment format
967 * addr: memory address to read from
968 * size: length of input data; if missing, proper '\0'
969 * termination is mandatory
970 */
Igor Grinbergd09b1782011-11-07 01:13:59 +0000971static int do_env_import(cmd_tbl_t *cmdtp, int flag,
972 int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200973{
Simon Glassfd37dac2013-10-25 23:01:31 -0600974 ulong addr;
975 char *cmd, *ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200976 char sep = '\n';
977 int chk = 0;
978 int fmt = 0;
979 int del = 0;
Alexander Hollerecd14462014-07-14 17:49:55 +0200980 int crlf_is_lf = 0;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200981 size_t size;
982
983 cmd = *argv;
984
985 while (--argc > 0 && **++argv == '-') {
986 char *arg = *argv;
987 while (*++arg) {
988 switch (*arg) {
989 case 'b': /* raw binary format */
990 if (fmt++)
991 goto sep_err;
992 sep = '\0';
993 break;
994 case 'c': /* external checksum format */
995 if (fmt++)
996 goto sep_err;
997 sep = '\0';
998 chk = 1;
999 break;
1000 case 't': /* text format */
1001 if (fmt++)
1002 goto sep_err;
1003 sep = '\n';
1004 break;
Alexander Hollerecd14462014-07-14 17:49:55 +02001005 case 'r': /* handle CRLF like LF */
1006 crlf_is_lf = 1;
1007 break;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001008 case 'd':
1009 del = 1;
1010 break;
1011 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +00001012 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001013 }
1014 }
1015 }
1016
Macpaul Linf3c615b2011-04-26 16:16:45 +00001017 if (argc < 1)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001018 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001019
1020 if (!fmt)
1021 printf("## Warning: defaulting to text format\n");
1022
Alexander Hollerecd14462014-07-14 17:49:55 +02001023 if (sep != '\n' && crlf_is_lf )
1024 crlf_is_lf = 0;
1025
Simon Glassfd37dac2013-10-25 23:01:31 -06001026 addr = simple_strtoul(argv[0], NULL, 16);
1027 ptr = map_sysmem(addr, 0);
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001028
1029 if (argc == 2) {
1030 size = simple_strtoul(argv[1], NULL, 16);
Tom Rini3775dcd2014-03-04 15:52:35 -05001031 } else if (argc == 1 && chk) {
1032 puts("## Error: external checksum format must pass size\n");
1033 return CMD_RET_FAILURE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001034 } else {
Simon Glassfd37dac2013-10-25 23:01:31 -06001035 char *s = ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001036
1037 size = 0;
1038
1039 while (size < MAX_ENV_SIZE) {
1040 if ((*s == sep) && (*(s+1) == '\0'))
1041 break;
1042 ++s;
1043 ++size;
1044 }
1045 if (size == MAX_ENV_SIZE) {
1046 printf("## Warning: Input data exceeds %d bytes"
1047 " - truncated\n", MAX_ENV_SIZE);
1048 }
Horst Kronstorferd3f80c72011-12-16 23:33:10 +00001049 size += 2;
Simon Glass79afc882011-11-04 06:42:36 +00001050 printf("## Info: input data size = %zu = 0x%zX\n", size, size);
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001051 }
1052
1053 if (chk) {
1054 uint32_t crc;
Simon Glassfd37dac2013-10-25 23:01:31 -06001055 env_t *ep = (env_t *)ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001056
1057 size -= offsetof(env_t, data);
1058 memcpy(&crc, &ep->crc, sizeof(crc));
1059
1060 if (crc32(0, ep->data, size) != crc) {
1061 puts("## Error: bad CRC, import failed\n");
1062 return 1;
1063 }
Simon Glassfd37dac2013-10-25 23:01:31 -06001064 ptr = (char *)ep->data;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001065 }
1066
Alexander Hollerecd14462014-07-14 17:49:55 +02001067 if (himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
1068 crlf_is_lf, 0, NULL) == 0) {
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001069 error("Environment import failed: errno = %d\n", errno);
1070 return 1;
1071 }
1072 gd->flags |= GD_FLG_ENV_READY;
1073
1074 return 0;
1075
1076sep_err:
1077 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
1078 cmd);
1079 return 1;
1080}
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001081#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001082
Andrew Ruder88733e22013-10-22 19:07:34 -05001083#if defined(CONFIG_CMD_ENV_EXISTS)
1084static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
1085 char * const argv[])
1086{
1087 ENTRY e, *ep;
1088
1089 if (argc < 2)
1090 return CMD_RET_USAGE;
1091
1092 e.key = argv[1];
1093 e.data = NULL;
1094 hsearch_r(e, FIND, &ep, &env_htab, 0);
1095
1096 return (ep == NULL) ? 1 : 0;
1097}
1098#endif
1099
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001100/*
1101 * New command line interface: "env" command with subcommands
1102 */
1103static cmd_tbl_t cmd_env_sub[] = {
1104#if defined(CONFIG_CMD_ASKENV)
1105 U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
1106#endif
1107 U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
Joe Hershberger9d8d6612012-12-11 22:16:36 -06001108 U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001109#if defined(CONFIG_CMD_EDITENV)
1110 U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
1111#endif
Joe Hershberger5e2b3e02012-12-11 22:16:25 -06001112#if defined(CONFIG_CMD_ENV_CALLBACK)
1113 U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
1114#endif
Joe Hershbergerfffad712012-12-11 22:16:33 -06001115#if defined(CONFIG_CMD_ENV_FLAGS)
1116 U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
1117#endif
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001118#if defined(CONFIG_CMD_EXPORTENV)
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001119 U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001120#endif
Kim Phillipsa000b792011-04-05 07:15:14 +00001121#if defined(CONFIG_CMD_GREPENV)
1122 U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
1123#endif
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001124#if defined(CONFIG_CMD_IMPORTENV)
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001125 U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001126#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001127 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
1128#if defined(CONFIG_CMD_RUN)
1129 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
1130#endif
1131#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1132 U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
1133#endif
1134 U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
Andrew Ruder88733e22013-10-22 19:07:34 -05001135#if defined(CONFIG_CMD_ENV_EXISTS)
1136 U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""),
1137#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001138};
1139
Wolfgang Denk2e5167c2010-10-28 20:00:11 +02001140#if defined(CONFIG_NEEDS_MANUAL_RELOC)
Heiko Schocher60f7da12010-10-05 14:17:00 +02001141void env_reloc(void)
1142{
1143 fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1144}
1145#endif
1146
Macpaul Linf3c615b2011-04-26 16:16:45 +00001147static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001148{
1149 cmd_tbl_t *cp;
1150
Thomas Weber5904da02010-11-24 13:07:52 +01001151 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001152 return CMD_RET_USAGE;
Thomas Weber5904da02010-11-24 13:07:52 +01001153
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001154 /* drop initial "env" arg */
1155 argc--;
1156 argv++;
1157
1158 cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1159
1160 if (cp)
1161 return cp->cmd(cmdtp, flag, argc, argv);
1162
Simon Glass4c12eeb2011-12-10 08:44:01 +00001163 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001164}
1165
Kim Phillips088f1b12012-10-29 13:34:31 +00001166#ifdef CONFIG_SYS_LONGHELP
1167static char env_help_text[] =
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001168#if defined(CONFIG_CMD_ASKENV)
1169 "ask name [message] [size] - ask for environment variable\nenv "
1170#endif
Joe Hershberger5e2b3e02012-12-11 22:16:25 -06001171#if defined(CONFIG_CMD_ENV_CALLBACK)
1172 "callbacks - print callbacks and their associated variables\nenv "
1173#endif
Gerlando Falautob64b7c32012-08-24 00:11:41 +00001174 "default [-f] -a - [forcibly] reset default environment\n"
1175 "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
Joe Hershberger9d8d6612012-12-11 22:16:36 -06001176 "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001177#if defined(CONFIG_CMD_EDITENV)
1178 "env edit name - edit environment variable\n"
1179#endif
Andrew Ruder88733e22013-10-22 19:07:34 -05001180#if defined(CONFIG_CMD_ENV_EXISTS)
1181 "env exists name - tests for existence of variable\n"
1182#endif
Benoît Thébaudeau4796bc42012-08-10 07:45:44 +00001183#if defined(CONFIG_CMD_EXPORTENV)
Wolfgang Denk37f2fe72011-11-06 22:49:44 +01001184 "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
Benoît Thébaudeau4796bc42012-08-10 07:45:44 +00001185#endif
Joe Hershbergerfffad712012-12-11 22:16:33 -06001186#if defined(CONFIG_CMD_ENV_FLAGS)
1187 "env flags - print variables that have non-default flags\n"
1188#endif
Kim Phillipsa000b792011-04-05 07:15:14 +00001189#if defined(CONFIG_CMD_GREPENV)
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001190#ifdef CONFIG_REGEX
1191 "env grep [-e] [-n | -v | -b] string [...] - search environment\n"
1192#else
Wolfgang Denkd87244d2013-03-23 23:50:30 +00001193 "env grep [-n | -v | -b] string [...] - search environment\n"
Kim Phillipsa000b792011-04-05 07:15:14 +00001194#endif
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001195#endif
Benoît Thébaudeau4796bc42012-08-10 07:45:44 +00001196#if defined(CONFIG_CMD_IMPORTENV)
Alexander Hollerecd14462014-07-14 17:49:55 +02001197 "env import [-d] [-t [-r] | -b | -c] addr [size] - import environment\n"
Benoît Thébaudeau4796bc42012-08-10 07:45:44 +00001198#endif
Joe Hershbergerbe112352012-12-11 22:16:23 -06001199 "env print [-a | name ...] - print environment\n"
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001200#if defined(CONFIG_CMD_RUN)
1201 "env run var [...] - run commands in an environment variable\n"
1202#endif
Horst Kronstorferd798a9b2011-12-10 02:25:19 +00001203#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001204 "env save - save environment\n"
Horst Kronstorferd798a9b2011-12-10 02:25:19 +00001205#endif
Kim Phillips088f1b12012-10-29 13:34:31 +00001206 "env set [-f] name [arg ...]\n";
1207#endif
1208
1209U_BOOT_CMD(
1210 env, CONFIG_SYS_MAXARGS, 1, do_env,
1211 "environment handling commands", env_help_text
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001212);
1213
1214/*
1215 * Old command line interface, kept for compatibility
1216 */
wdenk8bde7f72003-06-27 21:31:46 +00001217
Peter Tyser246c6922009-10-25 15:12:56 -05001218#if defined(CONFIG_CMD_EDITENV)
Mike Frysinger722b0612010-10-20 03:52:39 -04001219U_BOOT_CMD_COMPLETE(
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001220 editenv, 2, 0, do_env_edit,
Peter Tyser246c6922009-10-25 15:12:56 -05001221 "edit environment variable",
1222 "name\n"
Mike Frysinger722b0612010-10-20 03:52:39 -04001223 " - edit environment variable 'name'",
1224 var_complete
Peter Tyser246c6922009-10-25 15:12:56 -05001225);
1226#endif
1227
Mike Frysinger722b0612010-10-20 03:52:39 -04001228U_BOOT_CMD_COMPLETE(
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001229 printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
Peter Tyser2fb26042009-01-27 18:03:12 -06001230 "print environment variables",
Joe Hershbergerbe112352012-12-11 22:16:23 -06001231 "[-a]\n - print [all] values of all environment variables\n"
wdenk8bde7f72003-06-27 21:31:46 +00001232 "printenv name ...\n"
Mike Frysinger722b0612010-10-20 03:52:39 -04001233 " - print value of environment variable 'name'",
1234 var_complete
wdenk8bde7f72003-06-27 21:31:46 +00001235);
1236
Kim Phillipsa000b792011-04-05 07:15:14 +00001237#ifdef CONFIG_CMD_GREPENV
1238U_BOOT_CMD_COMPLETE(
1239 grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
1240 "search environment variables",
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001241#ifdef CONFIG_REGEX
1242 "[-e] [-n | -v | -b] string ...\n"
1243#else
Wolfgang Denkd87244d2013-03-23 23:50:30 +00001244 "[-n | -v | -b] string ...\n"
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001245#endif
Wolfgang Denkd87244d2013-03-23 23:50:30 +00001246 " - list environment name=value pairs matching 'string'\n"
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001247#ifdef CONFIG_REGEX
1248 " \"-e\": enable regular expressions;\n"
1249#endif
Wolfgang Denkd87244d2013-03-23 23:50:30 +00001250 " \"-n\": search variable names; \"-v\": search values;\n"
1251 " \"-b\": search both names and values (default)",
Kim Phillipsa000b792011-04-05 07:15:14 +00001252 var_complete
1253);
1254#endif
1255
Mike Frysinger722b0612010-10-20 03:52:39 -04001256U_BOOT_CMD_COMPLETE(
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001257 setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
Peter Tyser2fb26042009-01-27 18:03:12 -06001258 "set environment variables",
Joe Hershberger24ab5a12012-12-11 22:16:35 -06001259 "[-f] name value ...\n"
1260 " - [forcibly] set environment variable 'name' to 'value ...'\n"
1261 "setenv [-f] name\n"
1262 " - [forcibly] delete environment variable 'name'",
Mike Frysinger722b0612010-10-20 03:52:39 -04001263 var_complete
wdenk8bde7f72003-06-27 21:31:46 +00001264);
1265
Jon Loeligerc76fe472007-07-08 18:02:23 -05001266#if defined(CONFIG_CMD_ASKENV)
wdenk8bde7f72003-06-27 21:31:46 +00001267
wdenk0d498392003-07-01 21:06:45 +00001268U_BOOT_CMD(
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001269 askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask,
Peter Tyser2fb26042009-01-27 18:03:12 -06001270 "get environment variables from stdin",
wdenk8bde7f72003-06-27 21:31:46 +00001271 "name [message] [size]\n"
Wolfgang Denk7d855912013-02-20 04:53:16 +00001272 " - get environment variable 'name' from stdin (max 'size' chars)"
wdenk8bde7f72003-06-27 21:31:46 +00001273);
Jon Loeliger90253172007-07-10 11:02:44 -05001274#endif
wdenk8bde7f72003-06-27 21:31:46 +00001275
Jon Loeligerc76fe472007-07-08 18:02:23 -05001276#if defined(CONFIG_CMD_RUN)
Mike Frysinger722b0612010-10-20 03:52:39 -04001277U_BOOT_CMD_COMPLETE(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001278 run, CONFIG_SYS_MAXARGS, 1, do_run,
Peter Tyser2fb26042009-01-27 18:03:12 -06001279 "run commands in an environment variable",
wdenk8bde7f72003-06-27 21:31:46 +00001280 "var [...]\n"
Mike Frysinger722b0612010-10-20 03:52:39 -04001281 " - run the commands in the environment variable(s) 'var'",
1282 var_complete
wdenk8bde7f72003-06-27 21:31:46 +00001283);
Jon Loeliger90253172007-07-10 11:02:44 -05001284#endif
Ilya Yanok7ac2fe22012-09-18 00:22:50 +00001285#endif /* CONFIG_SPL_BUILD */