public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [RFC, PATCH] fdt: Make sure there is no stale initrd left
@ 2025-05-29 15:02 Richard Weinberger
  2025-06-12 22:15 ` Tom Rini
  0 siblings, 1 reply; 12+ messages in thread
From: Richard Weinberger @ 2025-05-29 15:02 UTC (permalink / raw)
  To: u-boot
  Cc: trini, ddrokosov, sjg, tharvey, ilias.apalodimas, kojima.masahisa,
	upstream+uboot, Richard Weinberger

Although if we we don't setup an initrd, there could be a stale
initrd setting from the previous boot firmware in the live
device tree. So, make sure there is no setting left if we
don't want an initrd.

This can happen when booting on a Raspberry Pi. The boot firmware
can happily load an initrd before us and configuring the addresses
in the live device tree we get handed over.

Especially the setting `auto_initramfs` in config.txt is dangerous.
When enabled (default), the firmware tries to be smart and looks for
initramfs files.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
Hi!

This foot gun hit me hard and invalidated an A/B
update concept...

Thanks,
//richard
---
 boot/fdt_support.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/boot/fdt_support.c b/boot/fdt_support.c
index 92f2f534ee0..b7331bb76b3 100644
--- a/boot/fdt_support.c
+++ b/boot/fdt_support.c
@@ -224,15 +224,24 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)
 	int is_u64;
 	uint64_t addr, size;
 
-	/* just return if the size of initrd is zero */
-	if (initrd_start == initrd_end)
-		return 0;
-
 	/* find or create "/chosen" node. */
 	nodeoffset = fdt_find_or_add_subnode(fdt, 0, "chosen");
 	if (nodeoffset < 0)
 		return nodeoffset;
 
+	/*
+	 * Although we didn't setup an initrd, there could be a stale
+	 * initrd setting from the previous boot firmware in the live
+	 * device tree. So, make sure there is no setting left if we
+	 * don't want an initrd.
+	 */
+	if (initrd_start == initrd_end) {
+		fdt_delprop(fdt, nodeoffset, "linux,initrd-start");
+		fdt_delprop(fdt, nodeoffset, "linux,initrd-end");
+
+		return 0;
+	}
+
 	total = fdt_num_mem_rsv(fdt);
 
 	/*
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-10-17 22:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-29 15:02 [RFC, PATCH] fdt: Make sure there is no stale initrd left Richard Weinberger
2025-06-12 22:15 ` Tom Rini
2025-07-08 22:58   ` Sam Protsenko
2025-07-09  6:24     ` Richard Weinberger
2025-07-09 17:05       ` Sam Protsenko
2025-07-10 14:40         ` Richard Weinberger
2025-07-10 17:20           ` Sam Protsenko
2025-09-20 23:01             ` Sam Protsenko
2025-10-03 19:09               ` Richard Weinberger
2025-10-03 21:01                 ` Tom Rini
2025-10-04  8:05                   ` Richard Weinberger
2025-10-17 22:08                     ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox