Add support for dynamic overriding of default SF bus
Subsystems (2)
v3 cover Add support for dynamic overriding of default SF bus
Currently the SPI flash to load from is defined through the compile time config CONFIG_SF_DEFAULT_BUS and CONFIG_SF_DEFAULT_CS, this prevents the loading of binaries from different SPI flash using the same build.
This series adds support for choosing the flash device based on the selected boot device thus allowing platforms to override the SF_BUS and SF_CS to load from the desired flash.
Changes tested on J721E for OSPI and QSPI boot.
V1->V2:
* drop unnecessary Kconfig option for SF bus override, suggested by Heiko Schocher.V2->V3
* drop unnecessary spl_spi_boot_cs() override for J721E, suggested by Pratyush Yadav
Vaishnav Achath (2):
common: spl: spl_spi: add support for dynamic override of sf bus
arm: k3: j721e: add dynamic sf bus override support for j721e
arch/arm/mach-k3/j721e_init.c | 11 +++++++++++ arch/arm/mach-k3/sysfw-loader.c | 4 ++-- common/spl/spl_spi.c | 16 +++++++++++++--- include/spl.h | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/2 common: spl: spl_spi: add support for dynamic override of sf bus
Currently the SPI flash to load from is defined through the compile time config CONFIG_SF_DEFAULT_BUS and CONFIG_SF_DEFAULT_CS, this prevents the loading of binaries from different SPI flash using the same build.E.g. supporting QSPI flash boot and OSPI flash boot on J721E platform is not possible due to this limitation.
This commit adds lookup functions spl_spi_boot_bus() and spl_spi_boot_cs for identifying the flash device based on the selected boot device, when not overridden the lookup functions are weakly defined in common/spl/spl_spi.c.
---
V1->V2 : removed newly introduced CONFIG_SPL_DYNAMIC_SF_BUS_DETECT. common/spl/spl_spi.c | 16 +++++++++++++--- include/spl.h | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-)
common/spl/spl_spi.c +13 -3
@@ -71,6 +71,16 @@ unsigned int __weak spl_spi_get_uboot_offs(struct spi_flash *flash)return CONFIG_SYS_SPI_U_BOOT_OFFS ; } +u32 __weak spl_spi_boot_bus (void ) +{ +return CONFIG_SF_DEFAULT_BUS ; +} + +u32 __weak spl_spi_boot_cs (void ) +{ +return CONFIG_SF_DEFAULT_CS ; +} +/* * The main entry for SPI booting. It's necessary that SDRAM is already * configured and available since this code loads the main U-Boot image
@@ -83,15 +93,15 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,unsigned int payload_offs;struct spi_flash *flash;struct image_header *header; +unsigned int sf_bus =spl_spi_boot_bus (); +unsigned int sf_cs =spl_spi_boot_cs ();/* * Load U-Boot image from SPI flash into RAM * In DM mode: defaults speed and mode will be * taken from DT when available */ - - flash =spi_flash_probe (CONFIG_SF_DEFAULT_BUS , -CONFIG_SF_DEFAULT_CS , + flash =spi_flash_probe (sf_bus, sf_cs,CONFIG_SF_DEFAULT_SPEED ,CONFIG_SF_DEFAULT_MODE );if (!flash) {
include/spl.h +16 -0
@@ -377,6 +377,22 @@ int spl_load_imx_container(struct spl_image_info *spl_image,void preloader_console_init (void );u32 spl_boot_device (void ); +/** +* spl_spi_boot_bus() - Lookup function for the SPI boot bus source. +* +* This function returns the SF bus to load from. +* If not overridden, it is weakly defined in common/spl/spl_spi.c. +*/ +u32 spl_spi_boot_bus (void ); + +/** +* spl_spi_boot_cs() - Lookup function for the SPI boot CS source. +* +* This function returns the SF CS to load from. +* If not overridden, it is weakly defined in common/spl/spl_spi.c. +*/ +u32 spl_spi_boot_cs (void ); +/** * spl_mmc_boot_mode() - Lookup function for the mode of an MMC boot source. * @boot_device: ID of the device which the MMC driver wants to read
Signature · 1 line
2.17.1
Re: [PATCH v3 1/2] common: spl: spl_spi: add support for dynamic override of sf bus
Quoted 6 lines · Vaishnav Achath
Currently the SPI flash to load from is defined through the compile time config
CONFIG_SF_DEFAULT_BUSandCONFIG_SF_DEFAULT_CS, this prevents the loading of binaries from different SPI flash using the same build.E.g. supporting QSPI flash boot and OSPI flash boot on J721E platform is not possible due to this limitation.
Quoted 7 lines
This commit adds lookup functions
spl_spi_boot_bus()andspl_spi_boot_csfor identifying the flash device based on the selected boot device, when not overridden the lookup functions are weakly defined incommon/spl/spl_spi.c.Signed-off-by Vaishnav Achath <[email protected]>Reviewed-by Heiko Schocher <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom
PATCH v3 2/2 arm: k3: j721e: add dynamic sf bus override support for j721e
In reply to Vaishnav Achathimplement overrides for spl_spi_boot_bus() and spl_spi_boot_cs() lookup functions according to bootmode selection, so as to support both QSPI and OSPI boot using the same build.
---
V2->V3 : removed unnecessary spl_spi_boot_cs() override for J721E arch/arm/mach-k3/j721e_init.c | 11 +++++++++++ arch/arm/mach-k3/sysfw-loader.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-)
arch/arm/mach-k3/j721e_init.c +11 -0
@@ -355,6 +355,17 @@ static u32 __get_primary_bootmedia(u32 main_devstat, u32 wkup_devstat)return bootmode; } +u32 spl_spi_boot_bus (void ) +{ +u32 wkup_devstat =readl (CTRLMMR_WKUP_DEVSTAT ); +u32 main_devstat =readl (CTRLMMR_MAIN_DEVSTAT ); +u32 bootmode = ((wkup_devstat &WKUP_DEVSTAT_PRIMARY_BOOTMODE_MASK ) >> +WKUP_DEVSTAT_PRIMARY_BOOTMODE_SHIFT ) | + ((main_devstat &MAIN_DEVSTAT_BOOT_MODE_B_MASK ) <<BOOT_MODE_B_SHIFT ); + +return (bootmode ==BOOT_DEVICE_QSPI ) ?1 :0 ; +} +u32 spl_boot_device (void ) {u32 wkup_devstat =readl (CTRLMMR_WKUP_DEVSTAT );
arch/arm/mach-k3/sysfw-loader.c +2 -2
@@ -324,9 +324,9 @@ static void *k3_sysfw_get_spi_addr(void)struct udevice *dev;fdt_addr_t addr;int ret; +unsigned int sf_bus =spl_spi_boot_bus (); - ret =uclass_find_device_by_seq (UCLASS_SPI ,CONFIG_SF_DEFAULT_BUS , - &dev); + ret =uclass_find_device_by_seq (UCLASS_SPI , sf_bus, &dev);if (ret)return NULL ;
Signature · 1 line
2.17.1
Re: [PATCH v3 2/2] arm: k3: j721e: add dynamic sf bus override support for j721e
Quoted 6 lines · Vaishnav Achath
implement overrides for
spl_spi_boot_bus()andspl_spi_boot_cs()lookup functions according to bootmode selection, so as to support both QSPI and OSPI boot using the same build.Signed-off-by Vaishnav Achath <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>
Applied to u-boot/next, thanks!
Signature · 1 line
Tom