X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=common%2Fconsole.c;h=0e0295514b21687fadced9a8827a0c7e4700eb6c;hb=beac7d33d9131d22ffbdbfbf2786858062b63786;hp=3f25e76fe79ea3c94a85d0306d668233320e2d47;hpb=e72d344386bf80738fab7a6bd37cb321f443093a;p=people%2Fms%2Fu-boot.git diff --git a/common/console.c b/common/console.c index 3f25e76fe7..0e0295514b 100644 --- a/common/console.c +++ b/common/console.c @@ -6,14 +6,19 @@ */ #include +#include +#include +#include #include #include #include +#include #include #include #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -38,14 +43,14 @@ static int on_console(const char *name, const char *value, enum env_op op, case env_op_create: case env_op_overwrite: -#ifdef CONFIG_CONSOLE_MUX +#if CONFIG_IS_ENABLED(CONSOLE_MUX) if (iomux_doenv(console, value)) return 1; #else /* Try assigning specified device */ if (console_assign(console, value) < 0) return 1; -#endif /* CONFIG_CONSOLE_MUX */ +#endif return 0; case env_op_delete: @@ -63,11 +68,11 @@ U_BOOT_ENV_CALLBACK(console, on_console); static int on_silent(const char *name, const char *value, enum env_op op, int flags) { -#ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_SET +#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET) if (flags & H_INTERACTIVE) return 0; #endif -#ifndef CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC +#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC) if ((flags & H_INTERACTIVE) == 0) return 0; #endif @@ -82,7 +87,7 @@ static int on_silent(const char *name, const char *value, enum env_op op, U_BOOT_ENV_CALLBACK(silent, on_silent); #endif -#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV +#if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) /* * if overwrite_console returns 1, the stdin, stderr and stdout * are switched to the serial port, else the settings in the @@ -95,7 +100,7 @@ extern int overwrite_console(void); #define OVERWRITE_CONSOLE 0 #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */ -#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ +#endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */ static int console_setfile(int file, struct stdio_dev * dev) { @@ -142,7 +147,30 @@ static int console_setfile(int file, struct stdio_dev * dev) return error; } -#if defined(CONFIG_CONSOLE_MUX) +/** + * 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, + * whether it is called "serial". + */ +static bool console_dev_is_serial(struct stdio_dev *sdev) +{ + bool is_serial; + +#ifdef CONFIG_DM_SERIAL + if (sdev->flags & DEV_FLAGS_DM) { + struct udevice *dev = sdev->priv; + + is_serial = device_get_uclass_id(dev) == UCLASS_SERIAL; + } else +#endif + is_serial = !strcmp(sdev->name, "serial"); + + return is_serial; +} + +#if CONFIG_IS_ENABLED(CONSOLE_MUX) /** Console I/O multiplexing *******************************************/ static struct stdio_dev *tstcdev; @@ -199,19 +227,17 @@ 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 && !console_dev_is_serial(dev)) + dev->puts(dev, s); } } -#endif static void console_puts(int file, const char *s) { @@ -225,11 +251,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); @@ -250,29 +271,22 @@ static inline void console_putc(int file, const char c) stdio_devices[file]->putc(stdio_devices[file], 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); + if (!console_dev_is_serial(stdio_devices[file])) + stdio_devices[file]->puts(stdio_devices[file], s); } -#endif 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); } -#endif /* defined(CONFIG_CONSOLE_MUX) */ +#endif /* CONIFIG_IS_ENABLED(CONSOLE_MUX) */ /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/ @@ -297,11 +311,12 @@ int serial_printf(const char *fmt, ...) int fgetc(int file) { if (file < MAX_FILES) { -#if defined(CONFIG_CONSOLE_MUX) +#if CONFIG_IS_ENABLED(CONSOLE_MUX) /* * Effectively poll for input wherever it may be available. */ for (;;) { + WATCHDOG_RESET(); /* * Upper layer may have already called tstc() so * check for that first. @@ -376,6 +391,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); @@ -394,7 +418,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); @@ -407,14 +436,18 @@ int tstc(void) #define PRE_CONSOLE_FLUSHPOINT1_SERIAL 0 #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL 1 -#ifdef CONFIG_PRE_CONSOLE_BUFFER +#if CONFIG_IS_ENABLED(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; + char *buffer; + + buffer = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c; + + unmap_sysmem(buffer); } static void pre_console_puts(const char *s) @@ -425,22 +458,28 @@ 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_out[CONFIG_PRE_CON_BUF_SZ + 1]; + char *buf_in; + buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); 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++)]; + unmap_sysmem(buf_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 +490,23 @@ 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_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; @@ -481,13 +532,20 @@ void putc(const char c) void puts(const char *s) { -#ifdef CONFIG_SANDBOX +#ifdef CONFIG_DEBUG_UART if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { - os_puts(s); + while (*s) { + int ch = *s++; + + printch(ch); + } 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; @@ -511,49 +569,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; -#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 - * anything we ever want to print. - */ - i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args); - va_end(args); + 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); - /* 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() */ @@ -624,44 +664,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) @@ -669,6 +671,10 @@ struct stdio_dev *search_device(int flags, const char *name) struct stdio_dev *dev; dev = stdio_get_by_name(name); +#ifdef CONFIG_VIDCONSOLE_AS_LCD + if (!dev && !strcmp(name, "lcd")) + dev = stdio_get_by_name("vidconsole"); +#endif if (dev && (dev->flags & flags)) return dev; @@ -704,15 +710,35 @@ int console_assign(int file, const char *devname) return -1; } +static void console_update_silent(void) +{ +#ifdef CONFIG_SILENT_CONSOLE + if (env_get("silent") != NULL) + gd->flags |= GD_FLG_SILENT; + else + gd->flags &= ~GD_FLG_SILENT; +#endif +} + +int console_announce_r(void) +{ +#if !CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER) + char buf[DISPLAY_OPTIONS_BANNER_LENGTH]; + + display_options_get_banner(false, buf, sizeof(buf)); + + console_puts_noserial(stdout, buf); +#endif + + return 0; +} + /* Called before relocation - use serial functions */ int console_init_f(void) { gd->have_console = 1; -#ifdef CONFIG_SILENT_CONSOLE - if (getenv("silent") != NULL) - gd->flags |= GD_FLG_SILENT; -#endif + console_update_silent(); print_pre_console_buffer(PRE_CONSOLE_FLUSHPOINT1_SERIAL); @@ -744,7 +770,7 @@ void stdio_print_current_devices(void) } } -#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV +#if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) /* Called after the relocation - use desired console functions */ int console_init_r(void) { @@ -753,7 +779,7 @@ int console_init_r(void) #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE int i; #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ -#ifdef CONFIG_CONSOLE_MUX +#if CONFIG_IS_ENABLED(CONSOLE_MUX) int iomux_err = 0; #endif @@ -766,15 +792,15 @@ int console_init_r(void) /* stdin stdout and stderr are in environment */ /* scan for it */ - stdinname = getenv("stdin"); - stdoutname = getenv("stdout"); - stderrname = getenv("stderr"); + stdinname = env_get("stdin"); + stdoutname = env_get("stdout"); + stderrname = env_get("stderr"); if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */ inputdev = search_device(DEV_FLAGS_INPUT, stdinname); outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname); errdev = search_device(DEV_FLAGS_OUTPUT, stderrname); -#ifdef CONFIG_CONSOLE_MUX +#if CONFIG_IS_ENABLED(CONSOLE_MUX) iomux_err = iomux_doenv(stdin, stdinname); iomux_err += iomux_doenv(stdout, stdoutname); iomux_err += iomux_doenv(stderr, stderrname); @@ -807,18 +833,22 @@ int console_init_r(void) console_doenv(stdin, inputdev); } -#ifdef CONFIG_CONSOLE_MUX +#if CONFIG_IS_ENABLED(CONSOLE_MUX) done: #endif #ifndef CONFIG_SYS_CONSOLE_INFO_QUIET stdio_print_current_devices(); #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ +#ifdef CONFIG_VIDCONSOLE_AS_LCD + if (strstr(stdoutname, "lcd")) + printf("Warning: Please change 'lcd' to 'vidconsole' in stdout/stderr environment vars\n"); +#endif #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE /* set the environment variables (will overwrite previous env settings) */ for (i = 0; i < 3; i++) { - setenv(stdio_names[i], stdio_devices[i]->name); + env_set(stdio_names[i], stdio_devices[i]->name); } #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ @@ -833,7 +863,7 @@ done: return 0; } -#else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ +#else /* !CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */ /* Called after the relocation - use desired console functions */ int console_init_r(void) @@ -844,6 +874,8 @@ int console_init_r(void) struct list_head *pos; struct stdio_dev *dev; + console_update_silent(); + #ifdef CONFIG_SPLASH_SCREEN /* * suppress all output if splash screen is enabled and we have @@ -851,7 +883,7 @@ int console_init_r(void) * console to serial console in this case or suppress it if * "silent" mode was requested. */ - if (getenv("splashimage") != NULL) { + if (env_get("splashimage") != NULL) { if (!(gd->flags & GD_FLG_SILENT)) outputdev = search_device (DEV_FLAGS_OUTPUT, "serial"); } @@ -875,7 +907,7 @@ int console_init_r(void) if (outputdev != NULL) { console_setfile(stdout, outputdev); console_setfile(stderr, outputdev); -#ifdef CONFIG_CONSOLE_MUX +#if CONFIG_IS_ENABLED(CONSOLE_MUX) console_devices[stdout][0] = outputdev; console_devices[stderr][0] = outputdev; #endif @@ -884,7 +916,7 @@ int console_init_r(void) /* Initializes input console */ if (inputdev != NULL) { console_setfile(stdin, inputdev); -#ifdef CONFIG_CONSOLE_MUX +#if CONFIG_IS_ENABLED(CONSOLE_MUX) console_devices[stdin][0] = inputdev; #endif } @@ -895,7 +927,7 @@ int console_init_r(void) /* Setting environment variables */ for (i = 0; i < 3; i++) { - setenv(stdio_names[i], stdio_devices[i]->name); + env_set(stdio_names[i], stdio_devices[i]->name); } gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ @@ -909,4 +941,4 @@ int console_init_r(void) return 0; } -#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */ +#endif /* CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) */