* [PATCH 1/4] of: fdt: implement of_del_reserve_entry
@ 2026-01-21 11:36 Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 2/4] ARM: sm: fix repeated call to of_add_reserve_entry on every fixup Ahmad Fatoum
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2026-01-21 11:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum, Claude Sonnet 4.5
OF_MAX_RESERVE_MAP is only 16 and we have instances in the code that add
reserve entries in device tree fixups, which means it can be exhausted
when fixups are applied repeatedly.
Whether it's still apt in 2026 to use reserve entries is a different
discussion, but let's just add a way to delete reserved entries again in
cleanup code.
Co-developed-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/of/fdt.c | 24 ++++++++++++++++++++++++
include/of.h | 1 +
2 files changed, 25 insertions(+)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index f2f4aa03de2d..ea763cf7a52a 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -651,6 +651,30 @@ int of_add_reserve_entry(resource_size_t start, resource_size_t end)
return 0;
}
+void of_del_reserve_entry(resource_size_t start, resource_size_t end)
+{
+ int i, index = -1;
+
+ /* Find the entry with matching start and end addresses */
+ for (i = 0; i < of_reserve_map.num_entries; i++) {
+ if (of_reserve_map.start[i] == start && of_reserve_map.end[i] == end) {
+ index = i;
+ break;
+ }
+ }
+
+ if (index < 0)
+ return;
+
+ /* Shift all subsequent entries up to close the gap */
+ for (i = index; i < of_reserve_map.num_entries - 1; i++) {
+ of_reserve_map.start[i] = of_reserve_map.start[i + 1];
+ of_reserve_map.end[i] = of_reserve_map.end[i + 1];
+ }
+
+ of_reserve_map.num_entries--;
+}
+
struct of_reserve_map *of_get_reserve_map(void)
{
return &of_reserve_map;
diff --git a/include/of.h b/include/of.h
index ef4430c52862..ba8d1e358d41 100644
--- a/include/of.h
+++ b/include/of.h
@@ -77,6 +77,7 @@ struct of_reserve_map {
};
int of_add_reserve_entry(resource_size_t start, resource_size_t end);
+void of_del_reserve_entry(resource_size_t start, resource_size_t end);
void of_clean_reserve_map(void);
void fdt_add_reserve_map(void *fdt);
void fdt_print_reserve_map(const void *fdt);
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/4] ARM: sm: fix repeated call to of_add_reserve_entry on every fixup
2026-01-21 11:36 [PATCH 1/4] of: fdt: implement of_del_reserve_entry Ahmad Fatoum
@ 2026-01-21 11:36 ` Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 3/4] bootm: delete initrd reserve entry on bootm_boot return Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 4/4] video: stmfb: add screen base only once Ahmad Fatoum
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2026-01-21 11:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
A fixup can be applied arbitrarily often through boot fallback, dry runs
or of_diff command runs.
There's no need to add the reserve entry at fixup time, so just add it
in sm_init.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/cpu/sm.c | 36 +++++++++++-------------------------
1 file changed, 11 insertions(+), 25 deletions(-)
diff --git a/arch/arm/cpu/sm.c b/arch/arm/cpu/sm.c
index 53f5142b63f9..a7edd9f565c2 100644
--- a/arch/arm/cpu/sm.c
+++ b/arch/arm/cpu/sm.c
@@ -185,30 +185,6 @@ int armv7_secure_monitor_install(void)
return 0;
}
-/*
- * of_secure_monitor_fixup - reserve memory region for secure monitor
- *
- * We currently do not support putting the secure monitor into onchip RAM,
- * hence it runs in SDRAM and we must reserve the memory region so that we
- * won't get overwritten from the Kernel.
- * Beware: despite the name this is not secure in any way. The Kernel obeys
- * the reserve map, but only because it's nice. It could always overwrite the
- * secure monitor and hijack secure mode.
- */
-static int of_secure_monitor_fixup(struct device_node *root, void *unused)
-{
- unsigned long res_start, res_end;
-
- res_start = (unsigned long)_stext;
- res_end = (unsigned long)__bss_stop;
-
- of_add_reserve_entry(res_start, res_end);
-
- pr_debug("Reserved memory range from 0x%08lx to 0x%08lx\n", res_start, res_end);
-
- return 0;
-}
-
static enum arm_security_state bootm_secure_state;
static const char * const bootm_secure_state_names[] = {
@@ -229,7 +205,17 @@ const char *bootm_arm_security_state_name(enum arm_security_state state)
static int sm_init(void)
{
- of_register_fixup(of_secure_monitor_fixup, NULL);
+ /*
+ * Reserve memory region for secure monitor
+ *
+ * We currently do not support putting the secure monitor into onchip RAM,
+ * hence it runs in SDRAM and we must reserve the memory region so that we
+ * won't get overwritten from the Kernel.
+ * Beware: despite the name this is not secure in any way. The Kernel obeys
+ * the reserve map, but only because it's nice. It could always overwrite the
+ * secure monitor and hijack secure mode.
+ */
+ of_add_reserve_entry((ulong)_stext, (ulong)__bss_stop);
globalvar_add_simple_enum("bootm.secure_state",
(unsigned int *)&bootm_secure_state,
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/4] bootm: delete initrd reserve entry on bootm_boot return
2026-01-21 11:36 [PATCH 1/4] of: fdt: implement of_del_reserve_entry Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 2/4] ARM: sm: fix repeated call to of_add_reserve_entry on every fixup Ahmad Fatoum
@ 2026-01-21 11:36 ` Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 4/4] video: stmfb: add screen base only once Ahmad Fatoum
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2026-01-21 11:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Repeating dry runs with an initrd will eventually lead to exhausting the
reserve memory entries as OF_MAX_RESERVE_MAP is only 16.
Make sure to clean up after ourselves if bootm_boot returns without
actually booting.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/bootm.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/common/bootm.c b/common/bootm.c
index e3bd2eecb0cc..c554fa9e4015 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -1247,6 +1247,8 @@ int bootm_boot(struct bootm_data *bootm_data)
err_out:
bootm_reset_overrides();
release_sdram_region(data->os_res);
+ if (data->initrd_res)
+ of_del_reserve_entry(data->initrd_res->start, data->initrd_res->end);
release_sdram_region(data->initrd_res);
release_sdram_region(data->oftree_res);
release_sdram_region(data->tee_res);
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 4/4] video: stmfb: add screen base only once
2026-01-21 11:36 [PATCH 1/4] of: fdt: implement of_del_reserve_entry Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 2/4] ARM: sm: fix repeated call to of_add_reserve_entry on every fixup Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 3/4] bootm: delete initrd reserve entry on bootm_boot return Ahmad Fatoum
@ 2026-01-21 11:36 ` Ahmad Fatoum
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2026-01-21 11:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The stmfb driver is the only user of fb_of_reserve_add_fixup()
and apparently supports reserving its frame buffer when booting a kernel.
I am not sure this hand off actually works, but the very least we can
do is to avoid adding a duplicate entry repeatedly on every of_diff call.
Thus remove the old one if it exists and add a new one if the frame
buffer was enabled at fixup time.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/video/fb.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index bfc075039e9e..10d34a39e2b2 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -208,11 +208,12 @@ static int fb_of_reserve_fixup(struct device_node *root, void *context)
{
struct fb_info *info = context;
- if (!info->enabled)
- return 0;
+ of_del_reserve_entry((unsigned long)info->screen_base,
+ (unsigned long)info->screen_base + info->screen_size);
- of_add_reserve_entry((unsigned long)info->screen_base,
- (unsigned long)info->screen_base + info->screen_size);
+ if (info->enabled)
+ of_add_reserve_entry((unsigned long)info->screen_base,
+ (unsigned long)info->screen_base + info->screen_size);
return 0;
}
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-21 11:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-21 11:36 [PATCH 1/4] of: fdt: implement of_del_reserve_entry Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 2/4] ARM: sm: fix repeated call to of_add_reserve_entry on every fixup Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 3/4] bootm: delete initrd reserve entry on bootm_boot return Ahmad Fatoum
2026-01-21 11:36 ` [PATCH 4/4] video: stmfb: add screen base only once Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox