]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/console.c
board/sbc405/strataflash.c: Fix GCC 4.6 build warning
[karo-tx-uboot.git] / common / console.c
index b09b7d15dbc83ceda10fdf2ce5489591d56094c8..f17875ead007703a76aec99a09c0f3705e759773 100644 (file)
@@ -201,7 +201,7 @@ static inline void console_doenv(int file, struct stdio_dev *dev)
 
 /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
 
-void serial_printf(const char *fmt, ...)
+int serial_printf(const char *fmt, ...)
 {
        va_list args;
        uint i;
@@ -216,6 +216,7 @@ void serial_printf(const char *fmt, ...)
        va_end(args);
 
        serial_puts(printbuffer);
+       return i;
 }
 
 int fgetc(int file)
@@ -269,7 +270,7 @@ void fputs(int file, const char *s)
                console_puts(file, s);
 }
 
-void fprintf(int file, const char *fmt, ...)
+int fprintf(int file, const char *fmt, ...)
 {
        va_list args;
        uint i;
@@ -285,6 +286,7 @@ void fprintf(int file, const char *fmt, ...)
 
        /* Send to desired file */
        fputs(file, printbuffer);
+       return i;
 }
 
 /** U-Boot INITIAL CONSOLE-COMPATIBLE FUNCTION *****************************/
@@ -296,6 +298,9 @@ int getc(void)
                return 0;
 #endif
 
+       if (!gd->have_console)
+               return 0;
+
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Get from the standard input */
                return fgetc(stdin);
@@ -312,6 +317,9 @@ int tstc(void)
                return 0;
 #endif
 
+       if (!gd->have_console)
+               return 0;
+
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Test the standard input */
                return ftstc(stdin);
@@ -321,6 +329,39 @@ int tstc(void)
        return serial_tstc();
 }
 
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+#define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ)
+
+static void pre_console_putc(const char c)
+{
+       char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
+
+       buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
+}
+
+static void pre_console_puts(const char *s)
+{
+       while (*s)
+               pre_console_putc(*s++);
+}
+
+static void print_pre_console_buffer(void)
+{
+       unsigned long i = 0;
+       char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
+
+       if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ)
+               i = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ;
+
+       while (i < gd->precon_buf_idx)
+               putc(buffer[CIRC_BUF_IDX(i++)]);
+}
+#else
+static inline void pre_console_putc(const char c) {}
+static inline void pre_console_puts(const char *s) {}
+static inline void print_pre_console_buffer(void) {}
+#endif
+
 void putc(const char c)
 {
 #ifdef CONFIG_SILENT_CONSOLE
@@ -333,6 +374,9 @@ void putc(const char c)
                return;
 #endif
 
+       if (!gd->have_console)
+               return pre_console_putc(c);
+
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Send to the standard output */
                fputc(stdout, c);
@@ -354,6 +398,9 @@ void puts(const char *s)
                return;
 #endif
 
+       if (!gd->have_console)
+               return pre_console_puts(s);
+
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Send to the standard output */
                fputs(stdout, s);
@@ -363,12 +410,17 @@ void puts(const char *s)
        }
 }
 
-void printf(const char *fmt, ...)
+int printf(const char *fmt, ...)
 {
        va_list args;
        uint i;
        char printbuffer[CONFIG_SYS_PBSIZE];
 
+#ifndef CONFIG_PRE_CONSOLE_BUFFER
+       if (!gd->have_console)
+               return 0;
+#endif
+
        va_start(args, fmt);
 
        /* For this to work, printbuffer must be larger than
@@ -379,13 +431,19 @@ void printf(const char *fmt, ...)
 
        /* Print the string */
        puts(printbuffer);
+       return i;
 }
 
-void vprintf(const char *fmt, va_list args)
+int vprintf(const char *fmt, va_list args)
 {
        uint i;
        char printbuffer[CONFIG_SYS_PBSIZE];
 
+#ifndef CONFIG_PRE_CONSOLE_BUFFER
+       if (!gd->have_console)
+               return 0;
+#endif
+
        /* For this to work, printbuffer must be larger than
         * anything we ever want to print.
         */
@@ -393,6 +451,7 @@ void vprintf(const char *fmt, va_list args)
 
        /* Print the string */
        puts(printbuffer);
+       return i;
 }
 
 /* test if ctrl-c was pressed */
@@ -475,7 +534,7 @@ inline void dbg(const char *fmt, ...)
 
 /** U-Boot INIT FUNCTIONS *************************************************/
 
-struct stdio_dev *search_device(int flags, char *name)
+struct stdio_dev *search_device(int flags, const char *name)
 {
        struct stdio_dev *dev;
 
@@ -487,7 +546,7 @@ struct stdio_dev *search_device(int flags, char *name)
        return NULL;
 }
 
-int console_assign(int file, char *devname)
+int console_assign(int file, const char *devname)
 {
        int flag;
        struct stdio_dev *dev;
@@ -525,6 +584,8 @@ int console_init_f(void)
                gd->flags |= GD_FLG_SILENT;
 #endif
 
+       print_pre_console_buffer();
+
        return 0;
 }