public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: grygorii tertychnyi <grembeter@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2] cmd: mmc: add mmc bootpart-check
Date: Wed, 17 Feb 2021 17:35:16 +0100	[thread overview]
Message-ID: <20210217163516.2183810-1-grembeter@gmail.com> (raw)
In-Reply-To: <20210212103214.14495-1-grembeter@gmail.com>

This patch allows to check the current boot partition. It is useful
when you use two different sets of (bootloader, kernel) images and
want to boot the corresponding kernel image in boot script. E.g.:

if mmc bootpart-check ${mmcdev} 1; then
    echo "booted from eMMC boot0 partition"
    ...load kernel image1
elif mmc bootpart-check ${mmcdev} 2; then
    echo "booted from eMMC boot1 partition"
    ...load kernel image2
fi

Signed-off-by: Grygorii Tertychnyi <grygorii.tertychnyi@leica-geosystems.com>
---
v2:
 - renamed the command, it is "bootpart-check" now
 - added <> to mandatory arguments help string
 - added more details to commit message

 cmd/mmc.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/cmd/mmc.c b/cmd/mmc.c
index 1529a3e05ddd..3332dee4b130 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -771,6 +771,41 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag,
 	return CMD_RET_SUCCESS;
 }
 
+static int do_mmc_boot_check(struct cmd_tbl *cmdtp, int flag,
+			     int argc, char *const argv[])
+{
+	int dev;
+	struct mmc *mmc;
+	u8 part_args, part_emmc;
+
+	if (argc != 3)
+		return CMD_RET_USAGE;
+
+	dev = simple_strtoul(argv[1], NULL, 10);
+
+	mmc = init_mmc_device(dev, false);
+	if (!mmc)
+		return CMD_RET_FAILURE;
+
+	if (IS_SD(mmc)) {
+		printf("It is not an eMMC device\n");
+		return CMD_RET_FAILURE;
+	}
+
+	if (mmc->part_config == MMCPART_NOAVAILABLE) {
+		printf("No part_config info for ver. 0x%x\n", mmc->version);
+		return CMD_RET_FAILURE;
+	}
+
+	part_emmc = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
+	part_args = simple_strtoul(argv[2], NULL, 10);
+
+	if (part_emmc == part_args)
+		return CMD_RET_SUCCESS;
+	else
+		return CMD_RET_FAILURE;
+}
+
 static int mmc_partconf_print(struct mmc *mmc)
 {
 	u8 ack, access, part;
@@ -952,6 +987,7 @@ static struct cmd_tbl cmd_mmc[] = {
 #endif
 #ifdef CONFIG_SUPPORT_EMMC_BOOT
 	U_BOOT_CMD_MKENT(bootbus, 5, 0, do_mmc_bootbus, "", ""),
+	U_BOOT_CMD_MKENT(bootpart-check, 3, 0, do_mmc_boot_check, "", ""),
 	U_BOOT_CMD_MKENT(bootpart-resize, 4, 0, do_mmc_boot_resize, "", ""),
 	U_BOOT_CMD_MKENT(partconf, 5, 0, do_mmc_partconf, "", ""),
 	U_BOOT_CMD_MKENT(rst-function, 3, 0, do_mmc_rst_func, "", ""),
@@ -1019,6 +1055,9 @@ U_BOOT_CMD(
 #ifdef CONFIG_SUPPORT_EMMC_BOOT
 	"mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode\n"
 	" - Set the BOOT_BUS_WIDTH field of the specified device\n"
+	"mmc bootpart-check <dev> <boot_partition>\n"
+	" - Return success if the given boot_partition value matches BOOT_PARTITION_ENABLE\n"
+	"   bit field of the specified device\n"
 	"mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\n"
 	" - Change sizes of boot and RPMB partitions of specified device\n"
 	"mmc partconf dev [boot_ack boot_partition partition_access]\n"
-- 
2.25.1

  parent reply	other threads:[~2021-02-17 16:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210212103248epcas1p302270c25ac7ac0b5b9f86267acfe9860@epcas1p3.samsung.com>
2021-02-12 10:32 ` [PATCH] cmd: mmc: add mmc partboot grygorii tertychnyi
2021-02-14 22:08   ` Jaehoon Chung
2021-02-15 13:04     ` gr embeter
2021-02-15 23:30       ` Jaehoon Chung
2021-02-16  8:18         ` gr embeter
2021-02-16  9:00           ` Jaehoon Chung
2021-02-17 15:35             ` gr embeter
2021-02-17 16:35   ` grygorii tertychnyi [this message]
2021-02-17 23:15     ` [PATCH v2] cmd: mmc: add mmc bootpart-check Jaehoon Chung

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=20210217163516.2183810-1-grembeter@gmail.com \
    --to=grembeter@gmail.com \
    --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