Merge branch 'master' of rsync://rsync.denx.de/git/u-boot
[platform/kernel/u-boot.git] / common / main.c
index 7ce9b75..758ef8d 100644 (file)
@@ -26,7 +26,9 @@
 #include <common.h>
 #include <watchdog.h>
 #include <command.h>
-#include <malloc.h>
+#ifdef CONFIG_MODEM_SUPPORT
+#include <malloc.h>            /* for free() prototype */
+#endif
 
 #ifdef CFG_HUSH_PARSER
 #include <hush.h>
 
 #include <post.h>
 
+#ifdef CONFIG_SILENT_CONSOLE
+DECLARE_GLOBAL_DATA_PTR;
+#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
@@ -103,14 +109,10 @@ static __inline__ int abortboot(int bootdelay)
        u_int i;
 
 #ifdef CONFIG_SILENT_CONSOLE
-       {
-               DECLARE_GLOBAL_DATA_PTR;
-
-               if (gd->flags & GD_FLG_SILENT) {
-                       /* Restore serial console */
-                       console_assign (stdout, "serial");
-                       console_assign (stderr, "serial");
-               }
+       if (gd->flags & GD_FLG_SILENT) {
+               /* Restore serial console */
+               console_assign (stdout, "serial");
+               console_assign (stderr, "serial");
        }
 #endif
 
@@ -193,17 +195,13 @@ static __inline__ int abortboot(int bootdelay)
 #  endif
 
 #ifdef CONFIG_SILENT_CONSOLE
-       {
-               DECLARE_GLOBAL_DATA_PTR;
-
-               if (abort) {
-                       /* permanently enable normal console output */
-                       gd->flags &= ~(GD_FLG_SILENT);
-               } else if (gd->flags & GD_FLG_SILENT) {
-                       /* Restore silent console */
-                       console_assign (stdout, "nulldev");
-                       console_assign (stderr, "nulldev");
-               }
+       if (abort) {
+               /* permanently enable normal console output */
+               gd->flags &= ~(GD_FLG_SILENT);
+       } else if (gd->flags & GD_FLG_SILENT) {
+               /* Restore silent console */
+               console_assign (stdout, "nulldev");
+               console_assign (stderr, "nulldev");
        }
 #endif
 
@@ -221,14 +219,10 @@ static __inline__ int abortboot(int bootdelay)
        int abort = 0;
 
 #ifdef CONFIG_SILENT_CONSOLE
-       {
-               DECLARE_GLOBAL_DATA_PTR;
-
-               if (gd->flags & GD_FLG_SILENT) {
-                       /* Restore serial console */
-                       console_assign (stdout, "serial");
-                       console_assign (stderr, "serial");
-               }
+       if (gd->flags & GD_FLG_SILENT) {
+               /* Restore serial console */
+               console_assign (stdout, "serial");
+               console_assign (stderr, "serial");
        }
 #endif
 
@@ -277,17 +271,13 @@ static __inline__ int abortboot(int bootdelay)
        putc ('\n');
 
 #ifdef CONFIG_SILENT_CONSOLE
-       {
-               DECLARE_GLOBAL_DATA_PTR;
-
-               if (abort) {
-                       /* permanently enable normal console output */
-                       gd->flags &= ~(GD_FLG_SILENT);
-               } else if (gd->flags & GD_FLG_SILENT) {
-                       /* Restore silent console */
-                       console_assign (stdout, "nulldev");
-                       console_assign (stderr, "nulldev");
-               }
+       if (abort) {
+               /* permanently enable normal console output */
+               gd->flags &= ~(GD_FLG_SILENT);
+       } else if (gd->flags & GD_FLG_SILENT) {
+               /* Restore silent console */
+               console_assign (stdout, "nulldev");
+               console_assign (stderr, "nulldev");
        }
 #endif
 
@@ -345,7 +335,7 @@ void main_loop (void)
 #ifdef CONFIG_MODEM_SUPPORT
        debug ("DEBUG: main_loop:   do_mdm_init=%d\n", do_mdm_init);
        if (do_mdm_init) {
-               uchar *str = strdup(getenv("mdm_cmd"));
+               char *str = strdup(getenv("mdm_cmd"));
                setenv ("preboot", str);  /* set or delete definition */
                if (str != NULL)
                        free (str);
@@ -432,7 +422,7 @@ void main_loop (void)
            s = getenv("menucmd");
            if (s) {
 # ifndef CFG_HUSH_PARSER
-               run_command (s, bd, 0);
+               run_command (s, 0);
 # else
                parse_string_outer(s, FLAG_PARSE_SEMICOLON |
                                    FLAG_EXIT_FROM_LOOP);
@@ -726,8 +716,8 @@ static void process_macros (const char *input, char *output)
        int inputcnt  = strlen (input);
        int outputcnt = CFG_CBSIZE;
        int state = 0;  /* 0 = waiting for '$'  */
-                       /* 1 = waiting for '('  */
-                       /* 2 = waiting for ')'  */
+                       /* 1 = waiting for '(' or '{' */
+                       /* 2 = waiting for ')' or '}' */
                        /* 3 = waiting for '''  */
 #ifdef DEBUG_PARSER
        char *output_start = output;
@@ -765,7 +755,7 @@ static void process_macros (const char *input, char *output)
                }
                break;
            case 1:                     /* Waiting for (        */
-               if (c == '(') {
+               if (c == '(' || c == '{') {
                        state++;
                        varname_start = input;
                } else {
@@ -780,7 +770,7 @@ static void process_macros (const char *input, char *output)
                }
                break;
            case 2:                     /* Waiting for )        */
-               if (c == ')') {
+               if (c == ')' || c == '}') {
                        int i;
                        char envname[CFG_CBSIZE], *envval;
                        int envcnt = input-varname_start-1; /* Varname # of chars */
@@ -917,7 +907,10 @@ int run_command (const char *cmd, int flag)
                process_macros (token, finaltoken);
 
                /* Extract arguments */
-               argc = parse_line (finaltoken, argv);
+               if ((argc = parse_line (finaltoken, argv)) == 0) {
+                       rc = -1;        /* no command at all */
+                       continue;
+               }
 
                /* Look up command in command table */
                if ((cmdtp = find_cmd(argv[0])) == NULL) {
@@ -943,9 +936,9 @@ int run_command (const char *cmd, int flag)
                                puts ("'bootd' recursion detected\n");
                                rc = -1;
                                continue;
-                       }
-                       else
+                       } else {
                                flag |= CMD_FLAG_BOOTD;
+                       }
                }
 #endif /* CFG_CMD_BOOTD */