blob: af404176aa24645a570b370eb3f08863a7703559 [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
Jean-Christophe PLAGNIOL-VILLARD9314cee2008-09-10 22:47:59 +020055#if !defined(CONFIG_ENV_IS_IN_NVRAM) && \
Jean-Christophe PLAGNIOL-VILLARDbb1f8b42008-09-05 09:19:30 +020056 !defined(CONFIG_ENV_IS_IN_EEPROM) && \
Jean-Christophe PLAGNIOL-VILLARD5a1aceb2008-09-10 22:48:04 +020057 !defined(CONFIG_ENV_IS_IN_FLASH) && \
Jean-Christophe PLAGNIOL-VILLARD057c8492008-09-10 22:47:58 +020058 !defined(CONFIG_ENV_IS_IN_DATAFLASH) && \
Jean-Christophe PLAGNIOL-VILLARD51bfee12008-09-10 22:47:58 +020059 !defined(CONFIG_ENV_IS_IN_NAND) && \
Jean-Christophe PLAGNIOL-VILLARD96561382008-09-10 22:47:59 +020060 !defined(CONFIG_ENV_IS_IN_ONENAND) && \
Jean-Christophe PLAGNIOL-VILLARD0b5099a2008-09-10 22:48:00 +020061 !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \
Jean-Christophe PLAGNIOL-VILLARD93f6d722008-09-10 22:48:00 +020062 !defined(CONFIG_ENV_IS_NOWHERE)
Jean-Christophe PLAGNIOL-VILLARD1ede7872008-09-10 22:48:05 +020063# error Define one of CONFIG_ENV_IS_IN_{NVRAM|EEPROM|FLASH|DATAFLASH|ONENAND|SPI_FLASH|NOWHERE}
wdenka68d3ed2002-10-11 08:38:32 +000064#endif
65
66#define XMK_STR(x) #x
67#define MK_STR(x) XMK_STR(x)
68
69/************************************************************************
70************************************************************************/
71
wdenka68d3ed2002-10-11 08:38:32 +000072/*
73 * Table with supported baudrates (defined in config_xyz.h)
74 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020075static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE;
wdenka68d3ed2002-10-11 08:38:32 +000076#define N_BAUDRATES (sizeof(baudrate_table) / sizeof(baudrate_table[0]))
77
78
79/************************************************************************
80 * Command interface: print one or all environment variables
81 */
82
83int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
84{
85 int i, j, k, nxt;
86 int rcode = 0;
87
88 if (argc == 1) { /* Print all env variables */
89 for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
90 for (nxt=i; env_get_char(nxt) != '\0'; ++nxt)
91 ;
92 for (k=i; k<nxt; ++k)
93 putc(env_get_char(k));
94 putc ('\n');
95
96 if (ctrlc()) {
97 puts ("\n ** Abort\n");
98 return 1;
99 }
100 }
101
Wolfgang Denkd5996dd2008-07-13 19:51:00 +0200102 printf("\nEnvironment size: %d/%ld bytes\n",
103 i, (ulong)ENV_SIZE);
wdenka68d3ed2002-10-11 08:38:32 +0000104
105 return 0;
106 }
107
108 for (i=1; i<argc; ++i) { /* print single env variables */
109 char *name = argv[i];
110
111 k = -1;
112
113 for (j=0; env_get_char(j) != '\0'; j=nxt+1) {
114
115 for (nxt=j; env_get_char(nxt) != '\0'; ++nxt)
116 ;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200117 k = envmatch((uchar *)name, j);
wdenka68d3ed2002-10-11 08:38:32 +0000118 if (k < 0) {
119 continue;
120 }
121 puts (name);
122 putc ('=');
123 while (k < nxt)
124 putc(env_get_char(k++));
125 putc ('\n');
126 break;
127 }
128 if (k < 0) {
129 printf ("## Error: \"%s\" not defined\n", name);
130 rcode ++;
131 }
132 }
133 return rcode;
134}
135
136/************************************************************************
137 * Set a new environment variable,
138 * or replace or delete an existing one.
139 *
140 * This function will ONLY work with a in-RAM copy of the environment
141 */
142
143int _do_setenv (int flag, int argc, char *argv[])
144{
wdenka68d3ed2002-10-11 08:38:32 +0000145 int i, len, oldval;
146 int console = -1;
147 uchar *env, *nxt = NULL;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200148 char *name;
wdenka68d3ed2002-10-11 08:38:32 +0000149 bd_t *bd = gd->bd;
150
151 uchar *env_data = env_get_addr(0);
152
153 if (!env_data) /* need copy in RAM */
154 return 1;
155
156 name = argv[1];
157
Wolfgang Denk471a7be2006-10-28 01:14:32 +0200158 if (strchr(name, '=')) {
159 printf ("## Error: illegal character '=' in variable name \"%s\"\n", name);
160 return 1;
161 }
162
wdenka68d3ed2002-10-11 08:38:32 +0000163 /*
164 * search if variable with this name already exists
165 */
166 oldval = -1;
167 for (env=env_data; *env; env=nxt+1) {
168 for (nxt=env; *nxt; ++nxt)
169 ;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200170 if ((oldval = envmatch((uchar *)name, env-env_data)) >= 0)
wdenka68d3ed2002-10-11 08:38:32 +0000171 break;
172 }
173
174 /*
175 * Delete any existing definition
176 */
177 if (oldval >= 0) {
178#ifndef CONFIG_ENV_OVERWRITE
179
180 /*
stroese05875972003-04-04 15:44:49 +0000181 * Ethernet Address and serial# can be set only once,
182 * ver is readonly.
wdenka68d3ed2002-10-11 08:38:32 +0000183 */
Steven A. Falcof6a69552008-06-12 13:24:42 -0400184 if (
Sergey Kubushync74b2102007-08-10 20:26:18 +0200185#ifdef CONFIG_HAS_UID
186 /* Allow serial# forced overwrite with 0xdeaf4add flag */
Steven A. Falcof6a69552008-06-12 13:24:42 -0400187 ((strcmp (name, "serial#") == 0) && (flag != 0xdeaf4add)) ||
Sergey Kubushync74b2102007-08-10 20:26:18 +0200188#else
Steven A. Falcof6a69552008-06-12 13:24:42 -0400189 (strcmp (name, "serial#") == 0) ||
Sergey Kubushync74b2102007-08-10 20:26:18 +0200190#endif
wdenka68d3ed2002-10-11 08:38:32 +0000191 ((strcmp (name, "ethaddr") == 0)
192#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200193 && (strcmp ((char *)env_get_addr(oldval),MK_STR(CONFIG_ETHADDR)) != 0)
wdenka68d3ed2002-10-11 08:38:32 +0000194#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
195 ) ) {
196 printf ("Can't overwrite \"%s\"\n", name);
197 return 1;
198 }
199#endif
200
201 /* Check for console redirection */
202 if (strcmp(name,"stdin") == 0) {
203 console = stdin;
204 } else if (strcmp(name,"stdout") == 0) {
205 console = stdout;
206 } else if (strcmp(name,"stderr") == 0) {
207 console = stderr;
208 }
209
210 if (console != -1) {
211 if (argc < 3) { /* Cannot delete it! */
212 printf("Can't delete \"%s\"\n", name);
213 return 1;
214 }
215
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100216#ifdef CONFIG_CONSOLE_MUX
217 i = iomux_doenv(console, argv[2]);
218 if (i)
219 return i;
220#else
wdenka68d3ed2002-10-11 08:38:32 +0000221 /* Try assigning specified device */
222 if (console_assign (console, argv[2]) < 0)
223 return 1;
wdenk281e00a2004-08-01 22:48:16 +0000224
225#ifdef CONFIG_SERIAL_MULTI
226 if (serial_assign (argv[2]) < 0)
227 return 1;
228#endif
Gary Jennejohn16a28ef2008-11-06 15:04:23 +0100229#endif /* CONFIG_CONSOLE_MUX */
wdenka68d3ed2002-10-11 08:38:32 +0000230 }
231
232 /*
233 * Switch to new baudrate if new baudrate is supported
234 */
235 if (strcmp(argv[1],"baudrate") == 0) {
236 int baudrate = simple_strtoul(argv[2], NULL, 10);
237 int i;
238 for (i=0; i<N_BAUDRATES; ++i) {
239 if (baudrate == baudrate_table[i])
240 break;
241 }
242 if (i == N_BAUDRATES) {
243 printf ("## Baudrate %d bps not supported\n",
244 baudrate);
245 return 1;
246 }
247 printf ("## Switch baudrate to %d bps and press ENTER ...\n",
248 baudrate);
249 udelay(50000);
250 gd->baudrate = baudrate;
Bartlomiej Siekac84bad02006-12-20 00:29:43 +0100251#if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2)
wdenkd0fb80c2003-01-11 09:48:40 +0000252 gd->bd->bi_baudrate = baudrate;
253#endif
254
wdenka68d3ed2002-10-11 08:38:32 +0000255 serial_setbrg ();
256 udelay(50000);
257 for (;;) {
258 if (getc() == '\r')
259 break;
260 }
261 }
262
263 if (*++nxt == '\0') {
264 if (env > env_data) {
265 env--;
266 } else {
267 *env = '\0';
268 }
269 } else {
270 for (;;) {
271 *env = *nxt++;
272 if ((*env == '\0') && (*nxt == '\0'))
273 break;
274 ++env;
275 }
276 }
277 *++env = '\0';
278 }
279
280#ifdef CONFIG_NET_MULTI
281 if (strncmp(name, "eth", 3) == 0) {
282 char *end;
283 int num = simple_strtoul(name+3, &end, 10);
284
285 if (strcmp(end, "addr") == 0) {
286 eth_set_enetaddr(num, argv[2]);
287 }
288 }
289#endif
290
291
292 /* Delete only ? */
293 if ((argc < 3) || argv[2] == NULL) {
294 env_crc_update ();
295 return 0;
296 }
297
298 /*
299 * Append new definition at the end
300 */
301 for (env=env_data; *env || *(env+1); ++env)
302 ;
303 if (env > env_data)
304 ++env;
305 /*
306 * Overflow when:
307 * "name" + "=" + "val" +"\0\0" > ENV_SIZE - (env-env_data)
308 */
309 len = strlen(name) + 2;
310 /* add '=' for first arg, ' ' for all others */
311 for (i=2; i<argc; ++i) {
312 len += strlen(argv[i]) + 1;
313 }
314 if (len > (&env_data[ENV_SIZE]-env)) {
315 printf ("## Error: environment overflow, \"%s\" deleted\n", name);
316 return 1;
317 }
318 while ((*env = *name++) != '\0')
319 env++;
320 for (i=2; i<argc; ++i) {
321 char *val = argv[i];
322
323 *env = (i==2) ? '=' : ' ';
324 while ((*++env = *val++) != '\0')
325 ;
326 }
327
328 /* end is marked with double '\0' */
329 *++env = '\0';
330
331 /* Update CRC */
332 env_crc_update ();
333
334 /*
335 * Some variables should be updated when the corresponding
336 * entry in the enviornment is changed
337 */
338
339 if (strcmp(argv[1],"ethaddr") == 0) {
340 char *s = argv[2]; /* always use only one arg */
341 char *e;
342 for (i=0; i<6; ++i) {
343 bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
344 if (s) s = (*e) ? e+1 : e;
345 }
346#ifdef CONFIG_NET_MULTI
347 eth_set_enetaddr(0, argv[2]);
348#endif
349 return 0;
350 }
351
352 if (strcmp(argv[1],"ipaddr") == 0) {
353 char *s = argv[2]; /* always use only one arg */
354 char *e;
355 unsigned long addr;
356 bd->bi_ip_addr = 0;
357 for (addr=0, i=0; i<4; ++i) {
358 ulong val = s ? simple_strtoul(s, &e, 10) : 0;
359 addr <<= 8;
360 addr |= (val & 0xFF);
361 if (s) s = (*e) ? e+1 : e;
362 }
363 bd->bi_ip_addr = htonl(addr);
364 return 0;
365 }
366 if (strcmp(argv[1],"loadaddr") == 0) {
367 load_addr = simple_strtoul(argv[2], NULL, 16);
368 return 0;
369 }
Jon Loeligerc76fe472007-07-08 18:02:23 -0500370#if defined(CONFIG_CMD_NET)
wdenka68d3ed2002-10-11 08:38:32 +0000371 if (strcmp(argv[1],"bootfile") == 0) {
372 copy_filename (BootFile, argv[2], sizeof(BootFile));
373 return 0;
374 }
Jon Loeliger90253172007-07-10 11:02:44 -0500375#endif
wdenkc7de8292002-11-19 11:04:11 +0000376
stroese05875972003-04-04 15:44:49 +0000377#ifdef CONFIG_AMIGAONEG3SE
wdenkc7de8292002-11-19 11:04:11 +0000378 if (strcmp(argv[1], "vga_fg_color") == 0 ||
379 strcmp(argv[1], "vga_bg_color") == 0 ) {
380 extern void video_set_color(unsigned char attr);
381 extern unsigned char video_get_attr(void);
382
383 video_set_color(video_get_attr());
384 return 0;
385 }
386#endif /* CONFIG_AMIGAONEG3SE */
387
wdenka68d3ed2002-10-11 08:38:32 +0000388 return 0;
389}
390
Steven A. Falco75678c82008-06-12 13:22:12 -0400391int setenv (char *varname, char *varvalue)
wdenka68d3ed2002-10-11 08:38:32 +0000392{
393 char *argv[4] = { "setenv", varname, varvalue, NULL };
Jeffrey Mann9ffd4512007-04-23 14:00:11 +0200394 if (varvalue == NULL)
Steven A. Falco75678c82008-06-12 13:22:12 -0400395 return _do_setenv (0, 2, argv);
Jeffrey Mann9ffd4512007-04-23 14:00:11 +0200396 else
Steven A. Falco75678c82008-06-12 13:22:12 -0400397 return _do_setenv (0, 3, argv);
wdenka68d3ed2002-10-11 08:38:32 +0000398}
399
Sergey Kubushync74b2102007-08-10 20:26:18 +0200400#ifdef CONFIG_HAS_UID
401void forceenv (char *varname, char *varvalue)
402{
403 char *argv[4] = { "forceenv", varname, varvalue, NULL };
404 _do_setenv (0xdeaf4add, 3, argv);
405}
406#endif
407
408int do_setenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenka68d3ed2002-10-11 08:38:32 +0000409{
410 if (argc < 2) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600411 cmd_usage(cmdtp);
wdenka68d3ed2002-10-11 08:38:32 +0000412 return 1;
413 }
414
415 return _do_setenv (flag, argc, argv);
416}
417
418/************************************************************************
419 * Prompt for environment variable
420 */
421
Jon Loeligerc76fe472007-07-08 18:02:23 -0500422#if defined(CONFIG_CMD_ASKENV)
wdenka68d3ed2002-10-11 08:38:32 +0000423int do_askenv ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
424{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200425 extern char console_buffer[CONFIG_SYS_CBSIZE];
426 char message[CONFIG_SYS_CBSIZE];
427 int size = CONFIG_SYS_CBSIZE - 1;
wdenka68d3ed2002-10-11 08:38:32 +0000428 int len;
429 char *local_args[4];
430
431 local_args[0] = argv[0];
432 local_args[1] = argv[1];
433 local_args[2] = NULL;
434 local_args[3] = NULL;
435
436 if (argc < 2) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600437 cmd_usage(cmdtp);
wdenka68d3ed2002-10-11 08:38:32 +0000438 return 1;
439 }
440 /* Check the syntax */
441 switch (argc) {
442 case 1:
Peter Tyser62c3ae72009-01-27 18:03:10 -0600443 cmd_usage(cmdtp);
wdenka68d3ed2002-10-11 08:38:32 +0000444 return 1;
445
446 case 2: /* askenv envname */
447 sprintf (message, "Please enter '%s':", argv[1]);
448 break;
449
450 case 3: /* askenv envname size */
451 sprintf (message, "Please enter '%s':", argv[1]);
452 size = simple_strtoul (argv[2], NULL, 10);
453 break;
454
455 default: /* askenv envname message1 ... messagen size */
456 {
457 int i;
458 int pos = 0;
459
460 for (i = 2; i < argc - 1; i++) {
461 if (pos) {
462 message[pos++] = ' ';
463 }
464 strcpy (message+pos, argv[i]);
465 pos += strlen(argv[i]);
466 }
467 message[pos] = '\0';
468 size = simple_strtoul (argv[argc - 1], NULL, 10);
469 }
470 break;
471 }
472
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200473 if (size >= CONFIG_SYS_CBSIZE)
474 size = CONFIG_SYS_CBSIZE - 1;
wdenka68d3ed2002-10-11 08:38:32 +0000475
476 if (size <= 0)
477 return 1;
478
479 /* prompt for input */
480 len = readline (message);
481
482 if (size < len)
483 console_buffer[size] = '\0';
484
485 len = 2;
486 if (console_buffer[0] != '\0') {
487 local_args[2] = console_buffer;
488 len = 3;
489 }
490
491 /* Continue calling setenv code */
492 return _do_setenv (flag, len, local_args);
493}
Jon Loeliger90253172007-07-10 11:02:44 -0500494#endif
wdenka68d3ed2002-10-11 08:38:32 +0000495
496/************************************************************************
497 * Look up variable from environment,
498 * return address of storage for that variable,
499 * or NULL if not found
500 */
501
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200502char *getenv (char *name)
wdenka68d3ed2002-10-11 08:38:32 +0000503{
504 int i, nxt;
505
wdenk2a3cb022002-11-05 21:01:48 +0000506 WATCHDOG_RESET();
507
wdenka68d3ed2002-10-11 08:38:32 +0000508 for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
509 int val;
510
511 for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) {
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200512 if (nxt >= CONFIG_ENV_SIZE) {
wdenka68d3ed2002-10-11 08:38:32 +0000513 return (NULL);
514 }
515 }
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200516 if ((val=envmatch((uchar *)name, i)) < 0)
wdenka68d3ed2002-10-11 08:38:32 +0000517 continue;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200518 return ((char *)env_get_addr(val));
wdenka68d3ed2002-10-11 08:38:32 +0000519 }
520
521 return (NULL);
522}
523
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200524int getenv_r (char *name, char *buf, unsigned len)
wdenka68d3ed2002-10-11 08:38:32 +0000525{
526 int i, nxt;
527
528 for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
529 int val, n;
530
531 for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) {
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200532 if (nxt >= CONFIG_ENV_SIZE) {
wdenka68d3ed2002-10-11 08:38:32 +0000533 return (-1);
534 }
535 }
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200536 if ((val=envmatch((uchar *)name, i)) < 0)
wdenka68d3ed2002-10-11 08:38:32 +0000537 continue;
538 /* found; copy out */
539 n = 0;
540 while ((len > n++) && (*buf++ = env_get_char(val++)) != '\0')
541 ;
542 if (len == n)
543 *buf = '\0';
544 return (n);
545 }
546 return (-1);
547}
548
Mike Frysingerba69dc22008-12-30 02:59:25 -0500549#if defined(CONFIG_CMD_ENV) && !defined(CONFIG_ENV_IS_NOWHERE)
550
wdenka68d3ed2002-10-11 08:38:32 +0000551int do_saveenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
552{
553 extern char * env_name_spec;
554
555 printf ("Saving Environment to %s...\n", env_name_spec);
556
557 return (saveenv() ? 1 : 0);
558}
wdenk8bde7f72003-06-27 21:31:46 +0000559
Mike Frysingerba69dc22008-12-30 02:59:25 -0500560U_BOOT_CMD(
561 saveenv, 1, 0, do_saveenv,
562 "saveenv - save environment variables to persistent storage\n",
563 NULL
564);
565
wdenka68d3ed2002-10-11 08:38:32 +0000566#endif
567
568
569/************************************************************************
570 * Match a name / name=value pair
571 *
572 * s1 is either a simple 'name', or a 'name=value' pair.
573 * i2 is the environment index for a 'name2=value2' pair.
574 * If the names match, return the index for the value2, else NULL.
575 */
576
Rafal Jaworowski26a41792008-01-09 18:05:27 +0100577int envmatch (uchar *s1, int i2)
wdenka68d3ed2002-10-11 08:38:32 +0000578{
579
580 while (*s1 == env_get_char(i2++))
581 if (*s1++ == '=')
582 return(i2);
583 if (*s1 == '\0' && env_get_char(i2-1) == '=')
584 return(i2);
585 return(-1);
586}
wdenk8bde7f72003-06-27 21:31:46 +0000587
588
589/**************************************************/
590
wdenk0d498392003-07-01 21:06:45 +0000591U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200592 printenv, CONFIG_SYS_MAXARGS, 1, do_printenv,
wdenk8bde7f72003-06-27 21:31:46 +0000593 "printenv- print environment variables\n",
594 "\n - print values of all environment variables\n"
595 "printenv name ...\n"
596 " - print value of environment variable 'name'\n"
597);
598
wdenk0d498392003-07-01 21:06:45 +0000599U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200600 setenv, CONFIG_SYS_MAXARGS, 0, do_setenv,
wdenk8bde7f72003-06-27 21:31:46 +0000601 "setenv - set environment variables\n",
602 "name value ...\n"
603 " - set environment variable 'name' to 'value ...'\n"
604 "setenv name\n"
605 " - delete environment variable 'name'\n"
606);
607
Jon Loeligerc76fe472007-07-08 18:02:23 -0500608#if defined(CONFIG_CMD_ASKENV)
wdenk8bde7f72003-06-27 21:31:46 +0000609
wdenk0d498392003-07-01 21:06:45 +0000610U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200611 askenv, CONFIG_SYS_MAXARGS, 1, do_askenv,
wdenk8bde7f72003-06-27 21:31:46 +0000612 "askenv - get environment variables from stdin\n",
613 "name [message] [size]\n"
614 " - get environment variable 'name' from stdin (max 'size' chars)\n"
615 "askenv name\n"
616 " - get environment variable 'name' from stdin\n"
617 "askenv name size\n"
618 " - get environment variable 'name' from stdin (max 'size' chars)\n"
619 "askenv name [message] size\n"
620 " - display 'message' string and get environment variable 'name'"
621 "from stdin (max 'size' chars)\n"
622);
Jon Loeliger90253172007-07-10 11:02:44 -0500623#endif
wdenk8bde7f72003-06-27 21:31:46 +0000624
Jon Loeligerc76fe472007-07-08 18:02:23 -0500625#if defined(CONFIG_CMD_RUN)
wdenk8bde7f72003-06-27 21:31:46 +0000626int do_run (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk0d498392003-07-01 21:06:45 +0000627U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200628 run, CONFIG_SYS_MAXARGS, 1, do_run,
wdenk8bde7f72003-06-27 21:31:46 +0000629 "run - run commands in an environment variable\n",
630 "var [...]\n"
631 " - run the commands in the environment variable(s) 'var'\n"
632);
Jon Loeliger90253172007-07-10 11:02:44 -0500633#endif