From: Thierry Reding <tred...@nvidia.com> This is mostly useful for debugging the early boot process. Often boards can provide some low-level code that outputs a character on some debug port prior to passing the early setup code. Allow boards to implement an early_putc() function that will be used to redirect printf() and friends to this debug port until the proper console becomes ready.
Cc: Simon Glass <s...@chromium.org> Cc: Tom Rini <tr...@konsulko.com> Signed-off-by: Thierry Reding <tred...@nvidia.com> --- README | 17 +++++++++++++++++ common/console.c | 21 +++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README b/README index b0124d6022e1..a7cb3d86d2d2 100644 --- a/README +++ b/README @@ -5014,6 +5014,23 @@ Low Level (hardware related) configuration options: driver that uses this: drivers/mtd/nand/davinci_nand.c +- CONFIG_EARLY_CONSOLE + Enables support for an early console. Output from puts() and + printf() will be redirected to this early console. A primary + use-case for this is early board bring up, where U-Boot does + not boot to the proper console yet, but it can also be quite + handy to help debug U-Boot's early boot phases. + + Boards that specify this option in their configuration must + provide an implementation of the early_putc() function: + + void early_putc(char ch); + + This function should output a single character on a device + that is available during early boot. Often this will be a + debug UART that has been preconfigured by a bootloader or + ROM before executing U-Boot. + Freescale QE/FMAN Firmware Support: ----------------------------------- diff --git a/common/console.c b/common/console.c index 3f25e76fe79e..d552dff4ee0f 100644 --- a/common/console.c +++ b/common/console.c @@ -479,6 +479,16 @@ void putc(const char c) } } +#ifdef CONFIG_EARLY_CONSOLE +extern void early_putc(char ch); + +static void early_puts(const char *s) +{ + while (*s) + early_putc(*s++); +} +#endif + void puts(const char *s) { #ifdef CONFIG_SANDBOX @@ -498,6 +508,11 @@ void puts(const char *s) return; #endif +#ifdef CONFIG_EARLY_CONSOLE + if (!gd->have_console) + early_puts(s); +#endif + if (!gd->have_console) return pre_console_puts(s); @@ -517,7 +532,8 @@ int printf(const char *fmt, ...) uint i; char printbuffer[CONFIG_SYS_PBSIZE]; -#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_PRE_CONSOLE_BUFFER) +#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_PRE_CONSOLE_BUFFER) && \ + !defined(CONFIG_EARLY_CONSOLE) if (!gd->have_console) return 0; #endif @@ -540,7 +556,8 @@ int vprintf(const char *fmt, va_list args) uint i; char printbuffer[CONFIG_SYS_PBSIZE]; -#if defined(CONFIG_PRE_CONSOLE_BUFFER) && !defined(CONFIG_SANDBOX) +#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_PRE_CONSOLE_BUFFER) && \ + !defined(CONFIG_EARLY_CONSOLE) if (!gd->have_console) return 0; #endif -- 2.3.2 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot