X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fconsole.c;h=ace206ca4ff5dd87651c32da857fae762916f41c;hb=7b95252d82267143e647d5fee96c7d9d5bf74560;hp=3f25e76fe79ea3c94a85d0306d668233320e2d47;hpb=358b8bc204f365be28fed94f23e53e04183a8c7f;p=u-boot diff --git a/common/console.c b/common/console.c index 3f25e76fe7..ace206ca4f 100644 --- a/common/console.c +++ b/common/console.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -200,15 +201,15 @@ static void console_putc(int file, const char c) } #ifdef CONFIG_PRE_CONSOLE_BUFFER -static void console_putc_noserial(int file, const char c) +static void console_puts_noserial(int file, const char *s) { int i; struct stdio_dev *dev; for (i = 0; i < cd_count[file]; i++) { dev = console_devices[file][i]; - if (dev->putc != NULL && strcmp(dev->name, "serial") != 0) - dev->putc(dev, c); + if (dev->puts != NULL && strcmp(dev->name, "serial") != 0) + dev->puts(dev, s); } } #endif @@ -251,10 +252,10 @@ static inline void console_putc(int file, const char c) } #ifdef CONFIG_PRE_CONSOLE_BUFFER -static inline void console_putc_noserial(int file, const char c) +static inline void console_puts_noserial(int file, const char *s) { if (strcmp(stdio_devices[file]->name, "serial") != 0) - stdio_devices[file]->putc(stdio_devices[file], c); + stdio_devices[file]->puts(stdio_devices[file], s); } #endif @@ -425,22 +426,26 @@ static void pre_console_puts(const char *s) static void print_pre_console_buffer(int flushpoint) { - unsigned long i = 0; - char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR; + unsigned long in = 0, out = 0; + char *buf_in = (char *)CONFIG_PRE_CON_BUF_ADDR; + char buf_out[CONFIG_PRE_CON_BUF_SZ + 1]; if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ) - i = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ; + in = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ; - while (i < gd->precon_buf_idx) - switch (flushpoint) { - case PRE_CONSOLE_FLUSHPOINT1_SERIAL: - putc(buffer[CIRC_BUF_IDX(i++)]); - break; - case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL: - console_putc_noserial(stdout, - buffer[CIRC_BUF_IDX(i++)]); - break; - } + while (in < gd->precon_buf_idx) + buf_out[out++] = buf_in[CIRC_BUF_IDX(in++)]; + + buf_out[out] = 0; + + switch (flushpoint) { + case PRE_CONSOLE_FLUSHPOINT1_SERIAL: + puts(buf_out); + break; + case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL: + console_puts_noserial(stdout, buf_out); + break; + } } #else static inline void pre_console_putc(const char c) {} @@ -451,11 +456,19 @@ static inline void print_pre_console_buffer(int flushpoint) {} void putc(const char c) { #ifdef CONFIG_SANDBOX + /* sandbox can send characters to stdout before it has a console */ if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { os_putc(c); return; } #endif +#ifdef CONFIG_DEBUG_UART + /* if we don't have a console yet, use the debug UART */ + if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { + printch(c); + return; + } +#endif #ifdef CONFIG_SILENT_CONSOLE if (gd->flags & GD_FLG_SILENT) return; @@ -487,7 +500,18 @@ void puts(const char *s) return; } #endif +#ifdef CONFIG_DEBUG_UART + if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { + while (*s) { + int ch = *s++; + printch(ch); + if (ch == '\n') + printch('\r'); + } + return; + } +#endif #ifdef CONFIG_SILENT_CONSOLE if (gd->flags & GD_FLG_SILENT) return; @@ -517,11 +541,6 @@ int printf(const char *fmt, ...) uint i; char printbuffer[CONFIG_SYS_PBSIZE]; -#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_PRE_CONSOLE_BUFFER) - if (!gd->have_console) - return 0; -#endif - va_start(args, fmt); /* For this to work, printbuffer must be larger than