Fix printf() format problems with configurable prompts
[platform/kernel/u-boot.git] / common / main.c
index 1c7d73e..187ef8a 100644 (file)
@@ -40,7 +40,7 @@
 
 #include <post.h>
 
-#ifdef CONFIG_SILENT_CONSOLE
+#if defined(CONFIG_SILENT_CONSOLE) || defined(CONFIG_POST) || defined(CONFIG_CMDLINE_EDITING)
 DECLARE_GLOBAL_DATA_PTR;
 #endif
 
@@ -67,11 +67,9 @@ static int abortboot(int);
 
 char        console_buffer[CFG_CBSIZE];                /* console I/O buffer   */
 
-#ifndef CONFIG_CMDLINE_EDITING
 static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen);
 static char erase_seq[] = "\b \b";             /* erase sequence       */
 static char   tab_seq[] = "        ";          /* used to expand TABs  */
-#endif /* CONFIG_CMDLINE_EDITING */
 
 #ifdef CONFIG_BOOT_RETRY_TIME
 static uint64_t endtime = 0;  /* must be set, default is instant timeout */
@@ -118,7 +116,7 @@ static __inline__ int abortboot(int bootdelay)
        u_int i;
 
 #  ifdef CONFIG_AUTOBOOT_PROMPT
-       printf(CONFIG_AUTOBOOT_PROMPT, bootdelay);
+       printf(CONFIG_AUTOBOOT_PROMPT);
 #  endif
 
 #  ifdef CONFIG_AUTOBOOT_DELAY_STR
@@ -214,7 +212,7 @@ static __inline__ int abortboot(int bootdelay)
        int abort = 0;
 
 #ifdef CONFIG_MENUPROMPT
-       printf(CONFIG_MENUPROMPT, bootdelay);
+       printf(CONFIG_MENUPROMPT);
 #else
        printf("Hit any key to stop autoboot: %2d ", bootdelay);
 #endif
@@ -369,6 +367,12 @@ void main_loop (void)
        init_cmd_timeout ();
 # endif        /* CONFIG_BOOT_RETRY_TIME */
 
+#ifdef CONFIG_POST
+       if (gd->flags & GD_FLG_POSTFAIL) {
+               s = getenv("failbootcmd");
+       }
+       else
+#endif /* CONFIG_POST */
 #ifdef CONFIG_BOOTCOUNT_LIMIT
        if (bootlimit && (bootcount > bootlimit)) {
                printf ("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n",
@@ -505,7 +509,7 @@ void reset_cmd_timeout(void)
  */
 
 #define putnstr(str,n) do {                    \
-               printf ("%.*s", n, str);        \
+               printf ("%.*s", (int)n, str);   \
        } while (0)
 
 #define CTL_CH(c)              ((c) - 'a' + 1)
@@ -709,6 +713,13 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
 
        while (1) {
                rlen = 1;
+#ifdef CONFIG_BOOT_RETRY_TIME
+               while (!tstc()) {       /* while no incoming data */
+                       if (retry_time >= 0 && get_ticks() > endtime)
+                               return (-2);    /* timed out */
+               }
+#endif
+
                ichar = getcmd_getch();
 
                if ((ichar == '\n') || (ichar == '\r')) {
@@ -929,16 +940,25 @@ int readline_into_buffer (const char *const prompt, char * buffer)
        int rc;
        static int initted = 0;
 
-       if (!initted) {
-               hist_init();
-               initted = 1;
-       }
+       /*
+        * History uses a global array which is not
+        * writable until after relocation to RAM.
+        * Revert to non-history version if still
+        * running from flash.
+        */
+       if (gd->flags & GD_FLG_RELOC) {
+               if (!initted) {
+                       hist_init();
+                       initted = 1;
+               }
 
-       puts (prompt);
+               puts (prompt);
 
-       rc = cread_line(prompt, p, &len);
-       return rc < 0 ? rc : len;
-#else
+               rc = cread_line(prompt, p, &len);
+               return rc < 0 ? rc : len;
+
+       } else {
+#endif /* CONFIG_CMDLINE_EDITING */
        char * p_buf = p;
        int     n = 0;                          /* buffer index         */
        int     plen = 0;                       /* prompt length        */
@@ -1034,12 +1054,13 @@ int readline_into_buffer (const char *const prompt, char * buffer)
                        }
                }
        }
-#endif /* CONFIG_CMDLINE_EDITING */
+#ifdef CONFIG_CMDLINE_EDITING
+       }
+#endif
 }
 
 /****************************************************************************/
 
-#ifndef CONFIG_CMDLINE_EDITING
 static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen)
 {
        char *s;
@@ -1069,7 +1090,6 @@ static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen)
        (*np)--;
        return (p);
 }
-#endif /* CONFIG_CMDLINE_EDITING */
 
 /****************************************************************************/