X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fconsole.c;h=b3f5fdc03a168682bb351734e2b0b897988d64fb;hb=eb04ab3492297941b285ff552645cc1c0ed72edb;hp=ace206ca4ff5dd87651c32da857fae762916f41c;hpb=7a1af7a79bd79ded6a78d0c1afdbc3353669e313;p=oweals%2Fu-boot.git diff --git a/common/console.c b/common/console.c index ace206ca4f..b3f5fdc03a 100644 --- a/common/console.c +++ b/common/console.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -226,11 +227,6 @@ static void console_puts(int file, const char *s) } } -static inline void console_printdevs(int file) -{ - iomux_printdevs(file); -} - static inline void console_doenv(int file, struct stdio_dev *dev) { iomux_doenv(file, dev->name); @@ -264,11 +260,6 @@ static inline void console_puts(int file, const char *s) stdio_devices[file]->puts(stdio_devices[file], s); } -static inline void console_printdevs(int file) -{ - printf("%s\n", stdio_devices[file]->name); -} - static inline void console_doenv(int file, struct stdio_dev *dev) { console_setfile(file, dev); @@ -377,6 +368,15 @@ int getc(void) if (!gd->have_console) return 0; +#ifdef CONFIG_CONSOLE_RECORD + if (gd->console_in.start) { + int ch; + + ch = membuff_getbyte(&gd->console_in); + if (ch != -1) + return 1; + } +#endif if (gd->flags & GD_FLG_DEVINIT) { /* Get from the standard input */ return fgetc(stdin); @@ -395,7 +395,12 @@ int tstc(void) if (!gd->have_console) return 0; - +#ifdef CONFIG_CONSOLE_RECORD + if (gd->console_in.start) { + if (membuff_peekbyte(&gd->console_in) != -1) + return 1; + } +#endif if (gd->flags & GD_FLG_DEVINIT) { /* Test the standard input */ return ftstc(stdin); @@ -469,6 +474,10 @@ void putc(const char c) return; } #endif +#ifdef CONFIG_CONSOLE_RECORD + if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start) + membuff_putbyte(&gd->console_out, c); +#endif #ifdef CONFIG_SILENT_CONSOLE if (gd->flags & GD_FLG_SILENT) return; @@ -512,6 +521,10 @@ void puts(const char *s) return; } #endif +#ifdef CONFIG_CONSOLE_RECORD + if (gd && (gd->flags & GD_FLG_RECORD) && gd->console_out.start) + membuff_put(&gd->console_out, s, strlen(s)); +#endif #ifdef CONFIG_SILENT_CONSOLE if (gd->flags & GD_FLG_SILENT) return; @@ -535,44 +548,31 @@ void puts(const char *s) } } -int printf(const char *fmt, ...) +#ifdef CONFIG_CONSOLE_RECORD +int console_record_init(void) { - va_list args; - uint i; - char printbuffer[CONFIG_SYS_PBSIZE]; + int ret; - va_start(args, fmt); + ret = membuff_new(&gd->console_out, CONFIG_CONSOLE_RECORD_OUT_SIZE); + if (ret) + return ret; + ret = membuff_new(&gd->console_in, CONFIG_CONSOLE_RECORD_IN_SIZE); - /* For this to work, printbuffer must be larger than - * anything we ever want to print. - */ - i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); - va_end(args); - - /* Print the string */ - puts(printbuffer); - return i; + return ret; } -int vprintf(const char *fmt, va_list args) +void console_record_reset(void) { - uint i; - char printbuffer[CONFIG_SYS_PBSIZE]; - -#if defined(CONFIG_PRE_CONSOLE_BUFFER) && !defined(CONFIG_SANDBOX) - if (!gd->have_console) - return 0; -#endif - - /* For this to work, printbuffer must be larger than - * anything we ever want to print. - */ - i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); + membuff_purge(&gd->console_out); + membuff_purge(&gd->console_in); +} - /* Print the string */ - puts(printbuffer); - return i; +void console_record_reset_enable(void) +{ + console_record_reset(); + gd->flags |= GD_FLG_RECORD; } +#endif /* test if ctrl-c was pressed */ static int ctrlc_disabled = 0; /* see disable_ctrl() */ @@ -643,44 +643,6 @@ void clear_ctrlc(void) ctrlc_was_pressed = 0; } -#ifdef CONFIG_MODEM_SUPPORT_DEBUG -char screen[1024]; -char *cursor = screen; -int once = 0; -inline void dbg(const char *fmt, ...) -{ - va_list args; - uint i; - char printbuffer[CONFIG_SYS_PBSIZE]; - - if (!once) { - memset(screen, 0, sizeof(screen)); - once++; - } - - va_start(args, fmt); - - /* For this to work, printbuffer must be larger than - * anything we ever want to print. - */ - i = vsnprintf(printbuffer, sizeof(printbuffer), fmt, args); - va_end(args); - - if ((screen + sizeof(screen) - 1 - cursor) - < strlen(printbuffer) + 1) { - memset(screen, 0, sizeof(screen)); - cursor = screen; - } - sprintf(cursor, printbuffer); - cursor += strlen(printbuffer); - -} -#else -static inline void dbg(const char *fmt, ...) -{ -} -#endif - /** U-Boot INIT FUNCTIONS *************************************************/ struct stdio_dev *search_device(int flags, const char *name)