Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0DA5EC433F5 for ; Mon, 9 May 2022 12:18:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 81FF983F35; Mon, 9 May 2022 14:17:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="E6AeATuT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5188682A53; Mon, 9 May 2022 08:43:18 +0200 (CEST) Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D9DD983E49 for ; Mon, 9 May 2022 08:43:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=vaishnav.a@ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 2496h75D128945; Mon, 9 May 2022 01:43:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1652078587; bh=fGLDm8LJlj7YAYffwY2kAZDWQEL4gAdU+FDtiyusuFw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=E6AeATuT6IZ/K/I1g10Rwv9jmsWQMNacHhRmZgG3VW7dAJmrEvIwQanX2krqUczxV yeUlMLULYgHpWlq/SYdhzmexy6l2vZq47UDLkWVDLWsmzvhgn5TwMk4+oqqLngclRD ssqPkUPSXFDFDgweK2JKbuBnxjz1KtrMK+d+gPp0= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 2496h70u002442 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 9 May 2022 01:43:07 -0500 Received: from DLEE107.ent.ti.com (157.170.170.37) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Mon, 9 May 2022 01:43:07 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14 via Frontend Transport; Mon, 9 May 2022 01:43:07 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 2496h5pY033336; Mon, 9 May 2022 01:43:06 -0500 From: Vaishnav Achath To: , , , , , , , , , , , , , , , CC: Subject: [PATCH 1/2] common: spl: spl_spi: add support for dynamic detection of sf bus Date: Mon, 9 May 2022 12:13:02 +0530 Message-ID: <20220509064303.28507-2-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220509064303.28507-1-vaishnav.a@ti.com> References: <20220509064303.28507-1-vaishnav.a@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Mailman-Approved-At: Mon, 09 May 2022 14:15:58 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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 --- 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