]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
env: Avoid mixing of environment and driver prints on env load
authorAlexander Koch <akoch@initse.com>
Thu, 11 Jun 2026 22:48:34 +0000 (00:48 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 29 Jun 2026 21:29:44 +0000 (15:29 -0600)
The current environment loading code prints a partial string
"Loading Environment from %s..." and then triggers env driver
loading function. That env driver loading function may trigger
further prints, either from the env driver itself or from any
other driver that gets probed at that time. The result is a
print which mixed environment loading code prints and driver
code prints, as follows:

"
       Environment code print        _________________________
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv                          vv
Loading Environment from SPIFlash... SF: Detected w25q128jw... OK
                                     ^^^^^^^^^^^^^^^^^^^^^^
                                        Driver code print
"

Adjust the environment loading code print such, that it places
CR at the end of the line. This way, when the driver code prints
something, it overwrites the previous "Loading Environment from %s"
output and the result is not mixed. Furthermore, in case the env
was loaded correctly, print the "Loading Environment from %s ... OK"
in full again. This either overwrites the "Loading Environment from"
message and appends the print with "OK", or, it prints the line in
full after all the driver code prints.

This is not ideal, but it is the best we can do with only CR and
without ANSI control sequences. The result looks as follows:

"
SF: Detected w25q128jw with page size 256 Bytes, erase size 4 KiB, total 16 MiB
Loading Environment from SPIFlash... OK
"

Signed-off-by: Alexander Koch <akoch@initse.com>
Signed-off-by: Marek Vasut <marex@nabladev.com>
env/env.c

index 7a9c96b4078ff2fcb088eedb2a0fba13f3d23195..404e8b7a26c5bf87401861c85ba6b95bf72dcd59 100644 (file)
--- a/env/env.c
+++ b/env/env.c
@@ -189,7 +189,7 @@ int env_load(void)
                if (!env_has_inited(drv->location))
                        continue;
 
-               printf("Loading Environment from %s... ", drv->name);
+               printf("Loading Environment from %s...\r", drv->name);
                /*
                 * In error case, the error message must be printed during
                 * drv->load() in some underlying API, and it must be exactly
@@ -197,7 +197,7 @@ int env_load(void)
                 */
                ret = drv->load();
                if (!ret) {
-                       printf("OK\n");
+                       printf("Loading Environment from %s... OK\n", drv->name);
                        gd->env_load_prio = prio;
 
                        return 0;
@@ -206,7 +206,7 @@ int env_load(void)
                        if (best_prio == -1)
                                best_prio = prio;
                } else {
-                       debug("Failed (%d)\n", ret);
+                       debug("Loading Environment from %s... Failed (%d)\n", drv->name, ret);
                }
        }