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 BA1A1C6FD18 for ; Tue, 18 Apr 2023 19:48:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 29FA4860BE; Tue, 18 Apr 2023 21:48:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="bibhJsoy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B93F9860B4; Tue, 18 Apr 2023 21:48:30 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (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 59DEA86059 for ; Tue, 18 Apr 2023 21:48:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 84C2662E69; Tue, 18 Apr 2023 19:48:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EEDDC433D2; Tue, 18 Apr 2023 19:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681847304; bh=61ysL15kPCgwvhHh3IL/jP4cMiR0jw6aje0otJxdieg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bibhJsoy5862h51Lfv3Bb5qV0WasJiKQGvn0aQrrkju3I6rHpyDrA7blowqMZI0PI /M8JBLhXE3WSnEO2xWvzAdj72M4VQ+8xYuGQOYbOaNXO8WbEgfkpGfz7LUreKl9ynT 1cv4RPdGIDzhtFRtn+1IBohO3TzqMokJmNTTHvXzOe23gCZf1P2rZTWFq6zR5wGBeC 8u/W42VMGpYdqeRIUiocj02soz/yjNqoy5/ldDxeUxi7CHCiFYHiHUJBOgup9TsH/E bSC3RuPgh+oZ3X/y8yG0OAWClq8QFz/4zHfyXvOs096C5vDexMkJeIYOVdIq9KtEF8 ayPm6/J0cV7Yw== Received: by pali.im (Postfix) id D404D735; Tue, 18 Apr 2023 21:48:21 +0200 (CEST) Date: Tue, 18 Apr 2023 21:48:21 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Fabio Estevam Cc: sbabic@denx.de, u-boot@lists.denx.de, eduard@lionizers.com, Fabio Estevam Subject: Re: [PATCH 07/13] smegw01: Enable EMMC boot from multiple partitions Message-ID: <20230418194821.yi7cky4gnvscorg4@pali> References: <20230418134744.343023-1-festevam@gmail.com> <20230418134744.343023-7-festevam@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230418134744.343023-7-festevam@gmail.com> User-Agent: NeoMutt/20180716 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.8 at phobos.denx.de X-Virus-Status: Clean On Tuesday 18 April 2023 10:47:38 Fabio Estevam wrote: > From: Eduard Strehlau > > GPT Partition labels are used for determining the right > root filesystem to boot from. > > The U-Boot environment is configured to reside in the eMMC hardware > boot partition we are currently booted from. > > This should enable a dual copy approach for upgrading the bootloader. > One can overwrite the inactive hardware partition with new bootloader > and environment and afterwards switch the eMMC boot partition for an > atomic bootloader switch. > > Signed-off-by: Eduard Strehlau > Signed-off-by: Fabio Estevam > --- > board/storopack/smegw01/smegw01.c | 20 ++++++++++++++++++++ > configs/smegw01_defconfig | 2 ++ > include/configs/smegw01.h | 12 ++++++++---- > 3 files changed, 30 insertions(+), 4 deletions(-) > > diff --git a/board/storopack/smegw01/smegw01.c b/board/storopack/smegw01/smegw01.c > index e6bff80e55..9482f88773 100644 > --- a/board/storopack/smegw01/smegw01.c > +++ b/board/storopack/smegw01/smegw01.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > > DECLARE_GLOBAL_DATA_PTR; > > @@ -93,3 +94,22 @@ int board_late_init(void) > > return 0; > } > + > +/* defined in JESD84-B50, PARTITION_CONFIG */ > +#define BOOT_PARTITION_ENABLE_MASK (0x7) > +#define BOOT_PARTITION_ENABLE_SHIFT (0x3) Please do not define a new mmc part macros. U-Boot already has them available, and recently I removed usage of custom macros, see commit: https://source.denx.de/u-boot/u-boot/-/commit/8b8820669646ceb08d6ceed4181b53042639f3ab > +uint mmc_get_env_part(struct mmc *mmc) > +{ > + uint part = (mmc->part_config >> BOOT_PARTITION_ENABLE_SHIFT) & > + BOOT_PARTITION_ENABLE_MASK; > + /* Default to Boot Partition 1 if not explicitly set. */ > + if (part != 1 && part != 2 && part != 7) > + part = 1; I'm not sure if this logic is complete. For example there is missing case for MMCPART_NOAVAILABLE or what is expected when booting from eMMC is disabled (value 0x0). For example, recently I sent this patch for U-Boot bubt command, hopefully handling all possible options: https://patchwork.ozlabs.org/project/uboot/patch/20230413211057.10975-3-pali@kernel.org/ > + > + /* 7 in BOOT_PARTITION_ENABLE is equivalent to 0 in PARTITION_ACCESS. */ > + if (part == 7) > + part = 0; > + > + return part; > +} > diff --git a/configs/smegw01_defconfig b/configs/smegw01_defconfig > index b3580d5d6e..54cf1cfc1f 100644 > --- a/configs/smegw01_defconfig > +++ b/configs/smegw01_defconfig > @@ -30,6 +30,7 @@ CONFIG_CMD_MEMTEST=y > CONFIG_CMD_UNZIP=y > CONFIG_CMD_DFU=y > CONFIG_CMD_GPIO=y > +CONFIG_CMD_GPT=y > CONFIG_CMD_MMC=y > CONFIG_CMD_PART=y > CONFIG_CMD_DHCP=y > @@ -44,6 +45,7 @@ CONFIG_OF_CONTROL=y > CONFIG_ENV_OVERWRITE=y > CONFIG_SYS_REDUNDAND_ENVIRONMENT=y > CONFIG_SYS_RELOC_GD_ENV_ADDR=y > +CONFIG_SYS_MMC_ENV_DEV=1 > CONFIG_NET_RANDOM_ETHADDR=y > CONFIG_BOUNCE_BUFFER=y > CONFIG_BOOTCOUNT_LIMIT=y > diff --git a/include/configs/smegw01.h b/include/configs/smegw01.h > index 277c828d0e..71f2d9c8e8 100644 > --- a/include/configs/smegw01.h > +++ b/include/configs/smegw01.h > @@ -32,17 +32,21 @@ > "mmcpart=1\0" \ > "mmcpart_committed=1\0" \ > "mmcargs=setenv bootargs console=${console},${baudrate} " \ > - "root=/dev/mmcblk0p${mmcpart_committed} rootwait rw " \ > - __stringify(EXTRA_BOOTPARAMS) "\0" \ > + "root=/dev/mmcblk${mmcdev}p${gpt_partition_entry} rootwait rw " \ > + __stringify(EXTRA_BOOTPARAMS) " SM_ROOT_DEV=${mmcdev} SM_ROOT_PART=${gpt_partition_entry} SM_BOOT_PART=${boot_part}\0" \ > "commit_mmc=if test \"${ustate}\" = 1 -a \"${mmcpart}\" != \"${mmcpart_committed}\"; then " \ > "setenv mmcpart_committed ${mmcpart};" \ > "saveenv;" \ > "fi;\0" \ > "bootlimit=3\0" \ > - "loadimage=load mmc ${mmcdev}:${mmcpart_committed} ${loadaddr} boot/${image}\0" \ > - "loadfdt=load mmc ${mmcdev}:${mmcpart_committed} ${fdt_addr} boot/${fdtfile}\0" \ > + "loadimage=load mmc ${mmcdev}#rootfs-${mmcpart_committed} ${loadaddr} boot/${image}\0" \ > + "loadfdt=load mmc ${mmcdev}#rootfs-${mmcpart_committed} ${fdt_addr} boot/${fdtfile}\0" \ > + "loadpart=gpt setenv mmc ${mmcdev} rootfs-${mmcpart_committed}\0" \ > + "loadbootpart=mmc partconf 1 boot_part\0" \ > "mmcboot=echo Booting from mmc ...; " \ > "run commit_mmc; " \ > + "run loadpart; " \ > + "run loadbootpart; " \ > "run mmcargs; " \ > "if run loadfdt; then " \ > "if bootz ${loadaddr} - ${fdt_addr}; then " \ > -- > 2.38.1 >