blob: be792ae746163d32048c27b6af22e1ff2ae98b2a [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)
430static int print_static_binding(const char *var_name, const char *callback_name)
431{
432 printf("\t%-20s %-20s\n", var_name, callback_name);
433
434 return 0;
435}
436
437static int print_active_callback(ENTRY *entry)
438{
439 struct env_clbk_tbl *clbkp;
440 int i;
441 int num_callbacks;
442
443 if (entry->callback == NULL)
444 return 0;
445
446 /* look up the callback in the linker-list */
447 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
448 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
449 i < num_callbacks;
450 i++, clbkp++) {
451#if defined(CONFIG_NEEDS_MANUAL_RELOC)
452 if (entry->callback == clbkp->callback + gd->reloc_off)
453#else
454 if (entry->callback == clbkp->callback)
455#endif
456 break;
457 }
458
459 if (i == num_callbacks)
460 /* this should probably never happen, but just in case... */
461 printf("\t%-20s %p\n", entry->key, entry->callback);
462 else
463 printf("\t%-20s %-20s\n", entry->key, clbkp->name);
464
465 return 0;
466}
467
468/*
469 * Print the callbacks available and what they are bound to
470 */
471int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
472{
473 struct env_clbk_tbl *clbkp;
474 int i;
475 int num_callbacks;
476
477 /* Print the available callbacks */
478 puts("Available callbacks:\n");
479 puts("\tCallback Name\n");
480 puts("\t-------------\n");
481 num_callbacks = ll_entry_count(struct env_clbk_tbl, env_clbk);
482 for (i = 0, clbkp = ll_entry_start(struct env_clbk_tbl, env_clbk);
483 i < num_callbacks;
484 i++, clbkp++)
485 printf("\t%s\n", clbkp->name);
486 puts("\n");
487
488 /* Print the static bindings that may exist */
489 puts("Static callback bindings:\n");
490 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
491 printf("\t%-20s %-20s\n", "-------------", "-------------");
492 env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
493 puts("\n");
494
495 /* walk through each variable and print the callback if it has one */
496 puts("Active callback bindings:\n");
497 printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
498 printf("\t%-20s %-20s\n", "-------------", "-------------");
499 hwalk_r(&env_htab, print_active_callback);
500 return 0;
501}
502#endif
503
Joe Hershbergerfffad712012-12-11 22:16:33 -0600504#if defined(CONFIG_CMD_ENV_FLAGS)
505static int print_static_flags(const char *var_name, const char *flags)
506{
507 enum env_flags_vartype type = env_flags_parse_vartype(flags);
Joe Hershberger267541f2012-12-11 22:16:34 -0600508 enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
Joe Hershbergerfffad712012-12-11 22:16:33 -0600509
Joe Hershberger267541f2012-12-11 22:16:34 -0600510 printf("\t%-20s %-20s %-20s\n", var_name,
511 env_flags_get_vartype_name(type),
512 env_flags_get_varaccess_name(access));
Joe Hershbergerfffad712012-12-11 22:16:33 -0600513
514 return 0;
515}
516
517static int print_active_flags(ENTRY *entry)
518{
519 enum env_flags_vartype type;
Joe Hershberger267541f2012-12-11 22:16:34 -0600520 enum env_flags_varaccess access;
Joe Hershbergerfffad712012-12-11 22:16:33 -0600521
522 if (entry->flags == 0)
523 return 0;
524
525 type = (enum env_flags_vartype)
526 (entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
Joe Hershberger267541f2012-12-11 22:16:34 -0600527 access = env_flags_parse_varaccess_from_binflags(entry->flags);
528 printf("\t%-20s %-20s %-20s\n", entry->key,
529 env_flags_get_vartype_name(type),
530 env_flags_get_varaccess_name(access));
Joe Hershbergerfffad712012-12-11 22:16:33 -0600531
532 return 0;
533}
534
535/*
536 * Print the flags available and what variables have flags
537 */
538int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
539{
540 /* Print the available variable types */
541 printf("Available variable type flags (position %d):\n",
542 ENV_FLAGS_VARTYPE_LOC);
543 puts("\tFlag\tVariable Type Name\n");
544 puts("\t----\t------------------\n");
545 env_flags_print_vartypes();
546 puts("\n");
547
Joe Hershberger267541f2012-12-11 22:16:34 -0600548 /* Print the available variable access types */
549 printf("Available variable access flags (position %d):\n",
550 ENV_FLAGS_VARACCESS_LOC);
551 puts("\tFlag\tVariable Access Name\n");
552 puts("\t----\t--------------------\n");
553 env_flags_print_varaccess();
554 puts("\n");
555
Joe Hershbergerfffad712012-12-11 22:16:33 -0600556 /* Print the static flags that may exist */
557 puts("Static flags:\n");
Joe Hershberger267541f2012-12-11 22:16:34 -0600558 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
559 "Variable Access");
560 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
561 "---------------");
Joe Hershbergerfffad712012-12-11 22:16:33 -0600562 env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
563 puts("\n");
564
565 /* walk through each variable and print the flags if non-default */
566 puts("Active flags:\n");
Joe Hershberger267541f2012-12-11 22:16:34 -0600567 printf("\t%-20s %-20s %-20s\n", "Variable Name", "Variable Type",
568 "Variable Access");
569 printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
570 "---------------");
Joe Hershbergerfffad712012-12-11 22:16:33 -0600571 hwalk_r(&env_htab, print_active_flags);
572 return 0;
573}
574#endif
575
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200576/*
Peter Tyser246c6922009-10-25 15:12:56 -0500577 * Interactively edit an environment variable
578 */
579#if defined(CONFIG_CMD_EDITENV)
Kim Phillips088f1b12012-10-29 13:34:31 +0000580static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
581 char * const argv[])
Peter Tyser246c6922009-10-25 15:12:56 -0500582{
583 char buffer[CONFIG_SYS_CBSIZE];
584 char *init_val;
Peter Tyser246c6922009-10-25 15:12:56 -0500585
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200586 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000587 return CMD_RET_USAGE;
Peter Tyser246c6922009-10-25 15:12:56 -0500588
589 /* Set read buffer to initial value or empty sting */
590 init_val = getenv(argv[1]);
591 if (init_val)
Marek Vasut7fcd9bb2011-09-26 02:26:03 +0200592 sprintf(buffer, "%s", init_val);
Peter Tyser246c6922009-10-25 15:12:56 -0500593 else
594 buffer[0] = '\0';
595
Simon Glasse1bf8242014-04-10 20:01:27 -0600596 if (cli_readline_into_buffer("edit: ", buffer, 0) < 0)
Joe Hershberger18a3cce2013-02-08 10:12:34 +0000597 return 1;
Peter Tyser246c6922009-10-25 15:12:56 -0500598
599 return setenv(argv[1], buffer);
600}
601#endif /* CONFIG_CMD_EDITENV */
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000602#endif /* CONFIG_SPL_BUILD */
Peter Tyser246c6922009-10-25 15:12:56 -0500603
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200604/*
wdenka68d3ed2002-10-11 08:38:32 +0000605 * Look up variable from environment,
606 * return address of storage for that variable,
607 * or NULL if not found
608 */
Wolfgang Denk84b5e802011-07-29 14:42:18 +0200609char *getenv(const char *name)
wdenka68d3ed2002-10-11 08:38:32 +0000610{
Igor Grinbergd09b1782011-11-07 01:13:59 +0000611 if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200612 ENTRY e, *ep;
wdenka68d3ed2002-10-11 08:38:32 +0000613
Wolfgang Denk91a76752010-07-24 20:22:02 +0200614 WATCHDOG_RESET();
wdenk2a3cb022002-11-05 21:01:48 +0000615
Igor Grinbergd09b1782011-11-07 01:13:59 +0000616 e.key = name;
617 e.data = NULL;
Joe Hershbergerc4e00572012-12-11 22:16:19 -0600618 hsearch_r(e, FIND, &ep, &env_htab, 0);
wdenka68d3ed2002-10-11 08:38:32 +0000619
Macpaul Linf3c615b2011-04-26 16:16:45 +0000620 return ep ? ep->data : NULL;
wdenka68d3ed2002-10-11 08:38:32 +0000621 }
622
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200623 /* restricted capabilities before import */
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200624 if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
625 return (char *)(gd->env_buf);
626
627 return NULL;
wdenka68d3ed2002-10-11 08:38:32 +0000628}
629
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200630/*
631 * Look up variable from environment for restricted C runtime env.
632 */
Wolfgang Denk84b5e802011-07-29 14:42:18 +0200633int getenv_f(const char *name, char *buf, unsigned len)
wdenka68d3ed2002-10-11 08:38:32 +0000634{
635 int i, nxt;
636
Igor Grinbergd09b1782011-11-07 01:13:59 +0000637 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
wdenka68d3ed2002-10-11 08:38:32 +0000638 int val, n;
639
Macpaul Linf3c615b2011-04-26 16:16:45 +0000640 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
641 if (nxt >= CONFIG_ENV_SIZE)
642 return -1;
wdenka68d3ed2002-10-11 08:38:32 +0000643 }
Macpaul Linf3c615b2011-04-26 16:16:45 +0000644
645 val = envmatch((uchar *)name, i);
646 if (val < 0)
wdenka68d3ed2002-10-11 08:38:32 +0000647 continue;
Wolfgang Denk9ed4a952010-07-24 22:16:20 +0200648
wdenka68d3ed2002-10-11 08:38:32 +0000649 /* found; copy out */
Macpaul Linf3c615b2011-04-26 16:16:45 +0000650 for (n = 0; n < len; ++n, ++buf) {
Igor Grinbergd09b1782011-11-07 01:13:59 +0000651 *buf = env_get_char(val++);
652 if (*buf == '\0')
Wolfgang Denk9ed4a952010-07-24 22:16:20 +0200653 return n;
654 }
655
656 if (n)
657 *--buf = '\0';
658
Wolfgang Denka02a8842011-05-04 10:29:49 +0000659 printf("env_buf [%d bytes] too small for value of \"%s\"\n",
660 len, name);
Wolfgang Denk9ed4a952010-07-24 22:16:20 +0200661
662 return n;
wdenka68d3ed2002-10-11 08:38:32 +0000663 }
Igor Grinbergd09b1782011-11-07 01:13:59 +0000664
Macpaul Linf3c615b2011-04-26 16:16:45 +0000665 return -1;
wdenka68d3ed2002-10-11 08:38:32 +0000666}
667
Simon Glass4a9b4132011-10-14 13:25:18 +0000668/**
669 * Decode the integer value of an environment variable and return it.
670 *
671 * @param name Name of environemnt variable
672 * @param base Number base to use (normally 10, or 16 for hex)
673 * @param default_val Default value to return if the variable is not
674 * found
675 * @return the decoded value, or default_val if not found
676 */
677ulong getenv_ulong(const char *name, int base, ulong default_val)
678{
679 /*
680 * We can use getenv() here, even before relocation, since the
681 * environment variable value is an integer and thus short.
682 */
683 const char *str = getenv(name);
684
685 return str ? simple_strtoul(str, NULL, base) : default_val;
686}
687
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000688#ifndef CONFIG_SPL_BUILD
Mike Frysingerbdab39d2009-01-28 19:08:14 -0500689#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Kim Phillips088f1b12012-10-29 13:34:31 +0000690static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
691 char * const argv[])
wdenka68d3ed2002-10-11 08:38:32 +0000692{
Macpaul Linf3c615b2011-04-26 16:16:45 +0000693 printf("Saving Environment to %s...\n", env_name_spec);
wdenka68d3ed2002-10-11 08:38:32 +0000694
Macpaul Linf3c615b2011-04-26 16:16:45 +0000695 return saveenv() ? 1 : 0;
wdenka68d3ed2002-10-11 08:38:32 +0000696}
wdenk8bde7f72003-06-27 21:31:46 +0000697
Mike Frysingerba69dc22008-12-30 02:59:25 -0500698U_BOOT_CMD(
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200699 saveenv, 1, 0, do_env_save,
Peter Tyser2fb26042009-01-27 18:03:12 -0600700 "save environment variables to persistent storage",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200701 ""
Mike Frysingerba69dc22008-12-30 02:59:25 -0500702);
wdenka68d3ed2002-10-11 08:38:32 +0000703#endif
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000704#endif /* CONFIG_SPL_BUILD */
wdenka68d3ed2002-10-11 08:38:32 +0000705
706
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200707/*
wdenka68d3ed2002-10-11 08:38:32 +0000708 * Match a name / name=value pair
709 *
710 * s1 is either a simple 'name', or a 'name=value' pair.
711 * i2 is the environment index for a 'name2=value2' pair.
Igor Grinbergd09b1782011-11-07 01:13:59 +0000712 * If the names match, return the index for the value2, else -1.
wdenka68d3ed2002-10-11 08:38:32 +0000713 */
Macpaul Linf3c615b2011-04-26 16:16:45 +0000714int envmatch(uchar *s1, int i2)
wdenka68d3ed2002-10-11 08:38:32 +0000715{
Joe Hershberger586197d2012-10-03 09:38:50 +0000716 if (s1 == NULL)
717 return -1;
718
wdenka68d3ed2002-10-11 08:38:32 +0000719 while (*s1 == env_get_char(i2++))
720 if (*s1++ == '=')
Macpaul Linf3c615b2011-04-26 16:16:45 +0000721 return i2;
Igor Grinbergd09b1782011-11-07 01:13:59 +0000722
wdenka68d3ed2002-10-11 08:38:32 +0000723 if (*s1 == '\0' && env_get_char(i2-1) == '=')
Macpaul Linf3c615b2011-04-26 16:16:45 +0000724 return i2;
Igor Grinbergd09b1782011-11-07 01:13:59 +0000725
Macpaul Linf3c615b2011-04-26 16:16:45 +0000726 return -1;
wdenka68d3ed2002-10-11 08:38:32 +0000727}
wdenk8bde7f72003-06-27 21:31:46 +0000728
Ilya Yanok7ac2fe22012-09-18 00:22:50 +0000729#ifndef CONFIG_SPL_BUILD
Gerlando Falautob64b7c32012-08-24 00:11:41 +0000730static int do_env_default(cmd_tbl_t *cmdtp, int __flag,
Igor Grinbergd09b1782011-11-07 01:13:59 +0000731 int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200732{
Gerlando Falautob64b7c32012-08-24 00:11:41 +0000733 int all = 0, flag = 0;
Macpaul Linf3c615b2011-04-26 16:16:45 +0000734
Gerlando Falautob64b7c32012-08-24 00:11:41 +0000735 debug("Initial value for argc=%d\n", argc);
736 while (--argc > 0 && **++argv == '-') {
737 char *arg = *argv;
738
739 while (*++arg) {
740 switch (*arg) {
741 case 'a': /* default all */
742 all = 1;
743 break;
744 case 'f': /* force */
745 flag |= H_FORCE;
746 break;
747 default:
748 return cmd_usage(cmdtp);
749 }
750 }
751 }
752 debug("Final value for argc=%d\n", argc);
753 if (all && (argc == 0)) {
754 /* Reset the whole environment */
755 set_default_env("## Resetting to default environment\n");
756 return 0;
757 }
758 if (!all && (argc > 0)) {
759 /* Reset individual variables */
760 set_default_vars(argc, argv);
761 return 0;
762 }
763
764 return cmd_usage(cmdtp);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200765}
wdenk8bde7f72003-06-27 21:31:46 +0000766
Igor Grinbergd09b1782011-11-07 01:13:59 +0000767static int do_env_delete(cmd_tbl_t *cmdtp, int flag,
768 int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200769{
Joe Hershberger9d8d6612012-12-11 22:16:36 -0600770 int env_flag = H_INTERACTIVE;
771 int ret = 0;
772
773 debug("Initial value for argc=%d\n", argc);
774 while (argc > 1 && **(argv + 1) == '-') {
775 char *arg = *++argv;
776
777 --argc;
778 while (*++arg) {
779 switch (*arg) {
780 case 'f': /* force */
781 env_flag |= H_FORCE;
782 break;
783 default:
784 return CMD_RET_USAGE;
785 }
786 }
787 }
788 debug("Final value for argc=%d\n", argc);
789
790 env_id++;
791
792 while (--argc > 0) {
793 char *name = *++argv;
794
795 if (!hdelete_r(name, &env_htab, env_flag))
796 ret = 1;
797 }
798
799 return ret;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200800}
801
Mike Frysinger0c79cda2010-12-26 23:09:45 -0500802#ifdef CONFIG_CMD_EXPORTENV
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200803/*
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100804 * env export [-t | -b | -c] [-s size] addr [var ...]
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200805 * -t: export as text format; if size is given, data will be
806 * padded with '\0' bytes; if not, one terminating '\0'
807 * will be added (which is included in the "filesize"
808 * setting so you can for exmple copy this to flash and
809 * keep the termination).
810 * -b: export as binary format (name=value pairs separated by
811 * '\0', list end marked by double "\0\0")
812 * -c: export as checksum protected environment format as
813 * used for example by "saveenv" command
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100814 * -s size:
815 * size of output buffer
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200816 * addr: memory address where environment gets stored
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100817 * var... List of variable names that get included into the
818 * export. Without arguments, the whole environment gets
819 * exported.
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200820 *
821 * With "-c" and size is NOT given, then the export command will
822 * format the data as currently used for the persistent storage,
823 * i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
824 * prepend a valid CRC32 checksum and, in case of resundant
825 * environment, a "current" redundancy flag. If size is given, this
826 * value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
827 * checksum and redundancy flag will be inserted.
828 *
829 * With "-b" and "-t", always only the real data (including a
830 * terminating '\0' byte) will be written; here the optional size
831 * argument will be used to make sure not to overflow the user
832 * provided buffer; the command will abort if the size is not
833 * sufficient. Any remainign space will be '\0' padded.
834 *
835 * On successful return, the variable "filesize" will be set.
836 * Note that filesize includes the trailing/terminating '\0' byte(s).
837 *
838 * Usage szenario: create a text snapshot/backup of the current settings:
839 *
840 * => env export -t 100000
841 * => era ${backup_addr} +${filesize}
842 * => cp.b 100000 ${backup_addr} ${filesize}
843 *
844 * Re-import this snapshot, deleting all other settings:
845 *
846 * => env import -d -t ${backup_addr}
847 */
Igor Grinbergd09b1782011-11-07 01:13:59 +0000848static int do_env_export(cmd_tbl_t *cmdtp, int flag,
849 int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200850{
851 char buf[32];
Simon Glassfd37dac2013-10-25 23:01:31 -0600852 ulong addr;
853 char *ptr, *cmd, *res;
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100854 size_t size = 0;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200855 ssize_t len;
856 env_t *envp;
857 char sep = '\n';
858 int chk = 0;
859 int fmt = 0;
860
861 cmd = *argv;
862
863 while (--argc > 0 && **++argv == '-') {
864 char *arg = *argv;
865 while (*++arg) {
866 switch (*arg) {
867 case 'b': /* raw binary format */
868 if (fmt++)
869 goto sep_err;
870 sep = '\0';
871 break;
872 case 'c': /* external checksum format */
873 if (fmt++)
874 goto sep_err;
875 sep = '\0';
876 chk = 1;
877 break;
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100878 case 's': /* size given */
879 if (--argc <= 0)
880 return cmd_usage(cmdtp);
881 size = simple_strtoul(*++argv, NULL, 16);
882 goto NXTARG;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200883 case 't': /* text format */
884 if (fmt++)
885 goto sep_err;
886 sep = '\n';
887 break;
888 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +0000889 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200890 }
891 }
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100892NXTARG: ;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200893 }
894
Macpaul Linf3c615b2011-04-26 16:16:45 +0000895 if (argc < 1)
Simon Glass4c12eeb2011-12-10 08:44:01 +0000896 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200897
Simon Glassfd37dac2013-10-25 23:01:31 -0600898 addr = simple_strtoul(argv[0], NULL, 16);
899 ptr = map_sysmem(addr, size);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200900
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100901 if (size)
Simon Glassfd37dac2013-10-25 23:01:31 -0600902 memset(ptr, '\0', size);
Wolfgang Denk37f2fe72011-11-06 22:49:44 +0100903
904 argc--;
905 argv++;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200906
907 if (sep) { /* export as text file */
Wolfgang Denkea009d42013-03-23 23:50:28 +0000908 len = hexport_r(&env_htab, sep,
909 H_MATCH_KEY | H_MATCH_IDENT,
Simon Glassfd37dac2013-10-25 23:01:31 -0600910 &ptr, size, argc, argv);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200911 if (len < 0) {
Igor Grinbergd09b1782011-11-07 01:13:59 +0000912 error("Cannot export environment: errno = %d\n", errno);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200913 return 1;
914 }
Andreas Bießmann8c3aff52011-02-09 15:10:29 +0100915 sprintf(buf, "%zX", (size_t)len);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200916 setenv("filesize", buf);
917
918 return 0;
919 }
920
Simon Glassfd37dac2013-10-25 23:01:31 -0600921 envp = (env_t *)ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200922
923 if (chk) /* export as checksum protected block */
924 res = (char *)envp->data;
925 else /* export as raw binary data */
Simon Glassfd37dac2013-10-25 23:01:31 -0600926 res = ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200927
Wolfgang Denkea009d42013-03-23 23:50:28 +0000928 len = hexport_r(&env_htab, '\0',
929 H_MATCH_KEY | H_MATCH_IDENT,
930 &res, ENV_SIZE, argc, argv);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200931 if (len < 0) {
Igor Grinbergd09b1782011-11-07 01:13:59 +0000932 error("Cannot export environment: errno = %d\n", errno);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200933 return 1;
934 }
935
936 if (chk) {
Igor Grinbergd09b1782011-11-07 01:13:59 +0000937 envp->crc = crc32(0, envp->data, ENV_SIZE);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200938#ifdef CONFIG_ENV_ADDR_REDUND
939 envp->flags = ACTIVE_FLAG;
940#endif
941 }
Simon Glass41ef3722013-02-24 17:33:22 +0000942 setenv_hex("filesize", len + offsetof(env_t, data));
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200943
944 return 0;
945
946sep_err:
Igor Grinbergd09b1782011-11-07 01:13:59 +0000947 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n", cmd);
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200948 return 1;
949}
Mike Frysinger0c79cda2010-12-26 23:09:45 -0500950#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200951
Mike Frysinger0c79cda2010-12-26 23:09:45 -0500952#ifdef CONFIG_CMD_IMPORTENV
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200953/*
Alexander Hollerecd14462014-07-14 17:49:55 +0200954 * env import [-d] [-t [-r] | -b | -c] addr [size]
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200955 * -d: delete existing environment before importing;
956 * otherwise overwrite / append to existion definitions
957 * -t: assume text format; either "size" must be given or the
958 * text data must be '\0' terminated
Alexander Hollerecd14462014-07-14 17:49:55 +0200959 * -r: handle CRLF like LF, that means exported variables with
960 * a content which ends with \r won't get imported. Used
961 * to import text files created with editors which are using CRLF
962 * for line endings. Only effective in addition to -t.
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200963 * -b: assume binary format ('\0' separated, "\0\0" terminated)
964 * -c: assume checksum protected environment format
965 * addr: memory address to read from
966 * size: length of input data; if missing, proper '\0'
967 * termination is mandatory
968 */
Igor Grinbergd09b1782011-11-07 01:13:59 +0000969static int do_env_import(cmd_tbl_t *cmdtp, int flag,
970 int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200971{
Simon Glassfd37dac2013-10-25 23:01:31 -0600972 ulong addr;
973 char *cmd, *ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200974 char sep = '\n';
975 int chk = 0;
976 int fmt = 0;
977 int del = 0;
Alexander Hollerecd14462014-07-14 17:49:55 +0200978 int crlf_is_lf = 0;
Wolfgang Denkea882ba2010-06-20 23:33:59 +0200979 size_t size;
980
981 cmd = *argv;
982
983 while (--argc > 0 && **++argv == '-') {
984 char *arg = *argv;
985 while (*++arg) {
986 switch (*arg) {
987 case 'b': /* raw binary format */
988 if (fmt++)
989 goto sep_err;
990 sep = '\0';
991 break;
992 case 'c': /* external checksum format */
993 if (fmt++)
994 goto sep_err;
995 sep = '\0';
996 chk = 1;
997 break;
998 case 't': /* text format */
999 if (fmt++)
1000 goto sep_err;
1001 sep = '\n';
1002 break;
Alexander Hollerecd14462014-07-14 17:49:55 +02001003 case 'r': /* handle CRLF like LF */
1004 crlf_is_lf = 1;
1005 break;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001006 case 'd':
1007 del = 1;
1008 break;
1009 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +00001010 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001011 }
1012 }
1013 }
1014
Macpaul Linf3c615b2011-04-26 16:16:45 +00001015 if (argc < 1)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001016 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001017
1018 if (!fmt)
1019 printf("## Warning: defaulting to text format\n");
1020
Alexander Hollerecd14462014-07-14 17:49:55 +02001021 if (sep != '\n' && crlf_is_lf )
1022 crlf_is_lf = 0;
1023
Simon Glassfd37dac2013-10-25 23:01:31 -06001024 addr = simple_strtoul(argv[0], NULL, 16);
1025 ptr = map_sysmem(addr, 0);
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001026
1027 if (argc == 2) {
1028 size = simple_strtoul(argv[1], NULL, 16);
Tom Rini3775dcd2014-03-04 15:52:35 -05001029 } else if (argc == 1 && chk) {
1030 puts("## Error: external checksum format must pass size\n");
1031 return CMD_RET_FAILURE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001032 } else {
Simon Glassfd37dac2013-10-25 23:01:31 -06001033 char *s = ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001034
1035 size = 0;
1036
1037 while (size < MAX_ENV_SIZE) {
1038 if ((*s == sep) && (*(s+1) == '\0'))
1039 break;
1040 ++s;
1041 ++size;
1042 }
1043 if (size == MAX_ENV_SIZE) {
1044 printf("## Warning: Input data exceeds %d bytes"
1045 " - truncated\n", MAX_ENV_SIZE);
1046 }
Horst Kronstorferd3f80c72011-12-16 23:33:10 +00001047 size += 2;
Simon Glass79afc882011-11-04 06:42:36 +00001048 printf("## Info: input data size = %zu = 0x%zX\n", size, size);
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001049 }
1050
1051 if (chk) {
1052 uint32_t crc;
Simon Glassfd37dac2013-10-25 23:01:31 -06001053 env_t *ep = (env_t *)ptr;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001054
1055 size -= offsetof(env_t, data);
1056 memcpy(&crc, &ep->crc, sizeof(crc));
1057
1058 if (crc32(0, ep->data, size) != crc) {
1059 puts("## Error: bad CRC, import failed\n");
1060 return 1;
1061 }
Simon Glassfd37dac2013-10-25 23:01:31 -06001062 ptr = (char *)ep->data;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001063 }
1064
Alexander Hollerecd14462014-07-14 17:49:55 +02001065 if (himport_r(&env_htab, ptr, size, sep, del ? 0 : H_NOCLEAR,
1066 crlf_is_lf, 0, NULL) == 0) {
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001067 error("Environment import failed: errno = %d\n", errno);
1068 return 1;
1069 }
1070 gd->flags |= GD_FLG_ENV_READY;
1071
1072 return 0;
1073
1074sep_err:
1075 printf("## %s: only one of \"-b\", \"-c\" or \"-t\" allowed\n",
1076 cmd);
1077 return 1;
1078}
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001079#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001080
Andrew Ruder88733e22013-10-22 19:07:34 -05001081#if defined(CONFIG_CMD_ENV_EXISTS)
1082static int do_env_exists(cmd_tbl_t *cmdtp, int flag, int argc,
1083 char * const argv[])
1084{
1085 ENTRY e, *ep;
1086
1087 if (argc < 2)
1088 return CMD_RET_USAGE;
1089
1090 e.key = argv[1];
1091 e.data = NULL;
1092 hsearch_r(e, FIND, &ep, &env_htab, 0);
1093
1094 return (ep == NULL) ? 1 : 0;
1095}
1096#endif
1097
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001098/*
1099 * New command line interface: "env" command with subcommands
1100 */
1101static cmd_tbl_t cmd_env_sub[] = {
1102#if defined(CONFIG_CMD_ASKENV)
1103 U_BOOT_CMD_MKENT(ask, CONFIG_SYS_MAXARGS, 1, do_env_ask, "", ""),
1104#endif
1105 U_BOOT_CMD_MKENT(default, 1, 0, do_env_default, "", ""),
Joe Hershberger9d8d6612012-12-11 22:16:36 -06001106 U_BOOT_CMD_MKENT(delete, CONFIG_SYS_MAXARGS, 0, do_env_delete, "", ""),
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001107#if defined(CONFIG_CMD_EDITENV)
1108 U_BOOT_CMD_MKENT(edit, 2, 0, do_env_edit, "", ""),
1109#endif
Joe Hershberger5e2b3e02012-12-11 22:16:25 -06001110#if defined(CONFIG_CMD_ENV_CALLBACK)
1111 U_BOOT_CMD_MKENT(callbacks, 1, 0, do_env_callback, "", ""),
1112#endif
Joe Hershbergerfffad712012-12-11 22:16:33 -06001113#if defined(CONFIG_CMD_ENV_FLAGS)
1114 U_BOOT_CMD_MKENT(flags, 1, 0, do_env_flags, "", ""),
1115#endif
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001116#if defined(CONFIG_CMD_EXPORTENV)
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001117 U_BOOT_CMD_MKENT(export, 4, 0, do_env_export, "", ""),
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001118#endif
Kim Phillipsa000b792011-04-05 07:15:14 +00001119#if defined(CONFIG_CMD_GREPENV)
1120 U_BOOT_CMD_MKENT(grep, CONFIG_SYS_MAXARGS, 1, do_env_grep, "", ""),
1121#endif
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001122#if defined(CONFIG_CMD_IMPORTENV)
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001123 U_BOOT_CMD_MKENT(import, 5, 0, do_env_import, "", ""),
Mike Frysinger0c79cda2010-12-26 23:09:45 -05001124#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001125 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_env_print, "", ""),
1126#if defined(CONFIG_CMD_RUN)
1127 U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
1128#endif
1129#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
1130 U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
1131#endif
1132 U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 0, do_env_set, "", ""),
Andrew Ruder88733e22013-10-22 19:07:34 -05001133#if defined(CONFIG_CMD_ENV_EXISTS)
1134 U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""),
1135#endif
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001136};
1137
Wolfgang Denk2e5167c2010-10-28 20:00:11 +02001138#if defined(CONFIG_NEEDS_MANUAL_RELOC)
Heiko Schocher60f7da12010-10-05 14:17:00 +02001139void env_reloc(void)
1140{
1141 fixup_cmdtable(cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1142}
1143#endif
1144
Macpaul Linf3c615b2011-04-26 16:16:45 +00001145static int do_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001146{
1147 cmd_tbl_t *cp;
1148
Thomas Weber5904da02010-11-24 13:07:52 +01001149 if (argc < 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +00001150 return CMD_RET_USAGE;
Thomas Weber5904da02010-11-24 13:07:52 +01001151
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001152 /* drop initial "env" arg */
1153 argc--;
1154 argv++;
1155
1156 cp = find_cmd_tbl(argv[0], cmd_env_sub, ARRAY_SIZE(cmd_env_sub));
1157
1158 if (cp)
1159 return cp->cmd(cmdtp, flag, argc, argv);
1160
Simon Glass4c12eeb2011-12-10 08:44:01 +00001161 return CMD_RET_USAGE;
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001162}
1163
Kim Phillips088f1b12012-10-29 13:34:31 +00001164#ifdef CONFIG_SYS_LONGHELP
1165static char env_help_text[] =
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001166#if defined(CONFIG_CMD_ASKENV)
1167 "ask name [message] [size] - ask for environment variable\nenv "
1168#endif
Joe Hershberger5e2b3e02012-12-11 22:16:25 -06001169#if defined(CONFIG_CMD_ENV_CALLBACK)
1170 "callbacks - print callbacks and their associated variables\nenv "
1171#endif
Gerlando Falautob64b7c32012-08-24 00:11:41 +00001172 "default [-f] -a - [forcibly] reset default environment\n"
1173 "env default [-f] var [...] - [forcibly] reset variable(s) to their default values\n"
Joe Hershberger9d8d6612012-12-11 22:16:36 -06001174 "env delete [-f] var [...] - [forcibly] delete variable(s)\n"
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001175#if defined(CONFIG_CMD_EDITENV)
1176 "env edit name - edit environment variable\n"
1177#endif
Andrew Ruder88733e22013-10-22 19:07:34 -05001178#if defined(CONFIG_CMD_ENV_EXISTS)
1179 "env exists name - tests for existence of variable\n"
1180#endif
Benoît Thébaudeau4796bc42012-08-10 07:45:44 +00001181#if defined(CONFIG_CMD_EXPORTENV)
Wolfgang Denk37f2fe72011-11-06 22:49:44 +01001182 "env export [-t | -b | -c] [-s size] addr [var ...] - export environment\n"
Benoît Thébaudeau4796bc42012-08-10 07:45:44 +00001183#endif
Joe Hershbergerfffad712012-12-11 22:16:33 -06001184#if defined(CONFIG_CMD_ENV_FLAGS)
1185 "env flags - print variables that have non-default flags\n"
1186#endif
Kim Phillipsa000b792011-04-05 07:15:14 +00001187#if defined(CONFIG_CMD_GREPENV)
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001188#ifdef CONFIG_REGEX
1189 "env grep [-e] [-n | -v | -b] string [...] - search environment\n"
1190#else
Wolfgang Denkd87244d2013-03-23 23:50:30 +00001191 "env grep [-n | -v | -b] string [...] - search environment\n"
Kim Phillipsa000b792011-04-05 07:15:14 +00001192#endif
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001193#endif
Benoît Thébaudeau4796bc42012-08-10 07:45:44 +00001194#if defined(CONFIG_CMD_IMPORTENV)
Alexander Hollerecd14462014-07-14 17:49:55 +02001195 "env import [-d] [-t [-r] | -b | -c] addr [size] - import environment\n"
Benoît Thébaudeau4796bc42012-08-10 07:45:44 +00001196#endif
Joe Hershbergerbe112352012-12-11 22:16:23 -06001197 "env print [-a | name ...] - print environment\n"
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001198#if defined(CONFIG_CMD_RUN)
1199 "env run var [...] - run commands in an environment variable\n"
1200#endif
Horst Kronstorferd798a9b2011-12-10 02:25:19 +00001201#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001202 "env save - save environment\n"
Horst Kronstorferd798a9b2011-12-10 02:25:19 +00001203#endif
Kim Phillips088f1b12012-10-29 13:34:31 +00001204 "env set [-f] name [arg ...]\n";
1205#endif
1206
1207U_BOOT_CMD(
1208 env, CONFIG_SYS_MAXARGS, 1, do_env,
1209 "environment handling commands", env_help_text
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001210);
1211
1212/*
1213 * Old command line interface, kept for compatibility
1214 */
wdenk8bde7f72003-06-27 21:31:46 +00001215
Peter Tyser246c6922009-10-25 15:12:56 -05001216#if defined(CONFIG_CMD_EDITENV)
Mike Frysinger722b0612010-10-20 03:52:39 -04001217U_BOOT_CMD_COMPLETE(
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001218 editenv, 2, 0, do_env_edit,
Peter Tyser246c6922009-10-25 15:12:56 -05001219 "edit environment variable",
1220 "name\n"
Mike Frysinger722b0612010-10-20 03:52:39 -04001221 " - edit environment variable 'name'",
1222 var_complete
Peter Tyser246c6922009-10-25 15:12:56 -05001223);
1224#endif
1225
Mike Frysinger722b0612010-10-20 03:52:39 -04001226U_BOOT_CMD_COMPLETE(
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001227 printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
Peter Tyser2fb26042009-01-27 18:03:12 -06001228 "print environment variables",
Joe Hershbergerbe112352012-12-11 22:16:23 -06001229 "[-a]\n - print [all] values of all environment variables\n"
wdenk8bde7f72003-06-27 21:31:46 +00001230 "printenv name ...\n"
Mike Frysinger722b0612010-10-20 03:52:39 -04001231 " - print value of environment variable 'name'",
1232 var_complete
wdenk8bde7f72003-06-27 21:31:46 +00001233);
1234
Kim Phillipsa000b792011-04-05 07:15:14 +00001235#ifdef CONFIG_CMD_GREPENV
1236U_BOOT_CMD_COMPLETE(
1237 grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
1238 "search environment variables",
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001239#ifdef CONFIG_REGEX
1240 "[-e] [-n | -v | -b] string ...\n"
1241#else
Wolfgang Denkd87244d2013-03-23 23:50:30 +00001242 "[-n | -v | -b] string ...\n"
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001243#endif
Wolfgang Denkd87244d2013-03-23 23:50:30 +00001244 " - list environment name=value pairs matching 'string'\n"
Wolfgang Denkbe29df62013-03-23 23:50:32 +00001245#ifdef CONFIG_REGEX
1246 " \"-e\": enable regular expressions;\n"
1247#endif
Wolfgang Denkd87244d2013-03-23 23:50:30 +00001248 " \"-n\": search variable names; \"-v\": search values;\n"
1249 " \"-b\": search both names and values (default)",
Kim Phillipsa000b792011-04-05 07:15:14 +00001250 var_complete
1251);
1252#endif
1253
Mike Frysinger722b0612010-10-20 03:52:39 -04001254U_BOOT_CMD_COMPLETE(
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001255 setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
Peter Tyser2fb26042009-01-27 18:03:12 -06001256 "set environment variables",
Joe Hershberger24ab5a12012-12-11 22:16:35 -06001257 "[-f] name value ...\n"
1258 " - [forcibly] set environment variable 'name' to 'value ...'\n"
1259 "setenv [-f] name\n"
1260 " - [forcibly] delete environment variable 'name'",
Mike Frysinger722b0612010-10-20 03:52:39 -04001261 var_complete
wdenk8bde7f72003-06-27 21:31:46 +00001262);
1263
Jon Loeligerc76fe472007-07-08 18:02:23 -05001264#if defined(CONFIG_CMD_ASKENV)
wdenk8bde7f72003-06-27 21:31:46 +00001265
wdenk0d498392003-07-01 21:06:45 +00001266U_BOOT_CMD(
Wolfgang Denkea882ba2010-06-20 23:33:59 +02001267 askenv, CONFIG_SYS_MAXARGS, 1, do_env_ask,
Peter Tyser2fb26042009-01-27 18:03:12 -06001268 "get environment variables from stdin",
wdenk8bde7f72003-06-27 21:31:46 +00001269 "name [message] [size]\n"
Wolfgang Denk7d855912013-02-20 04:53:16 +00001270 " - get environment variable 'name' from stdin (max 'size' chars)"
wdenk8bde7f72003-06-27 21:31:46 +00001271);
Jon Loeliger90253172007-07-10 11:02:44 -05001272#endif
wdenk8bde7f72003-06-27 21:31:46 +00001273
Jon Loeligerc76fe472007-07-08 18:02:23 -05001274#if defined(CONFIG_CMD_RUN)
Mike Frysinger722b0612010-10-20 03:52:39 -04001275U_BOOT_CMD_COMPLETE(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001276 run, CONFIG_SYS_MAXARGS, 1, do_run,
Peter Tyser2fb26042009-01-27 18:03:12 -06001277 "run commands in an environment variable",
wdenk8bde7f72003-06-27 21:31:46 +00001278 "var [...]\n"
Mike Frysinger722b0612010-10-20 03:52:39 -04001279 " - run the commands in the environment variable(s) 'var'",
1280 var_complete
wdenk8bde7f72003-06-27 21:31:46 +00001281);
Jon Loeliger90253172007-07-10 11:02:44 -05001282#endif
Ilya Yanok7ac2fe22012-09-18 00:22:50 +00001283#endif /* CONFIG_SPL_BUILD */