X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=common%2Fconsole.c;h=10ab361d006928016ed12b309f6284c9462a9319;hb=d1f4b090dd17ee11373859f2c91af94bf254af7a;hp=2bccc8ab1032f66b45a2d5f28b95331431ed2ca1;hpb=5fec3c853d5e6b998db66f586871839c408195a3;p=platform%2Fkernel%2Fu-boot.git diff --git a/common/console.c b/common/console.c index 2bccc8a..10ab361 100644 --- a/common/console.c +++ b/common/console.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -198,6 +199,7 @@ static int console_setfile(int file, struct stdio_dev * dev) case stdout: gd->jt->putc = putc; gd->jt->puts = puts; + STDIO_DEV_ASSIGN_FLUSH(gd->jt, flush); gd->jt->printf = printf; break; } @@ -213,7 +215,7 @@ static int console_setfile(int file, struct stdio_dev * dev) * console_dev_is_serial() - Check if a stdio device is a serial device * * @sdev: Device to check - * @return true if this device is in the serial uclass (or for pre-driver-model, + * Return: true if this device is in the serial uclass (or for pre-driver-model, * whether it is called "serial". */ static bool console_dev_is_serial(struct stdio_dev *sdev) @@ -363,6 +365,19 @@ static void console_puts(int file, const char *s) } } +#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT +static void console_flush(int file) +{ + int i; + struct stdio_dev *dev; + + for_each_console_dev(i, file, dev) { + if (dev->flush != NULL) + dev->flush(dev); + } +} +#endif + #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) static inline void console_doenv(int file, struct stdio_dev *dev) { @@ -412,6 +427,14 @@ static inline void console_puts(int file, const char *s) stdio_devices[file]->puts(stdio_devices[file], s); } +#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT +static inline void console_flush(int file) +{ + if (stdio_devices[file]->flush) + stdio_devices[file]->flush(stdio_devices[file]); +} +#endif + #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) static inline void console_doenv(int file, struct stdio_dev *dev) { @@ -474,12 +497,12 @@ int serial_printf(const char *fmt, ...) int fgetc(int file) { - if (file < MAX_FILES) { + if ((unsigned int)file < MAX_FILES) { /* * Effectively poll for input wherever it may be available. */ for (;;) { - WATCHDOG_RESET(); + schedule(); if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { /* * Upper layer may have already called tstc() so @@ -507,7 +530,7 @@ int fgetc(int file) int ftstc(int file) { - if (file < MAX_FILES) + if ((unsigned int)file < MAX_FILES) return console_tstc(file); return -1; @@ -515,16 +538,24 @@ int ftstc(int file) void fputc(int file, const char c) { - if (file < MAX_FILES) + if ((unsigned int)file < MAX_FILES) console_putc(file, c); } void fputs(int file, const char *s) { - if (file < MAX_FILES) + if ((unsigned int)file < MAX_FILES) console_puts(file, s); } +#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT +void fflush(int file) +{ + if ((unsigned int)file < MAX_FILES) + console_flush(file); +} +#endif + int fprintf(int file, const char *fmt, ...) { va_list args; @@ -593,13 +624,16 @@ int tstc(void) #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL 1 #if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER) -#define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ) +#define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_VAL(PRE_CON_BUF_SZ)) static void pre_console_putc(const char c) { char *buffer; - buffer = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); + if (gd->precon_buf_idx < 0) + return; + + buffer = map_sysmem(CONFIG_VAL(PRE_CON_BUF_ADDR), CONFIG_VAL(PRE_CON_BUF_SZ)); buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c; @@ -608,22 +642,25 @@ static void pre_console_putc(const char c) static void pre_console_puts(const char *s) { + if (gd->precon_buf_idx < 0) + return; + while (*s) pre_console_putc(*s++); } static void print_pre_console_buffer(int flushpoint) { - unsigned long in = 0, out = 0; - char buf_out[CONFIG_PRE_CON_BUF_SZ + 1]; + long in = 0, out = 0; + char buf_out[CONFIG_VAL(PRE_CON_BUF_SZ) + 1]; char *buf_in; if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) return; - buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); - if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ) - in = gd->precon_buf_idx - CONFIG_PRE_CON_BUF_SZ; + buf_in = map_sysmem(CONFIG_VAL(PRE_CON_BUF_ADDR), CONFIG_VAL(PRE_CON_BUF_SZ)); + if (gd->precon_buf_idx > CONFIG_VAL(PRE_CON_BUF_SZ)) + in = gd->precon_buf_idx - CONFIG_VAL(PRE_CON_BUF_SZ); while (in < gd->precon_buf_idx) buf_out[out++] = buf_in[CIRC_BUF_IDX(in++)]; @@ -631,6 +668,7 @@ static void print_pre_console_buffer(int flushpoint) buf_out[out] = 0; + gd->precon_buf_idx = -1; switch (flushpoint) { case PRE_CONSOLE_FLUSHPOINT1_SERIAL: puts(buf_out); @@ -639,6 +677,7 @@ static void print_pre_console_buffer(int flushpoint) console_puts_select(stdout, false, buf_out); break; } + gd->precon_buf_idx = in; } #else static inline void pre_console_putc(const char c) {} @@ -731,6 +770,40 @@ void puts(const char *s) } } +#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT +void flush(void) +{ + if (!gd) + return; + + /* sandbox can send characters to stdout before it has a console */ + if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) { + os_flush(); + return; + } + + if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) + return; + + if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) + return; + + if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE)) + return; + + if (!gd->have_console) + return; + + if (gd->flags & GD_FLG_DEVINIT) { + /* Send to the standard output */ + fflush(stdout); + } else { + /* Send directly to the handler */ + serial_flush(); + } +} +#endif + #ifdef CONFIG_CONSOLE_RECORD int console_record_init(void) {