All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2]  Add support for dynamic overriding of default SF bus
@ 2022-05-11  6:03 Vaishnav Achath
  2022-05-11  6:03 ` [PATCH v2 1/2] common: spl: spl_spi: add support for dynamic override of sf bus Vaishnav Achath
  2022-05-11  6:03 ` [PATCH v2 2/2] arm: k3: j721e: add dynamic sf bus override support for j721e Vaishnav Achath
  0 siblings, 2 replies; 7+ messages in thread
From: Vaishnav Achath @ 2022-05-11  6:03 UTC (permalink / raw)
  To: hs, u-boot, sjg, mr.nuke.me, jh80.chung, michal.simek,
	marek.behun, pali, sr, marex, ricardo, vigneshr, s-anna, kishon,
	j-keerthy, p.yadav
  Cc: vaishnav.a

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.

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   | 17 +++++++++++++++++
 arch/arm/mach-k3/sysfw-loader.c |  4 ++--
 common/spl/spl_spi.c            | 16 +++++++++++++---
 include/spl.h                   | 16 ++++++++++++++++
 4 files changed, 48 insertions(+), 5 deletions(-)

-- 
2.17.1


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

* [PATCH v2 1/2] common: spl: spl_spi: add support for dynamic override of sf bus
  2022-05-11  6:03 [PATCH v2 0/2] Add support for dynamic overriding of default SF bus Vaishnav Achath
@ 2022-05-11  6:03 ` Vaishnav Achath
  2022-05-11  8:24   ` Heiko Schocher
  2022-05-31  8:59   ` Pratyush Yadav
  2022-05-11  6:03 ` [PATCH v2 2/2] arm: k3: j721e: add dynamic sf bus override support for j721e Vaishnav Achath
  1 sibling, 2 replies; 7+ messages in thread
From: Vaishnav Achath @ 2022-05-11  6:03 UTC (permalink / raw)
  To: hs, u-boot, sjg, mr.nuke.me, jh80.chung, michal.simek,
	marek.behun, pali, sr, marex, ricardo, vigneshr, s-anna, kishon,
	j-keerthy, p.yadav
  Cc: vaishnav.a

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.

Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
---
 common/spl/spl_spi.c | 16 +++++++++++++---
 include/spl.h        | 16 ++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index cf3f7ef4c0..3eef2f8d68 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,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) {
diff --git a/include/spl.h b/include/spl.h
index 6134aba857..438f2fdf7c 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -361,6 +361,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
-- 
2.17.1


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

* [PATCH v2 2/2] arm: k3: j721e: add dynamic sf bus override support for j721e
  2022-05-11  6:03 [PATCH v2 0/2] Add support for dynamic overriding of default SF bus Vaishnav Achath
  2022-05-11  6:03 ` [PATCH v2 1/2] common: spl: spl_spi: add support for dynamic override of sf bus Vaishnav Achath
@ 2022-05-11  6:03 ` Vaishnav Achath
  2022-05-31 10:59   ` Pratyush Yadav
  1 sibling, 1 reply; 7+ messages in thread
From: Vaishnav Achath @ 2022-05-11  6:03 UTC (permalink / raw)
  To: hs, u-boot, sjg, mr.nuke.me, jh80.chung, michal.simek,
	marek.behun, pali, sr, marex, ricardo, vigneshr, s-anna, kishon,
	j-keerthy, p.yadav
  Cc: vaishnav.a

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.

Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
---
 arch/arm/mach-k3/j721e_init.c   | 17 +++++++++++++++++
 arch/arm/mach-k3/sysfw-loader.c |  4 ++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index f503f15f19..82391b5cf8 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -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);
diff --git a/arch/arm/mach-k3/sysfw-loader.c b/arch/arm/mach-k3/sysfw-loader.c
index 5e48c36ccd..8ff36759c1 100644
--- a/arch/arm/mach-k3/sysfw-loader.c
+++ b/arch/arm/mach-k3/sysfw-loader.c
@@ -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;
 
-- 
2.17.1


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

* Re: [PATCH v2 1/2] common: spl: spl_spi: add support for dynamic override of sf bus
  2022-05-11  6:03 ` [PATCH v2 1/2] common: spl: spl_spi: add support for dynamic override of sf bus Vaishnav Achath
@ 2022-05-11  8:24   ` Heiko Schocher
  2022-05-12  6:28     ` Vaishnav Achath
  2022-05-31  8:59   ` Pratyush Yadav
  1 sibling, 1 reply; 7+ messages in thread
From: Heiko Schocher @ 2022-05-11  8:24 UTC (permalink / raw)
  To: Vaishnav Achath, u-boot, sjg, mr.nuke.me, jh80.chung,
	michal.simek, marek.behun, pali, sr, marex, ricardo, vigneshr,
	s-anna, kishon, j-keerthy, p.yadav

Hello Achath,

On 11.05.22 08:03, Vaishnav Achath wrote:
> 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.
> 
> Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
> ---

you miss here change history. May you want to look into patman tool in

u-boot:/tools/patman/README

which can help you here much.

>  common/spl/spl_spi.c | 16 +++++++++++++---
>  include/spl.h        | 16 ++++++++++++++++
>  2 files changed, 29 insertions(+), 3 deletions(-)

Looks fine for me, thanks!

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
-- 
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: hs@denx.de

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

* Re: [PATCH v2 1/2] common: spl: spl_spi: add support for dynamic override of sf bus
  2022-05-11  8:24   ` Heiko Schocher
@ 2022-05-12  6:28     ` Vaishnav Achath
  0 siblings, 0 replies; 7+ messages in thread
From: Vaishnav Achath @ 2022-05-12  6:28 UTC (permalink / raw)
  To: hs, u-boot, sjg, mr.nuke.me, jh80.chung, michal.simek,
	marek.behun, pali, sr, marex, ricardo, Raghavendra, Vignesh,
	Anna, Suman, Kishon Vijay Abraham, J, KEERTHY, Yadav, Pratyush

Hi Heiko,

On 11/05/22 13:54, Heiko Schocher wrote:
> Hello Achath,
> 
> On 11.05.22 08:03, Vaishnav Achath wrote:
>> 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.
>>
>> Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
>> ---
> 
> you miss here change history. May you want to look into patman tool in
> 
> u-boot:/tools/patman/README
> 
> which can help you here much.
> 
Noted, sorry I missed this, will wait for further feedback and
include the change history in next revision, please let me
know if a v3 with the change history alone fixed is required.
>>   common/spl/spl_spi.c | 16 +++++++++++++---
>>   include/spl.h        | 16 ++++++++++++++++
>>   2 files changed, 29 insertions(+), 3 deletions(-)
> 
> Looks fine for me, thanks!
> 
> Reviewed-by: Heiko Schocher <hs@denx.de>
> 
Thank you for the review.
> bye,
> Heiko

-- 
Regards,
Vaishnav

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

* Re: [PATCH v2 1/2] common: spl: spl_spi: add support for dynamic override of sf bus
  2022-05-11  6:03 ` [PATCH v2 1/2] common: spl: spl_spi: add support for dynamic override of sf bus Vaishnav Achath
  2022-05-11  8:24   ` Heiko Schocher
@ 2022-05-31  8:59   ` Pratyush Yadav
  1 sibling, 0 replies; 7+ messages in thread
From: Pratyush Yadav @ 2022-05-31  8:59 UTC (permalink / raw)
  To: Vaishnav Achath
  Cc: hs, u-boot, sjg, mr.nuke.me, jh80.chung, michal.simek,
	marek.behun, pali, sr, marex, ricardo, vigneshr, s-anna, kishon,
	j-keerthy

On 11/05/22 11:33AM, Vaishnav Achath wrote:
> 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.
> 
> Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

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

* Re: [PATCH v2 2/2] arm: k3: j721e: add dynamic sf bus override support for j721e
  2022-05-11  6:03 ` [PATCH v2 2/2] arm: k3: j721e: add dynamic sf bus override support for j721e Vaishnav Achath
@ 2022-05-31 10:59   ` Pratyush Yadav
  0 siblings, 0 replies; 7+ messages in thread
From: Pratyush Yadav @ 2022-05-31 10:59 UTC (permalink / raw)
  To: Vaishnav Achath
  Cc: hs, u-boot, sjg, mr.nuke.me, jh80.chung, michal.simek,
	marek.behun, pali, sr, marex, ricardo, vigneshr, s-anna, kishon,
	j-keerthy

Hi Vaishnav,

On 11/05/22 11:33AM, Vaishnav Achath wrote:
> 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.
> 
> Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
> ---
>  arch/arm/mach-k3/j721e_init.c   | 17 +++++++++++++++++
>  arch/arm/mach-k3/sysfw-loader.c |  4 ++--
>  2 files changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
> index f503f15f19..82391b5cf8 100644
> --- a/arch/arm/mach-k3/j721e_init.c
> +++ b/arch/arm/mach-k3/j721e_init.c
> @@ -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;
> +}
> +

I don't think we need to hard-code the chip select here. Let that come 
from the config. Other than this,

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

>  u32 spl_boot_device(void)
>  {
>  	u32 wkup_devstat = readl(CTRLMMR_WKUP_DEVSTAT);
> diff --git a/arch/arm/mach-k3/sysfw-loader.c b/arch/arm/mach-k3/sysfw-loader.c
> index 5e48c36ccd..8ff36759c1 100644
> --- a/arch/arm/mach-k3/sysfw-loader.c
> +++ b/arch/arm/mach-k3/sysfw-loader.c
> @@ -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;
>  
> -- 
> 2.17.1
> 

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

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

end of thread, other threads:[~2022-05-31 10:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-11  6:03 [PATCH v2 0/2] Add support for dynamic overriding of default SF bus Vaishnav Achath
2022-05-11  6:03 ` [PATCH v2 1/2] common: spl: spl_spi: add support for dynamic override of sf bus Vaishnav Achath
2022-05-11  8:24   ` Heiko Schocher
2022-05-12  6:28     ` Vaishnav Achath
2022-05-31  8:59   ` Pratyush Yadav
2022-05-11  6:03 ` [PATCH v2 2/2] arm: k3: j721e: add dynamic sf bus override support for j721e Vaishnav Achath
2022-05-31 10:59   ` Pratyush Yadav

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.