[PATCH 1/2] common: spl: spl_spi: add support for dynamic detection of sf bus
Vaishnav Achath
vaishnav.a at ti.com
Mon May 9 08:43:02 CEST 2022
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 devic, when not overridden the lookup functions are
weakly defined in common/spl/spl_spi.c.
Signed-off-by: Vaishnav Achath <vaishnav.a at ti.com>
---
common/spl/Kconfig | 4 ++++
common/spl/spl_spi.c | 19 +++++++++++++++++--
include/spl.h | 18 ++++++++++++++++++
3 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index ac61b25a06..b13492b6a2 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -1103,6 +1103,10 @@ config SPL_SPI_FLASH_SUPPORT
lines). This enables the drivers in drivers/mtd/spi as part of an
SPL build. This normally requires SPL_SPI.
+config SPL_DYNAMIC_SF_BUS_DETECT
+ bool "Detect which SPI flash to load from"
+ depends on SPL_SPI_FLASH_SUPPORT
+
if SPL_SPI_FLASH_SUPPORT
config SPL_SPI_FLASH_TINY
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index cf3f7ef4c0..f08c4752ce 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -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,20 @@ 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 = CONFIG_SF_DEFAULT_BUS;
+ unsigned int sf_cs = CONFIG_SF_DEFAULT_CS;
/*
* Load U-Boot image from SPI flash into RAM
* In DM mode: defaults speed and mode will be
* taken from DT when available
*/
+ if (IS_ENABLED(CONFIG_SPL_DYNAMIC_SF_BUS_DETECT)) {
+ sf_bus = spl_spi_boot_bus();
+ sf_cs = spl_spi_boot_cs();
+ }
- 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) {
diff --git a/include/spl.h b/include/spl.h
index 6134aba857..7ee6d0216b 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -361,6 +361,24 @@ int spl_load_imx_container(struct spl_image_info *spl_image,
void preloader_console_init(void);
u32 spl_boot_device(void);
+#ifdef CONFIG_SPL_DYNAMIC_SF_BUS_DETECT
+/**
+ * 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);
+#endif
+
/**
* 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
--
2.17.1
More information about the U-Boot
mailing list