@@ -619,6 +619,20 @@ The following options need to be configured:
must be defined, to setup the maximum idle timeout for
the SMC.
+- Pre-Console Buffer:
+ Prior to the console being initialised (i.e. serial UART
+ initialised etc) all console output is silently discarded.
+ Defining CONFIG_PRE_CONSOLE_BUFFER will cause U-Boot to
+ buffer any console messages prior to the console being
+ initialised to a buffer of size CONFIG_PRE_CON_BUF_SZ
+ bytes located at CONFIG_PRE_CON_BUF_ADDR. The buffer is
+ a cicular buffer, so if more than CONFIG_PRE_CON_BUF_SZ
+ bytes are output before the console is initialised, the
+ earlier bytes are discarded.
+
+ 'Sane' compilers will generate smaller code if
+ CONFIG_PRE_CON_BUF_SZ is a power of 2
+
- Boot Delay: CONFIG_BOOTDELAY - in seconds
Delay before automatically booting the default image;
set to -1 to disable autoboot.
@@ -38,6 +38,9 @@ typedef struct global_data {
unsigned long flags;
unsigned long baudrate;
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
unsigned long env_addr; /* Address of Environment struct */
unsigned long env_valid; /* Checksum of Environment valid? */
unsigned long fb_base; /* base address of frame buffer */
@@ -38,6 +38,9 @@ typedef struct global_data {
unsigned long baudrate;
unsigned long stack_end; /* highest stack address */
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
unsigned long reloc_off; /* Relocation Offset */
unsigned long env_addr; /* Address of env struct */
unsigned long env_valid; /* Checksum of env valid? */
@@ -45,6 +45,9 @@ typedef struct global_data {
unsigned long board_type;
unsigned long baudrate;
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
phys_size_t ram_size; /* RAM size */
unsigned long env_addr; /* Address of Environment struct */
unsigned long env_valid; /* Checksum of Environment valid? */
@@ -57,6 +57,9 @@ typedef struct global_data {
unsigned long env_addr; /* Address of Environment struct */
unsigned long env_valid; /* Checksum of Environment valid? */
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
unsigned long fb_base; /* Base addr of framebuffer memory */
#endif
@@ -39,6 +39,9 @@ typedef struct global_data {
unsigned long flags;
unsigned long baudrate;
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
unsigned long env_addr; /* Address of Environment struct */
unsigned long env_valid; /* Checksum of Environment valid? */
unsigned long fb_base; /* base address of frame buffer */
@@ -41,6 +41,9 @@ typedef struct global_data {
unsigned long flags;
unsigned long baudrate;
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
phys_size_t ram_size; /* RAM size */
unsigned long reloc_off; /* Relocation Offset */
unsigned long env_addr; /* Address of Environment struct */
@@ -29,6 +29,9 @@ typedef struct global_data {
unsigned long baudrate;
unsigned long cpu_clk; /* CPU clock in Hz! */
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
phys_size_t ram_size; /* RAM size */
unsigned long env_addr; /* Address of Environment struct */
unsigned long env_valid; /* Checksum of Environment valid */
@@ -138,6 +138,9 @@ typedef struct global_data {
unsigned long env_addr; /* Address of Environment struct */
unsigned long env_valid; /* Checksum of Environment valid? */
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
#if defined(CONFIG_SYS_ALLOC_DPRAM) || defined(CONFIG_CPM2)
unsigned int dp_alloc_base;
unsigned int dp_alloc_top;
@@ -34,6 +34,9 @@ typedef struct global_data
unsigned long baudrate;
unsigned long cpu_clk; /* CPU clock in Hz! */
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
phys_size_t ram_size; /* RAM size */
unsigned long env_addr; /* Address of Environment struct */
unsigned long env_valid; /* Checksum of Environment valid */
@@ -53,6 +53,9 @@ typedef struct global_data {
unsigned long env_valid; /* Checksum of Environment valid? */
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
#if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
unsigned long fb_base; /* Base address of framebuffer memory */
#endif
@@ -40,6 +40,9 @@ typedef struct global_data {
unsigned long flags;
unsigned long baudrate;
unsigned long have_console; /* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+ unsigned long precon_buf_idx; /* Pre-Console buffer index */
+#endif
unsigned long reloc_off; /* Relocation Offset */
unsigned long load_off; /* Load Offset */
unsigned long env_addr; /* Address of Environment struct */
@@ -329,6 +329,39 @@ int tstc(void)
return serial_tstc();
}
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+#define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ)
+
+void pre_console_putc(const char c)
+{
+ char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
+
+ buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
+}
+
+void pre_console_puts(const char *s)
+{
+ while (*s)
+ pre_console_putc(*s++);
+}
+
+void print_pre_console_buffer(void)
+{
+ unsigned long i = 0;
+ char *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;
+
+ while (i < gd->precon_buf_idx)
+ putc(buffer[CIRC_BUF_IDX(i++)]);
+}
+#else
+static inline void pre_console_putc(const char c) {}
+static inline void pre_console_puts(const char *s) {}
+static inline void print_pre_console_buffer(void) {}
+#endif
+
void putc(const char c)
{
#ifdef CONFIG_SILENT_CONSOLE
@@ -342,7 +375,7 @@ void putc(const char c)
#endif
if (!gd->have_console)
- return;
+ return pre_console_putc(c);
if (gd->flags & GD_FLG_DEVINIT) {
/* Send to the standard output */
@@ -366,7 +399,7 @@ void puts(const char *s)
#endif
if (!gd->have_console)
- return;
+ return pre_console_puts(s);
if (gd->flags & GD_FLG_DEVINIT) {
/* Send to the standard output */
@@ -383,8 +416,10 @@ int printf(const char *fmt, ...)
uint i;
char printbuffer[CONFIG_SYS_PBSIZE];
+#ifndef CONFIG_PRE_CONSOLE_BUFFER
if (!gd->have_console)
return 0;
+#endif
va_start(args, fmt);
@@ -404,8 +439,10 @@ int vprintf(const char *fmt, va_list args)
uint i;
char printbuffer[CONFIG_SYS_PBSIZE];
+#ifndef CONFIG_PRE_CONSOLE_BUFFER
if (!gd->have_console)
return 0;
+#endif
/* For this to work, printbuffer must be larger than
* anything we ever want to print.
@@ -547,6 +584,8 @@ int console_init_f(void)
gd->flags |= GD_FLG_SILENT;
#endif
+ print_pre_console_buffer();
+
return 0;
}
Date: Mon, 29 Aug 2011 21:04:45 +1000 Subject: [PATCH V3] console: Implement pre-console buffer Allow redirection of console output prior to console initialisation to a temporary buffer. To enable this functionality, the board configuration file must define: - CONFIG_PRE_CONSOLE_BUFFER - Enable pre-console buffer - CONFIG_PRE_CON_BUF_ADDR - Base address of pre-console buffer - CONFIG_PRE_CON_BUF_SZ - Size of pre-console buffer (in bytes) The pre-console buffer will buffer the last CONFIG_PRE_CON_BUF_SZ bytes Any earlier characters are silently dropped. Signed-off-by: Graeme Russ <graeme.russ@gmail.com> --- Changes since V2 - Cast buffer size to unsigned long to help compilers produce tighter code - Use inline stub functions to reduce #ifdef clutter - Add documentation to README Changes Since V1 - Implemented circular buffer - Trivial code styl corrections README | 14 +++++++++ arch/arm/include/asm/global_data.h | 3 ++ arch/avr32/include/asm/global_data.h | 3 ++ arch/blackfin/include/asm/global_data.h | 3 ++ arch/m68k/include/asm/global_data.h | 3 ++ arch/microblaze/include/asm/global_data.h | 3 ++ arch/mips/include/asm/global_data.h | 3 ++ arch/nios2/include/asm/global_data.h | 3 ++ arch/powerpc/include/asm/global_data.h | 3 ++ arch/sh/include/asm/global_data.h | 3 ++ arch/sparc/include/asm/global_data.h | 3 ++ arch/x86/include/asm/global_data.h | 3 ++ common/console.c | 43 +++++++++++++++++++++++++++- 13 files changed, 88 insertions(+), 2 deletions(-) -- 1.7.5.2.317.g391b14