[RFC PATCH 1/2] defaultenv: add defaultenv_append_external() to re-apply BSP environment
Florijan Plohl
florijan.plohl at norik.com
Tue Oct 6 22:59:52 PDT 2026
From: Primoz Fiser <primoz.fiser at norik.com>
Since commit 7f1cc5dd869d ("defaultenv: add base and external
defaultenv in pure_initcall"), the Kconfig/BSP-supplied environment
(CONFIG_DEFAULT_ENVIRONMENT_PATH) is appended to the defaultenv list
once, very early, from a pure_initcall. Board code that appends its
own defaultenv directories later (e.g. from a postcore_platform_driver
probe, via defaultenv_append_directory()) now wins any path collision
against it, since defaultenv_append() is a plain list_add_tail() with
last-appended-wins semantics.
Boards that still want the BSP-supplied environment to take final
precedence over their own board-specific defaults (e.g. to keep a
board-level fallback environment for standalone/non-Yocto builds while
still letting a Yocto BSP's per-machine environment win when supplied)
have no way to reassert it after their own appends.
Add defaultenv_append_external(), a small wrapper that re-appends the
already-compiled-in BSP environment blob. Boards can call it after
their own defaultenv_append_directory() calls to restore the
pre-7f1cc5dd869d precedence where it matters.
Signed-off-by: Primoz Fiser <primoz.fiser at norik.com>
Signed-off-by: Florijan Plohl <florijan.plohl at norik.com>
---
defaultenv/defaultenv.c | 16 ++++++++++++++++
include/envfs.h | 5 +++++
2 files changed, 21 insertions(+)
diff --git a/defaultenv/defaultenv.c b/defaultenv/defaultenv.c
index 573b1f862f..626218477b 100644
--- a/defaultenv/defaultenv.c
+++ b/defaultenv/defaultenv.c
@@ -166,3 +166,19 @@ static int defaultenv_init(void)
return 0;
}
pure_initcall(defaultenv_init);
+
+/*
+ * defaultenv_init() (pure_initcall) already appends the Kconfig/BSP-supplied
+ * environment (DEFAULT_ENVIRONMENT_PATH) once, early. Boards that append
+ * their own board-specific defaultenv directories later (e.g. from a
+ * postcore_platform_driver probe) win any path collision, since
+ * defaultenv_append() is plain list_add_tail() / last-appended-wins.
+ * Call this after such board-specific appends to make the Kconfig/BSP
+ * environment win again instead - restores the pre-pure_initcall
+ * precedence for that board.
+ */
+void defaultenv_append_external(void)
+{
+ defaultenv_append((void *)default_environment,
+ default_environment_size, "defaultenv");
+}
diff --git a/include/envfs.h b/include/envfs.h
index 0c6b2e6815..a3b5a8bd98 100644
--- a/include/envfs.h
+++ b/include/envfs.h
@@ -134,6 +134,7 @@ static inline const char *of_env_get_device_alias_by_path(const char *of_path)
#ifdef CONFIG_DEFAULT_ENVIRONMENT
void defaultenv_append(void *buf, unsigned int size, const char *name);
void defaultenv_append_runtime_directory(const char *srcdir);
+void defaultenv_append_external(void);
int defaultenv_load(const char *dir, unsigned flags);
#else
static inline void defaultenv_append(void *buf, unsigned int size, const char *name)
@@ -144,6 +145,10 @@ static inline void defaultenv_append_runtime_directory(const char *srcdir)
{
}
+static inline void defaultenv_append_external(void)
+{
+}
+
static inline int defaultenv_load(const char *dir, unsigned flags)
{
return -ENOSYS;
--
2.43.0
More information about the barebox
mailing list