Skip to contentSkip to conversation

Add support for dynamic overriding of default SF bus

PATCH Superseded Vaishnav Achath 2 participants 5 messages May 9, 2022 – May 11, 2022

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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.

Vaishnav Achath (2):
common: spl: spl_spi: add support for dynamic detection of sf bus
arm: k3: j721e: enable dynamic sf bus detect support for j721e

 arch/arm/mach-k3/j721e_init.c   | 17 +++++++++++++++++
 arch/arm/mach-k3/sysfw-loader.c |  6 ++++--
 common/spl/Kconfig              |  4 ++++
 common/spl/spl_spi.c            | 19 +++++++++++++++++--
 configs/j721e_evm_a72_defconfig |  1 +
 configs/j721e_evm_r5_defconfig  |  1 +
 include/spl.h                   | 18 ++++++++++++++++++
 7 files changed, 62 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 common: spl: spl_spi: add support for dynamic detection 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 devic, when not overridden the lookup functions are
weakly defined in common/spl/spl_spi.c.

---
 common/spl/Kconfig   |  4 ++++
 common/spl/spl_spi.c | 19 +++++++++++++++++--
 include/spl.h        | 18 ++++++++++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)
common/spl/Kconfig +4 -0
index ac61b25a06..b13492b6a2 100644
@@ -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
common/spl/spl_spi.c +17 -2
index cf3f7ef4c0..f08c4752ce 100644
@@ -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) {
include/spl.h +18 -0
index 6134aba857..7ee6d0216b 100644
@@ -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
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/2] common: spl: spl_spi: add support for dynamic detection of sf bus

Hello Achat,

Quoted 23 lines · Vaishnav Achath

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.

---
 common/spl/Kconfig   |  4 ++++
 common/spl/spl_spi.c | 19 +++++++++++++++++--
 include/spl.h        | 18 ++++++++++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)
common/spl/Kconfig +0 -0
index ac61b25a06..b13492b6a2 100644

common/spl/Kconfig config SPL_SPI_FLASH_SUPPORT · line 1108

Quoted 6 lines
common/spl/Kconfig +3 -0
@@ -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

Do you really need here a new Kconfig option? I think you can drop it...

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#3 lore raw

Re: [EXTERNAL] Re: [PATCH 1/2] common: spl: spl_spi: add support for dynamic detection of sf bus

Hi Heiko,

Quoted 29 lines · Heiko Schocher

Hello Achat,

Quoted 26 lines · Vaishnav Achath

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.

---
  common/spl/Kconfig   |  4 ++++
  common/spl/spl_spi.c | 19 +++++++++++++++++--
  include/spl.h        | 18 ++++++++++++++++++
  3 files changed, 39 insertions(+), 2 deletions(-)
common/spl/Kconfig +0 -0
index ac61b25a06..b13492b6a2 100644
@@ -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.
 
Quoted 6 lines

common/spl/Kconfig config SPL_SPI_FLASH_SUPPORT · line 1108

Quoted 3 lines
common/spl/Kconfig +3 -0
+config SPL_DYNAMIC_SF_BUS_DETECT
+	bool "Detect which SPI flash to load from"
+	depends on SPL_SPI_FLASH_SUPPORT

Do you really need here a new Kconfig option? I think you can drop it...

adding the Kconfig option is not necessary, will drop it in V2. Thank you for the feedback.

Quoted 3 lines

bye,
Heiko

Signature · 2 lines
Thanks and Regards,
Vaishnav
#4 lore raw

PATCH 2/2 arm: k3: j721e: enable dynamic sf bus detect support for j721e

In reply to Vaishnav Achath

implement 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.

Also enable the CONFIG_SPL_DYNAMIC_SF_BUS_DETECT for j721e R5 and A72.

---
 arch/arm/mach-k3/j721e_init.c   | 17 +++++++++++++++++
 arch/arm/mach-k3/sysfw-loader.c |  6 ++++--
 configs/j721e_evm_a72_defconfig |  1 +
 configs/j721e_evm_r5_defconfig  |  1 +
 4 files changed, 23 insertions(+), 2 deletions(-)
arch/arm/mach-k3/j721e_init.c +17 -0
index f503f15f19..82391b5cf8 100644
@@ -355,6 +355,23 @@ 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;
+}
+
+/* both OSPI and QSPI flash are in CS0 */
+u32 spl_spi_boot_cs(void)
+{
+	return 0;
+}
+
 u32 spl_boot_device(void)
 {
 	u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
arch/arm/mach-k3/sysfw-loader.c +4 -2
index 5e48c36ccd..ef9d7e9c91 100644
@@ -324,9 +324,11 @@ static void *k3_sysfw_get_spi_addr(void)
 	struct udevice *dev;
 	fdt_addr_t addr;
 	int ret;
+	unsigned int sf_bus = CONFIG_SF_DEFAULT_BUS;
 
-	ret = uclass_find_device_by_seq(UCLASS_SPI, CONFIG_SF_DEFAULT_BUS,
-					&dev);
+	if (IS_ENABLED(CONFIG_SPL_DYNAMIC_SF_BUS_DETECT))
+		sf_bus = spl_spi_boot_bus();
+	ret = uclass_find_device_by_seq(UCLASS_SPI, sf_bus, &dev);
 	if (ret)
 		return NULL;
 
configs/j721e_evm_a72_defconfig +1 -0
index 931abf5e59..18ba759da3 100644
@@ -127,6 +127,7 @@ CONFIG_MMC_SDHCI_AM654=y
 CONFIG_MTD=y
 CONFIG_DM_MTD=y
 CONFIG_MTD_NOR_FLASH=y
+CONFIG_SPL_DYNAMIC_SF_BUS_DETECT=y
 CONFIG_CFI_FLASH=y
 CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
 CONFIG_FLASH_CFI_MTD=y
configs/j721e_evm_r5_defconfig +1 -0
index 6553212de8..c437d3c118 100644
@@ -21,6 +21,7 @@ CONFIG_SPL_FS_FAT=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
+CONFIG_SPL_DYNAMIC_SF_BUS_DETECT=y
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_SPL_LOAD_FIT_ADDRESS=0x80080000
Signature · 1 line
2.17.1