[U-Boot] [PATCH v3] Add board_pre_console_putc to deal with early console output

Simon Glass sjg at chromium.org
Wed Oct 19 00:57:08 CEST 2011


This patch adds support for console output before the console is inited.
The main purpose of this is to deal with a very early panic() which would
otherwise cause a silent hang.

A new board_pre_console_putc() function is added to the board API. If
provided by the board it will be called in the event of console output
before the console is ready. This function should turn on all UARTs and
spray the character out if it possibly can.

The feature is controlled by a new CONFIG_PRE_CONSOLE_PUTC option.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2:
- Made this feature conditional on CONFIG_PRE_CONSOLE_PANIC

Changes in v3:
- Rewrite this to be independent of panic()
- Rename feature to CONFIG_PRE_CONSOLE_PUTC

 README           |   17 +++++++++++++++++
 common/console.c |   21 ++++++++++++++++++++-
 include/common.h |    7 +++++++
 3 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/README b/README
index eb9ade9..613c3f9 100644
--- a/README
+++ b/README
@@ -634,6 +634,23 @@ The following options need to be configured:
 		'Sane' compilers will generate smaller code if
 		CONFIG_PRE_CON_BUF_SZ is a power of 2
 
+- Pre-console putc():
+		Prior to the console being initialised, console output is
+		normally silently discarded. This can be annoying if a
+		panic() happens in this time.
+
+		If the CONFIG_PRE_CONSOLE_PUTC option is defined, then
+		U-Boot will call board_pre_console_putc() for each output
+		character in this case, This function should try to output
+		the character if possible, perhaps on all available UARTs
+		(it will need to do this directly, since the console code
+		is not functional yet). Note that if the panic happens
+		early enough, then it is possible that board_init_f()
+		(or even arch_cpu_init() on ARM) has not been called yet.
+		You should init all clocks, GPIOs, etc. that are needed
+		to get the character out. Baud rates will need to default
+		to something sensible.
+
 - Boot Delay:	CONFIG_BOOTDELAY - in seconds
 		Delay before automatically booting the default image;
 		set to -1 to disable autoboot.
diff --git a/common/console.c b/common/console.c
index f17875e..d79bcf4 100644
--- a/common/console.c
+++ b/common/console.c
@@ -329,14 +329,30 @@ int tstc(void)
 	return serial_tstc();
 }
 
-#ifdef CONFIG_PRE_CONSOLE_BUFFER
+#ifdef CONFIG_PRE_CONSOLE_PUTC
+/* Provide a default function for when no console is available */
+static void __board_pre_console_putc(int ch)
+{
+	/* Just return since we can't access the console */
+}
+
+void board_pre_console_putc(const char *msg) __attribute__((weak,
+					alias("__board_pre_console_putc")));
+#endif
+
+#if defined(CONFIG_PRE_CONSOLE_BUFFER) || defined(CONFIG_PRE_CONSOLE_PUTC)
 #define CIRC_BUF_IDX(idx) ((idx) % (unsigned long)CONFIG_PRE_CON_BUF_SZ)
 
 static void pre_console_putc(const char c)
 {
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
 	char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
 
 	buffer[CIRC_BUF_IDX(gd->precon_buf_idx++)] = c;
+#endif
+#ifdef CONFIG_PRE_CONSOLE_PUTC
+	board_pre_console_putc(c);
+#endif
 }
 
 static void pre_console_puts(const char *s)
@@ -347,6 +363,7 @@ static void pre_console_puts(const char *s)
 
 static void print_pre_console_buffer(void)
 {
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
 	unsigned long i = 0;
 	char *buffer = (char *)CONFIG_PRE_CON_BUF_ADDR;
 
@@ -355,7 +372,9 @@ static void print_pre_console_buffer(void)
 
 	while (i < gd->precon_buf_idx)
 		putc(buffer[CIRC_BUF_IDX(i++)]);
+#endif
 }
+
 #else
 static inline void pre_console_putc(const char c) {}
 static inline void pre_console_puts(const char *s) {}
diff --git a/include/common.h b/include/common.h
index 4c3e3a6..cff6c9b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -277,6 +277,13 @@ int	last_stage_init(void);
 extern ulong monitor_flash_len;
 int mac_read_from_eeprom(void);
 
+/*
+ * Called when console output is requested before the console is available.
+ * The board should do its best to get the character out to the user any way
+ * it can.
+ */
+void board_pre_console_putc(int ch);
+
 /* common/flash.c */
 void flash_perror (int);
 
-- 
1.7.3.1



More information about the U-Boot mailing list