From mboxrd@z Thu Jan 1 00:00:00 1970 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 B3824C433EF for ; Fri, 22 Jul 2022 16:07:30 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2232C83FB5; Fri, 22 Jul 2022 18:07:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=0leil.net 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 B2C7F840B3; Fri, 22 Jul 2022 18:07:15 +0200 (CEST) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [IPv6:2001:4b98:dc4:8::232]) (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 C18DB84119 for ; Fri, 22 Jul 2022 18:07:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=0leil.net Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=foss+uboot@0leil.net Received: (Authenticated sender: foss@0leil.net) by mail.gandi.net (Postfix) with ESMTPSA id 3233D20000F; Fri, 22 Jul 2022 16:07:10 +0000 (UTC) From: Quentin Schulz To: Cc: sjg@chromium.org, philipp.tomsich@vrull.eu, kever.yang@rock-chips.com, klaus.goger@theobroma-systems.com, knaerzche@gmail.com, u-boot@lists.denx.de, Quentin Schulz , Quentin Schulz Subject: [PATCH 01/12] rockchip: puma-rk3399: fix boot_targets swap depending on U-Boot proper load medium Date: Fri, 22 Jul 2022 18:06:44 +0200 Message-Id: <20220722160655.3904213-2-foss+uboot@0leil.net> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722160655.3904213-1-foss+uboot@0leil.net> References: <20220722160655.3904213-1-foss+uboot@0leil.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean From: Quentin Schulz distroboot should try first on the same MMC medium as the one the SPL loaded U-Boot proper from. This was the case when the introducing commit was merged because the default order was eMMC first and then SD card. The check was therefore made only on whether we booted from SD card, because otherwise the order was the expected one. However, in commit b212ad24a604 ("rockchip: Fix MMC boot order"), the order was swapped. Meaning our simple check is now useless. Let's fix that by accounting for all scenarii: default boot_targets has mmc0 first but booting from SD Card, mmc1 first but booting from eMMC. Fixes: b212ad24a604 ("rockchip: Fix MMC boot order") Cc: Quentin Schulz Signed-off-by: Quentin Schulz --- Depends on https://lore.kernel.org/u-boot/20220715151552.953654-1-foss+uboot@0leil.net/ https://lore.kernel.org/u-boot/20220715151552.953654-2-foss+uboot@0leil.net/ .../puma_rk3399/puma-rk3399.c | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c b/board/theobroma-systems/puma_rk3399/puma-rk3399.c index deeba3084a..ce3436b770 100644 --- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c +++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c @@ -77,18 +77,16 @@ static int setup_boottargets(void) } /* - * Only run, if booting from mmc1 (i.e. /mmc@fe320000) and - * only consider cases where the default boot-order first - * tries to boot from mmc0 (eMMC) and then from mmc1 - * (i.e. external SD). - * - * In other words: the SD card will be moved to earlier in the - * order, if U-Boot was also loaded from the SD-card. + * Make the default boot medium between SD Card and eMMC, the one that + * was used to load U-Boot proper. If SPI-NOR flash was used, keep + * original default order. */ - if (!strcmp(boot_device, "/mmc@fe320000")) { + if (strcmp(boot_device, "/spi@ff1d0000/flash@0")) { + bool sd_booted = !strcmp(boot_device, "/mmc@fe320000"); char *mmc0, *mmc1; - debug("%s: booted from SD-Card\n", __func__); + debug("%s: booted from %s\n", __func__, + sd_booted ? "SD-Card" : "eMMC"); mmc0 = strstr(env, "mmc0"); mmc1 = strstr(env, "mmc1"); @@ -98,10 +96,13 @@ static int setup_boottargets(void) } /* - * If mmc0 comes first in the boot order, we need to change - * the strings to make mmc1 first. + * If mmc0 comes first in the boot order and U-Boot proper was + * loaded from mmc1, swap mmc0 and mmc1 in the list. + * If mmc1 comes first in the boot order and U-Boot proper was + * loaded from mmc0, swap mmc0 and mmc1 in the list. */ - if (mmc0 < mmc1) { + if ((mmc0 < mmc1 && sd_booted) || + (mmc0 > mmc1 && !sd_booted)) { mmc0[3] = '1'; mmc1[3] = '0'; debug("%s: set boot_targets to: %s\n", __func__, env); -- 2.37.1