[PATCH 2/3] environment: add global.env.path

Sascha Hauer s.hauer at pengutronix.de
Tue Apr 28 02:24:11 PDT 2026


barebox doesn't give an indication where the environment is stored without
actually doing a loadenv/saveenv. Add global.env.path which can be used to
show the path or even to set it.

A variable added with globalvar_add_simple_string() will be set to an empty
string whereas default_environment_path_get() used to return NULL when unset,
so we have to catch this explicitly.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/environment.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/common/environment.c b/common/environment.c
index 207b58e743..f883a520c6 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -126,7 +126,7 @@ const char *default_environment_path_get(void)
 {
 	struct cdev *cdev;
 
-	if (default_environment_path)
+	if (default_environment_path && *default_environment_path)
 		return default_environment_path;
 
 	cdev = default_environment_path_search();
@@ -547,9 +547,13 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
 static int register_env_vars(void)
 {
 	globalvar_add_simple_bool("env.autoprobe", &global_env_autoprobe);
+	globalvar_add_simple_string("env.path", &default_environment_path);
+
 	return 0;
 }
 postcore_initcall(register_env_vars);
 BAREBOX_MAGICVAR(global.env.autoprobe,
                  "Automatically probe known block devices for environment");
+BAREBOX_MAGICVAR(global.env.path,
+                 "The path the environment is stored");
 #endif

-- 
2.47.3




More information about the barebox mailing list