mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] defaultenv: board defaultenv now overrides CONFIG_DEFAULT_ENVIRONMENT_PATH
@ 2026-10-07  5:59 Florijan Plohl
  2026-10-07  5:59 ` [RFC PATCH 1/2] defaultenv: add defaultenv_append_external() to re-apply BSP environment Florijan Plohl
  2026-10-07  5:59 ` [RFC PATCH 2/2] ARM: boards: phytec-som-imx6: re-apply BSP environment after board defaultenv Florijan Plohl
  0 siblings, 2 replies; 3+ messages in thread
From: Florijan Plohl @ 2026-10-07  5:59 UTC (permalink / raw)
  To: s.hauer, barebox; +Cc: upstream, a.fatoum

Hi,

since commit 7f1cc5dd869d ("defaultenv: add base and external
defaultenv in pure_initcall"), a board's own defaultenv overrides the
environment from CONFIG_DEFAULT_ENVIRONMENT_PATH instead of the other
way round:

  before: base -> board defaultenv -> CONFIG_DEFAULT_ENVIRONMENT_PATH
  after:  base -> CONFIG_DEFAULT_ENVIRONMENT_PATH -> board defaultenv

Documentation/user/defaultenv-2.rst still describes the old order.

On phytec-som-imx6 this means the board's boot/* scripts now replace
the ones with the same names from our Yocto BSP (meta-phytec). Booting
via these entries then skips the BSP's additional setup, e.g. the
device tree overlays it applies for mmc, emmc and nand boot.

This RFC restores the old order for this board only: patch 1 adds
defaultenv_append_external(), patch 2 calls it at the end of
physom_imx6_probe(). Before polishing it, we'd like to ask:

1. Is the new order intended?

2. If not, is a per-board opt-in like this series acceptable, or would
   you rather see this fixed generically in defaultenv.c?

3. If it is, what is the recommended way for a BSP to replace a board's
   boot scripts?

Thanks,
Florijan

Primoz Fiser (2):
  defaultenv: add defaultenv_append_external() to re-apply BSP
    environment
  ARM: boards: phytec-som-imx6: re-apply BSP environment after board
    defaultenv

 arch/arm/boards/phytec-som-imx6/board.c | 12 ++++++++++++
 defaultenv/defaultenv.c                 | 16 ++++++++++++++++
 include/envfs.h                         |  5 +++++
 3 files changed, 33 insertions(+)


base-commit: ba8e34dfa96f80ae405e0ea7ac1e62762c28246a
-- 
2.43.0




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC PATCH 1/2] defaultenv: add defaultenv_append_external() to re-apply BSP environment
  2026-10-07  5:59 [RFC PATCH 0/2] defaultenv: board defaultenv now overrides CONFIG_DEFAULT_ENVIRONMENT_PATH Florijan Plohl
@ 2026-10-07  5:59 ` Florijan Plohl
  2026-10-07  5:59 ` [RFC PATCH 2/2] ARM: boards: phytec-som-imx6: re-apply BSP environment after board defaultenv Florijan Plohl
  1 sibling, 0 replies; 3+ messages in thread
From: Florijan Plohl @ 2026-10-07  5:59 UTC (permalink / raw)
  To: s.hauer, barebox; +Cc: upstream, a.fatoum

From: Primoz Fiser <primoz.fiser@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@norik.com>
Signed-off-by: Florijan Plohl <florijan.plohl@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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC PATCH 2/2] ARM: boards: phytec-som-imx6: re-apply BSP environment after board defaultenv
  2026-10-07  5:59 [RFC PATCH 0/2] defaultenv: board defaultenv now overrides CONFIG_DEFAULT_ENVIRONMENT_PATH Florijan Plohl
  2026-10-07  5:59 ` [RFC PATCH 1/2] defaultenv: add defaultenv_append_external() to re-apply BSP environment Florijan Plohl
@ 2026-10-07  5:59 ` Florijan Plohl
  1 sibling, 0 replies; 3+ messages in thread
From: Florijan Plohl @ 2026-10-07  5:59 UTC (permalink / raw)
  To: s.hauer, barebox; +Cc: upstream, a.fatoum

From: Primoz Fiser <primoz.fiser@norik.com>

physom_imx6_probe() appends the board's own defaultenv-physom-imx6*
directories via defaultenv_append_directory(). Since commit 7f1cc5dd869d
("defaultenv: add base and external defaultenv in pure_initcall") moved
the Kconfig/BSP-supplied environment (CONFIG_DEFAULT_ENVIRONMENT_PATH)
to an early pure_initcall, this probe - which runs later - now wins any
path collision against it.

For this board that silently shadows the per-machine environment a
Yocto BSP supplies via DEFAULT_ENVIRONMENT_PATH (e.g. meta-phytec's
env_add()-generated boot scripts) with the board's own, much older,
generic defaultenv-physom-imx6* content, without any build failure or
warning to indicate it.

Call the new defaultenv_append_external() after the board-specific
appends so the BSP-supplied environment, when actually provided, takes
final precedence again - restoring the pre-7f1cc5dd869d behavior for
this board. Standalone (non-Yocto) builds without a
DEFAULT_ENVIRONMENT_PATH are unaffected, and the board's own
defaultenv-physom-imx6* directories remain as the fallback for that
case.

Fixes: 7f1cc5dd869d ("defaultenv: add base and external defaultenv in pure_initcall")
Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>
Signed-off-by: Florijan Plohl <florijan.plohl@norik.com>
---
 arch/arm/boards/phytec-som-imx6/board.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boards/phytec-som-imx6/board.c b/arch/arm/boards/phytec-som-imx6/board.c
index 7e6f61bc36..7f59f8864b 100644
--- a/arch/arm/boards/phytec-som-imx6/board.c
+++ b/arch/arm/boards/phytec-som-imx6/board.c
@@ -276,6 +276,18 @@ static int physom_imx6_probe(struct device *dev)
 		defaultenv_append_directory(defaultenv_physom_imx6ul_phycore);
 	}
 
+	/*
+	 * Since barebox commit 7f1cc5dd869d ("defaultenv: add base and
+	 * external defaultenv in pure_initcall"), the Kconfig/BSP-supplied
+	 * environment (CONFIG_DEFAULT_ENVIRONMENT_PATH, i.e. Yocto's
+	 * env_add()-generated content) is appended very early and no longer
+	 * automatically wins over the board-specific defaultenv-physom-imx6*
+	 * directories appended above. Re-append it here so it takes final
+	 * precedence again when it is actually supplied (standalone/non-Yocto
+	 * builds without DEFAULT_ENVIRONMENT_PATH content are unaffected).
+	 */
+	defaultenv_append_external();
+
 	return 0;
 }
 
-- 
2.43.0




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-07  6:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-07  5:59 [RFC PATCH 0/2] defaultenv: board defaultenv now overrides CONFIG_DEFAULT_ENVIRONMENT_PATH Florijan Plohl
2026-10-07  5:59 ` [RFC PATCH 1/2] defaultenv: add defaultenv_append_external() to re-apply BSP environment Florijan Plohl
2026-10-07  5:59 ` [RFC PATCH 2/2] ARM: boards: phytec-som-imx6: re-apply BSP environment after board defaultenv Florijan Plohl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox