ARM: at91: xload: Unify loader functions to use a single xload_instance structure
Subsystems (4)
PATCH 1/7 ARM: at91: xload: Unify loader functions to use a single xload_instance structure
The loader function structures use the same members,
so they can be rewritten to use a single xload_instance structure.
--- arch/arm/mach-at91/xload.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)
arch/arm/mach-at91/xload.c +15 -18
@@ -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++) {
Signature · 1 line
2.39.1
PATCH 2/7 ARM: at91: xload: Replace magic values with definitions
--- arch/arm/mach-at91/xload.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
arch/arm/mach-at91/xload.c +17 -4
@@ -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 + } }, };
Signature · 1 line
2.39.1
PATCH 3/7 ARM: at91: xload: Remove len argument from at91_fat_start_image()
In reply to Alexander ShiyanThe 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.
--- arch/arm/mach-at91/xload.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
arch/arm/mach-at91/xload.c +5 -7
@@ -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" );
Signature · 1 line
2.39.1
PATCH 4/7 ARM: at91: xload: Use the variable name as described in include/mach/at91/xload.h
In reply to Alexander Shiyan--- arch/arm/mach-at91/xload.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm/mach-at91/xload.c +4 -4
@@ -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" );
Signature · 1 line
2.39.1
PATCH 5/7 ARM: at91: xload: Remove intermediate variable
In reply to Alexander Shiyan--- arch/arm/mach-at91/xload.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
arch/arm/mach-at91/xload.c +1 -4
@@ -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[] = {
Signature · 1 line
2.39.1
PATCH 6/7 ARM: at91: xload: Rename the sama5d2 output image names
In reply to Alexander ShiyanLet'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.
--- 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(-)
arch/arm/boards/sama5d27-giantboard/lowlevel.c +2 -2
@@ -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[];
arch/arm/boards/sama5d27-som1/lowlevel.c +2 -2
@@ -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[];
arch/arm/mach-at91/xload.c +14 -1
@@ -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 ),
images/Makefile.at91 +8 -8
@@ -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
include/mach/at91/xload.h +1 -1
@@ -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);
Signature · 1 line
2.39.1
PATCH 7/7 ARM: at91: xload: Add QSPI boot support for SAMA5D2
In reply to Alexander ShiyanThis adds QSPI NOR boot support for sama5d2 CPUs. One first-stage (after ROMboot) xload image can now boot from both MMC and QSPI.
--- arch/arm/mach-at91/xload.c | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+)
arch/arm/mach-at91/xload.c +84 -0
@@ -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 ; }
Signature · 1 line
2.39.1
Sascha Hauer
AppliedQuoted 4 lines · Alexander Shiyan
The loader function structures use the same members,
so they can be rewritten to use a singlexload_instancestructure.
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,
Signature · 1 line
Sascha Hauer <[email protected]>