From patchwork Mon May 24 00:36:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 1482584 X-Patchwork-Delegate: andre.przywara@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FpJG5657vz9s5R for ; Mon, 24 May 2021 10:37:49 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E0A6E82E82; Mon, 24 May 2021 02:37:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 632A782E6A; Mon, 24 May 2021 02:37:18 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 2AE1382E4E for ; Mon, 24 May 2021 02:37:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1EC4C113E; Sun, 23 May 2021 17:37:08 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9CE913F73D; Sun, 23 May 2021 17:37:06 -0700 (PDT) From: Andre Przywara To: Simon Glass , Jagan Teki Cc: u-boot@lists.denx.de, linux-sunxi@lists.linux.dev, Patrick Delaunay , Sean Anderson , Heiko Schocher , Kever Yang , Philipp Tomsich Subject: [RFC PATCH 1/3] fastboot: Allow runtime determination of MMC device Date: Mon, 24 May 2021 01:36:48 +0100 Message-Id: <20210524003650.24469-2-andre.przywara@arm.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20210524003650.24469-1-andre.przywara@arm.com> References: <20210524003650.24469-1-andre.przywara@arm.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean At the moment the fastboot code relies on the Kconfig variable CONFIG_FASTBOOT_FLASH_MMC_DEV to point to the MMC device to use for the flash command. This value needs to be the *U-Boot device number*, which recently got more dynamic, and depends on other MMC nodes in the devicetree, but also on mmc aliases defined. This leads to situations where it's hard to fix this number at compile time, because a WiFi device might enumerate before the wanted eMMC device, for instance. To avoid this fragile situation, allow this value to be determined at runtime. This decision is probably platform specific, so introduce a weak function that returns the needed number, and use that everywhere instead of the Kconfig variable. For now the default implementation just returns this very Kconfig variable, but this can be overwritten by platforms later. No functional change at this point. Signed-off-by: Andre Przywara --- drivers/fastboot/fb_command.c | 6 +++--- drivers/fastboot/fb_common.c | 3 ++- drivers/fastboot/fb_mmc.c | 12 ++++++++---- include/fastboot.h | 7 +++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c index 3a5db5b08fc..77184901505 100644 --- a/drivers/fastboot/fb_command.c +++ b/drivers/fastboot/fb_command.c @@ -452,7 +452,7 @@ static void oem_format(char *cmd_parameter, char *response) fastboot_fail("partitions not set", response); } else { sprintf(cmdbuf, "gpt write mmc %x $partitions", - CONFIG_FASTBOOT_FLASH_MMC_DEV); + fastboot_get_mmc_device()); if (run_command(cmdbuf, 0)) fastboot_fail("", response); else @@ -479,7 +479,7 @@ static void oem_partconf(char *cmd_parameter, char *response) /* execute 'mmc partconfg' command with cmd_parameter arguments*/ snprintf(cmdbuf, sizeof(cmdbuf), "mmc partconf %x %s 0", - CONFIG_FASTBOOT_FLASH_MMC_DEV, cmd_parameter); + fastboot_get_mmc_device(), cmd_parameter); printf("Execute: %s\n", cmdbuf); if (run_command(cmdbuf, 0)) fastboot_fail("Cannot set oem partconf", response); @@ -506,7 +506,7 @@ static void oem_bootbus(char *cmd_parameter, char *response) /* execute 'mmc bootbus' command with cmd_parameter arguments*/ snprintf(cmdbuf, sizeof(cmdbuf), "mmc bootbus %x %s", - CONFIG_FASTBOOT_FLASH_MMC_DEV, cmd_parameter); + fastboot_get_mmc_device(), cmd_parameter); printf("Execute: %s\n", cmdbuf); if (run_command(cmdbuf, 0)) fastboot_fail("Cannot set oem bootbus", response); diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c index cbcc3683c47..a64fefc7d72 100644 --- a/drivers/fastboot/fb_common.c +++ b/drivers/fastboot/fb_common.c @@ -101,7 +101,8 @@ int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) if (reason >= FASTBOOT_REBOOT_REASONS_COUNT) return -EINVAL; - return bcb_write_reboot_reason(CONFIG_FASTBOOT_FLASH_MMC_DEV, "misc", boot_cmds[reason]); + return bcb_write_reboot_reason(fastboot_get_mmc_device(), "misc", + boot_cmds[reason]); #else return -EINVAL; #endif diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index 2f3837e5591..c97e88a3bbd 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -76,13 +76,18 @@ static int raw_part_get_info_by_name(struct blk_desc *dev_desc, return 0; } +int __weak fastboot_get_mmc_device(void) +{ + return CONFIG_FASTBOOT_FLASH_MMC_DEV; +} + static int do_get_part_info(struct blk_desc **dev_desc, const char *name, struct disk_partition *info) { int ret; /* First try partition names on the default device */ - *dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); + *dev_desc = blk_get_dev("mmc", fastboot_get_mmc_device()); if (*dev_desc) { ret = part_get_info_by_name(*dev_desc, name, info); if (ret >= 0) @@ -489,8 +494,7 @@ int fastboot_mmc_get_part_info(const char *part_name, static struct blk_desc *fastboot_mmc_get_dev(char *response) { - struct blk_desc *ret = blk_get_dev("mmc", - CONFIG_FASTBOOT_FLASH_MMC_DEV); + struct blk_desc *ret = blk_get_dev("mmc", fastboot_get_mmc_device()); if (!ret || ret->type == DEV_TYPE_UNKNOWN) { pr_err("invalid mmc device\n"); @@ -641,7 +645,7 @@ void fastboot_mmc_erase(const char *cmd, char *response) struct blk_desc *dev_desc; struct disk_partition info; lbaint_t blks, blks_start, blks_size, grp_size; - struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV); + struct mmc *mmc = find_mmc_device(fastboot_get_mmc_device()); #ifdef CONFIG_FASTBOOT_MMC_BOOT_SUPPORT if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT1_NAME) == 0) { diff --git a/include/fastboot.h b/include/fastboot.h index 57daaf12982..839877f6a67 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -173,6 +173,13 @@ void fastboot_data_download(const void *fastboot_data, */ void fastboot_data_complete(char *response); +/** + * fastboot_get_mmc_device() - Get mmc device number of fastboot flash storage + * + * Return: U-Boot number of MMC device to use as the flash provider. + */ +int fastboot_get_mmc_device(void); + #if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT) void fastboot_acmd_complete(void); #endif From patchwork Mon May 24 00:36:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 1482583 X-Patchwork-Delegate: andre.przywara@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FpJG13TC4z9s5R for ; Mon, 24 May 2021 10:37:45 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8384D82E85; Mon, 24 May 2021 02:37:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 0FACB82E6A; Mon, 24 May 2021 02:37:16 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id A202982E6D for ; Mon, 24 May 2021 02:37:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CBA6311B3; Sun, 23 May 2021 17:37:09 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 564643F73D; Sun, 23 May 2021 17:37:08 -0700 (PDT) From: Andre Przywara To: Simon Glass , Jagan Teki Cc: u-boot@lists.denx.de, linux-sunxi@lists.linux.dev, Patrick Delaunay , Sean Anderson , Heiko Schocher , Kever Yang , Philipp Tomsich Subject: [RFC PATCH 2/3] sunxi: Implement fastboot_get_mmc_device() Date: Mon, 24 May 2021 01:36:49 +0100 Message-Id: <20210524003650.24469-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20210524003650.24469-1-andre.przywara@arm.com> References: <20210524003650.24469-1-andre.przywara@arm.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean The default MMC device to use for the fastboot flash command is hard to decide at runtime, since the numbering of the MMC devices depends on devicetree nodes. On the hardware side, the eMMC is connected to device 2, but this might be U-Boot's device 1 or 2, depending on whether the DT contains a WiFi node for the hardware MMC1 device. To avoid hardcoding this for each board, let's scan all MMC devices, and try to find the eMMC device, given that this is enabled. If not, we use the SD card. Signed-off-by: Andre Przywara --- board/sunxi/board.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 21651a1bfca..5f64887e48b 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -625,6 +625,43 @@ int board_mmc_init(struct bd_info *bis) } #endif +#ifdef CONFIG_FASTBOOT_FLASH_MMC +int fastboot_get_mmc_device(void) +{ + struct udevice *dev; + static int mmc_dev = -1; + int sd_card = -1; + + if (mmc_dev != -1) + return mmc_dev; + + for (uclass_first_device(UCLASS_MMC, &dev); + dev; + uclass_next_device(&dev)) { + struct mmc *mmc = mmc_get_mmc_dev(dev); + + mmc_init(mmc); + if (!mmc->has_init) + continue; + + if (IS_SD(mmc)) { + sd_card = dev->seq_; + continue; + } else { + mmc_dev = dev->seq_; + break; + } + } + + if (mmc_dev == -1) + mmc_dev = sd_card; + if (mmc_dev == -1) + mmc_dev = 0; + + return mmc_dev; +} +#endif + #ifdef CONFIG_SPL_BUILD static void sunxi_spl_store_dram_size(phys_addr_t dram_size) From patchwork Mon May 24 00:36:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 1482585 X-Patchwork-Delegate: andre.przywara@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FpJGJ5Zbgz9s5R for ; Mon, 24 May 2021 10:38:00 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B55FD82E91; Mon, 24 May 2021 02:37:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id C2A9582E65; Mon, 24 May 2021 02:37:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 985FB82E39 for ; Mon, 24 May 2021 02:37:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 885D612FC; Sun, 23 May 2021 17:37:11 -0700 (PDT) Received: from localhost.localdomain (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0EA933F73D; Sun, 23 May 2021 17:37:09 -0700 (PDT) From: Andre Przywara To: Simon Glass , Jagan Teki Cc: u-boot@lists.denx.de, linux-sunxi@lists.linux.dev, Patrick Delaunay , Sean Anderson , Heiko Schocher , Kever Yang , Philipp Tomsich Subject: [RFC PATCH 3/3] sunxi: Drop sunxi FASTBOOT_FLASH_MMC_DEV defaults Date: Mon, 24 May 2021 01:36:50 +0100 Message-Id: <20210524003650.24469-4-andre.przywara@arm.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20210524003650.24469-1-andre.przywara@arm.com> References: <20210524003650.24469-1-andre.przywara@arm.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean Now that we have a runtime function to decide the default MMC device to use on Allwinner boards, we don't need the hardcoded Kconfig variable anymore (we do the same logic at runtime now). Drop the sunxi defaults, and since there is only one other user left, use one generic default of 0 now. An "int" type KConfig variable needs a default anyway, (even when this is never used), otherwise *every* user has to specify one. Signed-off-by: Andre Przywara --- drivers/fastboot/Kconfig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 2d1836a80e0..06536e249c4 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -98,9 +98,7 @@ endchoice config FASTBOOT_FLASH_MMC_DEV int "Define FASTBOOT MMC FLASH default device" depends on FASTBOOT_FLASH_MMC - default 0 if ARCH_ROCKCHIP - default 0 if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1 - default 1 if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1 + default 0 help The fastboot "flash" command requires additional information regarding the non-volatile storage device. Define this to