It is possible to enable pre-console buffer in SPL and later extract log messages from it when updating stdio consoles in u-boot.
Signed-off-by: Siarhei Siamashka <[email protected]> --- common/console.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/common/console.c b/common/console.c index fc1963b..fbbe897 100644 --- a/common/console.c +++ b/common/console.c @@ -404,17 +404,49 @@ int tstc(void) return serial_tstc(); } +/* + * The pre-console buffer helps to ensure that log messages can reach stdio + * consoles even from the very bottom of SPL. + * + * To get the full use of it, the SPL build should have the following defines: + * CONFIG_PRE_CONSOLE_BUFFER - define to enable the SPL pre-console buffer + * CONFIG_PRE_CON_BUF_ADDR - address in SRAM of the SPL pre-console buffer + * CONFIG_PRE_CON_BUF_SZ - size of the SPL pre-console buffer + * CONFIG_PRE_CON_IDX_ADDR - address of the index variable duplicate + * + * The main u-boot build should have the following defines: + * CONFIG_PRE_CONSOLE_BUFFER - define to enable the main pre-console buffer + * CONFIG_PRE_CON_BUF_ADDR - address in DRAM of the main pre-console buffer + * CONFIG_PRE_CON_BUF_SZ - size of the main pre-console buffer + * and + * CONFIG_SPL_PRE_CONSOLE_BUFFER - same as CONFIG_PRE_CONSOLE_BUFFER in SPL + * CONFIG_SPL_PRE_CON_BUF_ADDR - same as CONFIG_SPL_CON_BUF_ADDR in SPL + * CONFIG_SPL_PRE_CON_BUF_SZ - same as CONFIG_PRE_CON_BUF_SZ in SPL + * CONFIG_SPL_PRE_CON_IDX_ADDR - same as CONFIG_PRE_CON_IDX_ADDR in SPL + */ #define PRE_CONSOLE_FLUSHPOINT1_SERIAL 0 #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL 1 #ifdef CONFIG_PRE_CONSOLE_BUFFER + +#ifdef CONFIG_PRE_CON_IDX_ADDR +#define PRECON_BUF_IDX (*(unsigned long *)(CONFIG_PRE_CON_IDX_ADDR)) +#else +#define PRECON_BUF_IDX (gd->precon_buf_idx) +#endif + +#define PRECON_SPL_BUF_IDX (*(unsigned long *)(CONFIG_SPL_PRE_CON_IDX_ADDR)) + #define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ) +#define CIRC_SPL_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_SPL_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; + /* Update the index variable duplicate */ + PRECON_BUF_IDX = gd->precon_buf_idx; } static void pre_console_puts(const char *s) @@ -425,13 +457,36 @@ 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 i; + char *buffer; + + /* Update the index variable duplicate (to do it at least once) */ + PRECON_BUF_IDX = gd->precon_buf_idx; + +#if defined(CONFIG_SPL_PRE_CONSOLE_BUFFER) && !defined(CONFIG_SPL_BUILD) + i = 0; + buffer = (char *)CONFIG_SPL_PRE_CON_BUF_ADDR; + + if (PRECON_SPL_BUF_IDX > CONFIG_SPL_PRE_CON_BUF_SZ) + i = PRECON_SPL_BUF_IDX - CONFIG_SPL_PRE_CON_BUF_SZ; + + while (i < PRECON_SPL_BUF_IDX) { + switch (flushpoint) { + case PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL: + console_putc_noserial(stdout, + buffer[CIRC_SPL_BUF_IDX(i)]); + break; + } + i++; + } +#endif + i = 0; + 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; + if (PRECON_BUF_IDX > CONFIG_PRE_CON_BUF_SZ) + i = PRECON_BUF_IDX - CONFIG_PRE_CON_BUF_SZ; - while (i < gd->precon_buf_idx) + while (i < PRECON_BUF_IDX) switch (flushpoint) { case PRE_CONSOLE_FLUSHPOINT1_SERIAL: putc(buffer[CIRC_BUF_IDX(i++)]); -- 2.0.5 _______________________________________________ U-Boot mailing list [email protected] http://lists.denx.de/mailman/listinfo/u-boot

