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

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@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);

Hi Simon,
On Wed, Oct 19, 2011 at 9:57 AM, Simon Glass sjg@chromium.org wrote:
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@chromium.org
[snip]
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)
I don't think we need this - If CONFIG_PRE_CONSOLE_PUTC then board_pre_console_putc() must also be defined - I would prefer a compilation due to undefined function that head-scratching as to why th output I expected did not occur
[snip]
Regards,
Graeme

Hi Graeme,
On Tue, Oct 18, 2011 at 4:31 PM, Graeme Russ graeme.russ@gmail.com wrote:
Hi Simon,
On Wed, Oct 19, 2011 at 9:57 AM, Simon Glass sjg@chromium.org wrote:
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@chromium.org
[snip]
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)
I don't think we need this - If CONFIG_PRE_CONSOLE_PUTC then board_pre_console_putc() must also be defined - I would prefer a compilation due to undefined function that head-scratching as to why th output I expected did not occur
Yes definitely, will adjust.
Regards, Simon
[snip]
Regards,
Graeme

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@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
Changes in v4: - Remove weak function, so we get a link error if it is undefined by the board
README | 17 +++++++++++++++++ common/console.c | 10 +++++++++- include/common.h | 7 +++++++ 3 files changed, 33 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..d34a0f4 100644 --- a/common/console.c +++ b/common/console.c @@ -329,14 +329,19 @@ int tstc(void) return serial_tstc(); }
-#ifdef CONFIG_PRE_CONSOLE_BUFFER +#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 +352,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 +361,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);

Hi Simon,
On Wed, Oct 19, 2011 at 10:43 AM, Simon Glass sjg@chromium.org wrote:
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@chromium.org
Acked-by: Graeme Russ graeme.russ@gmail.com

Hi,
On Tue, Oct 18, 2011 at 4:50 PM, Graeme Russ graeme.russ@gmail.com wrote:
Hi Simon,
On Wed, Oct 19, 2011 at 10:43 AM, Simon Glass sjg@chromium.org wrote:
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@chromium.org
Acked-by: Graeme Russ graeme.russ@gmail.com
Just going through my backlog. Any interest in merging this?
Regards, Simon

On 25/11/2011 08:35, Simon Glass wrote:
Hi,
On Tue, Oct 18, 2011 at 4:50 PM, Graeme Russ graeme.russ@gmail.com wrote:
Hi Simon,
Hi Simon,
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@chromium.org
Acked-by: Graeme Russ graeme.russ@gmail.com
Just going through my backlog. Any interest in merging this?
I have frankly missed the patch - I will read the related thread, and I will take a look. For now I will put this patch in my TODO list in patchwork.
Best regards, Stefano

On Fri, Nov 25, 2011 at 3:53 AM, Stefano Babic sbabic@denx.de wrote:
On 25/11/2011 08:35, Simon Glass wrote:
Hi,
On Tue, Oct 18, 2011 at 4:50 PM, Graeme Russ graeme.russ@gmail.com wrote:
Hi Simon,
Hi Simon,
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@chromium.org
Acked-by: Graeme Russ graeme.russ@gmail.com
Just going through my backlog. Any interest in merging this?
I have frankly missed the patch - I will read the related thread, and I will take a look. For now I will put this patch in my TODO list in patchwork.
Hi Stefano,
Thank you - no particular reason for you to notice it, but I thought I would cc you. The original purpose was to get some sort of message out of a board that fails very early (before console_init_f()). It is useful when using an fdt, since if the fdt cannot be found it is nice to print a friendly message somehow.
Regards, Simon
Best regards, Stefano
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de =====================================================================

On 19/10/2011 01:43, Simon Glass wrote:
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@chromium.org
Hi Simon,
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
Changes in v4:
- Remove weak function, so we get a link error if it is undefined by the board
maybe I have not understood the real goal of this patch. We have already a CONFIG_PRE_CONSOLE_BUFFER, that tries to store the output when the console is not avalable - and can be retrieved with a JTAG debugger.
Your patch adds a way to call some serial setup in board code, but it is not said that works or can work for all / most boards. Compared to the usage of the circular buffer, it is not so general - am I missing something ?
Best regards, Stefano Babic

Hi Stefan,
On Fri, Dec 2, 2011 at 9:09 AM, Stefano Babic sbabic@denx.de wrote:
On 19/10/2011 01:43, Simon Glass wrote:
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@chromium.org
Hi Simon,
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
Changes in v4:
- Remove weak function, so we get a link error if it is undefined by the board
maybe I have not understood the real goal of this patch. We have already a CONFIG_PRE_CONSOLE_BUFFER, that tries to store the output when the console is not avalable - and can be retrieved with a JTAG debugger.
Your patch adds a way to call some serial setup in board code, but it is not said that works or can work for all / most boards. Compared to the usage of the circular buffer, it is not so general - am I missing something ?
It actually started as a last-ditch panic message printer. It morphed into the general pre-console putc after discussions on the list (with Graeme).
It can happen that your early board code does not know what clocks to use, or can't find a console, or some other critical error. It then calls panic() which silently dies or maybe reboots if you are lucky. This problem mostly comes about with device trees, where we must have certain info in the device tree before we can even get to relocation.
The idea is that boards provide a way of outputting characters which tries to work on all types of boards with that SOC. For example, they output the characters on all UARTs with various clock options, etc.
We use it on Tegra to print a friendly panic message when something is horribly wrong. In this case we will never make it to relocation so the pre-console buffer will not be displayed. So we can't rely on that.
Regards, Simon
Best regards, Stefano Babic
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de =====================================================================

On 02/12/2011 19:16, Simon Glass wrote:
It actually started as a last-ditch panic message printer. It morphed into the general pre-console putc after discussions on the list (with Graeme).
It can happen that your early board code does not know what clocks to use, or can't find a console, or some other critical error. It then calls panic() which silently dies or maybe reboots if you are lucky. This problem mostly comes about with device trees, where we must have certain info in the device tree before we can even get to relocation.
The idea is that boards provide a way of outputting characters which tries to work on all types of boards with that SOC. For example, they output the characters on all UARTs with various clock options, etc.
We use it on Tegra to print a friendly panic message when something is horribly wrong. In this case we will never make it to relocation so the pre-console buffer will not be displayed. So we can't rely on that.
I do not know if this mechanism can be used on other SOCs, but IMHO it does not hurt and it helps at least on Tegra, as you explained me.
Applied to u-boot-staging, sbabic@denx.de branch
Best regards, Stefano Babic

Hi Stefan,
On Sun, Dec 4, 2011 at 10:56 AM, Stefano Babic sbabic@denx.de wrote:
On 02/12/2011 19:16, Simon Glass wrote:
It actually started as a last-ditch panic message printer. It morphed into the general pre-console putc after discussions on the list (with Graeme).
It can happen that your early board code does not know what clocks to use, or can't find a console, or some other critical error. It then calls panic() which silently dies or maybe reboots if you are lucky. This problem mostly comes about with device trees, where we must have certain info in the device tree before we can even get to relocation.
The idea is that boards provide a way of outputting characters which tries to work on all types of boards with that SOC. For example, they output the characters on all UARTs with various clock options, etc.
We use it on Tegra to print a friendly panic message when something is horribly wrong. In this case we will never make it to relocation so the pre-console buffer will not be displayed. So we can't rely on that.
I do not know if this mechanism can be used on other SOCs, but IMHO it does not hurt and it helps at least on Tegra, as you explained me.
Applied to u-boot-staging, sbabic@denx.de branch
Thanks. I think it can be used on any SOC with internal UARTs and a reasonably small list of permitted clock speeds. I suspect I will be trying it out on a few before long.
Regards, Simon
Best regards, Stefano Babic
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de =====================================================================

Hi Simon,
On Mon, Dec 5, 2011 at 2:34 PM, Simon Glass sjg@chromium.org wrote:
Hi Stefan,
On Sun, Dec 4, 2011 at 10:56 AM, Stefano Babic sbabic@denx.de wrote:
On 02/12/2011 19:16, Simon Glass wrote:
It actually started as a last-ditch panic message printer. It morphed into the general pre-console putc after discussions on the list (with Graeme).
It can happen that your early board code does not know what clocks to use, or can't find a console, or some other critical error. It then calls panic() which silently dies or maybe reboots if you are lucky. This problem mostly comes about with device trees, where we must have certain info in the device tree before we can even get to relocation.
The idea is that boards provide a way of outputting characters which tries to work on all types of boards with that SOC. For example, they output the characters on all UARTs with various clock options, etc.
We use it on Tegra to print a friendly panic message when something is horribly wrong. In this case we will never make it to relocation so the pre-console buffer will not be displayed. So we can't rely on that.
I do not know if this mechanism can be used on other SOCs, but IMHO it does not hurt and it helps at least on Tegra, as you explained me.
Applied to u-boot-staging, sbabic@denx.de branch
Thanks. I think it can be used on any SOC with internal UARTs and a reasonably small list of permitted clock speeds. I suspect I will be trying it out on a few before long.
Can it be used in conjuction with PRE_CONSOLE_BUFFER? i.e. panic() prints the contents of the PRE_CONSOLE_BUFFER before the panic message? I think that would be invaluable in determining what was happening leading up to the panic
Regards,
Graeme

Hi Graeme,
On Sun, Dec 4, 2011 at 7:40 PM, Graeme Russ graeme.russ@gmail.com wrote:
Hi Simon,
On Mon, Dec 5, 2011 at 2:34 PM, Simon Glass sjg@chromium.org wrote:
Hi Stefan,
On Sun, Dec 4, 2011 at 10:56 AM, Stefano Babic sbabic@denx.de wrote:
On 02/12/2011 19:16, Simon Glass wrote:
It actually started as a last-ditch panic message printer. It morphed into the general pre-console putc after discussions on the list (with Graeme).
It can happen that your early board code does not know what clocks to use, or can't find a console, or some other critical error. It then calls panic() which silently dies or maybe reboots if you are lucky. This problem mostly comes about with device trees, where we must have certain info in the device tree before we can even get to relocation.
The idea is that boards provide a way of outputting characters which tries to work on all types of boards with that SOC. For example, they output the characters on all UARTs with various clock options, etc.
We use it on Tegra to print a friendly panic message when something is horribly wrong. In this case we will never make it to relocation so the pre-console buffer will not be displayed. So we can't rely on that.
I do not know if this mechanism can be used on other SOCs, but IMHO it does not hurt and it helps at least on Tegra, as you explained me.
Applied to u-boot-staging, sbabic@denx.de branch
Thanks. I think it can be used on any SOC with internal UARTs and a reasonably small list of permitted clock speeds. I suspect I will be trying it out on a few before long.
Can it be used in conjuction with PRE_CONSOLE_BUFFER? i.e. panic() prints the contents of the PRE_CONSOLE_BUFFER before the panic message? I think that would be invaluable in determining what was happening leading up to the panic
It could have been when it was still a pre-console panic. But now that it has morphed into a general putc(), I suppose the only option is to somehow detect the first call and send the pre-console text first?
Regards, Simon
Regards,
Graeme

Hi Simon,
On Mon, Dec 5, 2011 at 3:31 PM, Simon Glass sjg@chromium.org wrote:
Hi Graeme,
On Sun, Dec 4, 2011 at 7:40 PM, Graeme Russ graeme.russ@gmail.com wrote:
Hi Simon,
On Mon, Dec 5, 2011 at 2:34 PM, Simon Glass sjg@chromium.org wrote:
Hi Stefan,
On Sun, Dec 4, 2011 at 10:56 AM, Stefano Babic sbabic@denx.de wrote:
On 02/12/2011 19:16, Simon Glass wrote:
It actually started as a last-ditch panic message printer. It morphed into the general pre-console putc after discussions on the list (with Graeme).
It can happen that your early board code does not know what clocks to use, or can't find a console, or some other critical error. It then calls panic() which silently dies or maybe reboots if you are lucky. This problem mostly comes about with device trees, where we must have certain info in the device tree before we can even get to relocation.
The idea is that boards provide a way of outputting characters which tries to work on all types of boards with that SOC. For example, they output the characters on all UARTs with various clock options, etc.
We use it on Tegra to print a friendly panic message when something is horribly wrong. In this case we will never make it to relocation so the pre-console buffer will not be displayed. So we can't rely on that.
I do not know if this mechanism can be used on other SOCs, but IMHO it does not hurt and it helps at least on Tegra, as you explained me.
Applied to u-boot-staging, sbabic@denx.de branch
Thanks. I think it can be used on any SOC with internal UARTs and a reasonably small list of permitted clock speeds. I suspect I will be trying it out on a few before long.
Can it be used in conjuction with PRE_CONSOLE_BUFFER? i.e. panic() prints the contents of the PRE_CONSOLE_BUFFER before the panic message? I think that would be invaluable in determining what was happening leading up to the panic
It could have been when it was still a pre-console panic. But now that it has morphed into a general putc(), I suppose the only option is to somehow detect the first call and send the pre-console text first?
Couldn't the panic() function detect that the pre console buffer is not empty and dump it before the panic message? Maybe even a generic panic_dump_pre_console_buffer() which checks if console has been initialised (in which case the buffer has already been dumped) and if the buffer is not empty, use pre_console_putc() to dump the buffer. This would be the first call in panic() followed by printing the panic message
Regards,
Graeme

Hi Graeme,
On Sun, Dec 4, 2011 at 8:35 PM, Graeme Russ graeme.russ@gmail.com wrote:
Hi Simon,
On Mon, Dec 5, 2011 at 3:31 PM, Simon Glass sjg@chromium.org wrote:
Hi Graeme,
On Sun, Dec 4, 2011 at 7:40 PM, Graeme Russ graeme.russ@gmail.com wrote:
Hi Simon,
On Mon, Dec 5, 2011 at 2:34 PM, Simon Glass sjg@chromium.org wrote:
Hi Stefan,
On Sun, Dec 4, 2011 at 10:56 AM, Stefano Babic sbabic@denx.de wrote:
On 02/12/2011 19:16, Simon Glass wrote:
It actually started as a last-ditch panic message printer. It morphed into the general pre-console putc after discussions on the list (with Graeme).
It can happen that your early board code does not know what clocks to use, or can't find a console, or some other critical error. It then calls panic() which silently dies or maybe reboots if you are lucky. This problem mostly comes about with device trees, where we must have certain info in the device tree before we can even get to relocation.
The idea is that boards provide a way of outputting characters which tries to work on all types of boards with that SOC. For example, they output the characters on all UARTs with various clock options, etc.
We use it on Tegra to print a friendly panic message when something is horribly wrong. In this case we will never make it to relocation so the pre-console buffer will not be displayed. So we can't rely on that.
I do not know if this mechanism can be used on other SOCs, but IMHO it does not hurt and it helps at least on Tegra, as you explained me.
Applied to u-boot-staging, sbabic@denx.de branch
Thanks. I think it can be used on any SOC with internal UARTs and a reasonably small list of permitted clock speeds. I suspect I will be trying it out on a few before long.
Can it be used in conjuction with PRE_CONSOLE_BUFFER? i.e. panic() prints the contents of the PRE_CONSOLE_BUFFER before the panic message? I think that would be invaluable in determining what was happening leading up to the panic
It could have been when it was still a pre-console panic. But now that it has morphed into a general putc(), I suppose the only option is to somehow detect the first call and send the pre-console text first?
Couldn't the panic() function detect that the pre console buffer is not empty and dump it before the panic message? Maybe even a generic panic_dump_pre_console_buffer() which checks if console has been initialised (in which case the buffer has already been dumped) and if the buffer is not empty, use pre_console_putc() to dump the buffer. This would be the first call in panic() followed by printing the panic message
Yes it could - sounds like a great idea. Patches welcome :-)
Regards, Simon
Regards,
Graeme
participants (3)
-
Graeme Russ
-
Simon Glass
-
Stefano Babic