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 24A65C433FE for ; Thu, 13 Oct 2022 12:26:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 82F2C84E82; Thu, 13 Oct 2022 14:26:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="xKZVXs0L"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 405BC84F0B; Thu, 13 Oct 2022 14:26:22 +0200 (CEST) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0932484DBA for ; Thu, 13 Oct 2022 14:26:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mkorpershoek@baylibre.com Received: by mail-wr1-x42f.google.com with SMTP id bp11so2550890wrb.9 for ; Thu, 13 Oct 2022 05:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=6bs0PJv1JTCgNIPObCWHZHEgvLPJJbTQrIHI7W/R/rY=; b=xKZVXs0LOewNagigHr6C7pOyGrS2hFM/3QjEjQ/yo60S3BeaYS8jTVgRGNDUCrYsV5 l4vWOPNODrV3sEsM4k1A8PadtdtAAfzfgnhsht+TdGiIpRkJsZWImtFTC5wDGNxK1Vjh A5ZIQEIlQ25nByydkTcAIkcSJJsf2AQklH2efBHAv1rcDuKyeRuAspEdLU/WTmoXXtRq Abb70ZZEunoI4EBamFoGjfMafuSfc3z5sKwAlXH3CeesrYsLQosgVc/DOP2J0eXHES6c 7p0SVs3Uhybx4Ugk/Avj4yv/x7IaXtUgV6TwhLmzzThUh7CZrl1qpBI4IuVuV5V/J7yP taSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6bs0PJv1JTCgNIPObCWHZHEgvLPJJbTQrIHI7W/R/rY=; b=Azz5zua/sPFz5/coB+PQpd7MHOd6aVPjK4uDFZIckEn8mHGOxJVnNEh2lAaRcZoFwV dunaJRWmyvPWfrh/tMFEmH/R2XOmzo9Z5kqLLBt8G3PPRKvfMnU+AohwB6bakHUv+jUK uQTE+qcDiX1SyY2y1qEyrD4byH3OLpWEifmjbUhTl34Eqx6cfBgvxVFHloovfAc97v9i ZoOEd1wipc1Bc3C2heKCCjQ6D7Gd9SYynIiMzZsZxKInqhF9XEQG2x2Z2p1XZhgLMwKE lqV46O1oFPm4jxj0zCOhw6YeUFRi2ggK8RIj/6P1Bc2XHv6sVE5cKAiNgmEGjw5TS+DH F6RQ== X-Gm-Message-State: ACrzQf2X5ggT1/JrIiRgRJoNcfLuyDJFHxxEEkShsWz4uX1g30ywRS6g Ni1vhkU59lD+jexVyYSVxo8dug== X-Google-Smtp-Source: AMsMyM7RJ6wFc/hp0a7ewr2tXxx+07wD6CdmkAaONvF+2efXifn9QzvsBuTCo0aShnGjXXpDxCkGfg== X-Received: by 2002:adf:d1e4:0:b0:22e:6bd4:9fc2 with SMTP id g4-20020adfd1e4000000b0022e6bd49fc2mr20506662wrd.234.1665663978521; Thu, 13 Oct 2022 05:26:18 -0700 (PDT) Received: from [192.168.2.252] ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id p31-20020a05600c1d9f00b003c6c3fb3cf6sm4293308wms.18.2022.10.13.05.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 05:26:17 -0700 (PDT) From: Mattijs Korpershoek Date: Thu, 13 Oct 2022 14:25:59 +0200 Subject: [PATCH v2] cmd: bcb: select user(0) hwpart in __bcb_load() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20221011-usb-hwpart-v2-0-e10181d4e0e6@baylibre.com> To: Sean Anderson Cc: Gary Bisson , Patrick Delaunay , u-boot@lists.denx.de, Simon Glass , Matthias Schiffer , Mattijs Korpershoek , Jaehoon Chung X-Mailer: b4 0.11.0-dev-5166b 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 For some blk operations, it's possible that a different hw partition gets selected via blk_dselect_hwpart(). In that case, only the region of the device covered by that partition is accessible. This breaks "bcb load" which attempts to read the gpt and assumes it's on the user(0) hw partition: => bcb load 2 misc GUID Partition Table Header signature is wrong: 0xDE7B17AD07D9E5D6 != 0x5452415020494645 find_valid_gpt: *** ERROR: Invalid GPT *** GUID Partition Table Header signature is wrong: 0x0 != 0x5452415020494645 find_valid_gpt: *** ERROR: Invalid Backup GPT *** Error: mmc 2:misc read failed (-2) Add a fail-safe in __bcb_load() to ensure we will always read from the user(0) hwpartition. This fixes the following fastboot sequence: $ fastboot erase mmc2boot1 # switch to hwpart1 $ fastboot reboot bootloader # switch to hwpart0, then reads GPT Signed-off-by: Mattijs Korpershoek --- Changes in v2: * Move hwpart selection into the bcb command instead of fb_mmc.c * Link to v1: https://lore.kernel.org/r/20221010-switch-hwpart-v1-0-52cbd34c72b7@baylibre.com --- cmd/bcb.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/bcb.c b/cmd/bcb.c index 1622a90c97f0..02d0c70d87e2 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -14,6 +14,7 @@ #include #include #include +#include enum bcb_cmd { BCB_CMD_LOAD, @@ -128,6 +129,16 @@ static int __bcb_load(int devnum, const char *partp) goto err_read_fail; } + /* + * always select the USER mmc hwpart in case another + * blk operation selected a different hwpart + */ + ret = blk_dselect_hwpart(desc, 0); + if (IS_ERR_VALUE(ret)) { + ret = -ENODEV; + goto err_read_fail; + } + part = simple_strtoul(partp, &endp, 0); if (*endp == '\0') { ret = part_get_info(desc, part, &info); --- base-commit: c4c32e359662aa95d9dbda2bd1272181bd9cb830 change-id: 20221011-usb-hwpart-599c278980b3 Best regards, -- Mattijs Korpershoek