[U-Boot] [PATCH 1/2] Add board_panic_no_console to deal with early critical errors

Simon Glass sjg at chromium.org
Tue Aug 30 17:32:15 CEST 2011


Hi Graeme,

On Mon, Aug 29, 2011 at 4:15 PM, Graeme Russ <graeme.russ at gmail.com> wrote:
> Hi Simon
>
> On Tue, Aug 30, 2011 at 2:05 AM, Simon Glass <sjg at chromium.org> wrote:
>> 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);
>>
>
> [snip]
>
>> +/* 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);
>> +       }
>> +
>
> This patch highlights why console squelching should be done in console.c.
> We are ending up with more and more if (gd->have_console) all over the
> place. With the console squelching patch I posted earlier, I think it might
> be easier to create a weak 'panic_printf()' which aliases to printf() which
> the board can override if it has the ability to generate emergency output
> before console is initialised. Console output will be squelched if the
> board does not define such an override.

My reasoning for putting this in panic is that the
board_panic_no_console() turns on all UARTS and might fiddle with baud
rates, etc. It should only be called once. Very much an emergency
function and not just a different implementation of puts(). That said,
with your approach above, I suppose panic_printf() would only be
called once.

I would suggest panic_puts() since this would call less external code
and be easier for boards to implement.

Regards,
Simon

>
> Regards,
>
> Graeme
>


More information about the U-Boot mailing list