diff mbox series

[3/3] mmc: select the hardware partition after partconf command

Message ID 20261105-upstream_partconf_fixes-v1-3-6abda284aacf@foss.st.com
State New
Delegated to: Peng Fan
Headers show
Series mmc: mmc_set_part_conf() fixes | expand

Commit Message

Patrice CHOTARD Nov. 5, 2026, 9:03 a.m. UTC
From: Patrick Delaunay <patrick.delaunay@foss.st.com>

Select the hardware partition after partconf command as it is already
done in mmc_select_hwpart() / mmc_switch_part().

This patch fixes a "mmc partconf" command issue.

For example for the sequence on STM32MP157c-ev1 board on which we got
mmc 0 (SDCARD) and mmc 1 (eMMC).

before :

STM32MP> mmc dev 1
switch to partitions #0, OK
mmc1(part 0) is current device

STM32MP> mmc info
Device: STM32 SD/MMC
Manufacturer ID: 11
OEM: 0
Name: 004GA0
Bus Speed: 52000000
Mode: MMC High Speed (52MHz)
Rd Block Len: 512
MMC version 5.0
High Capacity: Yes
Capacity: 3.7 GiB
Bus Width: 8-bit
Erase Group Size: 512 KiB
HC WP Group Size: 4 MiB
User Capacity: 3.7 GiB WRREL
Boot Capacity: 2 MiB ENH
RPMB Capacity: 512 KiB ENH
Boot area 0 is not write protected
Boot area 1 is not write protected

STM32MP> mmc partconf 1 1 1 1

STM32MP> mmc info
Device: STM32 SD/MMC
Manufacturer ID: 11
OEM: 0
Name: 004GA0
Bus Speed: 52000000
Mode: MMC High Speed (52MHz)
Rd Block Len: 512
MMC version 5.0
High Capacity: Yes
Capacity: 3.7 GiB            <== incorrect size for EMMC_HWPART_BOOT1,
                                 still EMMC_HWPART_DEFAULT's size
Bus Width: 8-bit
Erase Group Size: 512 KiB
HC WP Group Size: 4 MiB
User Capacity: 3.7 GiB WRREL
Boot Capacity: 2 MiB ENH
RPMB Capacity: 512 KiB ENH
Boot area 0 is not write protected
Boot area 1 is not write protected

after :

STM32MP> mmc dev 1
switch to partitions #0, OK
mmc1(part 0) is current device

STM32MP> mmc info
Device: STM32 SD/MMC
Manufacturer ID: 11
OEM: 0
Name: 004GA0
Bus Speed: 52000000
Mode: MMC High Speed (52MHz)
Rd Block Len: 512
MMC version 5.0
High Capacity: Yes
Capacity: 3.7 GiB
Bus Width: 8-bit
Erase Group Size: 512 KiB
HC WP Group Size: 4 MiB
User Capacity: 3.7 GiB WRREL
Boot Capacity: 2 MiB ENH
RPMB Capacity: 512 KiB ENH
Boot area 0 is not write protected
Boot area 1 is not write protected

STM32MP> mmc partconf 1 1 1 1

STM32MP> mmc info
Device: STM32 SD/MMC
Manufacturer ID: 11
OEM: 0
Name: 004GA0
Bus Speed: 52000000
Mode: MMC High Speed (52MHz)
Rd Block Len: 512
MMC version 5.0
High Capacity: Yes
Capacity: 2 MiB              <== correct size for EMMC_HWPART_BOOT1
Bus Width: 8-bit
Erase Group Size: 512 KiB
HC WP Group Size: 4 MiB
User Capacity: 3.7 GiB WRREL
Boot Capacity: 2 MiB ENH
RPMB Capacity: 512 KiB ENH
Boot area 0 is not write protected
Boot area 1 is not write protected

The previous mmc_set_part_conf() implementation set access to boot
partition without correctly managing the internal mmc variables.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
---
 drivers/mmc/mmc_boot.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/mmc/mmc_boot.c b/drivers/mmc/mmc_boot.c
index 986e6c500b1..859aa5fd1d8 100644
--- a/drivers/mmc/mmc_boot.c
+++ b/drivers/mmc/mmc_boot.c
@@ -216,6 +216,7 @@  int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
 {
 	int ret;
 	u8 part_conf;
+	struct blk_desc *desc = mmc_get_blk_desc(mmc);
 
 	part_conf = EXT_CSD_BOOT_ACK(ack) |
 		    EXT_CSD_BOOT_PART_NUM(part_num) |
@@ -223,10 +224,20 @@  int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
 
 	ret = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
 			 part_conf);
-	if (!ret)
-		mmc->part_config = part_conf;
+	if (ret)
+		return ret;
+
+	mmc->part_config = part_conf;
+	/* Keep the block device in sync with the new PARTITION_ACCESS */
+	if (desc && desc->hwpart != access) {
+		ret = mmc_set_capacity(mmc, access);
+		if (ret)
+			return ret;
+		desc->hwpart = access;
+		blkcache_invalidate(desc->uclass_id, desc->devnum);
+	}
 
-	return ret;
+	return 0;
 }
 
 /*