U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mmc: mmc_boot: support sandisk and micron emmc boot/rpmb partition resizing
@ 2025-03-17  8:46 ziniu.wang_1
  2025-03-24  8:20 ` Peng Fan
  2025-03-24 14:11 ` Marek Vasut
  0 siblings, 2 replies; 4+ messages in thread
From: ziniu.wang_1 @ 2025-03-17  8:46 UTC (permalink / raw)
  To: peng.fan, jh80.chung, trini
  Cc: pbrobinson, marek.vasut+renesas, tharvey, jonas, sjg, u-boot

From: Luke Wang <ziniu.wang_1@nxp.com>

Current mmc bootpart-resize cmd only support samsung emmc boot/rpmb
partition resizing. Add sandisk and micron emmc boot/rpmb partition
resizing support. The commands and parameters for resizing partitions
are different for each manufacturer. Select the corresponding function
according to cid.

Signed-off-by: Luke Wang <ziniu.wang_1@nxp.com>
---
Changed in v2:
- define some macros according to Tom's comment
- correct emmc manufacturer id
---
 drivers/mmc/mmc_boot.c | 173 ++++++++++++++++++++++++++++++++++-------
 include/mmc.h          |   6 ++
 2 files changed, 150 insertions(+), 29 deletions(-)

diff --git a/drivers/mmc/mmc_boot.c b/drivers/mmc/mmc_boot.c
index 367c957b518..ba6261a8ffe 100644
--- a/drivers/mmc/mmc_boot.c
+++ b/drivers/mmc/mmc_boot.c
@@ -8,20 +8,107 @@
 #include <mmc.h>
 #include "mmc_private.h"
 
-/*
- * This function changes the size of boot partition and the size of rpmb
- * partition present on EMMC devices.
- *
- * Input Parameters:
- * struct *mmc: pointer for the mmc device strcuture
- * bootsize: size of boot partition
- * rpmbsize: size of rpmb partition
- *
- * Returns 0 on success.
- */
+static int mmc_resize_boot_micron(struct mmc *mmc, unsigned long bootsize,
+				  unsigned long rpmbsize)
+{
+	int err;
 
-int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
-				unsigned long rpmbsize)
+	/* micron emmc doesn't support resizing rpmb partition */
+	(void)rpmbsize;
+
+	/* boot partition size is multiple of 128KB */
+	bootsize = (bootsize * 1024) / 128;
+
+	if (bootsize > 0xff)
+		bootsize = 0xff;
+
+	/* Set EXT_CSD[175] ERASE_GROUP_DEF to 0x01 */
+	err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
+			 EXT_CSD_ERASE_GROUP_DEF, 0x01);
+	if (err)
+		goto error;
+
+	/* Set EXT_CSD[127:125] for boot partition size, [125] is low byte */
+	err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
+			 EXT_CSD_BOOT_SIZE_MULT_MICRON, bootsize);
+	if (err)
+		goto error;
+
+	err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
+			 EXT_CSD_BOOT_SIZE_MULT_MICRON + 1, 0x00);
+	if (err)
+		goto error;
+
+	err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
+			 EXT_CSD_BOOT_SIZE_MULT_MICRON + 2, 0x00);
+	if (err)
+		goto error;
+
+	/* Set EXT_CSD[155] PARTITION_SETTING_COMPLETE to 0x01 */
+	err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
+			 EXT_CSD_PARTITION_SETTING, 0x01);
+	if (err)
+		goto error;
+
+	return 0;
+
+error:
+	debug("%s: Error = %d\n", __func__, err);
+	return err;
+}
+
+static int mmc_resize_boot_sandisk(struct mmc *mmc, unsigned long bootsize,
+				   unsigned long rpmbsize)
+{
+	int err;
+	struct mmc_cmd cmd;
+
+	/* boot/rpmb partition size is multiple of 128KB */
+	bootsize = (bootsize * 1024) / 128;
+	rpmbsize = (rpmbsize * 1024) / 128;
+
+	if (bootsize > 0xff)
+		bootsize = 0xff;
+
+	if (rpmbsize > 0xff)
+		rpmbsize = 0xff;
+
+	/* Send boot/rpmb resize op code */
+	cmd.cmdidx = MMC_CMD_RES_MAN;
+	cmd.resp_type = MMC_RSP_R1b;
+	cmd.cmdarg = MMC_CMD62_ARG_SANDISK;
+
+	err = mmc_send_cmd(mmc, &cmd, NULL);
+	if (err)
+		goto error;
+
+	/* Arg: boot partition size */
+	cmd.cmdidx = MMC_CMD_RES_MAN;
+	cmd.resp_type = MMC_RSP_R1b;
+	cmd.cmdarg = bootsize;
+
+	err = mmc_send_cmd(mmc, &cmd, NULL);
+	if (err)
+		goto error;
+
+	/* Arg: RPMB partition size */
+	cmd.cmdidx = MMC_CMD_RES_MAN;
+	cmd.resp_type = MMC_RSP_R1b;
+	cmd.cmdarg = rpmbsize;
+
+	err = mmc_send_cmd(mmc, &cmd, NULL);
+	if (err)
+		goto error;
+
+	return 0;
+
+error:
+	debug("%s: Error = %d\n", __func__, err);
+	return err;
+}
+
+static int mmc_resize_boot_samsung(struct mmc *mmc, unsigned long bootsize,
+				   unsigned long rpmbsize)
 {
 	int err;
 	struct mmc_cmd cmd;
@@ -32,10 +119,8 @@ int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
 	cmd.cmdarg = MMC_CMD62_ARG1;
 
 	err = mmc_send_cmd(mmc, &cmd, NULL);
-	if (err) {
-		debug("mmc_boot_partition_size_change: Error1 = %d\n", err);
-		return err;
-	}
+	if (err)
+		goto error;
 
 	/* Boot partition changing mode */
 	cmd.cmdidx = MMC_CMD_RES_MAN;
@@ -43,10 +128,9 @@ int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
 	cmd.cmdarg = MMC_CMD62_ARG2;
 
 	err = mmc_send_cmd(mmc, &cmd, NULL);
-	if (err) {
-		debug("mmc_boot_partition_size_change: Error2 = %d\n", err);
-		return err;
-	}
+	if (err)
+		goto error;
+
 	/* boot partition size is multiple of 128KB */
 	bootsize = (bootsize * 1024) / 128;
 
@@ -56,10 +140,9 @@ int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
 	cmd.cmdarg = bootsize;
 
 	err = mmc_send_cmd(mmc, &cmd, NULL);
-	if (err) {
-		debug("mmc_boot_partition_size_change: Error3 = %d\n", err);
-		return err;
-	}
+	if (err)
+		goto error;
+
 	/* RPMB partition size is multiple of 128KB */
 	rpmbsize = (rpmbsize * 1024) / 128;
 	/* Arg: RPMB partition size */
@@ -68,11 +151,43 @@ int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
 	cmd.cmdarg = rpmbsize;
 
 	err = mmc_send_cmd(mmc, &cmd, NULL);
-	if (err) {
-		debug("mmc_boot_partition_size_change: Error4 = %d\n", err);
-		return err;
-	}
+	if (err)
+		goto error;
+
 	return 0;
+
+error:
+	debug("%s: Error = %d\n", __func__, err);
+	return err;
+}
+
+/*
+ * This function changes the size of boot partition and the size of rpmb
+ * partition present on EMMC devices.
+ *
+ * Input Parameters:
+ * struct *mmc: pointer for the mmc device strcuture
+ * bootsize: size of boot partition
+ * rpmbsize: size of rpmb partition
+ *
+ * Returns 0 on success.
+ */
+
+int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
+				   unsigned long rpmbsize)
+{
+	switch (mmc->cid[0] >> 24) {
+	case CID_MANFID_MICRON:
+		return mmc_resize_boot_micron(mmc, bootsize, rpmbsize);
+	case CID_MANFID_SAMSUNG:
+		return mmc_resize_boot_samsung(mmc, bootsize, rpmbsize);
+	case CID_MANFID_SANDISK:
+		return mmc_resize_boot_sandisk(mmc, bootsize, rpmbsize);
+	default:
+		printf("Unsupported manufacturer id 0x%02x\n",
+		       mmc->cid[0] >> 24);
+		return -EPERM;
+	}
 }
 
 /*
diff --git a/include/mmc.h b/include/mmc.h
index 81bccb4cf12..11e95e7a716 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -79,6 +79,10 @@ struct bd_info;
 #define IS_SD(x)	((x)->version & SD_VERSION_SD)
 #define IS_MMC(x)	((x)->version & MMC_VERSION_MMC)
 
+#define CID_MANFID_MICRON       0x13
+#define CID_MANFID_SAMSUNG      0x15
+#define CID_MANFID_SANDISK      0x45
+
 #define MMC_DATA_READ		1
 #define MMC_DATA_WRITE		2
 
@@ -112,6 +116,7 @@ struct bd_info;
 
 #define MMC_CMD62_ARG1			0xefac62ec
 #define MMC_CMD62_ARG2			0xcbaea7
+#define MMC_CMD62_ARG_SANDISK		0x254ddec4
 
 #define SD_CMD_SEND_RELATIVE_ADDR	3
 #define SD_CMD_SWITCH_FUNC		6
@@ -205,6 +210,7 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
 /*
  * EXT_CSD fields
  */
+#define EXT_CSD_BOOT_SIZE_MULT_MICRON	125	/* R/W, vendor specific field */
 #define EXT_CSD_ENH_START_ADDR		136	/* R/W */
 #define EXT_CSD_ENH_SIZE_MULT		140	/* R/W */
 #define EXT_CSD_GP_SIZE_MULT		143	/* R/W */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mmc: mmc_boot: support sandisk and micron emmc boot/rpmb partition resizing
  2025-03-17  8:46 [PATCH v2] mmc: mmc_boot: support sandisk and micron emmc boot/rpmb partition resizing ziniu.wang_1
@ 2025-03-24  8:20 ` Peng Fan
  2025-03-24 14:11 ` Marek Vasut
  1 sibling, 0 replies; 4+ messages in thread
From: Peng Fan @ 2025-03-24  8:20 UTC (permalink / raw)
  To: ziniu.wang_1
  Cc: peng.fan, jh80.chung, trini, pbrobinson, marek.vasut+renesas,
	tharvey, jonas, sjg, u-boot

On Mon, Mar 17, 2025 at 04:46:49PM +0800, ziniu.wang_1@nxp.com wrote:
>From: Luke Wang <ziniu.wang_1@nxp.com>
>
>Current mmc bootpart-resize cmd only support samsung emmc boot/rpmb
>partition resizing. Add sandisk and micron emmc boot/rpmb partition
>resizing support. The commands and parameters for resizing partitions
>are different for each manufacturer. Select the corresponding function
>according to cid.
>
>Signed-off-by: Luke Wang <ziniu.wang_1@nxp.com>

LGTM:

Reviewed-by: Peng Fan <peng.fan@nxp.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mmc: mmc_boot: support sandisk and micron emmc boot/rpmb partition resizing
  2025-03-17  8:46 [PATCH v2] mmc: mmc_boot: support sandisk and micron emmc boot/rpmb partition resizing ziniu.wang_1
  2025-03-24  8:20 ` Peng Fan
@ 2025-03-24 14:11 ` Marek Vasut
  2025-03-25  3:20   ` [EXT] " Luke Wang
  1 sibling, 1 reply; 4+ messages in thread
From: Marek Vasut @ 2025-03-24 14:11 UTC (permalink / raw)
  To: ziniu.wang_1, peng.fan, jh80.chung, trini
  Cc: pbrobinson, marek.vasut+renesas, tharvey, jonas, sjg, u-boot

On 3/17/25 9:46 AM, ziniu.wang_1@nxp.com wrote:
> From: Luke Wang <ziniu.wang_1@nxp.com>
> 
> Current mmc 

MMC

> bootpart-resize cmd

command

> only support samsung emmc boot/rpmb

Samsung eMMC BOOT/RPMB hardware

> partition resizing. Add sandisk and micron emmc boot/rpmb

Sandisk and Micron eMMC BOOT/RPMB hardware

Please fix capital letters and upper case abbreviations globally.

> partition
> resizing support. The commands and parameters for resizing partitions
> are different for each manufacturer. Select the corresponding function
> according to cid.

[...]

> +/*
> + * This function changes the size of boot partition and the size of rpmb
> + * partition present on EMMC devices.

eMMC

> + * Input Parameters:
> + * struct *mmc: pointer for the mmc device strcuture
> + * bootsize: size of boot partition
> + * rpmbsize: size of rpmb partition
> + *
> + * Returns 0 on success.
> + */
> +
Thanks !

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [EXT] Re: [PATCH v2] mmc: mmc_boot: support sandisk and micron emmc boot/rpmb partition resizing
  2025-03-24 14:11 ` Marek Vasut
@ 2025-03-25  3:20   ` Luke Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Luke Wang @ 2025-03-25  3:20 UTC (permalink / raw)
  To: Marek Vasut, Peng Fan, jh80.chung@samsung.com, trini@konsulko.com
  Cc: pbrobinson@gmail.com, marek.vasut+renesas@mailbox.org,
	tharvey@gateworks.com, jonas@kwiboo.se, sjg@chromium.org,
	u-boot@lists.denx.de



> -----Original Message-----
> From: Marek Vasut <marek.vasut@mailbox.org>
> Sent: Monday, March 24, 2025 10:11 PM
> To: Luke Wang <ziniu.wang_1@nxp.com>; Peng Fan <peng.fan@nxp.com>;
> jh80.chung@samsung.com; trini@konsulko.com
> Cc: pbrobinson@gmail.com; marek.vasut+renesas@mailbox.org;
> tharvey@gateworks.com; jonas@kwiboo.se; sjg@chromium.org; u-
> boot@lists.denx.de
> Subject: [EXT] Re: [PATCH v2] mmc: mmc_boot: support sandisk and micron
> emmc boot/rpmb partition resizing
> 
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report
> this email' button
> 
> 
> On 3/17/25 9:46 AM, ziniu.wang_1@nxp.com wrote:
> > From: Luke Wang <ziniu.wang_1@nxp.com>
> >
> > Current mmc
> 
> MMC

'mmc bootpart-resize' is a uboot command. I think we should keep low case.
> 
> > bootpart-resize cmd
> 
> command
> 
> > only support samsung emmc boot/rpmb
> 
> Samsung eMMC BOOT/RPMB hardware

OK
> 
> > partition resizing. Add sandisk and micron emmc boot/rpmb
> 
> Sandisk and Micron eMMC BOOT/RPMB hardware
> 
> Please fix capital letters and upper case abbreviations globally.

Thanks Marek. I will fix it in v3.

Regards,
Luke
> 
> > partition
> > resizing support. The commands and parameters for resizing partitions
> > are different for each manufacturer. Select the corresponding function
> > according to cid.
> 
> [...]
> 
> > +/*
> > + * This function changes the size of boot partition and the size of rpmb
> > + * partition present on EMMC devices.
> 
> eMMC
> 
> > + * Input Parameters:
> > + * struct *mmc: pointer for the mmc device strcuture
> > + * bootsize: size of boot partition
> > + * rpmbsize: size of rpmb partition
> > + *
> > + * Returns 0 on success.
> > + */
> > +
> Thanks !

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-25 14:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17  8:46 [PATCH v2] mmc: mmc_boot: support sandisk and micron emmc boot/rpmb partition resizing ziniu.wang_1
2025-03-24  8:20 ` Peng Fan
2025-03-24 14:11 ` Marek Vasut
2025-03-25  3:20   ` [EXT] " Luke Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox