[PATCH v2 10/11] ARM: at91: make bootsource code generic to all SAMA5

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Jan 9 05:08:21 PST 2023


While I couldn't find documentation, the BootROM of all of SAMA5D2, D3
and D4 populates R4 when calling next stage bootloader with information
about the booutsource. barebox PBL will pass along this information to
barebox proper, so add a generic initcall that sets the bootsource.

Acked-by: Sam Ravnborg <sam at ravnborg.org>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/mach-at91/Kconfig                    |  3 ++
 arch/arm/mach-at91/Makefile                   |  1 +
 arch/arm/mach-at91/bootm-barebox.c            |  3 +-
 arch/arm/mach-at91/include/mach/cpu.h         |  1 -
 .../mach-at91/include/mach/sama5_bootsource.h |  2 ++
 arch/arm/mach-at91/sama5_bootsource.c         | 36 +++++++++++++++++++
 arch/arm/mach-at91/sama5d2.c                  | 15 --------
 arch/arm/mach-at91/setup.c                    |  3 --
 8 files changed, 43 insertions(+), 21 deletions(-)
 create mode 100644 arch/arm/mach-at91/sama5_bootsource.c

diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
index bc55b1c4e76e..529512b6c0db 100644
--- a/arch/arm/mach-at91/Kconfig
+++ b/arch/arm/mach-at91/Kconfig
@@ -75,6 +75,9 @@ config SOC_SAMA5
 	select HAVE_AT91SAM9_RST
 	select CPU_V7
 
+config SOC_SAMA5_MULTI
+	def_bool SOC_SAMA5 && AT91_MULTI_BOARDS
+
 config SOC_SAMA5D2
 	bool
 	select SOC_SAMA5
diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
index b9fda00b2e1a..bd39aad97410 100644
--- a/arch/arm/mach-at91/Makefile
+++ b/arch/arm/mach-at91/Makefile
@@ -40,3 +40,4 @@ obj-$(CONFIG_SOC_AT91SAM9G20) += at91sam9260.o at91sam9260_devices.o
 obj-$(CONFIG_SOC_AT91SAM9G45) += at91sam9g45.o at91sam9g45_devices.o
 obj-$(CONFIG_SOC_AT91SAM9X5)	+= at91sam9x5.o at91sam9x5_devices.o
 obj-$(CONFIG_SOC_AT91SAM9N12)	+= at91sam9n12.o at91sam9n12_devices.o
+obj-$(CONFIG_SOC_SAMA5_MULTI)	+= sama5_bootsource.o
diff --git a/arch/arm/mach-at91/bootm-barebox.c b/arch/arm/mach-at91/bootm-barebox.c
index 3c99d5813b53..afd0c3cf6962 100644
--- a/arch/arm/mach-at91/bootm-barebox.c
+++ b/arch/arm/mach-at91/bootm-barebox.c
@@ -6,7 +6,6 @@
 #include <common.h>
 #include <init.h>
 #include <memory.h>
-#include <mach/cpu.h>
 #include <mach/sama5_bootsource.h>
 
 static int do_bootm_at91_barebox_image(struct image_data *data)
@@ -40,7 +39,7 @@ static struct image_handler image_handler_at91_barebox_image = {
 
 static int at91_register_barebox_image_handler(void)
 {
-	if (!of_machine_is_compatible("atmel,sama5d2"))
+	if (!of_machine_is_compatible("atmel,sama5"))
 	    return 0;
 
 	return register_image_handler(&image_handler_at91_barebox_image);
diff --git a/arch/arm/mach-at91/include/mach/cpu.h b/arch/arm/mach-at91/include/mach/cpu.h
index 37e516947b57..ca85e8be6e24 100644
--- a/arch/arm/mach-at91/include/mach/cpu.h
+++ b/arch/arm/mach-at91/include/mach/cpu.h
@@ -160,7 +160,6 @@ struct at91_socinfo {
 extern struct at91_socinfo at91_soc_initdata;
 const char *at91_get_soc_type(struct at91_socinfo *c);
 const char *at91_get_soc_subtype(struct at91_socinfo *c);
-extern unsigned long at91_bootsource;
 
 static inline int at91_soc_is_detected(void)
 {
diff --git a/arch/arm/mach-at91/include/mach/sama5_bootsource.h b/arch/arm/mach-at91/include/mach/sama5_bootsource.h
index b31d20bc7c34..8072e7c25154 100644
--- a/arch/arm/mach-at91/include/mach/sama5_bootsource.h
+++ b/arch/arm/mach-at91/include/mach/sama5_bootsource.h
@@ -52,6 +52,8 @@ static inline int sama5_bootsource_instance(u32 reg)
 #define __sama5d4_stashed_bootrom_r4 \
 	(*(volatile u32 *)(SAMA5D4_SRAM_BASE + SAMA5D4_SRAM_SIZE - 0x4))
 
+extern unsigned long at91_bootsource;
+
 static inline void __noreturn sama5_boot_xload(void __noreturn (*bb)(void), u32 r4)
 {
 	asm volatile("mov r4, %0" : : "r"(r4) : );
diff --git a/arch/arm/mach-at91/sama5_bootsource.c b/arch/arm/mach-at91/sama5_bootsource.c
new file mode 100644
index 000000000000..ea657ae36011
--- /dev/null
+++ b/arch/arm/mach-at91/sama5_bootsource.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <mach/sama5_bootsource.h>
+#include <linux/export.h>
+#include <bootsource.h>
+#include <init.h>
+#include <of.h>
+
+unsigned long at91_bootsource;
+EXPORT_SYMBOL(at91_bootsource);
+
+/*
+ * sama5_bootsource_init - initialize bootsource
+ *
+ * BootROM will populate r4 when loading first stage bootloader
+ * with information about boot source. The entry points for
+ * multi-image capable SAMA5 boards will pass this information
+ * along. If you use a bootloader before barebox, you need to
+ * ensure that r4 is initialized for $bootsource to be correct
+ * in barebox. Example implementing it for AT91Bootstrap:
+ * https://github.com/linux4sam/at91bootstrap/pull/159
+ */
+static int sama5_bootsource_init(void)
+{
+	if (!of_machine_is_compatible("atmel,sama5"))
+		return 0;
+
+	at91_bootsource = __sama5d2_stashed_bootrom_r4;
+
+	if (at91_bootsource)
+		bootsource_set_raw(sama5_bootsource(at91_bootsource),
+				   sama5_bootsource_instance(at91_bootsource));
+
+	return 0;
+}
+postcore_initcall(sama5_bootsource_init);
diff --git a/arch/arm/mach-at91/sama5d2.c b/arch/arm/mach-at91/sama5d2.c
index b05d6a56bdd8..b0a04beb639e 100644
--- a/arch/arm/mach-at91/sama5d2.c
+++ b/arch/arm/mach-at91/sama5d2.c
@@ -6,7 +6,6 @@
 #include <mach/aic.h>
 #include <mach/sama5d2.h>
 #include <asm/cache-l2x0.h>
-#include <mach/sama5_bootsource.h>
 #include <asm/mmu.h>
 #include <mach/cpu.h>
 
@@ -54,17 +53,3 @@ static int sama5d2_init(void)
 	return 0;
 }
 postmmu_initcall(sama5d2_init);
-
-static int sama5d2_bootsource_init(void)
-{
-	if (!of_machine_is_compatible("atmel,sama5d2"))
-		return 0;
-
-	at91_bootsource = __sama5d2_stashed_bootrom_r4;
-
-	bootsource_set_raw(sama5_bootsource(at91_bootsource),
-			   sama5_bootsource_instance(at91_bootsource));
-
-	return 0;
-}
-postcore_initcall(sama5d2_bootsource_init);
diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
index 8a21d8debcd5..3d49624cd5c1 100644
--- a/arch/arm/mach-at91/setup.c
+++ b/arch/arm/mach-at91/setup.c
@@ -403,6 +403,3 @@ void at91sam_phy_reset(void __iomem *rstc_base)
 	/* Restore NRST value */
 	writel(AT91_RSTC_KEY | (rstc) | AT91_RSTC_URSTEN, rstc_base + AT91_RSTC_MR);
 }
-
-unsigned long at91_bootsource;
-EXPORT_SYMBOL(at91_bootsource);
-- 
2.30.2




More information about the barebox mailing list