* MA 02111-1307 USA
*/
+/* #define DEBUG */
+
#include <common.h>
#include <watchdog.h>
#include <command.h>
-#include <cmd_nvedit.h>
-#include <cmd_bootm.h>
#include <malloc.h>
-#if defined(CONFIG_BOOT_RETRY_TIME) && defined(CONFIG_RESET_TO_RETRY)
-#include <cmd_boot.h> /* for do_reset() prototype */
-#endif
#ifdef CFG_HUSH_PARSER
#include <hush.h>
#endif
+#if defined(CONFIG_BOOT_RETRY_TIME) && defined(CONFIG_RESET_TO_RETRY)
+extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /* for do_reset() prototype */
+#endif
+
+extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
+
+
#define MAX_DELAY_STOP_STR 32
static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen);
if (delaykey[i].len > 0 &&
presskey_len >= delaykey[i].len &&
memcmp (presskey + presskey_len - delaykey[i].len,
- delaykey[i].str,
+ delaykey[i].str,
delaykey[i].len) == 0) {
# if DEBUG_BOOTKEYS
printf("got %skey\n",
#endif
#if defined CONFIG_ZERO_BOOTDELAY_CHECK
- /*
- * Check if key already pressed
- * Don't check if bootdelay < 0
- */
+ /*
+ * Check if key already pressed
+ * Don't check if bootdelay < 0
+ */
if (bootdelay >= 0) {
if (tstc()) { /* we got a key press */
(void) getc(); /* consume input */
printf ("\b\b\b 0\n");
return 1; /* don't auto boot */
}
- }
+ }
#endif
while (bootdelay > 0) {
}
#endif /* CONFIG_MODEM_SUPPORT */
+#ifdef CONFIG_VERSION_VARIABLE
+ {
+ extern char version_string[];
+ char *str = getenv("ver");
+
+ if (!str)
+ setenv ("ver", version_string); /* set version variable */
+ }
+#endif /* CONFIG_VERSION_VARIABLE */
+
#ifdef CFG_HUSH_PARSER
u_boot_hush_start ();
#endif
s = getenv ("bootdelay");
bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
-#if 0
- printf ("### main_loop entered:\n\n");
-#endif
+ debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
# ifdef CONFIG_BOOT_RETRY_TIME
- s = getenv ("bootretry");
- if (s != NULL)
- retry_time = (int)simple_strtoul(s, NULL, 10);
- else
- retry_time = CONFIG_BOOT_RETRY_TIME;
- if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
- retry_time = CONFIG_BOOT_RETRY_MIN;
+ init_cmd_timeout ();
# endif /* CONFIG_BOOT_RETRY_TIME */
s = getenv ("bootcmd");
+
+ debug ("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
+
if (bootdelay >= 0 && s && !abortboot (bootdelay)) {
# ifdef CONFIG_AUTOBOOT_KEYED
int prev = disable_ctrlc(1); /* disable Control C checking */
}
# ifdef CONFIG_MENUKEY
- if (menukey == CONFIG_MENUKEY)
- {
+ if (menukey == CONFIG_MENUKEY) {
s = getenv("menucmd");
- if (s)
- {
+ if (s) {
# ifndef CFG_HUSH_PARSER
run_command (s, bd, 0);
# else
#endif /*CFG_HUSH_PARSER*/
}
+#ifdef CONFIG_BOOT_RETRY_TIME
+/***************************************************************************
+ * initialise command line timeout
+ */
+void init_cmd_timeout(void)
+{
+ char *s = getenv ("bootretry");
+
+ if (s != NULL)
+ retry_time = (int)simple_strtoul(s, NULL, 10);
+ else
+ retry_time = CONFIG_BOOT_RETRY_TIME;
+
+ if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
+ retry_time = CONFIG_BOOT_RETRY_MIN;
+}
+
/***************************************************************************
* reset command line timeout to retry_time seconds
*/
-#ifdef CONFIG_BOOT_RETRY_TIME
void reset_cmd_timeout(void)
{
endtime = endtick(retry_time);
int state = 0; /* 0 = waiting for '$' */
/* 1 = waiting for '(' */
/* 2 = waiting for ')' */
-
+ /* 3 = waiting for ''' */
#ifdef DEBUG_PARSER
char *output_start = output;
c = *input++;
inputcnt--;
+ if (state!=3) {
/* remove one level of escape characters */
if ((c == '\\') && (prev != '\\')) {
if (inputcnt-- == 0)
break;
prev = c;
- c = *input++;
+ c = *input++;
+ }
}
switch (state) {
case 0: /* Waiting for (unescaped) $ */
+ if ((c == '\'') && (prev != '\\')) {
+ state = 3;
+ break;
+ }
if ((c == '$') && (prev != '\\')) {
state++;
} else {
state = 0;
}
break;
+ case 3: /* Waiting for ' */
+ if ((c == '\'') && (prev != '\\')) {
+ state = 0;
+ } else {
+ *(output++) = c;
+ outputcnt--;
+ }
+ break;
}
-
prev = c;
}
char finaltoken[CFG_CBSIZE];
char *str = cmdbuf;
char *argv[CFG_MAXARGS + 1]; /* NULL terminated */
- int argc;
+ int argc, inquotes;
int repeatable = 1;
+ int rc = 0;
#ifdef DEBUG_PARSER
printf ("[RUN_COMMAND] cmd[%p]=\"", cmd);
* Find separator, or string end
* Allow simple escape of ';' by writing "\;"
*/
- for (sep = str; *sep; sep++) {
- if ((*sep == ';') && /* separator */
+ for (inquotes = 0, sep = str; *sep; sep++) {
+ if ((*sep=='\'') &&
+ (*(sep-1) != '\\'))
+ inquotes=!inquotes;
+
+ if (!inquotes &&
+ (*sep == ';') && /* separator */
( sep != str) && /* past string start */
(*(sep-1) != '\\')) /* and NOT escaped */
break;
/* Look up command in command table */
if ((cmdtp = find_cmd(argv[0])) == NULL) {
printf ("Unknown command '%s' - try 'help'\n", argv[0]);
- return -1; /* give up after bad command */
+ rc = -1; /* give up after bad command */
+ continue;
}
/* found - check max args */
if (argc > cmdtp->maxargs) {
printf ("Usage:\n%s\n", cmdtp->usage);
- return -1;
+ rc = -1;
+ continue;
}
#if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
#endif
if (flag & CMD_FLAG_BOOTD) {
printf ("'bootd' recursion detected\n");
- return -1;
+ rc = -1;
+ continue;
}
else
flag |= CMD_FLAG_BOOTD;
/* OK - call function to do the command */
if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) {
- return (-1);
+ rc = -1;
}
repeatable &= cmdtp->repeatable;
return 0; /* if stopped then not repeatable */
}
- return repeatable;
+ return rc ? rc : repeatable;
}
/****************************************************************************/
int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
int i;
- int rcode = 1;
if (argc < 2) {
printf ("Usage:\n%s\n", cmdtp->usage);
}
for (i=1; i<argc; ++i) {
+ char *arg;
+
+ if ((arg = getenv (argv[i])) == NULL) {
+ printf ("## Error: \"%s\" not defined\n", argv[i]);
+ return 1;
+ }
#ifndef CFG_HUSH_PARSER
- if (run_command (getenv (argv[i]), flag) != -1) ++rcode;
+ if (run_command (arg, flag) == -1)
+ return 1;
#else
- if (parse_string_outer(getenv (argv[i]),
- FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) == 0) ++rcode;
+ if (parse_string_outer(arg,
+ FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
+ return 1;
#endif
}
- return ((rcode == i) ? 0 : 1);
+ return 0;
}
-#endif
+#endif /* CFG_CMD_RUN */