From: Marco Felsch <m.felsch@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@barebox.org>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] environment: support DT-compatible-specific overlays
Date: Mon, 13 Apr 2026 14:59:39 +0200 [thread overview]
Message-ID: <gbnshsxi4aafyos5edll7jlyyf74j637zdwixs3h4oaopheoen@epcerzdhkwwr> (raw)
In-Reply-To: <20260413102026.1469330-1-a.fatoum@barebox.org>
Hi Ahmad,
On 26-04-13, Ahmad Fatoum wrote:
> Board-specific environments are registered from board code via
> defaultenv_append_directory(), but this isn't possible when using
> CONFIG_DEFAULT_ENVIRONMENT_PATH with an external environment.
>
> Add support for a match.of_compatible/ directory convention within
> the default environment. Subdirectories named after DT root compatible
> strings are overlaid onto /env from most generic to most specific
> after the default environment is loaded. The match.of_compatible/
> directory is removed afterwards to keep /env clean.
That's a nice feature!
> Example layout in CONFIG_DEFAULT_ENVIRONMENT_PATH:
>
> barebox-defaultenv/
> nv/boot.default
> match.of_compatible/
> fsl,imx8mm/
> nv/boot.default
> fsl,imx8mq-evk/
^
fsl,imx8mm-evk/ ?
> nv/boot.default
>
> For compatible = "fsl,imx8mm-evk", "fsl,imx8mm":
> 1. fsl,imx8mm/ overlay applied first (most generic)
> 2. fsl,imx8mm-evk/ overlay applied second (most specific)
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
> ---
> common/startup.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
Can we have a Documentation update for this mechanism please incl. the
search order? :)
Regards,
Marco
> 1 file changed, 47 insertions(+)
>
> diff --git a/common/startup.c b/common/startup.c
> index 2e2b5f820fe9..e630033e3505 100644
> --- a/common/startup.c
> +++ b/common/startup.c
> @@ -46,6 +46,7 @@
> #include <pbl/handoff-data.h>
> #include <libfile.h>
> #include <fuzz.h>
> +#include <of.h>
>
> extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
> __barebox_initcalls_end[];
> @@ -95,6 +96,50 @@ void autoload_external_env(bool endis)
> }
> #endif
>
> +static void env_merge_of_compat_overlays(const char *dir)
> +{
> + struct device_node *root;
> + const char *compat;
> + struct stat s;
> + char *ofdir, *src;
> + int count;
> +
> + root = of_get_root_node();
> + if (!root)
> + return;
> +
> + ofdir = xasprintf("%s/match.of_compatible", dir);
> +
> + if (stat(ofdir, &s) || !S_ISDIR(s.st_mode))
> + goto out;
> +
> + count = of_property_count_strings(root, "compatible");
> +
> + /*
> + * Apply overlays from most generic to most specific, so that
> + * more specific entries take precedence.
> + */
> + for (int i = count - 1; i >= 0; i--) {
> + if (of_property_read_string_index(root, "compatible",
> + i, &compat))
> + continue;
> +
> + src = xasprintf("%s/%s", ofdir, compat);
> +
> + if (stat(src, &s) == 0 && S_ISDIR(s.st_mode)) {
> + pr_debug("Applying '%s'-compatible environment overlay\n",
> + compat);
> + copy_recursive(src, dir, 0);
> + }
> +
> + free(src);
> + }
> +
> + unlink_recursive(ofdir, NULL);
> +out:
> + free(ofdir);
> +}
> +
> static int load_environment(void)
> {
> const char *default_environment_path;
> @@ -115,6 +160,8 @@ static int load_environment(void)
> pr_info("external environment support %s. Using default environment\n",
> IS_ENABLED(CONFIG_ENV_HANDLING) ? "disallowed" : "disabled");
>
> + env_merge_of_compat_overlays("/env");
> +
> nvvar_load();
>
> return 0;
> --
> 2.47.3
>
>
>
--
#gernperDu
#CallMeByMyFirstName
Pengutronix e.K. | |
Steuerwalder Str. 21 | https://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
prev parent reply other threads:[~2026-04-13 13:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 10:20 Ahmad Fatoum
2026-04-13 10:20 ` [PATCH 2/2] sandbox: add a match.of_compatible directory to exercise the feature Ahmad Fatoum
2026-04-13 12:59 ` Marco Felsch [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=gbnshsxi4aafyos5edll7jlyyf74j637zdwixs3h4oaopheoen@epcerzdhkwwr \
--to=m.felsch@pengutronix.de \
--cc=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/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