[PATCH] env: Avoid mixing of environment and driver prints on env load

Marek Vasut marex at nabladev.com
Fri Jun 12 00:48:34 CEST 2026


From: Alexander Koch <akoch at initse.com>

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 at initse.com>
Signed-off-by: Marek Vasut <marex at nabladev.com>
---
Cc: Alexander Koch <akoch at initse.com>
Cc: David Lechner <dlechner at baylibre.com>
Cc: Flaviu Nistor <flaviu.nistor at gmail.com>
Cc: Miquel Raynal <miquel.raynal at bootlin.com>
Cc: Takahiro Kuwano <takahiro.kuwano at infineon.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: Tudor Ambarus <tudor.ambarus at linaro.org>
Cc: Vignesh R <vigneshr at ti.com>
Cc: u-boot at lists.denx.de
---
 env/env.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/env/env.c b/env/env.c
index 7a9c96b4078..404e8b7a26c 100644
--- 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);
 		}
 	}
 
-- 
2.53.0



More information about the U-Boot mailing list