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 6252CC433EF for ; Wed, 6 Oct 2021 16:30:34 +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 6C87760F6C for ; Wed, 6 Oct 2021 16:30:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6C87760F6C 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 DBE9683297; Wed, 6 Oct 2021 18:30:23 +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=1633537824; bh=whRTQbr6OOJAGZ8ADGr6rFg2HUj5ariUR3GO1GTKLjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Hfcp3fqyGptjiuqoOT6MN00DFokXJzGRoCKcRWw0Gz/0mB00MDp8g0qSkiJxsCXL9 t9h1N7CJ1EwuhYZWPkRbYKLpMNpFO+Jhq5ATKr8+6v2bFwtVasqgOLHmHoP+kqYPRj 8Y6pePhM3KlaChAKPtcFYYFlPF3kot6UJ3n7OeLCLQZOTrYcwlAr0YM8jkBHOUYTpl s+7/FTWOfDRts9lXCvymhMEedihoXT1Cn9j+6zQS8GTyUz8hddbLvAR375cwTcSjEv dtwsegB+CMwJMiT5mbgrpHOXuT8QwEYi+sSxvrLCd0SwGM8TWru2sqDEdF4E1lPloA 5h9ehNi0KzIgA== 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 9312281545; Wed, 6 Oct 2021 18:30:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1633537815; bh=whRTQbr6OOJAGZ8ADGr6rFg2HUj5ariUR3GO1GTKLjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ag37UKXRiGwW6lpyqXbNK+D8EMhKDwqsVRsCNQ0QRA1NL4vSSPesK4oQB749zxUfD dH94oGHnIT9Jd941/emOGTW1LGQSC+57xWrm8/fUE4hLjLLmAZek9Gtav/PUIkH1SF g86tsM/t3TeuchktCmdtJGYml5PuHOWNDAduVv7MhzTppLOx12ohuocvSkUjoVgugx 4EUPoDGyaGYnZCxoMtLd1NBypjy+r2Xx1SiognO1vGEX6D3HWbVE0Y+uYl24k+iE5W r5l8YGJ2kzvaMGNDo41NHA74Thf15f1YY7w2UGKdnNbbEzYY1a49iB3cdusnf8u5w8 B1xl5uFueyDow== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Fabio Estevam , Jaehoon Chung , Peng Fan , Stefano Babic Subject: [PATCH 2/2] env: mmc: Add support for redundant env in both eMMC boot partitions Date: Wed, 6 Oct 2021 18:29:54 +0200 Message-Id: <20211006162954.63596-2-marex@denx.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211006162954.63596-1-marex@denx.de> References: <20211006162954.63596-1-marex@denx.de> 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 Currently the MMC environment driver supports storing redundant environment only in one eMMC partition at different offsets. This is sub-optimal, since if this one boot partition is erased, both copies of environment are lost. Since the eMMC has two boot partitions, add support for storing one copy of environment in each of the two boot partitions. To enable this functionality, select CONFIG_SYS_REDUNDAND_ENVIRONMENT to indicate redundant environment should be used. Set CONFIG_SYS_MMC_ENV_PART to 1 to indicate environment should be stored in eMMC boot partition. Set CONFIG_ENV_OFFSET equal to CONFIG_ENV_OFFSET_REDUND, and both to the offset from start of eMMC boot partition where the environment should be located. Signed-off-by: Marek Vasut Cc: Fabio Estevam Cc: Jaehoon Chung Cc: Peng Fan Cc: Stefano Babic --- env/mmc.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/env/mmc.c b/env/mmc.c index e111d8e5881..465b104559b 100644 --- a/env/mmc.c +++ b/env/mmc.c @@ -26,6 +26,18 @@ DECLARE_GLOBAL_DATA_PTR; +/* + * In case the environment is redundant, stored in eMMC hardware boot + * partition and the environment and redundant environment offsets are + * identical, store the environment and redundant environment in both + * eMMC boot partitions, one copy in each. + * */ +#if (defined(CONFIG_SYS_REDUNDAND_ENVIRONMENT) && \ + (CONFIG_SYS_MMC_ENV_PART == 1) && \ + (CONFIG_ENV_OFFSET == CONFIG_ENV_OFFSET_REDUND)) +#define ENV_MMC_HWPART_REDUND +#endif + #if CONFIG_IS_ENABLED(OF_CONTROL) static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val) { @@ -126,13 +138,11 @@ __weak uint mmc_get_env_part(struct mmc *mmc) static unsigned char env_mmc_orig_hwpart; -static int mmc_set_env_part(struct mmc *mmc) +static int mmc_set_env_part(struct mmc *mmc, uint part) { - uint part = mmc_get_env_part(mmc); int dev = mmc_get_env_dev(); int ret = 0; - env_mmc_orig_hwpart = mmc_get_blk_desc(mmc)->hwpart; ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part); if (ret) puts("MMC partition switch failed\n"); @@ -140,7 +150,7 @@ static int mmc_set_env_part(struct mmc *mmc) return ret; } #else -static inline int mmc_set_env_part(struct mmc *mmc) {return 0; }; +static inline int mmc_set_env_part(struct mmc *mmc, uint part) {return 0; }; #endif static const char *init_mmc_for_env(struct mmc *mmc) @@ -157,7 +167,8 @@ static const char *init_mmc_for_env(struct mmc *mmc) if (mmc_init(mmc)) return "MMC init failed"; #endif - if (mmc_set_env_part(mmc)) + env_mmc_orig_hwpart = mmc_get_blk_desc(mmc)->hwpart; + if (mmc_set_env_part(mmc, mmc_get_env_part(mmc))) return "MMC partition switch failed"; return NULL; @@ -209,6 +220,13 @@ static int env_mmc_save(void) #ifdef CONFIG_ENV_OFFSET_REDUND if (gd->env_valid == ENV_VALID) copy = 1; + +#ifdef ENV_MMC_HWPART_REDUND + ret = mmc_set_env_part(mmc, copy + 1); + if (ret) + goto fini; +#endif + #endif if (mmc_get_env_addr(mmc, copy, &offset)) { @@ -273,6 +291,12 @@ static int env_mmc_erase(void) #ifdef CONFIG_ENV_OFFSET_REDUND copy = 1; +#ifdef ENV_MMC_HWPART_REDUND + ret = mmc_set_env_part(mmc, copy + 1); + if (ret) + goto fini; +#endif + if (mmc_get_env_addr(mmc, copy, &offset)) { ret = CMD_RET_FAILURE; goto fini; @@ -331,7 +355,20 @@ static int env_mmc_load(void) goto fini; } +#ifdef ENV_MMC_HWPART_REDUND + ret = mmc_set_env_part(mmc, 1); + if (ret) + goto fini; +#endif + read1_fail = read_env(mmc, CONFIG_ENV_SIZE, offset1, tmp_env1); + +#ifdef ENV_MMC_HWPART_REDUND + ret = mmc_set_env_part(mmc, 2); + if (ret) + goto fini; +#endif + read2_fail = read_env(mmc, CONFIG_ENV_SIZE, offset2, tmp_env2); ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2, -- 2.33.0