[PATCH 42/50] ARM: stm32mp: Make safe for multi-arch

Sascha Hauer s.hauer at pengutronix.de
Fri Mar 3 01:21:23 PST 2023


Make sure stm32mp initcalls are only executed when running on
a stm32mp SoC.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-stm32mp/init.c       | 20 +++++++++++++++++++-
 arch/arm/mach-stm32mp/stm32image.c |  4 ++++
 include/mach/stm32mp/stm32.h       |  2 ++
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-stm32mp/init.c b/arch/arm/mach-stm32mp/init.c
index d46762e0b7..b63c1be5be 100644
--- a/arch/arm/mach-stm32mp/init.c
+++ b/arch/arm/mach-stm32mp/init.c
@@ -297,11 +297,29 @@ static int setup_cpu_type(void)
 	return 0;
 }
 
+static int __st32mp_soc;
+
+int stm32mp_soc(void)
+{
+	return __st32mp_soc;
+}
+
 static int stm32mp_init(void)
 {
+	if (of_machine_is_compatible("st,stm32mp135"))
+		__st32mp_soc = 32135;
+	else if (of_machine_is_compatible("st,stm32mp151"))
+		__st32mp_soc = 32151;
+	else if (of_machine_is_compatible("st,stm32mp153"))
+		__st32mp_soc = 32153;
+	else if (of_machine_is_compatible("st,stm32mp157"))
+		__st32mp_soc = 32157;
+	else
+		return 0;
+
 	setup_cpu_type();
 	setup_boot_mode();
 
 	return 0;
 }
-core_initcall(stm32mp_init);
+postcore_initcall(stm32mp_init);
diff --git a/arch/arm/mach-stm32mp/stm32image.c b/arch/arm/mach-stm32mp/stm32image.c
index 7867418e6c..37d7c73120 100644
--- a/arch/arm/mach-stm32mp/stm32image.c
+++ b/arch/arm/mach-stm32mp/stm32image.c
@@ -7,6 +7,7 @@
 #include <init.h>
 #include <memory.h>
 #include <linux/sizes.h>
+#include <mach/stm32mp/stm32.h>
 
 #define BAREBOX_STAGE2_OFFSET	256
 
@@ -45,6 +46,9 @@ static struct image_handler image_handler_stm32_image_v1_handler = {
 
 static int stm32mp_register_stm32image_image_handler(void)
 {
+	if (!stm32mp_soc())
+		return 0;
+
 	return register_image_handler(&image_handler_stm32_image_v1_handler);
 }
 late_initcall(stm32mp_register_stm32image_image_handler);
diff --git a/include/mach/stm32mp/stm32.h b/include/mach/stm32mp/stm32.h
index adb898fa26..5ce93e5eb3 100644
--- a/include/mach/stm32mp/stm32.h
+++ b/include/mach/stm32mp/stm32.h
@@ -34,4 +34,6 @@
 #define STM32_DDR_BASE			0xC0000000
 #define STM32_DDR_SIZE			SZ_1G
 
+int stm32mp_soc(void);
+
 #endif /* _MACH_STM32_H_ */
-- 
2.30.2




More information about the barebox mailing list