]> git.sur5r.net Git - u-boot/blobdiff - common/main.c
* Update for AT91RM9200DK and CMC_PU2 boards:
[u-boot] / common / main.c
index d08bc47d73604ee5bc053e6f5fd0aae9d4ee122c..0869426f17dd1830f6a4e8514e7179f37ddc40c4 100644 (file)
@@ -102,6 +102,18 @@ static __inline__ int abortboot(int bootdelay)
        u_int presskey_max = 0;
        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");
+               }
+       }
+#endif
+
 #  ifdef CONFIG_AUTOBOOT_PROMPT
        printf (CONFIG_AUTOBOOT_PROMPT, bootdelay);
 #  endif
@@ -177,9 +189,24 @@ static __inline__ int abortboot(int bootdelay)
        }
 #  if DEBUG_BOOTKEYS
        if (!abort)
-               printf("key timeout\n");
+               puts ("key timeout\n");
 #  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");
+               }
+       }
+#endif
+
        return abort;
 }
 
@@ -193,6 +220,18 @@ 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");
+               }
+       }
+#endif
+
 #ifdef CONFIG_MENUPROMPT
        printf(CONFIG_MENUPROMPT, bootdelay);
 #else
@@ -207,13 +246,13 @@ static __inline__ int abortboot(int bootdelay)
        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      */
+                       puts ("\b\b\b 0");
+                       abort = 1;      /* don't auto boot      */
                }
        }
 #endif
 
-       while (bootdelay > 0) {
+       while ((bootdelay > 0) && (!abort)) {
                int i;
 
                --bootdelay;
@@ -237,6 +276,21 @@ 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");
+               }
+       }
+#endif
+
        return abort;
 }
 # endif        /* CONFIG_AUTOBOOT_KEYED */
@@ -311,6 +365,10 @@ void main_loop (void)
        u_boot_hush_start ();
 #endif
 
+#ifdef CONFIG_AUTO_COMPLETE
+       install_auto_complete();
+#endif
+
 #ifdef CONFIG_PREBOOT
        if ((p = getenv ("preboot")) != NULL) {
 # ifdef CONFIG_AUTOBOOT_KEYED
@@ -419,7 +477,7 @@ void main_loop (void)
                else if (len == -2) {
                        /* -2 means timed out, retry autoboot
                         */
-                       printf("\nTimed out waiting for command\n");
+                       puts ("\nTimed out waiting for command\n");
 # ifdef CONFIG_RESET_TO_RETRY
                        /* Reinit board to run initialization code again */
                        do_reset (NULL, 0, 0, NULL);
@@ -430,7 +488,7 @@ void main_loop (void)
 #endif
 
                if (len == -1)
-                       printf ("<INTERRUPT>\n");
+                       puts ("<INTERRUPT>\n");
                else
                        rc = run_command (lastcommand, flag);
 
@@ -451,7 +509,7 @@ void init_cmd_timeout(void)
        char *s = getenv ("bootretry");
 
        if (s != NULL)
-               retry_time = (int)simple_strtoul(s, NULL, 10);
+               retry_time = (int)simple_strtol(s, NULL, 10);
        else
                retry_time =  CONFIG_BOOT_RETRY_TIME;
 
@@ -520,6 +578,9 @@ int readline (const char *const prompt)
                        puts ("\r\n");
                        return (p - console_buffer);
 
+               case '\0':                              /* nul                  */
+                       continue;
+
                case 0x03:                              /* ^C - break           */
                        console_buffer[0] = '\0';       /* discard input */
                        return (-1);
@@ -551,6 +612,14 @@ int readline (const char *const prompt)
                         */
                        if (n < CFG_CBSIZE-2) {
                                if (c == '\t') {        /* expand TABs          */
+#ifdef CONFIG_AUTO_COMPLETE
+                                       /* if auto completion triggered just continue */
+                                       *p = '\0';
+                                       if (cmd_auto_complete(prompt, console_buffer, &n, &col)) {
+                                               p = console_buffer + n; /* reset */
+                                               continue;
+                                       }
+#endif
                                        puts (tab_seq+(col&07));
                                        col += 8 - (col&07);
                                } else {
@@ -657,8 +726,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;
@@ -696,7 +765,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 {
@@ -711,7 +780,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 */
@@ -871,7 +940,7 @@ int run_command (const char *cmd, int flag)
                        printf ("[%s]\n", finaltoken);
 #endif
                        if (flag & CMD_FLAG_BOOTD) {
-                               printf ("'bootd' recursion detected\n");
+                               puts ("'bootd' recursion detected\n");
                                rc = -1;
                                continue;
                        }