blob: 85025daec7a37f5ab8b8feb59d603dfbca08636b [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>
wdenk7ac16102004-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 Loeligerd76b5c12007-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 Denk6405a152006-03-31 18:32:53 +020053DECLARE_GLOBAL_DATA_PTR;
54
Jean-Christophe PLAGNIOL-VILLARDfdb79c32008-09-10 22:47:59 +020055#if !defined(CONFIG_ENV_IS_IN_NVRAM) && \
Jean-Christophe PLAGNIOL-VILLARDe46af642008-09-05 09:19:30 +020056 !defined(CONFIG_ENV_IS_IN_EEPROM) && \
Jean-Christophe PLAGNIOL-VILLARD53db4cd2008-09-10 22:48:04 +020057 !defined(CONFIG_ENV_IS_IN_FLASH) && \
Jean-Christophe PLAGNIOL-VILLARD2b14d2b2008-09-10 22:47:58 +020058 !defined(CONFIG_ENV_IS_IN_DATAFLASH) && \
Jean-Christophe PLAGNIOL-VILLARDdda84dd2008-09-10 22:47:58 +020059 !defined(CONFIG_ENV_IS_IN_NAND) && \
Jean-Christophe PLAGNIOL-VILLARD75989162008-09-10 22:47:59 +020060 !defined(CONFIG_ENV_IS_IN_ONENAND) && \
Jean-Christophe PLAGNIOL-VILLARD4539b1c2008-09-10 22:48:00 +020061 !defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \
Jean-Christophe PLAGNIOL-VILLARD68a87562008-09-10 22:48:00 +020062 !defined(CONFIG_ENV_IS_NOWHERE)
Jean-Christophe PLAGNIOL-VILLARDf80353b2008-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-VILLARD03836942008-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 Denkfe036dd2008-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 Denk7fb52662005-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 Denk7fb52662005-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 Denkbc50f8c2006-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 Denk7fb52662005-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 /*
stroesef8105cf2003-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. Falco2a1d4e42008-06-12 13:24:42 -0400184 if (
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200185#ifdef CONFIG_HAS_UID
186 /* Allow serial# forced overwrite with 0xdeaf4add flag */
Steven A. Falco2a1d4e42008-06-12 13:24:42 -0400187 ((strcmp (name, "serial#") == 0) && (flag != 0xdeaf4add)) ||
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200188#else
Steven A. Falco2a1d4e42008-06-12 13:24:42 -0400189 (strcmp (name, "serial#") == 0) ||
Sergey Kubushyne8f39122007-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 Denk7fb52662005-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 Jennejohnc6dc7552008-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;
wdenk7ac16102004-08-01 22:48:16 +0000224
225#ifdef CONFIG_SERIAL_MULTI
226 if (serial_assign (argv[2]) < 0)
227 return 1;
228#endif
Gary Jennejohnc6dc7552008-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 Sieka23d43282006-12-20 00:29:43 +0100251#if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2)
wdenke7f34c62003-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 Loeligerd76b5c12007-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 Loeligerd704d912007-07-10 11:02:44 -0500375#endif
wdenk452cfd62002-11-19 11:04:11 +0000376
stroesef8105cf2003-04-04 15:44:49 +0000377#ifdef CONFIG_AMIGAONEG3SE
wdenk452cfd62002-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. Falco1ce6f992008-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 Mann62b896f2007-04-23 14:00:11 +0200394 if (varvalue == NULL)
Steven A. Falco1ce6f992008-06-12 13:22:12 -0400395 return _do_setenv (0, 2, argv);
Jeffrey Mann62b896f2007-04-23 14:00:11 +0200396 else
Steven A. Falco1ce6f992008-06-12 13:22:12 -0400397 return _do_setenv (0, 3, argv);
wdenka68d3ed2002-10-11 08:38:32 +0000398}
399
Sergey Kubushyne8f39122007-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) {
411 printf ("Usage:\n%s\n", cmdtp->usage);
412 return 1;
413 }
414
415 return _do_setenv (flag, argc, argv);
416}
417
418/************************************************************************
419 * Prompt for environment variable
420 */
421
Jon Loeligerd76b5c12007-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-VILLARD03836942008-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) {
437 printf ("Usage:\n%s\n", cmdtp->usage);
438 return 1;
439 }
440 /* Check the syntax */
441 switch (argc) {
442 case 1:
443 printf ("Usage:\n%s\n", cmdtp->usage);
444 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-VILLARD03836942008-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 Loeligerd704d912007-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 Denk7fb52662005-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-VILLARD7e1cda62008-09-10 22:48:06 +0200512 if (nxt >= CONFIG_ENV_SIZE) {
wdenka68d3ed2002-10-11 08:38:32 +0000513 return (NULL);
514 }
515 }
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200516 if ((val=envmatch((uchar *)name, i)) < 0)
wdenka68d3ed2002-10-11 08:38:32 +0000517 continue;
Wolfgang Denk7fb52662005-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 Denk7fb52662005-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-VILLARD7e1cda62008-09-10 22:48:06 +0200532 if (nxt >= CONFIG_ENV_SIZE) {
wdenka68d3ed2002-10-11 08:38:32 +0000533 return (-1);
534 }
535 }
Wolfgang Denk7fb52662005-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
Jean-Christophe PLAGNIOL-VILLARDfdb79c32008-09-10 22:47:59 +0200549#if ((defined(CONFIG_ENV_IS_IN_NVRAM) || defined(CONFIG_ENV_IS_IN_EEPROM) \
Jon Loeliger3de8b242007-06-11 19:01:54 -0500550 || (defined(CONFIG_CMD_ENV) && defined(CONFIG_CMD_FLASH)) \
Kyungmin Parkaf3d11c2007-09-10 17:15:14 +0900551 || (defined(CONFIG_CMD_ENV) && defined(CONFIG_CMD_NAND)) \
Jean-Christophe PLAGNIOL-VILLARD43ad6232008-02-23 12:15:56 +0100552 || (defined(CONFIG_CMD_ENV) && defined(CONFIG_CMD_ONENAND))) \
Jean-Christophe PLAGNIOL-VILLARD68a87562008-09-10 22:48:00 +0200553 && !defined(CONFIG_ENV_IS_NOWHERE))
wdenka68d3ed2002-10-11 08:38:32 +0000554int do_saveenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
555{
556 extern char * env_name_spec;
557
558 printf ("Saving Environment to %s...\n", env_name_spec);
559
560 return (saveenv() ? 1 : 0);
561}
wdenk57b2d802003-06-27 21:31:46 +0000562
wdenka68d3ed2002-10-11 08:38:32 +0000563#endif
564
565
566/************************************************************************
567 * Match a name / name=value pair
568 *
569 * s1 is either a simple 'name', or a 'name=value' pair.
570 * i2 is the environment index for a 'name2=value2' pair.
571 * If the names match, return the index for the value2, else NULL.
572 */
573
Rafal Jaworowski75b54422008-01-09 18:05:27 +0100574int envmatch (uchar *s1, int i2)
wdenka68d3ed2002-10-11 08:38:32 +0000575{
576
577 while (*s1 == env_get_char(i2++))
578 if (*s1++ == '=')
579 return(i2);
580 if (*s1 == '\0' && env_get_char(i2-1) == '=')
581 return(i2);
582 return(-1);
583}
wdenk57b2d802003-06-27 21:31:46 +0000584
585
586/**************************************************/
587
wdenkf287a242003-07-01 21:06:45 +0000588U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200589 printenv, CONFIG_SYS_MAXARGS, 1, do_printenv,
wdenk57b2d802003-06-27 21:31:46 +0000590 "printenv- print environment variables\n",
591 "\n - print values of all environment variables\n"
592 "printenv name ...\n"
593 " - print value of environment variable 'name'\n"
594);
595
wdenkf287a242003-07-01 21:06:45 +0000596U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200597 setenv, CONFIG_SYS_MAXARGS, 0, do_setenv,
wdenk57b2d802003-06-27 21:31:46 +0000598 "setenv - set environment variables\n",
599 "name value ...\n"
600 " - set environment variable 'name' to 'value ...'\n"
601 "setenv name\n"
602 " - delete environment variable 'name'\n"
603);
604
Jean-Christophe PLAGNIOL-VILLARDfdb79c32008-09-10 22:47:59 +0200605#if ((defined(CONFIG_ENV_IS_IN_NVRAM) || defined(CONFIG_ENV_IS_IN_EEPROM) \
Jon Loeliger3de8b242007-06-11 19:01:54 -0500606 || (defined(CONFIG_CMD_ENV) && defined(CONFIG_CMD_FLASH)) \
Kyungmin Parkaf3d11c2007-09-10 17:15:14 +0900607 || (defined(CONFIG_CMD_ENV) && defined(CONFIG_CMD_NAND)) \
Jean-Christophe PLAGNIOL-VILLARD43ad6232008-02-23 12:15:56 +0100608 || (defined(CONFIG_CMD_ENV) && defined(CONFIG_CMD_ONENAND))) \
Jean-Christophe PLAGNIOL-VILLARD68a87562008-09-10 22:48:00 +0200609 && !defined(CONFIG_ENV_IS_NOWHERE))
wdenkf287a242003-07-01 21:06:45 +0000610U_BOOT_CMD(
611 saveenv, 1, 0, do_saveenv,
wdenk57b2d802003-06-27 21:31:46 +0000612 "saveenv - save environment variables to persistent storage\n",
613 NULL
614);
615
Jon Loeligerd704d912007-07-10 11:02:44 -0500616#endif
wdenk57b2d802003-06-27 21:31:46 +0000617
Jon Loeligerd76b5c12007-07-08 18:02:23 -0500618#if defined(CONFIG_CMD_ASKENV)
wdenk57b2d802003-06-27 21:31:46 +0000619
wdenkf287a242003-07-01 21:06:45 +0000620U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200621 askenv, CONFIG_SYS_MAXARGS, 1, do_askenv,
wdenk57b2d802003-06-27 21:31:46 +0000622 "askenv - get environment variables from stdin\n",
623 "name [message] [size]\n"
624 " - get environment variable 'name' from stdin (max 'size' chars)\n"
625 "askenv name\n"
626 " - get environment variable 'name' from stdin\n"
627 "askenv name size\n"
628 " - get environment variable 'name' from stdin (max 'size' chars)\n"
629 "askenv name [message] size\n"
630 " - display 'message' string and get environment variable 'name'"
631 "from stdin (max 'size' chars)\n"
632);
Jon Loeligerd704d912007-07-10 11:02:44 -0500633#endif
wdenk57b2d802003-06-27 21:31:46 +0000634
Jon Loeligerd76b5c12007-07-08 18:02:23 -0500635#if defined(CONFIG_CMD_RUN)
wdenk57b2d802003-06-27 21:31:46 +0000636int do_run (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenkf287a242003-07-01 21:06:45 +0000637U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200638 run, CONFIG_SYS_MAXARGS, 1, do_run,
wdenk57b2d802003-06-27 21:31:46 +0000639 "run - run commands in an environment variable\n",
640 "var [...]\n"
641 " - run the commands in the environment variable(s) 'var'\n"
642);
Jon Loeligerd704d912007-07-10 11:02:44 -0500643#endif