This cropped up as an aside to another thread so I thought I would give it a go. It's pretty rough-and-ready but it does the trick :)
--- arch/x86/cpu/cpu.c | 2 + arch/x86/include/asm/global_data.h | 14 +++++---- common/console.c | 56 ++++++++++++++++++++++++++++-------- include/configs/eNET.h | 5 ++- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c index cac12c0..602fb51 100644 --- a/arch/x86/cpu/cpu.c +++ b/arch/x86/cpu/cpu.c @@ -90,6 +90,8 @@ int x86_cpu_init_f(void) const u32 em_rst = ~X86_CR0_EM; const u32 mp_ne_set = X86_CR0_MP | X86_CR0_NE; + printf("Example pre-console printf()\n"); + /* initialize FPU, reset EM, set MP and NE */ asm ("fninit\n" \ "movl %%cr0, %%eax\n" \ diff --git a/arch/x86/include/asm/global_data.h b/arch/x86/include/asm/global_data.h index 2902e61..4ebc5bd 100644 --- a/arch/x86/include/asm/global_data.h +++ b/arch/x86/include/asm/global_data.h @@ -44,6 +44,7 @@ typedef struct global_data { unsigned long env_addr; /* Address of Environment struct */ unsigned long cpu_clk; /* CPU clock in Hz! */ unsigned long bus_clk; + unsigned long con_buf_idx; /* Console buffer index */ unsigned long relocaddr; /* Start address of U-Boot in RAM */ unsigned long start_addr_sp; /* start_addr_stackpointer */ phys_size_t ram_size; /* RAM size */ @@ -65,13 +66,14 @@ extern gd_t *gd; #define GD_ENV_ADDR 5 #define GD_CPU_CLK 6 #define GD_BUS_CLK 7 -#define GD_RELOC_ADDR 8 -#define GD_START_ADDR_SP 9 -#define GD_RAM_SIZE 10 -#define GD_RESET_STATUS 11 -#define GD_JT 12 +#define GD_CON_BUF_IDX 8 +#define GD_RELOC_ADDR 9 +#define GD_START_ADDR_SP 10 +#define GD_RAM_SIZE 11 +#define GD_RESET_STATUS 12 +#define GD_JT 13 -#define GD_SIZE 13 +#define GD_SIZE 14 /* * Global Data Flags diff --git a/common/console.c b/common/console.c index acc4df3..1fa862d 100644 --- a/common/console.c +++ b/common/console.c @@ -323,6 +323,28 @@ int tstc(void) return serial_tstc(); } +void pre_console_putc(const char c) +{ + char *buffer = (char *)CONFIG_SYS_TMP_CON_BUF_ADDR; + + if (gd->con_buf_idx < CONFIG_SYS_TMP_CON_BUF_SZ) + buffer[gd->con_buf_idx++] = c; +} + +void pre_console_puts(const char *s) +{ + while (*s) + pre_console_putc(*s++); +} + +void print_pre_console_buffer(void) +{ + char *buffer = (char *)CONFIG_SYS_TMP_CON_BUF_ADDR; + + buffer[gd->con_buf_idx] = 0x00; + puts(buffer); +} + void putc(const char c) { #ifdef CONFIG_SILENT_CONSOLE @@ -334,13 +356,16 @@ void putc(const char c) if (gd->flags & GD_FLG_DISABLE_CONSOLE) return; #endif - - if (gd->flags & GD_FLG_DEVINIT) { - /* Send to the standard output */ - fputc(stdout, c); + if (gd->flags & GD_FLG_HAVE_CONSOLE) { + if (gd->flags & GD_FLG_DEVINIT) { + /* Send to the standard output */ + fputc(stdout, c); + } else { + /* Send directly to the handler */ + serial_putc(c); + } } else { - /* Send directly to the handler */ - serial_putc(c); + pre_console_putc(c); } } @@ -355,13 +380,16 @@ void puts(const char *s) if (gd->flags & GD_FLG_DISABLE_CONSOLE) return; #endif - - if (gd->flags & GD_FLG_DEVINIT) { - /* Send to the standard output */ - fputs(stdout, s); + if (gd->flags & GD_FLG_HAVE_CONSOLE) { + if (gd->flags & GD_FLG_DEVINIT) { + /* Send to the standard output */ + fputs(stdout, s); + } else { + /* Send directly to the handler */ + serial_puts(s); + } } else { - /* Send directly to the handler */ - serial_puts(s); + pre_console_puts(s); } } @@ -529,6 +557,10 @@ int console_init_f(void) gd->flags |= GD_FLG_SILENT; #endif + printf("console initialised - dumping buffer\n"); + print_pre_console_buffer(); + printf("buffer dumped\n"); + return 0; } diff --git a/include/configs/eNET.h b/include/configs/eNET.h index 548d52c..4fb971f 100644 --- a/include/configs/eNET.h +++ b/include/configs/eNET.h @@ -164,8 +164,11 @@ #define CONFIG_SYS_STACK_SIZE (32 * 1024) #define CONFIG_SYS_CAR_ADDR 0x19200000 #define CONFIG_SYS_CAR_SIZE (16 * 1024) +#define CONFIG_SYS_TMP_CON_BUF_SZ (1 * 1024) #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_CAR_ADDR + \ - CONFIG_SYS_CAR_SIZE) + CONFIG_SYS_CAR_SIZE - \ + CONFIG_SYS_TMP_CON_BUF_SZ) +#define CONFIG_SYS_TMP_CON_BUF_ADDR CONFIG_SYS_INIT_SP_ADDR + 1 #define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE #define CONFIG_SYS_MONITOR_LEN (256 * 1024) #define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SECT_SIZE + \ -- 1.7.5.2.317.g391b14 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot