env: Fix errors printing on env loading
RFC 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: OK
instead of this:
Loading Environment from FAT... MMC: no card present ** Bad device mmc 0 **
Failed (-5)
Loading Environment from MMC... OK
The only way I see to do so is to use ASCII escape codes for moving the cursor (in non-error case).
I'd also like to add prefixes to error messages, like it's done in [2], but it requires adding one pointer to global data struct.
[1] https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences
[2] https://lists.denx.de/pipermail/u-boot/2018-July/335072.html
--- env/env.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
env/env.c +10 -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,17 @@ 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); ret = drv->load (); -if (ret) +if (ret) {printf ("Failed (%d)\n" , ret); -else -printf ("OK\n" ); + }else { +size_t len =strlen (msg); + +printf ("\033[1A\033[%zuC OK\n" , len -1 ); + }if (!ret)return 0 ;
Signature · 1 line
2.18.0
Dear Sam,
Quoted 11 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: OK
Quoted 6 lines
instead of this:
Loading Environment from FAT... MMC: no card present ** Bad device mmc 0 **
Failed (-5)
Loading Environment from MMC... OK
The new output is worse, as it consumes even more lines of output.
Quoted 2 lines
The only way I see to do so is to use ASCII escape codes for moving the cursor (in non-error case).
NAK!!! Please keep in mind that output usually goes to a serial port, and should not assume any speific "terminal" capabilities. Even simple in-line "editing" like "overprinting by outputting backspace characters causes a LOT of hassle when you try to parse output for example in automatic test suites.
Adding more complex terminal control or other fancy stuff (like colors etc) is a _strict_ no, no!
Quoted 2 lines
I'd also like to add prefixes to error messages, like it's done in [2], but it requires adding one pointer to global data struct.
As I explained befoire, this has a lot of negative consequences. You think about beauty, but please keep functionality and efficiency (boot time) in mind!
Best regards,
Wolfgang Denk
Signature · 4 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 There's an old proverb that says just about whatever you want it to.