[U-Boot] [RFC v2] env: Fix errors printing on env loading
Sam Protsenko
semen.protsenko at linaro.org
Thu Jul 19 19:30:28 UTC 2018
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
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
Signed-off-by: Sam Protsenko <semen.protsenko at linaro.org>
---
common/console.c | 6 ++++++
env/env.c | 17 +++++++++++++----
include/asm-generic/global_data.h | 1 +
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/common/console.c b/common/console.c
index 2ba33dc574..a0db0ffea6 100644
--- a/common/console.c
+++ b/common/console.c
@@ -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) {
diff --git a/env/env.c b/env/env.c
index 5c0842ac07..ff044ccee1 100644
--- a/env/env.c
+++ b/env/env.c
@@ -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;
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 0fd4900392..7e83617664 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -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 */
--
2.18.0
More information about the U-Boot
mailing list