blob: 3ee971ab0e3165c9bbcd680f6994b6b1833ddef1 [file] [log] [blame]
wdenka68d3ed2002-10-11 08:38:32 +00001/*
2 * (C) Copyright 2000-2002
3 * 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>
7
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27/**************************************************************************
28 *
29 * Support for persistent environment data
30 *
31 * The "environment" is stored as a list of '\0' terminated
32 * "name=value" strings. The end of the list is marked by a double
33 * '\0'. New entries are always added at the end. Deleting an entry
34 * shifts the remaining entries to the front. Replacing an entry is a
35 * combination of deleting the old value and adding the new one.
36 *
37 * The environment is preceeded by a 32 bit CRC over the data part.
38 *
39 **************************************************************************
40 */
41
42#include <common.h>
43#include <command.h>
44#include <environment.h>
wdenk2a3cb022002-11-05 21:01:48 +000045#include <watchdog.h>
wdenk281e00a2004-08-01 22:48:16 +000046#include <serial.h>
wdenka68d3ed2002-10-11 08:38:32 +000047#include <linux/stddef.h>
48#include <asm/byteorder.h>
Jon Loeligerc76fe472007-07-08 18:02:23 -050049#if defined(CONFIG_CMD_NET)
wdenka68d3ed2002-10-11 08:38:32 +000050#include <net.h>
51#endif
52
Wolfgang Denkd87080b2006-03-31 18:32:53 +020053DECLARE_GLOBAL_DATA_PTR;
54
unsik Kim75eb82e2009-02-25 11:31:24 +090055#if !defined(CONFIG_ENV_IS_IN_EEPROM) && \
Jean-Christophe PLAGNIOL-VILLARD5a1aceb2008-09-10 22:48:04 +020056 !defined(CONFIG_ENV_IS_IN_FLASH) && \
Jean-Christophe PLAGNIOL-VILLARD057c8492008-09-10 22:47:58 +020057 !defined(CONFIG_ENV_IS_IN_DATAFLASH) && \
unsik Kim75eb82e2009-02-25 11:31:24 +090058 !defined(CONFIG_ENV_IS_IN_MG_DISK) && \
Jean-Christophe PLAGNIOL-VILLARD51bfee12008-09-10 22:47:58 +020059 !defined(CONFIG_ENV_IS_IN_NAND) && \
unsik Kim75eb82e2009-02-25 11:31:24 +090060 !defined(CONFIG_ENV_IS_IN_NVRAM) && \
Jean-Christophe PLAGNIOL-VILLARD96561382008-09-10 22:47:59 +020061 !defined(CONFIG_ENV_IS_IN_ONENAND) && \
Jean-Christophe PLAGNIOL-VILLARD0b5099a2008-09-10 22:48:00 +020062 !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \
Jean-Christophe PLAGNIOL-VILLARD93f6d722008-09-10 22:48:00 +020063 !defined(CONFIG_ENV_IS_NOWHERE)
unsik Kim75eb82e2009-02-25 11:31:24 +090064# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
65SPI_FLASH|MG_DISK|NVRAM|NOWHERE}
wdenka68d3ed2002-10-11 08:38:32 +000066#endif
67
68#define XMK_STR(x) #x
69#define MK_STR(x) XMK_STR(x)
70
71/************************************************************************
72************************************************************************/
73
wdenka68d3ed2002-10-11 08:38:32 +000074/*
75 * Table with supported baudrates (defined in config_xyz.h)
76 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020077static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE;
wdenka68d3ed2002-10-11 08:38:32 +000078#define N_BAUDRATES (sizeof(baudrate_table) / sizeof(baudrate_table[0]))
79
Heiko Schocherda954272009-04-28 08:36:11 +020080/*
81 * This variable is incremented on each do_setenv (), so it can
82 * be used via get_env_id() as an indication, if the environment
83 * has changed or not. So it is possible to reread an environment
84 * variable only if the environment was changed ... done so for
85 * example in NetInitLoop()
86 */
Heiko Schocher2f70c492009-02-10 09:38:52 +010087static int env_id = 1;
wdenka68d3ed2002-10-11 08:38:32 +000088
Heiko Schocher2f70c492009-02-10 09:38:52 +010089int get_env_id (void)
90{
91 return env_id;
92}
wdenka68d3ed2002-10-11 08:38:32 +000093/************************************************************************
94 * Command interface: print one or all environment variables
95 */
96
97int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
98{
99 int i, j, k, nxt;
100 int rcode = 0;
101
102 if (argc == 1) { /* Print all env variables */
103 for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
104 for (nxt=i; env_get_char(nxt) != '\0'; ++nxt)
105 ;
106 for (k=i; k<nxt; ++k)
107 putc(env_get_char(k));
108 putc ('\n');
109
110 if (ctrlc()) {
111 puts ("\n ** Abort\n");
112 return 1;
113 }
114 }
115
Wolfgang Denkd5996dd2008-07-13 19:51:00 +0200116 printf("\nEnvironment size: %d/%ld bytes\n",
117 i, (ulong)ENV_SIZE);
wdenka68d3ed2002-10-11 08:38:32 +0000118
119 return 0;
120 }
121
122 for (i=1; i<argc; ++i) { /* print single env variables */
123 char *name = argv[i];
124
125 k = -1;
126
127 for (j=0; env_get_char(j) != '\0'; j=nxt+1) {
128
129 for (nxt=j; env_get_char(nxt) != '\0'; ++nxt)
130 ;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200131 k = envmatch((uchar *)name, j);
wdenka68d3ed2002-10-11 08:38:32 +0000132 if (k < 0) {
133 continue;
134 }
135 puts (name);
136 putc ('=');
137 while (k < nxt)
138 putc(env_get_char(k++));
139 putc ('\n');
140 break;
141 }
142 if (k < 0) {
143 printf ("## Error: \"%s\" not defined\n", name);
144 rcode ++;
145 }
146 }
147 return rcode;
148}
149
150/************************************************************************
151 * Set a new environment variable,
152 * or replace or delete an existing one.
153 *
154 * This function will ONLY work with a in-RAM copy of the environment
155 */
156
157int _do_setenv (int flag, int argc, char *argv[])
158{
wdenka68d3ed2002-10-11 08:38:32 +0000159 int i, len, oldval;
160 int console = -1;
161 uchar *env, *nxt = NULL;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200162 char *name;
wdenka68d3ed2002-10-11 08:38:32 +0000163 bd_t *bd = gd->bd;
164
165 uchar *env_data = env_get_addr(0);
166
167 if (!env_data) /* need copy in RAM */
168 return 1;
169
170 name = argv[1];
171
Wolfgang Denk471a7be2006-10-28 01:14:32 +0200172 if (strchr(name, '=')) {
173 printf ("## Error: illegal character '=' in variable name \"%s\"\n", name);
174 return 1;
175 }
176
Heiko Schocher2f70c492009-02-10 09:38:52 +0100177 env_id++;
wdenka68d3ed2002-10-11 08:38:32 +0000178 /*
179 * search if variable with this name already exists
180 */
181 oldval = -1;
182 for (env=env_data; *env; env=nxt+1) {
183 for (nxt=env; *nxt; ++nxt)
184 ;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200185 if ((oldval = envmatch((uchar *)name, env-env_data)) >= 0)
wdenka68d3ed2002-10-11 08:38:32 +0000186 break;
187 }
188
189 /*
190 * Delete any existing definition
191 */
192 if (oldval >= 0) {
193#ifndef CONFIG_ENV_OVERWRITE
194
195 /*
stroese05875972003-04-04 15:44:49 +0000196 * Ethernet Address and serial# can be set only once,
197 * ver is readonly.
wdenka68d3ed2002-10-11 08:38:32 +0000198 */
Steven A. Falcof6a69552008-06-12 13:24:42 -0400199 if (
Sergey Kubushync74b2102007-08-10 20:26:18 +0200200#ifdef CONFIG_HAS_UID
201 /* Allow serial# forced overwrite with 0xdeaf4add flag */
Steven A. Falcof6a69552008-06-12 13:24:42 -0400202 ((strcmp (name, "serial#") == 0) && (flag != 0xdeaf4add)) ||
Sergey Kubushync74b2102007-08-10 20:26:18 +0200203#else
Steven A. Falcof6a69552008-06-12 13:24:42 -0400204 (strcmp (name, "serial#") == 0) ||
Sergey Kubushync74b2102007-08-10 20:26:18 +0200205#endif
wdenka68d3ed2002-10-11 08:38:32 +0000206 ((strcmp (name, "ethaddr") == 0)
207#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200208 && (strcmp ((char *)env_get_addr(oldval),MK_STR(CONFIG_ETHADDR)) != 0)
wdenka68d3ed2002-10-11 08:38:32 +0000209#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
210 ) ) {
211 printf ("Can't overwrite \"%s\"\n", name);
212 return 1;
213 }
214#endif
215
216 /* Check for console redirection */
217 if (strcmp(name,"stdin") == 0) {
218 console = stdin;
219 } else if (strcmp(name,"stdout") == 0) {
220 console = stdout;
221 } else if (strcmp(name,"stderr") == 0) {
222 console = stderr;
223 }
224
225 if (console != -1) {
226 if (argc < 3) { /* Cannot delete it! */
227 printf("Can't delete \"%s\"\n", name);
228 return 1;
229 }
230
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100231#ifdef CONFIG_CONSOLE_MUX
232 i = iomux_doenv(console, argv[2]);
233 if (i)
234 return i;
235#else
wdenka68d3ed2002-10-11 08:38:32 +0000236 /* Try assigning specified device */
237 if (console_assign (console, argv[2]) < 0)
238 return 1;
wdenk281e00a2004-08-01 22:48:16 +0000239
240#ifdef CONFIG_SERIAL_MULTI
241 if (serial_assign (argv[2]) < 0)
242 return 1;
243#endif
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100244#endif /* CONFIG_CONSOLE_MUX */
wdenka68d3ed2002-10-11 08:38:32 +0000245 }
246
247 /*
248 * Switch to new baudrate if new baudrate is supported
249 */
250 if (strcmp(argv[1],"baudrate") == 0) {
251 int baudrate = simple_strtoul(argv[2], NULL, 10);
252 int i;
253 for (i=0; i<N_BAUDRATES; ++i) {
254 if (baudrate == baudrate_table[i])
255 break;
256 }
257 if (i == N_BAUDRATES) {
258 printf ("## Baudrate %d bps not supported\n",
259 baudrate);
260 return 1;
261 }
262 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
263 baudrate);
264 udelay(50000);
265 gd->baudrate = baudrate;
Bartlomiej Siekac84bad02006-12-20 00:29:43 +0100266#if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2)
wdenkd0fb80c2003-01-11 09:48:40 +0000267 gd->bd->bi_baudrate = baudrate;
268#endif
269
wdenka68d3ed2002-10-11 08:38:32 +0000270 serial_setbrg ();
271 udelay(50000);
272 for (;;) {
273 if (getc() == '\r')
274 break;
275 }
276 }
277
278 if (*++nxt == '\0') {
279 if (env > env_data) {
280 env--;
281 } else {
282 *env = '\0';
283 }
284 } else {
285 for (;;) {
286 *env = *nxt++;
287 if ((*env == '\0') && (*nxt == '\0'))
288 break;
289 ++env;
290 }
291 }
292 *++env = '\0';
293 }
294
wdenka68d3ed2002-10-11 08:38:32 +0000295 /* Delete only ? */
296 if ((argc < 3) || argv[2] == NULL) {
297 env_crc_update ();
298 return 0;
299 }
300
301 /*
302 * Append new definition at the end
303 */
304 for (env=env_data; *env || *(env+1); ++env)
305 ;
306 if (env > env_data)
307 ++env;
308 /*
309 * Overflow when:
310 * "name" + "=" + "val" +"\0\0" > ENV_SIZE - (env-env_data)
311 */
312 len = strlen(name) + 2;
313 /* add '=' for first arg, ' ' for all others */
314 for (i=2; i<argc; ++i) {
315 len += strlen(argv[i]) + 1;
316 }
317 if (len > (&env_data[ENV_SIZE]-env)) {
318 printf ("## Error: environment overflow, \"%s\" deleted\n", name);
319 return 1;
320 }
321 while ((*env = *name++) != '\0')
322 env++;
323 for (i=2; i<argc; ++i) {
324 char *val = argv[i];
325
326 *env = (i==2) ? '=' : ' ';
327 while ((*++env = *val++) != '\0')
328 ;
329 }
330
331 /* end is marked with double '\0' */
332 *++env = '\0';
333
334 /* Update CRC */
335 env_crc_update ();
336
337 /*
338 * Some variables should be updated when the corresponding
339 * entry in the enviornment is changed
340 */
341
Mike Frysinger56b555a2009-02-11 18:52:38 -0500342 if (strcmp(argv[1],"ethaddr") == 0)
wdenka68d3ed2002-10-11 08:38:32 +0000343 return 0;
wdenka68d3ed2002-10-11 08:38:32 +0000344
345 if (strcmp(argv[1],"ipaddr") == 0) {
346 char *s = argv[2]; /* always use only one arg */
347 char *e;
348 unsigned long addr;
349 bd->bi_ip_addr = 0;
350 for (addr=0, i=0; i<4; ++i) {
351 ulong val = s ? simple_strtoul(s, &e, 10) : 0;
352 addr <<= 8;
353 addr |= (val & 0xFF);
354 if (s) s = (*e) ? e+1 : e;
355 }
356 bd->bi_ip_addr = htonl(addr);
357 return 0;
358 }
359 if (strcmp(argv[1],"loadaddr") == 0) {
360 load_addr = simple_strtoul(argv[2], NULL, 16);
361 return 0;
362 }
Jon Loeligerc76fe472007-07-08 18:02:23 -0500363#if defined(CONFIG_CMD_NET)
wdenka68d3ed2002-10-11 08:38:32 +0000364 if (strcmp(argv[1],"bootfile") == 0) {
365 copy_filename (BootFile, argv[2], sizeof(BootFile));
366 return 0;
367 }
Jon Loeliger90253172007-07-10 11:02:44 -0500368#endif
wdenkc7de8292002-11-19 11:04:11 +0000369
stroese05875972003-04-04 15:44:49 +0000370#ifdef CONFIG_AMIGAONEG3SE
wdenkc7de8292002-11-19 11:04:11 +0000371 if (strcmp(argv[1], "vga_fg_color") == 0 ||
372 strcmp(argv[1], "vga_bg_color") == 0 ) {
373 extern void video_set_color(unsigned char attr);
374 extern unsigned char video_get_attr(void);
375
376 video_set_color(video_get_attr());
377 return 0;
378 }
379#endif /* CONFIG_AMIGAONEG3SE */
380
wdenka68d3ed2002-10-11 08:38:32 +0000381 return 0;
382}
383
Steven A. Falco75678c82008-06-12 13:22:12 -0400384int setenv (char *varname, char *varvalue)
wdenka68d3ed2002-10-11 08:38:32 +0000385{
386 char *argv[4] = { "setenv", varname, varvalue, NULL };
Jeffrey Mann9ffd4512007-04-23 14:00:11 +0200387 if (varvalue == NULL)
Steven A. Falco75678c82008-06-12 13:22:12 -0400388 return _do_setenv (0, 2, argv);
Jeffrey Mann9ffd4512007-04-23 14:00:11 +0200389 else
Steven A. Falco75678c82008-06-12 13:22:12 -0400390 return _do_setenv (0, 3, argv);
wdenka68d3ed2002-10-11 08:38:32 +0000391}
392
Sergey Kubushync74b2102007-08-10 20:26:18 +0200393#ifdef CONFIG_HAS_UID
394void forceenv (char *varname, char *varvalue)
395{
396 char *argv[4] = { "forceenv", varname, varvalue, NULL };
397 _do_setenv (0xdeaf4add, 3, argv);
398}
399#endif
400
401int do_setenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenka68d3ed2002-10-11 08:38:32 +0000402{
403 if (argc < 2) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600404 cmd_usage(cmdtp);
wdenka68d3ed2002-10-11 08:38:32 +0000405 return 1;
406 }
407
408 return _do_setenv (flag, argc, argv);
409}
410
411/************************************************************************
412 * Prompt for environment variable
413 */
414
Jon Loeligerc76fe472007-07-08 18:02:23 -0500415#if defined(CONFIG_CMD_ASKENV)
wdenka68d3ed2002-10-11 08:38:32 +0000416int do_askenv ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
417{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200418 extern char console_buffer[CONFIG_SYS_CBSIZE];
419 char message[CONFIG_SYS_CBSIZE];
420 int size = CONFIG_SYS_CBSIZE - 1;
wdenka68d3ed2002-10-11 08:38:32 +0000421 int len;
422 char *local_args[4];
423
424 local_args[0] = argv[0];
425 local_args[1] = argv[1];
426 local_args[2] = NULL;
427 local_args[3] = NULL;
428
429 if (argc < 2) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600430 cmd_usage(cmdtp);
wdenka68d3ed2002-10-11 08:38:32 +0000431 return 1;
432 }
433 /* Check the syntax */
434 switch (argc) {
435 case 1:
Peter Tyser62c3ae72009-01-27 18:03:10 -0600436 cmd_usage(cmdtp);
wdenka68d3ed2002-10-11 08:38:32 +0000437 return 1;
438
439 case 2: /* askenv envname */
440 sprintf (message, "Please enter '%s':", argv[1]);
441 break;
442
443 case 3: /* askenv envname size */
444 sprintf (message, "Please enter '%s':", argv[1]);
445 size = simple_strtoul (argv[2], NULL, 10);
446 break;
447
448 default: /* askenv envname message1 ... messagen size */
449 {
450 int i;
451 int pos = 0;
452
453 for (i = 2; i < argc - 1; i++) {
454 if (pos) {
455 message[pos++] = ' ';
456 }
457 strcpy (message+pos, argv[i]);
458 pos += strlen(argv[i]);
459 }
460 message[pos] = '\0';
461 size = simple_strtoul (argv[argc - 1], NULL, 10);
462 }
463 break;
464 }
465
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200466 if (size >= CONFIG_SYS_CBSIZE)
467 size = CONFIG_SYS_CBSIZE - 1;
wdenka68d3ed2002-10-11 08:38:32 +0000468
469 if (size <= 0)
470 return 1;
471
472 /* prompt for input */
473 len = readline (message);
474
475 if (size < len)
476 console_buffer[size] = '\0';
477
478 len = 2;
479 if (console_buffer[0] != '\0') {
480 local_args[2] = console_buffer;
481 len = 3;
482 }
483
484 /* Continue calling setenv code */
485 return _do_setenv (flag, len, local_args);
486}
Jon Loeliger90253172007-07-10 11:02:44 -0500487#endif
wdenka68d3ed2002-10-11 08:38:32 +0000488
489/************************************************************************
490 * Look up variable from environment,
491 * return address of storage for that variable,
492 * or NULL if not found
493 */
494
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200495char *getenv (char *name)
wdenka68d3ed2002-10-11 08:38:32 +0000496{
497 int i, nxt;
498
wdenk2a3cb022002-11-05 21:01:48 +0000499 WATCHDOG_RESET();
500
wdenka68d3ed2002-10-11 08:38:32 +0000501 for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
502 int val;
503
504 for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) {
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200505 if (nxt >= CONFIG_ENV_SIZE) {
wdenka68d3ed2002-10-11 08:38:32 +0000506 return (NULL);
507 }
508 }
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200509 if ((val=envmatch((uchar *)name, i)) < 0)
wdenka68d3ed2002-10-11 08:38:32 +0000510 continue;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200511 return ((char *)env_get_addr(val));
wdenka68d3ed2002-10-11 08:38:32 +0000512 }
513
514 return (NULL);
515}
516
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200517int getenv_r (char *name, char *buf, unsigned len)
wdenka68d3ed2002-10-11 08:38:32 +0000518{
519 int i, nxt;
520
521 for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
522 int val, n;
523
524 for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) {
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200525 if (nxt >= CONFIG_ENV_SIZE) {
wdenka68d3ed2002-10-11 08:38:32 +0000526 return (-1);
527 }
528 }
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200529 if ((val=envmatch((uchar *)name, i)) < 0)
wdenka68d3ed2002-10-11 08:38:32 +0000530 continue;
531 /* found; copy out */
532 n = 0;
533 while ((len > n++) && (*buf++ = env_get_char(val++)) != '\0')
534 ;
535 if (len == n)
536 *buf = '\0';
537 return (n);
538 }
539 return (-1);
540}
541
Mike Frysingerbdab39d2009-01-28 19:08:14 -0500542#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Mike Frysingerba69dc22008-12-30 02:59:25 -0500543
wdenka68d3ed2002-10-11 08:38:32 +0000544int do_saveenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
545{
546 extern char * env_name_spec;
547
548 printf ("Saving Environment to %s...\n", env_name_spec);
549
550 return (saveenv() ? 1 : 0);
551}
wdenk8bde7f72003-06-27 21:31:46 +0000552
Mike Frysingerba69dc22008-12-30 02:59:25 -0500553U_BOOT_CMD(
554 saveenv, 1, 0, do_saveenv,
Peter Tyser2fb26042009-01-27 18:03:12 -0600555 "save environment variables to persistent storage",
Mike Frysingerba69dc22008-12-30 02:59:25 -0500556 NULL
557);
558
wdenka68d3ed2002-10-11 08:38:32 +0000559#endif
560
561
562/************************************************************************
563 * Match a name / name=value pair
564 *
565 * s1 is either a simple 'name', or a 'name=value' pair.
566 * i2 is the environment index for a 'name2=value2' pair.
567 * If the names match, return the index for the value2, else NULL.
568 */
569
Rafal Jaworowski26a41792008-01-09 18:05:27 +0100570int envmatch (uchar *s1, int i2)
wdenka68d3ed2002-10-11 08:38:32 +0000571{
572
573 while (*s1 == env_get_char(i2++))
574 if (*s1++ == '=')
575 return(i2);
576 if (*s1 == '\0' && env_get_char(i2-1) == '=')
577 return(i2);
578 return(-1);
579}
wdenk8bde7f72003-06-27 21:31:46 +0000580
581
582/**************************************************/
583
wdenk0d498392003-07-01 21:06:45 +0000584U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200585 printenv, CONFIG_SYS_MAXARGS, 1, do_printenv,
Peter Tyser2fb26042009-01-27 18:03:12 -0600586 "print environment variables",
wdenk8bde7f72003-06-27 21:31:46 +0000587 "\n - print values of all environment variables\n"
588 "printenv name ...\n"
589 " - print value of environment variable 'name'\n"
590);
591
wdenk0d498392003-07-01 21:06:45 +0000592U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200593 setenv, CONFIG_SYS_MAXARGS, 0, do_setenv,
Peter Tyser2fb26042009-01-27 18:03:12 -0600594 "set environment variables",
wdenk8bde7f72003-06-27 21:31:46 +0000595 "name value ...\n"
596 " - set environment variable 'name' to 'value ...'\n"
597 "setenv name\n"
598 " - delete environment variable 'name'\n"
599);
600
Jon Loeligerc76fe472007-07-08 18:02:23 -0500601#if defined(CONFIG_CMD_ASKENV)
wdenk8bde7f72003-06-27 21:31:46 +0000602
wdenk0d498392003-07-01 21:06:45 +0000603U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200604 askenv, CONFIG_SYS_MAXARGS, 1, do_askenv,
Peter Tyser2fb26042009-01-27 18:03:12 -0600605 "get environment variables from stdin",
wdenk8bde7f72003-06-27 21:31:46 +0000606 "name [message] [size]\n"
607 " - get environment variable 'name' from stdin (max 'size' chars)\n"
608 "askenv name\n"
609 " - get environment variable 'name' from stdin\n"
610 "askenv name size\n"
611 " - get environment variable 'name' from stdin (max 'size' chars)\n"
612 "askenv name [message] size\n"
613 " - display 'message' string and get environment variable 'name'"
614 "from stdin (max 'size' chars)\n"
615);
Jon Loeliger90253172007-07-10 11:02:44 -0500616#endif
wdenk8bde7f72003-06-27 21:31:46 +0000617
Jon Loeligerc76fe472007-07-08 18:02:23 -0500618#if defined(CONFIG_CMD_RUN)
wdenk8bde7f72003-06-27 21:31:46 +0000619int do_run (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk0d498392003-07-01 21:06:45 +0000620U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200621 run, CONFIG_SYS_MAXARGS, 1, do_run,
Peter Tyser2fb26042009-01-27 18:03:12 -0600622 "run commands in an environment variable",
wdenk8bde7f72003-06-27 21:31:46 +0000623 "var [...]\n"
624 " - run the commands in the environment variable(s) 'var'\n"
625);
Jon Loeliger90253172007-07-10 11:02:44 -0500626#endif