[U-Boot] [PATCH 1/2] Add board_panic_no_console to deal with early critical errors
Simon Glass
sjg at chromium.org
Mon Aug 29 18:05:09 CEST 2011
Tested-by: Simon Glass <sjg at chromium.org>
Signed-off-by: Simon Glass <sjg at chromium.org>
---
include/common.h | 8 ++++++++
lib/vsprintf.c | 26 ++++++++++++++++++++++++--
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/include/common.h b/include/common.h
index 12a1074..856df9a 100644
--- a/include/common.h
+++ b/include/common.h
@@ -250,6 +250,14 @@ int last_stage_init(void);
extern ulong monitor_flash_len;
int mac_read_from_eeprom(void);
+/*
+ * Called during a panic() when no console is available. The board should do
+ * its best to get a message to the user any way it can. This function should
+ * return if it can, in which case the system will either hang or reset.
+ * See panic().
+ */
+void board_panic_no_console(const char *str);
+
/* common/flash.c */
void flash_perror (int);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c029fbb..fd742a9 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -24,6 +24,8 @@
# define NUM_TYPE long long
#define noinline __attribute__((noinline))
+DECLARE_GLOBAL_DATA_PTR;
+
const char hex_asc[] = "0123456789abcdef";
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
@@ -714,13 +716,33 @@ int sprintf(char * buf, const char *fmt, ...)
return i;
}
+/* Provide a default function for when no console is available */
+static void __board_panic_no_console(const char *msg)
+{
+ /* Just return since we can't access the console */
+}
+
+void board_panic_no_console(const char *msg) __attribute__((weak,
+ alias("__board_panic_no_console")));
+
void panic(const char *fmt, ...)
{
+ char str[CONFIG_SYS_PBSIZE];
va_list args;
+
va_start(args, fmt);
- vprintf(fmt, args);
- putc('\n');
+
+ /* TODO)sjg): Move to vsnprintf() when available */
+ vsprintf(str, fmt, args);
va_end(args);
+
+ if (gd->have_console) {
+ puts(str);
+ putc('\n');
+ } else {
+ board_panic_no_console(str);
+ }
+
#if defined (CONFIG_PANIC_HANG)
hang();
#else
--
1.7.3.1
More information about the U-Boot
mailing list