env: Fix errors printing on env loading
RFC v2 1/1 env: Fix errors printing on env loading
This is just a draft to discuss ideas related to "Make U-Boot log great again" thread.
With this patch we will have something like this:
Attempting to load environment from FAT:
-> MMC: no card present
-> ** Bad device mmc 0 **
-> Failed (-5)
Attempting to load environment from MMC: OKinstead of this:
Loading Environment from FAT... MMC: no card present ** Bad device mmc 0 **
Failed (-5)
Loading Environment from MMC... OK
Two things were done in this patch:
- print messages from drivers in nested style (with "->" prefix); to do so, add GD_FLG_PR_PREFIX flag and check it in puts()
- make "OK" to be printed on the same line as main message; to do so, issue ASCII escape codes [1] to move cursor back to main message line
[1] https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
--- common/console.c | 6 ++++++ env/env.c | 17 +++++++++++++---- include/asm-generic/global_data.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-)
common/console.c +6 -0
@@ -533,6 +533,12 @@ void putc(const char c)void puts (const char *s) { +if (gd->flags &GD_FLG_PR_PREFIX ) { + gd->flags &= ~GD_FLG_PR_PREFIX ; +puts (" -> " ); + gd->flags |=GD_FLG_PR_PREFIX ; + } +#ifdef CONFIG_DEBUG_UART if (!gd || !(gd->flags &GD_FLG_SERIAL_READY )) {while (*s) {
env/env.c +13 -4
@@ -187,6 +187,7 @@ int env_load(void)for (prio =0 ; (drv =env_driver_lookup (ENVOP_LOAD , prio)); prio++) {int ret; +char msg[75 ];if (!drv->load)continue ;
@@ -194,12 +195,20 @@ int env_load(void)if (!env_has_inited (drv->location))continue ; -printf ("Loading Environment from %s... " , drv->name); +snprintf (msg,75 ,"Attempting to load environment from %s:\n" , + drv->name); +puts (msg); + gd->flags |=GD_FLG_PR_PREFIX ; ret = drv->load (); -if (ret) +if (ret) {printf ("Failed (%d)\n" , ret); -else -printf ("OK\n" ); + gd->flags &= ~GD_FLG_PR_PREFIX ; + }else { +size_t len =strlen (msg); + + gd->flags &= ~GD_FLG_PR_PREFIX ; +printf ("\033[1A\033[%zuC OK\n" , len -1 ); + }if (!ret)return 0 ;
include/asm-generic/global_data.h +1 -0
@@ -150,5 +150,6 @@ typedef struct global_data {#define GD_FLG_ENV_DEFAULT 0x02000/* Default variable flag */ #define GD_FLG_SPL_EARLY_INIT 0x04000/* Early SPL init is done */ #define GD_FLG_LOG_READY 0x08000/* Log system is ready for use */ +#define GD_FLG_PR_PREFIX 0x10000/* Print prefix before message */ #endif /* __ASM_GENERIC_GBL_DATA_H */
Signature · 1 line
2.18.0
Dear Sam Protsenko,
Quoted 18 lines · In message <[email protected]> you wrote:
This is just a draft to discuss ideas related to "Make U-Boot log great again" thread.
With this patch we will have something like this:
Attempting to load environment from FAT: -> MMC: no card present -> ** Bad device mmc 0 ** -> Failed (-5) Attempting to load environment from MMC: OKinstead of this:
Loading Environment from FAT... MMC: no card present ** Bad device mmc 0 **
Failed (-5)
Loading Environment from MMC... OK
Quoted 5 lines
Two things were done in this patch:
- print messages from drivers in nested style (with "->" prefix); to do so, addGD_FLG_PR_PREFIXflag and check it inputs()
- make "OK" to be printed on the same line as main message; to do so, issue ASCII escape codes [1] to move cursor back to main message line
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The IQ of the group is the lowest IQ of a member of the group divided by the number of people in the group.