]> git.sur5r.net Git - u-boot/blobdiff - common/console.c
sandbox: config: enable fdt and snprintf() options
[u-boot] / common / console.c
index f17875ead007703a76aec99a09c0f3705e759773..1d9fd7ff42bd7ac200bf3b89cbce7afe35ea7b1a 100644 (file)
@@ -212,7 +212,7 @@ int serial_printf(const char *fmt, ...)
        /* For this to work, printbuffer must be larger than
         * anything we ever want to print.
         */
-       i = vsprintf(printbuffer, fmt, args);
+       i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
        va_end(args);
 
        serial_puts(printbuffer);
@@ -281,7 +281,7 @@ int fprintf(int file, const char *fmt, ...)
        /* For this to work, printbuffer must be larger than
         * anything we ever want to print.
         */
-       i = vsprintf(printbuffer, fmt, args);
+       i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
        va_end(args);
 
        /* Send to desired file */
@@ -329,14 +329,19 @@ int tstc(void)
        return serial_tstc();
 }
 
-#ifdef CONFIG_PRE_CONSOLE_BUFFER
+#if defined(CONFIG_PRE_CONSOLE_BUFFER) || defined(CONFIG_PRE_CONSOLE_PUTC)
 #define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ)
 
 static void pre_console_putc(const char c)
 {
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
        char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
 
        buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
+#endif
+#ifdef CONFIG_PRE_CONSOLE_PUTC
+       board_pre_console_putc(c);
+#endif
 }
 
 static void pre_console_puts(const char *s)
@@ -347,6 +352,7 @@ static void pre_console_puts(const char *s)
 
 static void print_pre_console_buffer(void)
 {
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
        unsigned long i = 0;
        char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
 
@@ -355,7 +361,9 @@ static void print_pre_console_buffer(void)
 
        while (i < gd->precon_buf_idx)
                putc(buffer[CIRC_BUF_IDX(i++)]);
+#endif
 }
+
 #else
 static inline void pre_console_putc(const char c) {}
 static inline void pre_console_puts(const char *s) {}
@@ -426,7 +434,7 @@ int printf(const char *fmt, ...)
        /* For this to work, printbuffer must be larger than
         * anything we ever want to print.
         */
-       i = vsprintf(printbuffer, fmt, args);
+       i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
        va_end(args);
 
        /* Print the string */
@@ -447,7 +455,7 @@ int vprintf(const char *fmt, va_list args)
        /* For this to work, printbuffer must be larger than
         * anything we ever want to print.
         */
-       i = vsprintf(printbuffer, fmt, args);
+       i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
 
        /* Print the string */
        puts(printbuffer);
@@ -514,7 +522,7 @@ inline void dbg(const char *fmt, ...)
        /* For this to work, printbuffer must be larger than
         * anything we ever want to print.
         */
-       i = vsprintf(printbuffer, fmt, args);
+       i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args);
        va_end(args);
 
        if ((screen + sizeof(screen) - 1 - cursor)