mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
	"Claude Opus 4.5" <noreply@anthropic.com>
Subject: [PATCH 12/16] bootm: overrides: add support for overlays
Date: Thu, 12 Mar 2026 15:44:55 +0100	[thread overview]
Message-ID: <20260312144505.2159816-12-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260312144505.2159816-1-a.fatoum@pengutronix.de>

Use loadables_from_files() for the oftree override, matching the initrd
pattern, to support colon-separated multi-file syntax. The first entry
is the base DT and subsequent entries are applied as overlays:

  bootm.oftree=a       use a as DT (unchanged behavior)
  bootm.oftree=a:b     use a as DT, apply b as overlay
  bootm.oftree=:b      keep existing DT, apply b as overlay
  bootm.oftree=a:b:c   use a as DT, apply b and c as overlays

Override overlays are applied during of_fix_tree() via a fixup registered
at of_populate_initcall level (13), placing them after global overlays
(device_initcall, 11) but before bootargs fixup (late_initcall, 14).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bootm-overrides.c  | 65 +++++++++++++++++++++++++++++++++------
 common/bootm.c            |  3 ++
 include/bootm-overrides.h |  6 ++++
 3 files changed, 65 insertions(+), 9 deletions(-)

diff --git a/common/bootm-overrides.c b/common/bootm-overrides.c
index 8c71ceb5f80d..720d5636f331 100644
--- a/common/bootm-overrides.c
+++ b/common/bootm-overrides.c
@@ -3,7 +3,9 @@
 #include <bootm.h>
 #include <bootm-overrides.h>
 #include <bootm-fit.h>
+#include <init.h>
 #include <libfile.h>
+#include <of.h>
 #include <linux/pagemap.h>
 
 /**
@@ -142,15 +144,11 @@ int bootm_apply_overrides(struct image_data *data,
 	}
 
 	if (overrides->oftree_file) {
-		loadable_release(&data->oftree);
-
-		/* Empty string means to mask the original FDT */
-		if (nonempty(overrides->oftree_file)) {
-			data->oftree = loadable_from_file(overrides->oftree_file,
-							   LOADABLE_FDT);
-			if (IS_ERR(data->oftree))
-				return PTR_ERR(data->oftree);
-		}
+		int ret = loadables_from_files(&data->oftree,
+					       overrides->oftree_file, ":",
+					       LOADABLE_FDT);
+		if (ret)
+			return ret;
 		data->is_override.oftree = true;
 	}
 
@@ -158,3 +156,52 @@ int bootm_apply_overrides(struct image_data *data,
 
 	return 0;
 }
+
+static struct loadable *pending_oftree_overlays;
+
+void bootm_set_pending_oftree_overlays(struct loadable *oftree)
+{
+	pending_oftree_overlays = oftree;
+}
+
+void bootm_clear_pending_oftree_overlays(void)
+{
+	pending_oftree_overlays = NULL;
+}
+
+static int bootm_override_overlay_fixup(struct device_node *root, void *ctx)
+{
+	struct loadable *ovl;
+
+	if (!pending_oftree_overlays)
+		return 0;
+
+	list_for_each_entry(ovl, &pending_oftree_overlays->chained_loadables, list) {
+		const void *dtbo;
+		size_t size;
+		int ret;
+
+		dtbo = loadable_view(ovl, &size);
+		if (IS_ERR(dtbo)) {
+			pr_err("could not load overlay \"%s\": %pe\n",
+			       ovl->name, dtbo);
+			continue;
+		}
+
+		ret = of_overlay_apply_dtbo(root, dtbo);
+		if (ret)
+			pr_err("failed to apply overlay \"%s\": %pe\n",
+			       ovl->name, ERR_PTR(ret));
+		loadable_view_free(ovl, dtbo, size);
+	}
+
+	return 0;
+}
+
+static int bootm_register_override_overlay_fixup(void)
+{
+	if (!IS_ENABLED(CONFIG_OF_OVERLAY))
+		return 0;
+	return of_register_fixup(bootm_override_overlay_fixup, NULL);
+}
+of_populate_initcall(bootm_register_override_overlay_fixup);
diff --git a/common/bootm.c b/common/bootm.c
index ed79c20c0972..d4a3a232743f 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -11,6 +11,7 @@
 #include <block.h>
 #include <libfile.h>
 #include <bootm-fit.h>
+#include <bootm-overrides.h>
 #include <bootm-uimage.h>
 #include <globalvar.h>
 #include <init.h>
@@ -325,7 +326,9 @@ void *bootm_get_devicetree(struct image_data *data)
 		of_add_reserve_entry(data->initrd_res->start, data->initrd_res->end);
 	}
 
+	bootm_set_pending_oftree_overlays(data->oftree);
 	of_fix_tree(data->of_root_node);
+	bootm_clear_pending_oftree_overlays();
 
 	oftree = of_flatten_dtb(data->of_root_node);
 	if (!oftree)
diff --git a/include/bootm-overrides.h b/include/bootm-overrides.h
index 9b133928a923..0dbf6e7fa823 100644
--- a/include/bootm-overrides.h
+++ b/include/bootm-overrides.h
@@ -9,6 +9,7 @@ struct bootm_overrides {
 };
 
 struct image_data;
+struct loadable;
 
 #ifdef CONFIG_BOOT_OVERRIDE
 static inline void bootm_merge_overrides(struct bootm_overrides *dst,
@@ -24,6 +25,8 @@ static inline void bootm_merge_overrides(struct bootm_overrides *dst,
 
 int bootm_apply_overrides(struct image_data *data,
 			  const struct bootm_overrides *overrides);
+void bootm_set_pending_oftree_overlays(struct loadable *oftree);
+void bootm_clear_pending_oftree_overlays(void);
 #else
 
 static inline void bootm_merge_overrides(struct bootm_overrides *dst,
@@ -36,6 +39,9 @@ static inline int bootm_apply_overrides(struct image_data *data,
 {
 	return 0;
 }
+
+static inline void bootm_set_pending_oftree_overlays(struct loadable *o) {}
+static inline void bootm_clear_pending_oftree_overlays(void) {}
 #endif
 
 #endif
-- 
2.47.3




  parent reply	other threads:[~2026-03-12 15:03 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 14:44 [PATCH 01/16] lib: add lazy loadable infrastructure for deferred boot component loading Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 02/16] bootm: split preparatory step from handler invocation Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 03/16] boot: add bootm_boot wrapper that takes struct bootentry Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 04/16] bootchooser: pass along " Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 05/16] bootm: switch plain file names case to loadable API Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 06/16] uimage: add offset parameter to uimage_load Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 07/16] bootm: uimage: switch to loadable API Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 08/16] bootm: fit: switch to new " Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 09/16] bootm: stash initial OS address/entry in image_data Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 10/16] bootm: support multiple entries for bootm.initrd Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 11/16] bootm: implement plain and FIT bootm.image override Ahmad Fatoum
2026-03-18  9:01   ` Sascha Hauer
2026-03-18  9:17     ` Ahmad Fatoum
2026-03-12 14:44 ` Ahmad Fatoum [this message]
2026-03-12 14:44 ` [PATCH 13/16] test: py: add test for initrd concatenation Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 14/16] defaultenv: base: add new devboot script Ahmad Fatoum
2026-03-18  9:50   ` Sascha Hauer
2026-03-18 10:50     ` Ahmad Fatoum
2026-03-18 14:49       ` Sascha Hauer
2026-03-12 14:44 ` [PATCH 15/16] Documentation: user: devboot: add section on forwarding build dirs Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 16/16] libfile: remove file_to_sdram Ahmad Fatoum
2026-03-18 10:06 ` [PATCH 01/16] lib: add lazy loadable infrastructure for deferred boot component loading Sascha Hauer

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=20260312144505.2159816-12-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=noreply@anthropic.com \
    /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