[PATCH 12/16] bootm: overrides: add support for overlays

Ahmad Fatoum
2026-03-12T15:03:17Z

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