diff mbox series

[v2,2/2] ARM: decompressor: add option to ignore MEM ATAGs

Message ID 20240121203009.9257-3-ansuelsmth@gmail.com (mailing list archive)
State New, archived
Headers show
Series ARM: decompressor: support AUTO_ZRELADDR and appended DTB | expand

Commit Message

Christian Marangi Jan. 21, 2024, 8:29 p.m. UTC
Some bootloaders can pass broken MEM ATAGs that provide hardcoded
information about mounted RAM size and physical location.
Example booloader provide RAM of size 1.7Gb but actual mounted RAM
size is 512Mb causing kernel panic.

Add option CONFIG_ARM_ATAG_DTB_COMPAT_IGNORE_MEM to ignore these ATAG
and not augument appended DTB memory node.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/Kconfig                        | 12 ++++++++++++
 arch/arm/boot/compressed/atags_to_fdt.c |  4 ++++
 2 files changed, 16 insertions(+)
diff mbox series

Patch

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b2ab8db63c4b..6bb5c6b28106 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1549,6 +1549,18 @@  config ARM_ATAG_DTB_COMPAT
 	  bootloaders, this option allows zImage to extract the information
 	  from the ATAG list and store it at run time into the appended DTB.
 
+config ARM_ATAG_DTB_COMPAT_IGNORE_MEM
+	bool "Ignore MEM ATAG information from bootloader"
+	depends on ARM_ATAG_DTB_COMPAT
+	help
+	  Some bootloaders can pass broken MEM ATAGs that provide hardcoded
+	  information about mounted RAM size and physical location.
+	  Example booloader provide RAM of size 1.7Gb but actual mounted RAM
+	  size is 512Mb causing kernel panic.
+
+	  Enable this option if MEM ATAGs should be ignored and the memory
+	  node in the appended DTB should NOT be augumented.
+
 choice
 	prompt "Kernel command line type" if ARM_ATAG_DTB_COMPAT
 	default ARM_ATAG_DTB_COMPAT_CMDLINE_FROM_BOOTLOADER
diff --git a/arch/arm/boot/compressed/atags_to_fdt.c b/arch/arm/boot/compressed/atags_to_fdt.c
index 627752f18661..b5bce4dad321 100644
--- a/arch/arm/boot/compressed/atags_to_fdt.c
+++ b/arch/arm/boot/compressed/atags_to_fdt.c
@@ -170,6 +170,10 @@  int atags_to_fdt(void *atag_list, void *fdt, int total_space)
 				setprop_string(fdt, "/chosen", "bootargs",
 					       atag->u.cmdline.cmdline);
 		} else if (atag->hdr.tag == ATAG_MEM) {
+			/* Bootloader MEM ATAG are broken and should be ignored */
+			if (IS_ENABLED(CONFIG_ARM_ATAG_DTB_COMPAT_IGNORE_MEM))
+				continue;
+
 			if (memcount >= sizeof(mem_reg_property)/4)
 				continue;
 			if (!atag->u.mem.size)