mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure
@ 2025-03-20  9:14 Alexander Shiyan
  2025-03-20  9:14 ` [PATCH 2/7] ARM: at91: xload: Replace magic values with definitions Alexander Shiyan
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Alexander Shiyan @ 2025-03-20  9:14 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Shiyan

The loader function structures use the same members,
so they can be rewritten to use a single xload_instance structure.

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 arch/arm/mach-at91/xload.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 9c03d2119c..4e7e80379f 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -11,6 +11,13 @@
 #include <asm/cache.h>
 #include <pbl/bio.h>
 
+struct xload_instance {
+	void __iomem *base;
+	unsigned id;
+	u8 periph;
+	s8 pins[15];
+};
+
 static void at91_fat_start_image(struct pbl_bio *bio,
 				 void *buf, unsigned int len,
 				 u32 r4)
@@ -31,12 +38,7 @@ static void at91_fat_start_image(struct pbl_bio *bio,
 	sama5_boot_xload(bb, r4);
 }
 
-static const struct sdhci_instance {
-	void __iomem *base;
-	unsigned id;
-	u8 periph;
-	s8 pins[15];
-} sdhci_instances[] = {
+static const struct xload_instance sama5d2_mci_instances[] = {
 	[0] = {
 		.base = SAMA5D2_BASE_SDHC0, .id = SAMA5D2_ID_SDMMC0, .periph = AT91_MUX_PERIPH_A,
 		.pins = { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 13, 10, 11, 12, -1 }
@@ -54,16 +56,16 @@ static const struct sdhci_instance {
 void __noreturn sama5d2_sdhci_start_image(u32 r4)
 {
 	void *buf = (void *)SAMA5_DDRCS;
-	const struct sdhci_instance *instance;
+	const struct xload_instance *instance;
 	struct pbl_bio bio;
 	const s8 *pin;
 	int ret;
 
 	ret = sama5_bootsource_instance(r4);
-	if (ret > 1)
+	if (ret > ARRAY_SIZE(sama5d2_mci_instances) - 1)
 		panic("Couldn't determine boot MCI instance\n");
 
-	instance = &sdhci_instances[ret];
+	instance = &sama5d2_mci_instances[ret];
 
 	sama5d2_pmc_enable_periph_clock(SAMA5D2_ID_PIOA);
 	for (pin = instance->pins; *pin >= 0; pin++) {
@@ -86,12 +88,7 @@ void __noreturn sama5d2_sdhci_start_image(u32 r4)
 	panic("FAT chainloading failed\n");
 }
 
-static const struct atmci_instance {
-	void __iomem *base;
-	unsigned id;
-	u8 periph;
-	s8 pins[15];
-} sama5d3_atmci_instances[] = {
+static const struct xload_instance sama5d3_mci_instances[] = {
 	[0] = {
 		.base = IOMEM(SAMA5D3_BASE_HSMCI0),
 		.id = SAMA5D3_ID_HSMCI0,
@@ -107,16 +104,16 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 					  unsigned int slot)
 {
 	void *buf = (void *)SAMA5_DDRCS;
-	const struct atmci_instance *instance;
+	const struct xload_instance *instance;
 	struct pbl_bio bio;
 	const s8 *pin;
 	int ret;
 
 	ret = sama5_bootsource_instance(boot_src);
-	if (ret > ARRAY_SIZE(sama5d3_atmci_instances) - 1)
+	if (ret > ARRAY_SIZE(sama5d3_mci_instances) - 1)
 		panic("Couldn't determine boot MCI instance\n");
 
-	instance = &sama5d3_atmci_instances[boot_src];
+	instance = &sama5d3_mci_instances[boot_src];
 
 	sama5d3_pmc_enable_periph_clock(SAMA5D3_ID_PIOD);
 	for (pin = instance->pins; *pin >= 0; pin++) {
-- 
2.39.1




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

* [PATCH 2/7] ARM: at91: xload: Replace magic values with definitions
  2025-03-20  9:14 [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Alexander Shiyan
@ 2025-03-20  9:14 ` Alexander Shiyan
  2025-03-20  9:14 ` [PATCH 3/7] ARM: at91: xload: Remove len argument from at91_fat_start_image() Alexander Shiyan
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alexander Shiyan @ 2025-03-20  9:14 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Shiyan

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 arch/arm/mach-at91/xload.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 4e7e80379f..fee2c715ec 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -40,12 +40,25 @@ static void at91_fat_start_image(struct pbl_bio *bio,
 
 static const struct xload_instance sama5d2_mci_instances[] = {
 	[0] = {
-		.base = SAMA5D2_BASE_SDHC0, .id = SAMA5D2_ID_SDMMC0, .periph = AT91_MUX_PERIPH_A,
-		.pins = { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 13, 10, 11, 12, -1 }
+		.base = SAMA5D2_BASE_SDHC0,
+		.id = SAMA5D2_ID_SDMMC0,
+		.periph = AT91_MUX_PERIPH_A,
+		.pins = {
+			AT91_PIN_PA2, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5,
+			AT91_PIN_PA6, AT91_PIN_PA7, AT91_PIN_PA8, AT91_PIN_PA9,
+			AT91_PIN_PA0, AT91_PIN_PA1, AT91_PIN_PA13, AT91_PIN_PA10,
+			AT91_PIN_PA11, AT91_PIN_PA12, -1
+		}
 	},
 	[1] = {
-		.base = SAMA5D2_BASE_SDHC1, .id = SAMA5D2_ID_SDMMC1, .periph = AT91_MUX_PERIPH_E,
-		.pins = { 18, 19, 20, 21, 22, 28, 30, -1 }
+		.base = SAMA5D2_BASE_SDHC1,
+		.id = SAMA5D2_ID_SDMMC1,
+		.periph = AT91_MUX_PERIPH_E,
+		.pins = {
+			AT91_PIN_PA18, AT91_PIN_PA19, AT91_PIN_PA20,
+			AT91_PIN_PA21, AT91_PIN_PA22, AT91_PIN_PA28,
+			AT91_PIN_PA30, -1
+		}
 	},
 };
 
-- 
2.39.1




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

* [PATCH 3/7] ARM: at91: xload: Remove len argument from at91_fat_start_image()
  2025-03-20  9:14 [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Alexander Shiyan
  2025-03-20  9:14 ` [PATCH 2/7] ARM: at91: xload: Replace magic values with definitions Alexander Shiyan
@ 2025-03-20  9:14 ` Alexander Shiyan
  2025-03-20  9:14 ` [PATCH 4/7] ARM: at91: xload: Use the variable name as described in include/mach/at91/xload.h Alexander Shiyan
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alexander Shiyan @ 2025-03-20  9:14 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Shiyan

The len argument to at91_fat_start_image() is common for all callers,
so it can be removed.
While we're at it, let's reduce the maximum image load size,
since 2M is sufficient for all cases.

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 arch/arm/mach-at91/xload.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index fee2c715ec..4fec02afe1 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -18,14 +18,12 @@ struct xload_instance {
 	s8 pins[15];
 };
 
-static void at91_fat_start_image(struct pbl_bio *bio,
-				 void *buf, unsigned int len,
-				 u32 r4)
+static void at91_fat_start_image(struct pbl_bio *bio, void *buf, u32 r4)
 {
 	void __noreturn (*bb)(void);
 	int ret;
 
-	ret = pbl_fat_load(bio, "barebox.bin", buf, len);
+	ret = pbl_fat_load(bio, "barebox.bin", buf, SZ_2M);
 	if (ret < 0) {
 		pr_err("pbl_fat_load: error %d\n", ret);
 		return;
@@ -95,7 +93,7 @@ void __noreturn sama5d2_sdhci_start_image(u32 r4)
 
 	/* TODO: eMMC boot partition handling: they are not FAT-formatted */
 
-	at91_fat_start_image(&bio, buf, SZ_16M, r4);
+	at91_fat_start_image(&bio, buf, r4);
 
 out_panic:
 	panic("FAT chainloading failed\n");
@@ -131,7 +129,7 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 	sama5d3_pmc_enable_periph_clock(SAMA5D3_ID_PIOD);
 	for (pin = instance->pins; *pin >= 0; pin++) {
 		at91_mux_pio3_pin(IOMEM(SAMA5D3_BASE_PIOD),
-					 pin_to_mask(*pin), instance->periph, 0);
+				  pin_to_mask(*pin), instance->periph, 0);
 	}
 
 	sama5d3_pmc_enable_periph_clock(instance->id);
@@ -140,7 +138,7 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 	if (ret)
 		goto out_panic;
 
-	at91_fat_start_image(&bio, buf, SZ_16M, boot_src);
+	at91_fat_start_image(&bio, buf, boot_src);
 
 out_panic:
 	panic("FAT chainloading failed\n");
-- 
2.39.1




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

* [PATCH 4/7] ARM: at91: xload: Use the variable name as described in include/mach/at91/xload.h
  2025-03-20  9:14 [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Alexander Shiyan
  2025-03-20  9:14 ` [PATCH 2/7] ARM: at91: xload: Replace magic values with definitions Alexander Shiyan
  2025-03-20  9:14 ` [PATCH 3/7] ARM: at91: xload: Remove len argument from at91_fat_start_image() Alexander Shiyan
@ 2025-03-20  9:14 ` Alexander Shiyan
  2025-03-20  9:14 ` [PATCH 5/7] ARM: at91: xload: Remove intermediate variable Alexander Shiyan
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alexander Shiyan @ 2025-03-20  9:14 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Shiyan

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 arch/arm/mach-at91/xload.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 4fec02afe1..94be353c9e 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -111,7 +111,7 @@ static const struct xload_instance sama5d3_mci_instances[] = {
 	},
 };
 
-void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
+void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 					  unsigned int slot)
 {
 	void *buf = (void *)SAMA5_DDRCS;
@@ -120,11 +120,11 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 	const s8 *pin;
 	int ret;
 
-	ret = sama5_bootsource_instance(boot_src);
+	ret = sama5_bootsource_instance(r4);
 	if (ret > ARRAY_SIZE(sama5d3_mci_instances) - 1)
 		panic("Couldn't determine boot MCI instance\n");
 
-	instance = &sama5d3_mci_instances[boot_src];
+	instance = &sama5d3_mci_instances[r4];
 
 	sama5d3_pmc_enable_periph_clock(SAMA5D3_ID_PIOD);
 	for (pin = instance->pins; *pin >= 0; pin++) {
@@ -138,7 +138,7 @@ void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
 	if (ret)
 		goto out_panic;
 
-	at91_fat_start_image(&bio, buf, boot_src);
+	at91_fat_start_image(&bio, buf, r4);
 
 out_panic:
 	panic("FAT chainloading failed\n");
-- 
2.39.1




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

* [PATCH 5/7] ARM: at91: xload: Remove intermediate variable
  2025-03-20  9:14 [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Alexander Shiyan
                   ` (2 preceding siblings ...)
  2025-03-20  9:14 ` [PATCH 4/7] ARM: at91: xload: Use the variable name as described in include/mach/at91/xload.h Alexander Shiyan
@ 2025-03-20  9:14 ` Alexander Shiyan
  2025-03-20  9:14 ` [PATCH 6/7] ARM: at91: xload: Rename the sama5d2 output image names Alexander Shiyan
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Alexander Shiyan @ 2025-03-20  9:14 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Shiyan

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 arch/arm/mach-at91/xload.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 94be353c9e..7a990f35c8 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -20,7 +20,6 @@ struct xload_instance {
 
 static void at91_fat_start_image(struct pbl_bio *bio, void *buf, u32 r4)
 {
-	void __noreturn (*bb)(void);
 	int ret;
 
 	ret = pbl_fat_load(bio, "barebox.bin", buf, SZ_2M);
@@ -29,11 +28,9 @@ static void at91_fat_start_image(struct pbl_bio *bio, void *buf, u32 r4)
 		return;
 	}
 
-	bb = buf;
-
 	sync_caches_for_execution();
 
-	sama5_boot_xload(bb, r4);
+	sama5_boot_xload(buf, r4);
 }
 
 static const struct xload_instance sama5d2_mci_instances[] = {
-- 
2.39.1




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

* [PATCH 6/7] ARM: at91: xload: Rename the sama5d2 output image names
  2025-03-20  9:14 [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Alexander Shiyan
                   ` (3 preceding siblings ...)
  2025-03-20  9:14 ` [PATCH 5/7] ARM: at91: xload: Remove intermediate variable Alexander Shiyan
@ 2025-03-20  9:14 ` Alexander Shiyan
  2025-03-20  9:14 ` [PATCH 7/7] ARM: at91: xload: Add QSPI boot support for SAMA5D2 Alexander Shiyan
  2025-03-20 11:45 ` [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Alexander Shiyan @ 2025-03-20  9:14 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Shiyan

Let's make the sama5d2_start_image() function dependent on the
bootsource rather than MMC-specific, so let's rename the calls
and output image names to reflect that.

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 arch/arm/boards/sama5d27-giantboard/lowlevel.c |  4 ++--
 arch/arm/boards/sama5d27-som1/lowlevel.c       |  4 ++--
 arch/arm/mach-at91/xload.c                     | 15 ++++++++++++++-
 images/Makefile.at91                           | 16 ++++++++--------
 include/mach/at91/xload.h                      |  2 +-
 5 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/arch/arm/boards/sama5d27-giantboard/lowlevel.c b/arch/arm/boards/sama5d27-giantboard/lowlevel.c
index 49540bede0..20042e649d 100644
--- a/arch/arm/boards/sama5d27-giantboard/lowlevel.c
+++ b/arch/arm/boards/sama5d27-giantboard/lowlevel.c
@@ -15,7 +15,7 @@
 /* PCK = 492MHz, MCK = 164MHz */
 #define MASTER_CLOCK	164000000
 
-SAMA5D2_ENTRY_FUNCTION(start_sama5d27_giantboard_xload_mmc, r4)
+SAMA5D2_ENTRY_FUNCTION(start_sama5d27_giantboard_xload, r4)
 {
 	void __iomem *dbgu_base;
 
@@ -31,7 +31,7 @@ SAMA5D2_ENTRY_FUNCTION(start_sama5d27_giantboard_xload_mmc, r4)
 
 	sama5d2_udelay_init(MASTER_CLOCK);
 	sama5d2_d1g_ddrconf();
-	sama5d2_sdhci_start_image(r4);
+	sama5d2_start_image(r4);
 }
 
 extern char __dtb_z_at91_sama5d27_giantboard_start[];
diff --git a/arch/arm/boards/sama5d27-som1/lowlevel.c b/arch/arm/boards/sama5d27-som1/lowlevel.c
index 67300587fe..633e15898e 100644
--- a/arch/arm/boards/sama5d27-som1/lowlevel.c
+++ b/arch/arm/boards/sama5d27-som1/lowlevel.c
@@ -39,7 +39,7 @@ static void ek_turn_led(unsigned color)
 	}
 }
 
-SAMA5D2_ENTRY_FUNCTION(start_sama5d27_som1_ek_xload_mmc, r4)
+SAMA5D2_ENTRY_FUNCTION(start_sama5d27_som1_ek_xload, r4)
 {
 	void __iomem *dbgu_base;
 	sama5d2_lowlevel_init();
@@ -55,7 +55,7 @@ SAMA5D2_ENTRY_FUNCTION(start_sama5d27_som1_ek_xload_mmc, r4)
 	ek_turn_led(RGB_LED_RED | RGB_LED_GREEN); /* Yellow */
 	sama5d2_udelay_init(MASTER_CLOCK);
 	sama5d2_d1g_ddrconf();
-	sama5d2_sdhci_start_image(r4);
+	sama5d2_start_image(r4);
 }
 
 extern char __dtb_z_at91_sama5d27_som1_ek_start[];
diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 7a990f35c8..d3bc6f2dc9 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -61,7 +61,7 @@ static const struct xload_instance sama5d2_mci_instances[] = {
  * sama5d2_sdhci_start_image - Load and start an image from FAT-formatted SDHCI
  * @r4: value of r4 passed by BootROM
  */
-void __noreturn sama5d2_sdhci_start_image(u32 r4)
+static void __noreturn sama5d2_sdhci_start_image(u32 r4)
 {
 	void *buf = (void *)SAMA5_DDRCS;
 	const struct xload_instance *instance;
@@ -96,6 +96,19 @@ void __noreturn sama5d2_sdhci_start_image(u32 r4)
 	panic("FAT chainloading failed\n");
 }
 
+void __noreturn sama5d2_start_image(u32 r4)
+{
+	switch (sama5_bootsource(r4)) {
+	case BOOTSOURCE_MMC:
+		sama5d2_sdhci_start_image(r4);
+		break;
+	default:
+		break;
+	}
+
+	panic("Unsupported boot configuration!\n");
+}
+
 static const struct xload_instance sama5d3_mci_instances[] = {
 	[0] = {
 		.base = IOMEM(SAMA5D3_BASE_HSMCI0),
diff --git a/images/Makefile.at91 b/images/Makefile.at91
index 81e7c22e8b..54f75624ed 100644
--- a/images/Makefile.at91
+++ b/images/Makefile.at91
@@ -42,19 +42,19 @@ pblb-$(CONFIG_MACH_SAMA5D27_SOM1) += start_sama5d27_som1_ek
 FILE_barebox-sama5d27-som1-ek.img = start_sama5d27_som1_ek.pblb
 image-$(CONFIG_MACH_SAMA5D27_SOM1) += barebox-sama5d27-som1-ek.img
 
-pblb-$(CONFIG_MACH_SAMA5D27_SOM1) += start_sama5d27_som1_ek_xload_mmc
-MAX_PBL_IMAGE_SIZE_start_sama5d27_som1_ek_xload_mmc = 0x10000
-FILE_barebox-sama5d27-som1-ek-xload-mmc.img = start_sama5d27_som1_ek_xload_mmc.pblb
-image-$(CONFIG_MACH_SAMA5D27_SOM1) += barebox-sama5d27-som1-ek-xload-mmc.img
+pblb-$(CONFIG_MACH_SAMA5D27_SOM1) += start_sama5d27_som1_ek_xload
+MAX_PBL_IMAGE_SIZE_start_sama5d27_som1_ek_xload = 0x10000
+FILE_barebox-sama5d27-som1-ek-xload.img = start_sama5d27_som1_ek_xload.pblb
+image-$(CONFIG_MACH_SAMA5D27_SOM1) += barebox-sama5d27-som1-ek-xload.img
 
 pblb-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += start_sama5d27_giantboard
 FILE_barebox-groboards-sama5d27-giantboard.img = start_sama5d27_giantboard.pblb
 image-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += barebox-groboards-sama5d27-giantboard.img
 
-pblb-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += start_sama5d27_giantboard_xload_mmc
-FILE_barebox-groboards-sama5d27-giantboard-xload-mmc.img = start_sama5d27_giantboard_xload_mmc.pblb
-MAX_PBL_IMAGE_SIZE_start_sama5d27_giantboard_xload_mmc = 0xffff
-image-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += barebox-groboards-sama5d27-giantboard-xload-mmc.img
+pblb-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += start_sama5d27_giantboard_xload
+FILE_barebox-groboards-sama5d27-giantboard-xload.img = start_sama5d27_giantboard_xload.pblb
+MAX_PBL_IMAGE_SIZE_start_sama5d27_giantboard_xload = 0x10000
+image-$(CONFIG_MACH_SAMA5D27_GIANTBOARD) += barebox-groboards-sama5d27-giantboard-xload.img
 
 pblb-$(CONFIG_MACH_SKOV_ARM9CPU) += start_skov_arm9cpu_xload_mmc
 FILE_barebox-skov-arm9cpu-xload-mmc.img = start_skov_arm9cpu_xload_mmc.pblb
diff --git a/include/mach/at91/xload.h b/include/mach/at91/xload.h
index 2886490246..d5fc7596fd 100644
--- a/include/mach/at91/xload.h
+++ b/include/mach/at91/xload.h
@@ -6,7 +6,7 @@
 #include <linux/compiler.h>
 #include <pbl/bio.h>
 
-void __noreturn sama5d2_sdhci_start_image(u32 r4);
+void __noreturn sama5d2_start_image(u32 r4);
 void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 					  unsigned int slot);
 
-- 
2.39.1




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

* [PATCH 7/7] ARM: at91: xload: Add QSPI boot support for SAMA5D2
  2025-03-20  9:14 [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Alexander Shiyan
                   ` (4 preceding siblings ...)
  2025-03-20  9:14 ` [PATCH 6/7] ARM: at91: xload: Rename the sama5d2 output image names Alexander Shiyan
@ 2025-03-20  9:14 ` Alexander Shiyan
  2025-03-20 11:45 ` [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Alexander Shiyan @ 2025-03-20  9:14 UTC (permalink / raw)
  To: barebox; +Cc: Alexander Shiyan

This adds QSPI NOR boot support for sama5d2 CPUs.
One first-stage (after ROMboot) xload image can now boot from
both MMC and QSPI.

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 arch/arm/mach-at91/xload.c | 84 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index d3bc6f2dc9..5d8105f07f 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <common.h>
+#include <filetype.h>
 #include <mach/at91/xload.h>
 #include <mach/at91/sama5_bootsource.h>
 #include <mach/at91/hardware.h>
@@ -96,12 +97,95 @@ static void __noreturn sama5d2_sdhci_start_image(u32 r4)
 	panic("FAT chainloading failed\n");
 }
 
+static const struct xload_instance sama5d2_qspi_ioset1_instances[] = {
+	[0] = {
+		.base = SAMA5D2_BASE_QSPI0,
+		.id = SAMA5D2_ID_QSPI0,
+		.periph = AT91_MUX_PERIPH_B,
+		.pins = {
+			AT91_PIN_PA0, AT91_PIN_PA1, AT91_PIN_PA2,
+			AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, -1
+		}
+	},
+	[1] = {
+		.base = SAMA5D2_BASE_QSPI1,
+		.id = SAMA5D2_ID_QSPI1,
+		.periph = AT91_MUX_PERIPH_B,
+		.pins = {
+			AT91_PIN_PA6, AT91_PIN_PA7, AT91_PIN_PA8,
+			AT91_PIN_PA9, AT91_PIN_PA10, AT91_PIN_PA11, -1
+		}
+	},
+};
+
+/**
+ * sama5d2_qspi_start_image - Start an image from QSPI NOR flash
+ * @r4: value of r4 passed by BootROM
+ */
+static void __noreturn sama5d2_qspi_start_image(u32 r4)
+{
+	void __iomem *mem, *dest = IOMEM(SAMA5_DDRCS);
+	const struct xload_instance *instance;
+	const s8 *pin;
+	u32 offs;
+	int ret;
+
+	ret = sama5_bootsource_instance(r4);
+	if (ret == 0)
+		mem = SAMA5D2_BASE_QSPI0_MEM;
+	else if (ret == 1)
+		mem = SAMA5D2_BASE_QSPI1_MEM;
+	else
+		panic("Couldn't determine boot QSPI instance\n");
+
+	instance = &sama5d2_qspi_ioset1_instances[ret];
+
+	sama5d2_pmc_enable_periph_clock(SAMA5D2_ID_PIOA);
+	for (pin = instance->pins; *pin >= 0; pin++)
+		at91_mux_pio4_set_periph(SAMA5D2_BASE_PIOA,
+					 BIT(*pin), instance->periph);
+
+	sama5d2_pmc_enable_periph_clock(instance->id);
+
+	/*
+	 * Since we booted from QSPI, we expect the QSPI registers to be
+	 * properly initialized already.
+	 * Let's just read the memory-mapped data.
+	 */
+
+	/* Find barebox pattern first */
+	for (offs = SZ_128K; offs <= SZ_1M; offs += SZ_128K) {
+		/* Fix cache coherency issue by reading each sector only once */
+		memcpy(dest, mem + offs, SZ_128K);
+
+		if (is_barebox_arm_head(dest)) {
+			u32 size = readl(dest + ARM_HEAD_SIZE_OFFSET);
+
+			pr_info("Image found at 0x%08x, size %u\n", offs, size);
+
+			/* Copy remaining barebox code */
+			if (size > SZ_128K)
+				memcpy(dest + SZ_128K, mem + offs + SZ_128K,
+				       size - SZ_128K);
+
+			sync_caches_for_execution();
+
+			sama5_boot_xload(dest, r4);
+		}
+	}
+
+	panic("No barebox image found!\n");
+}
+
 void __noreturn sama5d2_start_image(u32 r4)
 {
 	switch (sama5_bootsource(r4)) {
 	case BOOTSOURCE_MMC:
 		sama5d2_sdhci_start_image(r4);
 		break;
+	case BOOTSOURCE_SPI:
+		sama5d2_qspi_start_image(r4);
+		break;
 	default:
 		break;
 	}
-- 
2.39.1




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

* Re: [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure
  2025-03-20  9:14 [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Alexander Shiyan
                   ` (5 preceding siblings ...)
  2025-03-20  9:14 ` [PATCH 7/7] ARM: at91: xload: Add QSPI boot support for SAMA5D2 Alexander Shiyan
@ 2025-03-20 11:45 ` Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2025-03-20 11:45 UTC (permalink / raw)
  To: barebox, Alexander Shiyan


On Thu, 20 Mar 2025 12:14:13 +0300, Alexander Shiyan wrote:
> The loader function structures use the same members,
> so they can be rewritten to use a single xload_instance structure.
> 
> 

Applied, thanks!

[1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure
      https://git.pengutronix.de/cgit/barebox/commit/?id=de261a15e9e6 (link may not be stable)
[2/7] ARM: at91: xload: Replace magic values with definitions
      https://git.pengutronix.de/cgit/barebox/commit/?id=b0495d1981dd (link may not be stable)
[3/7] ARM: at91: xload: Remove len argument from at91_fat_start_image()
      https://git.pengutronix.de/cgit/barebox/commit/?id=358c761c9943 (link may not be stable)
[4/7] ARM: at91: xload: Use the variable name as described in include/mach/at91/xload.h
      https://git.pengutronix.de/cgit/barebox/commit/?id=6da72bb19dd7 (link may not be stable)
[5/7] ARM: at91: xload: Remove intermediate variable
      https://git.pengutronix.de/cgit/barebox/commit/?id=9dded8d8fb04 (link may not be stable)
[6/7] ARM: at91: xload: Rename the sama5d2 output image names
      https://git.pengutronix.de/cgit/barebox/commit/?id=dca0152f2943 (link may not be stable)
[7/7] ARM: at91: xload: Add QSPI boot support for SAMA5D2
      https://git.pengutronix.de/cgit/barebox/commit/?id=2d47ec01ab52 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2025-03-20 12:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-20  9:14 [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Alexander Shiyan
2025-03-20  9:14 ` [PATCH 2/7] ARM: at91: xload: Replace magic values with definitions Alexander Shiyan
2025-03-20  9:14 ` [PATCH 3/7] ARM: at91: xload: Remove len argument from at91_fat_start_image() Alexander Shiyan
2025-03-20  9:14 ` [PATCH 4/7] ARM: at91: xload: Use the variable name as described in include/mach/at91/xload.h Alexander Shiyan
2025-03-20  9:14 ` [PATCH 5/7] ARM: at91: xload: Remove intermediate variable Alexander Shiyan
2025-03-20  9:14 ` [PATCH 6/7] ARM: at91: xload: Rename the sama5d2 output image names Alexander Shiyan
2025-03-20  9:14 ` [PATCH 7/7] ARM: at91: xload: Add QSPI boot support for SAMA5D2 Alexander Shiyan
2025-03-20 11:45 ` [PATCH 1/7] ARM: at91: xload: Unify loader functions to use a single xload_instance structure Sascha Hauer

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