X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fconsole.c;h=f17875ead007703a76aec99a09c0f3705e759773;hb=b609009801b8a00644926f49b7d0d0cc0d3d8797;hp=8c650e05e1c352ff5406b576387cb25dd2f5dd35;hpb=32ff4b7fe410bdea29ca38ab15f57e731fc920d1;p=u-boot diff --git a/common/console.c b/common/console.c index 8c650e05e1..f17875ead0 100644 --- a/common/console.c +++ b/common/console.c @@ -298,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); @@ -314,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); @@ -323,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 @@ -335,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); @@ -356,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); @@ -371,6 +416,11 @@ int printf(const char *fmt, ...) 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 @@ -389,6 +439,11 @@ 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. */ @@ -529,6 +584,8 @@ int console_init_f(void) gd->flags |= GD_FLG_SILENT; #endif + print_pre_console_buffer(); + return 0; }