From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: "Jan Lübbe" <j.luebbe@pengutronix.de>,
"Ahmad Fatoum" <a.fatoum@pengutronix.de>
Subject: [PATCH v2 4/4] defaultenv: add base and external defaultenv in pure_initcall
Date: Tue, 25 Nov 2025 07:23:51 +0100 [thread overview]
Message-ID: <20251125062603.2614867-9-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251125062603.2614867-2-a.fatoum@pengutronix.de>
We currently depend on the order of the calls to defaultenv_append() to
decide which overlays to apply first.
To ensure the base environment is always loaded first, all of
defaultenv_append(), defaultenv_append_runtime_directory() and
defaultenv_load() call defaultenv_add_base() first.
Simplify this by adding base and external (i.e. from the BSP) defaultenv
in the earliest initcall.
This has a welcome side effect: Previously, fw_cfg env was applied
before an external defaultenv, but now it's applied afterwards and thus
can override it.
Reported-by: Jan Lübbe <j.luebbe@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- no change
---
defaultenv/defaultenv.c | 78 +++++++++++++++--------------------------
1 file changed, 28 insertions(+), 50 deletions(-)
diff --git a/defaultenv/defaultenv.c b/defaultenv/defaultenv.c
index 99f681f6520e..94858f2eff07 100644
--- a/defaultenv/defaultenv.c
+++ b/defaultenv/defaultenv.c
@@ -32,48 +32,6 @@ struct defaultenv {
size_t size;
};
-static void defaultenv_add_base(void)
-{
- static int base_added;
-
- if (base_added)
- return;
-
- base_added = 1;
-
- if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW))
- defaultenv_append_directory(defaultenv_2_base);
- if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU))
- defaultenv_append_directory(defaultenv_2_menu);
- if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_DFU))
- defaultenv_append_directory(defaultenv_2_dfu);
- if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_REBOOT_MODE))
- defaultenv_append_directory(defaultenv_2_reboot_mode);
- if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_SECURITY_POLICY))
- defaultenv_append_directory(defaultenv_2_security_policy);
- if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_IKCONFIG))
- defaultenv_append_directory(defaultenv_2_ikconfig);
- if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC))
- defaultenv_append_directory(defaultenv_1);
-}
-
-static void defaultenv_add_external(void)
-{
- static int external_added;
-
- if (external_added)
- return;
-
- external_added = 1;
-
- /*
- * The traditional or external environment given with
- * CONFIG_DEFAULT_ENVIRONMENT_PATH.
- */
- defaultenv_append((void *)default_environment,
- default_environment_size, "defaultenv");
-}
-
/*
* defaultenv_append - append a envfs buffer to the default environment
* @buf: The buffer containing the binary environment. If it is
@@ -87,8 +45,6 @@ void defaultenv_append(void *buf, unsigned int size, const char *name)
{
struct defaultenv *df;
- defaultenv_add_base();
-
df = xzalloc(sizeof(*df));
df->buf = buf;
df->size = size;
@@ -101,8 +57,6 @@ void defaultenv_append_runtime_directory(const char *srcdir)
{
struct defaultenv *df;
- defaultenv_add_base();
-
df = xzalloc(sizeof(*df));
df->srcdir = srcdir;
df->name = srcdir;
@@ -174,10 +128,6 @@ int defaultenv_load(const char *dir, unsigned flags)
struct defaultenv *df;
int err = 0;
- defaultenv_add_base();
-
- defaultenv_add_external();
-
list_for_each_entry(df, &defaultenv_list, list) {
int ret = defaultenv_load_one(df, dir, flags);
if (ret)
@@ -186,3 +136,31 @@ int defaultenv_load(const char *dir, unsigned flags)
return err;
}
+
+static int defaultenv_init(void)
+{
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW))
+ defaultenv_append_directory(defaultenv_2_base);
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU))
+ defaultenv_append_directory(defaultenv_2_menu);
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_DFU))
+ defaultenv_append_directory(defaultenv_2_dfu);
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_REBOOT_MODE))
+ defaultenv_append_directory(defaultenv_2_reboot_mode);
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_SECURITY_POLICY))
+ defaultenv_append_directory(defaultenv_2_security_policy);
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_IKCONFIG))
+ defaultenv_append_directory(defaultenv_2_ikconfig);
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC))
+ defaultenv_append_directory(defaultenv_1);
+
+ /*
+ * The traditional or external environment given with
+ * CONFIG_DEFAULT_ENVIRONMENT_PATH.
+ */
+ defaultenv_append((void *)default_environment,
+ default_environment_size, "defaultenv");
+
+ return 0;
+}
+pure_initcall(defaultenv_init);
--
2.47.3
prev parent reply other threads:[~2025-11-25 6:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-25 6:23 [PATCH v2 1/4] fs: qemu_fw_cfg: make use of the automount Ahmad Fatoum
2025-11-25 6:23 ` [PATCH v2 2/4] fs: qemu_fw_cfg: handle non-existent opt/org.barebox.env key gracefully Ahmad Fatoum
2025-11-25 6:23 ` [PATCH v2 3/4] defaultenv: don't abort defaultenv_load silently on error Ahmad Fatoum
2025-11-25 6:23 ` Ahmad Fatoum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251125062603.2614867-9-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=j.luebbe@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox