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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FC99C433F5 for ; Wed, 6 Oct 2021 16:30:22 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1A91860F6C for ; Wed, 6 Oct 2021 16:30:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1A91860F6C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3970D8281E; Wed, 6 Oct 2021 18:30:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1633537818; bh=e2e4i78Bom3IVk3TWR8gUANdMgRPelTOdOCwYPDbb0g=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=UilGv9Ta/Bd2LbNQ+A4jcMMGydQ4OfKdibMoLG3nKLTMLWF8tkskiDM4hDILlzz/5 ED1EZvVA9VItmhXILqw4MbhIJoSK0D3+BPCPY7Cz3YDBg9FuUO5TYnWIt6V1djsiKJ gkejY80JuZJNp9Rah84jetFBBC1fZc9vbS3p+qvKPQ7WaKEQWUs3sqg9x5PCA4+qsr 44QzbHFYYLvbp7Hj9vsRAYnUObFwlkHckpjdWfCJYrcZXbUZLoqPskHyClsj8tHdDV Di07lFUL0l2+iKqc3Z6sl5uHbhbln20l7iieTWa9vz0k9gf8PsO4nwjndgYr0dAQa/ Y3qcqQPs/69sQ== Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id DBDFC807CD; Wed, 6 Oct 2021 18:30:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1633537815; bh=e2e4i78Bom3IVk3TWR8gUANdMgRPelTOdOCwYPDbb0g=; h=From:To:Cc:Subject:Date:From; b=Z1G5yTDKhPzbrLtlU411A09rsTaXtX6qhn7DLVNBdh6zYlaLqI6LMrVO51o4YFkEl oxq3DANw2cbHx7dr/dW+dUzqN73BlwCiNzVuc9anCEhemWhyVRwhFwWhl3oKFteymp xPsgrQ7YMPvlZLpyxFxdtNlRHSE9/fPJ2qVt6jIgZglzSLp2XLBFAsId0LLTI3w1mG XCFOcK7MkahXeHmKRmiQhBpha7mI4etpCvmjOj7V5VZf46qNYuS5uHWzFlYfSJE4ci PLBqZVdTkPRhSw+1jPQ0FztMi/kwPxZUYULsw0hKVxTNopMxo2n8D/VbFCDrf4HFVl 9nD+yJI3TVlXw== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Fabio Estevam , Jaehoon Chung , Peng Fan , Stefano Babic Subject: [PATCH 1/2] env: mmc: Add missing eMMC bootpart restoration to env erase Date: Wed, 6 Oct 2021 18:29:53 +0200 Message-Id: <20211006162954.63596-1-marex@denx.de> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.103.2 at phobos.denx.de X-Virus-Status: Clean If the environment is stored in eMMC hardware boot partition, the environment driver first stores the currently selected eMMC boot partition, then does the requested operation, and then restores the original boot partition settings. In case the environment operation fails, the boot partition settings are also restored. The 'env erase' implementation in the MMC environment driver lacks the path which restores the boot partition. This could lead to various failure modes, like the system boots the wrong copy of bootloader etc. Fix this by filling in the missing restoration path. Signed-off-by: Marek Vasut Cc: Fabio Estevam Cc: Jaehoon Chung Cc: Peng Fan Cc: Stefano Babic --- env/mmc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/env/mmc.c b/env/mmc.c index c4cb1639914..e111d8e5881 100644 --- a/env/mmc.c +++ b/env/mmc.c @@ -263,20 +263,26 @@ static int env_mmc_erase(void) return 1; } - if (mmc_get_env_addr(mmc, copy, &offset)) - return CMD_RET_FAILURE; + if (mmc_get_env_addr(mmc, copy, &offset)) { + ret = CMD_RET_FAILURE; + goto fini; + } ret = erase_env(mmc, CONFIG_ENV_SIZE, offset); #ifdef CONFIG_ENV_OFFSET_REDUND copy = 1; - if (mmc_get_env_addr(mmc, copy, &offset)) - return CMD_RET_FAILURE; + if (mmc_get_env_addr(mmc, copy, &offset)) { + ret = CMD_RET_FAILURE; + goto fini; + } ret |= erase_env(mmc, CONFIG_ENV_SIZE, offset); #endif +fini: + fini_mmc_for_env(mmc); return ret; } #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */ -- 2.33.0