public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Fabio Estevam <festevam@gmail.com>
To: sbabic@denx.de
Cc: eduard@lionizers.com, u-boot@lists.denx.de,
	"Fabio Estevam" <festevam@denx.de>,
	"Pali Rohár" <pali@kernel.org>
Subject: [PATCH v2 7/7] smegw01: Enable EMMC boot from multiple partitions
Date: Fri, 21 Apr 2023 07:56:50 -0300	[thread overview]
Message-ID: <20230421105656.1062558-7-festevam@gmail.com> (raw)
In-Reply-To: <20230421105656.1062558-1-festevam@gmail.com>

From: Eduard Strehlau <eduard@lionizers.com>

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 <eduard@lionizers.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>
---
Changes since v1:
- Remove custom mmc macro (Pali)
- Handle all the possible partition cases (Pali).

Cc: Pali Rohár <pali@kernel.org>

 board/storopack/smegw01/smegw01.c | 32 +++++++++++++++++++++++++++++++
 configs/smegw01_defconfig         |  2 ++
 include/configs/smegw01.h         | 12 ++++++++----
 3 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/board/storopack/smegw01/smegw01.c b/board/storopack/smegw01/smegw01.c
index e6bff80e5565..db6069a02722 100644
--- a/board/storopack/smegw01/smegw01.c
+++ b/board/storopack/smegw01/smegw01.c
@@ -17,6 +17,7 @@
 #include <asm/arch/crm_regs.h>
 #include <asm/setup.h>
 #include <asm/bootm.h>
+#include <mmc.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -93,3 +94,34 @@ int board_late_init(void)
 
 	return 0;
 }
+
+uint mmc_get_env_part(struct mmc *mmc)
+{
+	uint part;
+
+	if (mmc->part_config == MMCPART_NOAVAILABLE) {
+		part = 0;
+	} else {
+		switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
+		case 0: /* Booting from this eMMC device is disabled */
+			printf("Error - Booting from this eMMC device is disabled\n");
+			printf("Hint: Use 'mmc partconf' command to choose boot partition\n");
+			return -ENODEV;
+		case 1: /* Boot partition 1 is used for booting */
+			part = 1;
+			break;
+		case 2: /* Boot partition 2 is used for booting */
+			part = 2;
+			break;
+		case 7: /* User area is used for booting */
+			part = 0;
+			break;
+		default: /* Other values are reserved / unsupported */
+			printf("Error - This eMMC device has configured Reserved boot option\n");
+			printf("Hint: Use 'mmc partconf' command to choose boot partition\n");
+			return -ENODEV;
+		}
+	}
+
+	return part;
+}
diff --git a/configs/smegw01_defconfig b/configs/smegw01_defconfig
index b3580d5d6e54..54cf1cfc1f1b 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 277c828d0e07..71f2d9c8e85c 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.34.1


  parent reply	other threads:[~2023-04-21 10:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-21 10:56 [PATCH v2 01/13] smegw01: Enable setting additional boot params Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 02/13] smegw01: Select CONFIG_CMD_SQUASHFS Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 03/13] smegw01: Select bootcount support Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 04/13] smegw01: Add altbootcmd Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 05/13] smegw01: Run altbootcmd in the case of failure Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 06/13] smegw01: Only commit to new partition if update was successful Fabio Estevam
2023-04-21 10:56 ` Fabio Estevam [this message]
2023-04-21 18:10   ` [PATCH v2 7/7] smegw01: Enable EMMC boot from multiple partitions Pali Rohár
2023-04-24 11:09     ` Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 08/13] smegw01: Change default boot device to eMMC Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 09/13] smegw01: Switch to fitImage Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 10/13] smegw01: Add lockdown U-Boot env support Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 11/13] smegw01: Read the second MAC address Fabio Estevam
2023-04-21 10:56 ` [PATCH v2 12/13] smegw01: Disable additional boot menu options Fabio Estevam
2023-04-21 10:56 ` [PATCH 13/13] smegw01: Fix fallback to altbootcmd Fabio Estevam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230421105656.1062558-7-festevam@gmail.com \
    --to=festevam@gmail.com \
    --cc=eduard@lionizers.com \
    --cc=festevam@denx.de \
    --cc=pali@kernel.org \
    --cc=sbabic@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox