[U-Boot] [RFC PATCH] Pre-console buffer for ARM

Simon Glass sjg at chromium.org
Mon Aug 29 19:21:57 CEST 2011


This patch is for Graeme to take a look at. I found that have_console is
not a flag yet. Also a few tidy-ups to handle buffer overflow and to avoid
printing a 'dumping buffer' message when nothing was outputted.

Also I tried to simplify the maths for the location of the pre-console buffer.
IMO this should be done in board.c though.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 arch/arm/include/asm/global_data.h |    1 +
 common/console.c                   |   36 ++++++++++++++++++++++++++++++++++++
 include/configs/tegra2-common.h    |    8 ++++++--
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/global_data.h b/arch/arm/include/asm/global_data.h
index 4fc51fd..8b028cc 100644
--- a/arch/arm/include/asm/global_data.h
+++ b/arch/arm/include/asm/global_data.h
@@ -71,6 +71,7 @@ typedef	struct	global_data {
 	unsigned long	start_addr_sp;	/* start_addr_stackpointer */
 	unsigned long	reloc_off;
 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
+	unsigned long	con_buf_idx;	/* Console buffer index */
 	unsigned long	tlb_addr;
 #endif
 	void		**jt;		/* jump table */
diff --git a/common/console.c b/common/console.c
index 8c650e0..2a7d2c8 100644
--- a/common/console.c
+++ b/common/console.c
@@ -323,6 +323,36 @@ 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;
+	int index = gd->con_buf_idx;
+
+	if (index) {
+		printf("console initialised - dumping pre-console buffer:\n");
+		index = min(index, CONFIG_SYS_TMP_CON_BUF_SZ - 1);
+		buffer[index] = '\0';
+		puts(buffer);
+		if (gd->con_buf_idx == CONFIG_SYS_TMP_CON_BUF_SZ)
+			puts("... (buffer overflowed)\n");
+		printf("buffer dumped\n");
+	}
+}
+
 void putc(const char c)
 {
 #ifdef CONFIG_SILENT_CONSOLE
@@ -341,6 +371,8 @@ void putc(const char c)
 	} else {
 		/* Send directly to the handler */
 		serial_putc(c);
+	} else {
+		pre_console_putc(c);
 	}
 }
 
@@ -362,6 +394,8 @@ void puts(const char *s)
 	} else {
 		/* Send directly to the handler */
 		serial_puts(s);
+	} else {
+		pre_console_puts(s);
 	}
 }
 
@@ -529,6 +563,8 @@ int console_init_f(void)
 		gd->flags |= GD_FLG_SILENT;
 #endif
 
+	print_pre_console_buffer();
+
 	return 0;
 }
 
diff --git a/include/configs/tegra2-common.h b/include/configs/tegra2-common.h
index 73e0f05..a42cce1 100644
--- a/include/configs/tegra2-common.h
+++ b/include/configs/tegra2-common.h
@@ -156,8 +156,12 @@
 
 #define CONFIG_SYS_INIT_RAM_ADDR	CONFIG_STACKBASE
 #define CONFIG_SYS_INIT_RAM_SIZE	CONFIG_SYS_MALLOC_LEN
-#define CONFIG_SYS_INIT_SP_ADDR		(CONFIG_SYS_INIT_RAM_ADDR + \
-						CONFIG_SYS_INIT_RAM_SIZE - \
+#define CONFIG_SYS_TMP_CON_BUF_SZ	(1 * 1024)
+#define CONFIG_SYS_INIT_RAM_TOP		(CONFIG_SYS_INIT_RAM_ADDR  + \
+						CONFIG_SYS_INIT_RAM_SIZE)
+#define CONFIG_SYS_TMP_CON_BUF_ADDR	(CONFIG_SYS_INIT_RAM_TOP - \
+					CONFIG_SYS_TMP_CON_BUF_SZ)
+#define CONFIG_SYS_INIT_SP_ADDR		(CONFIG_SYS_TMP_CON_BUF_ADDR - \
 						GENERATED_GBL_DATA_SIZE)
 
 #define CONFIG_TEGRA2_GPIO
-- 
1.7.3.1



More information about the U-Boot mailing list