[U-Boot] [PATCH] debug uart: don't print before initialization

Simon Goldschmidt simon.k.r.goldschmidt at gmail.com
Sun Oct 7 17:52:11 UTC 2018


At least on socfpga gen5, _debug_uart_putc() can be called
before debug_uart_init(), which leaves us stuck in an
infinite loop in the ns16550 debug uart driver.

Since this prevents debugging startup problems instead
of helping, let's add a field to 'gd' that prevents
calling the _debug_uart_putc() until debug_uart_init()
has been called.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt at gmail.com>
---

 include/asm-generic/global_data.h |  3 +++
 include/debug_uart.h              | 19 ++++++++++++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index c83fc01b76..9de7f48476 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -122,6 +122,9 @@ typedef struct global_data {
 	struct list_head log_head;	/* List of struct log_device */
 	int log_fmt;			/* Mask containing log format info */
 #endif
+#ifdef CONFIG_DEBUG_UART
+	int debug_uart_initialized;	/* No print before debug_uart_init */
+#endif
 } gd_t;
 #endif
 
diff --git a/include/debug_uart.h b/include/debug_uart.h
index 34e8b2fc81..4133c5612c 100644
--- a/include/debug_uart.h
+++ b/include/debug_uart.h
@@ -128,9 +128,12 @@ void printhex8(uint value);
 \
 	static inline void _printch(int ch) \
 	{ \
-		if (ch == '\n') \
-			_debug_uart_putc('\r'); \
-		_debug_uart_putc(ch); \
+		DECLARE_GLOBAL_DATA_PTR; \
+		if (gd->debug_uart_initialized) { \
+			if (ch == '\n') \
+				_debug_uart_putc('\r'); \
+			_debug_uart_putc(ch); \
+		} \
 	} \
 \
 	void printch(int ch) \
@@ -146,8 +149,12 @@ void printhex8(uint value);
 \
 	static inline void printhex1(uint digit) \
 	{ \
-		digit &= 0xf; \
-		_debug_uart_putc(digit > 9 ? digit - 10 + 'a' : digit + '0'); \
+		DECLARE_GLOBAL_DATA_PTR; \
+		if (gd->debug_uart_initialized) { \
+			digit &= 0xf; \
+			_debug_uart_putc(digit > 9 ? digit - 10 + 'a' : \
+					 digit + '0'); \
+		} \
 	} \
 \
 	static inline void printhex(uint value, int digits) \
@@ -173,8 +180,10 @@ void printhex8(uint value);
 \
 	void debug_uart_init(void) \
 	{ \
+		DECLARE_GLOBAL_DATA_PTR; \
 		board_debug_uart_init(); \
 		_debug_uart_init(); \
+		gd->debug_uart_initialized = 1; \
 		_DEBUG_UART_ANNOUNCE \
 	} \
 
-- 
2.17.1



More information about the U-Boot mailing list