Skip to contentSkip to conversation

spl: mmc: Pass eMMC HW partition and SW partition to spl_mmc_get_uboot_raw_sector()

PATCH In review Marek Vasut 3 participants 10 messages Apr 4, 2023 – Apr 5, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 spl: mmc: Pass eMMC HW partition and SW partition to spl_mmc_get_uboot_raw_sector()

Pass both eMMC HW partition and software partition numbers to spl_mmc_get_uboot_raw_sector() so the function can better decide which offset within the partition to load payload from.

---
Cc: Jaehoon Chung <[email protected]>
Cc: Peng Fan <[email protected]>
---
V2: No change
V3: Update on u-boot/master, update spl.h function prototype

---
 arch/arm/mach-imx/image-container.c               |  2 ++
 arch/arm/mach-sunxi/board.c                       |  2 ++
 .../advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c |  4 +++-
 common/spl/spl_mmc.c                              | 15 +++++++++------
 include/spl.h                                     |  4 ++++
 5 files changed, 20 insertions(+), 7 deletions(-)
arch/arm/mach-imx/image-container.c +2 -0
index 5b059a64292..2eb8d5f6b9d 100644
@@ -216,6 +216,8 @@ unsigned long spl_spi_get_uboot_offs(struct spi_flash *flash)
 
 #ifdef CONFIG_SPL_MMC
 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
+					   unsigned long hw_part,
+					   unsigned long raw_part,
 					   unsigned long raw_sect)
 {
 	int end;
arch/arm/mach-sunxi/board.c +2 -0
index 391a65a5495..3be444d84fe 100644
@@ -324,6 +324,8 @@ uint32_t sunxi_get_spl_size(void)
  * immediately follow the SPL if that is bigger than that.
  */
 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
+					   unsigned long hw_part,
+					   unsigned long raw_part,
 					   unsigned long raw_sect)
 {
 	unsigned long spl_size = sunxi_get_spl_size();
board/advantech/imx8mp_rsb3720a1/imx8mp_rsb3720a1.c +3 -1
index 466174679e8..af9d0040261 100644
@@ -194,7 +194,9 @@ int board_late_init(void)
 #ifdef CONFIG_SPL_MMC
 #define UBOOT_RAW_SECTOR_OFFSET 0x40
 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
-					   unsigned long raw_sector)
+					   unsigned long hw_part,
+					   unsigned long raw_part,
+					   unsigned long raw_sect);
 {
 	u32 boot_dev = spl_boot_device();
 
common/spl/spl_mmc.c +9 -6
index bd5e6adf1ea..f1f87d78ba7 100644
@@ -362,6 +362,8 @@ int __weak spl_mmc_boot_partition(const u32 boot_device)
 #endif
 
 unsigned long __weak spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
+						  unsigned long hw_part,
+						  unsigned long raw_part,
 						  unsigned long raw_sect)
 {
 	return raw_sect;
@@ -410,7 +412,7 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 	static struct mmc *mmc;
 	u32 boot_mode;
 	int err = 0;
-	__maybe_unused int part = 0;
+	__maybe_unused int hw_part = 0;
 	int mmc_dev;
 
 	/* Perform peripheral init only once for an mmc device */
@@ -434,12 +436,12 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 	err = -EINVAL;
 	switch (boot_mode) {
 	case MMCSD_MODE_EMMCBOOT:
-		part = spl_mmc_emmc_boot_partition(mmc);
+		hw_part = spl_mmc_emmc_boot_partition(mmc);
 
 		if (CONFIG_IS_ENABLED(MMC_TINY))
-			err = mmc_switch_part(mmc, part);
+			err = mmc_switch_part(mmc, hw_part);
 		else
-			err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part);
+			err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), hw_part);
 
 		if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
@@ -457,7 +459,8 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 				return err;
 		}
 
-		raw_sect = spl_mmc_get_uboot_raw_sector(mmc, raw_sect);
+		raw_sect = spl_mmc_get_uboot_raw_sector(mmc, hw_part,
+							raw_part, raw_sect);
 
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
 		err = mmc_load_image_raw_partition(spl_image, bootdev,
@@ -468,7 +471,7 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 #endif
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 		err = mmc_load_image_raw_sector(spl_image, bootdev, mmc,
-				raw_sect + spl_mmc_raw_uboot_offset(part));
+				raw_sect + spl_mmc_raw_uboot_offset(hw_part));
 		if (!err)
 			return err;
 #endif
include/spl.h +4 -0
index 7e0f5ac63b0..5e174547f26 100644
@@ -473,10 +473,14 @@ void spl_set_bd(void);
  * where the start of the U-Boot image has been written to.
  *
  * @mmc: struct mmc that describes the devie where U-Boot resides
+ * @hw_part: The eMMC hardware partition where U-Boot is by default.
+ * @raw_part: The software partition where U-Boot is by default.
  * @raw_sect: The raw sector number where U-Boot is by default.
  * Return: The raw sector location that U-Boot resides at
  */
 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
+					   unsigned long hw_part,
+					   unsigned long raw_part,
 					   unsigned long raw_sect);
 
 /**
Signature · 1 line
2.39.2
#1 lore raw

PATCH v3 2/2 spl: mmc: Pass eMMC HW partition 7 through

The eMMC HW partition 0 and 7 both mean USER HW partition. Use this as a mean of propagating A/B copy selection within USER HW partition. The spl_mmc_get_uboot_raw_sector() can detect that a USER HW partition is in use and based on whether it is 0 or 7, select appropriate sector to load from.

---
Cc: Jaehoon Chung <[email protected]>
Cc: Peng Fan <[email protected]>
---
V2: Initialize the part variable, else it is passed uninitialized to
mmc_load_image_raw_sector(..raw_sect + spl_mmc_raw_uboot_offset(part)); and that prevents pine64 from booting. Interestingly enough, there is no warning emitted, which sounds like a compiler bug.
V3: Update on u-boot/master

---
 common/spl/spl_mmc.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
common/spl/spl_mmc.c +5 -4
index f1f87d78ba7..865c395b9fe 100644
@@ -412,7 +412,7 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 	static struct mmc *mmc;
 	u32 boot_mode;
 	int err = 0;
-	__maybe_unused int hw_part = 0;
+	__maybe_unused int part = 0, hw_part = 0;
 	int mmc_dev;
 
 	/* Perform peripheral init only once for an mmc device */
@@ -437,11 +437,12 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 	switch (boot_mode) {
 	case MMCSD_MODE_EMMCBOOT:
 		hw_part = spl_mmc_emmc_boot_partition(mmc);
+		part = hw_part == 7 ? 0 : hw_part;
 
 		if (CONFIG_IS_ENABLED(MMC_TINY))
-			err = mmc_switch_part(mmc, hw_part);
+			err = mmc_switch_part(mmc, part);
 		else
-			err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), hw_part);
+			err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part);
 
 		if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
@@ -471,7 +472,7 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 #endif
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 		err = mmc_load_image_raw_sector(spl_image, bootdev, mmc,
-				raw_sect + spl_mmc_raw_uboot_offset(hw_part));
+				raw_sect + spl_mmc_raw_uboot_offset(part));
 		if (!err)
 			return err;
 #endif
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v3 2/2] spl: mmc: Pass eMMC HW partition 7 through

Quoted 1 line · On Tuesday 04 April 2023 20:05:15 Marek Vasut wrote:

The eMMC HW partition 0 and 7 both mean USER HW partition.

This is not truth!

Quoted 35 lines

Use this as
a mean of propagating A/B copy selection within USER HW partition. The spl_mmc_get_uboot_raw_sector() can detect that a USER HW partition is in use and based on whether it is 0 or 7, select appropriate sector to load from.

---
Cc: Jaehoon Chung <[email protected]>
Cc: Peng Fan <[email protected]>
---
V2: Initialize the part variable, else it is passed uninitialized to
mmc_load_image_raw_sector(..raw_sect + spl_mmc_raw_uboot_offset(part)); and that prevents pine64 from booting. Interestingly enough, there is no warning emitted, which sounds like a compiler bug.
V3: Update on u-boot/master

---
 common/spl/spl_mmc.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
common/spl/spl_mmc.c +1 -1
index f1f87d78ba7..865c395b9fe 100644
@@ -412,7 +412,7 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 	static struct mmc *mmc;
 	u32 boot_mode;
 	int err = 0;
-	__maybe_unused int hw_part = 0;
+	__maybe_unused int part = 0, hw_part = 0;
 	int mmc_dev;
 
 	/* Perform peripheral init only once for an mmc device */

common/spl/spl_mmc.c int spl_mmc_load(struct spl_image_info *spl_image, · line 440

Quoted 4 lines
common/spl/spl_mmc.c +1 -0
@@ -437,11 +437,12 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 	switch (boot_mode) {
 	case MMCSD_MODE_EMMCBOOT:
 		hw_part = spl_mmc_emmc_boot_partition(mmc);
+		part = hw_part == 7 ? 0 : hw_part;

... and so this change will break accessing eMMC part 7 / GP4.

Quoted 22 lines
common/spl/spl_mmc.c +3 -3
 		if (CONFIG_IS_ENABLED(MMC_TINY))
-			err = mmc_switch_part(mmc, hw_part);
+			err = mmc_switch_part(mmc, part);
 		else
-			err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), hw_part);
+			err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part);
 
 		if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
@@ -471,7 +472,7 @@ int spl_mmc_load(struct spl_image_info *spl_image,
 #endif
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 		err = mmc_load_image_raw_sector(spl_image, bootdev, mmc,
-				raw_sect + spl_mmc_raw_uboot_offset(hw_part));
+				raw_sect + spl_mmc_raw_uboot_offset(part));
 		if (!err)
 			return err;
 #endif
Signature · 1 line
2.39.2
#3 lore raw

Re: [PATCH v3 2/2] spl: mmc: Pass eMMC HW partition 7 through

Quoted 4 lines · Pali Rohár
Quoted 1 line · On Tuesday 04 April 2023 20:05:15 Marek Vasut wrote:

The eMMC HW partition 0 and 7 both mean USER HW partition.

This is not truth!

Can you please provide further details to back your claim ?

This kind of screaming feedback with zero additional information is worthless, sorry. Before you proceed with any further replies, please have a look at JEDEC JESD84-B51 section 7.4.69 PARTITION_CONFIG Bit[5:3] BOOT_PARTITION_ENABLE , this is what is being discussed here. Value 1/2 is either BOOT HW partition, value 0/7 is treated as USER HW partition by the boot code.

#4 lore raw

Re: [PATCH v3 2/2] spl: mmc: Pass eMMC HW partition 7 through

Quoted 7 lines · On Wednesday 05 April 2023 00:11:17 Marek Vasut wrote:
Quoted 4 lines · Pali Rohár
Quoted 1 line · On Tuesday 04 April 2023 20:05:15 Marek Vasut wrote:

The eMMC HW partition 0 and 7 both mean USER HW partition.

This is not truth!

Can you please provide further details to back your claim ?

Yes, see a patch with explanation which I meanwhile sent:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Quoted 6 lines

This kind of screaming feedback with zero additional information is worthless, sorry. Before you proceed with any further replies, please have a look at JEDEC JESD84-B51 section 7.4.69 PARTITION_CONFIG Bit[5:3] BOOT_PARTITION_ENABLE , this is what is being discussed here. Value 1/2 is either BOOT HW partition, value 0/7 is treated as USER HW partition by the boot code.

#5 lore raw

Re: [PATCH v3 2/2] spl: mmc: Pass eMMC HW partition 7 through

Quoted 11 lines · Pali Rohár
Quoted 7 lines · On Wednesday 05 April 2023 00:11:17 Marek Vasut wrote:
Quoted 4 lines · Pali Rohár
Quoted 1 line · On Tuesday 04 April 2023 20:05:15 Marek Vasut wrote:

The eMMC HW partition 0 and 7 both mean USER HW partition.

This is not truth!

Can you please provide further details to back your claim ?

Yes, see a patch with explanation which I meanwhile sent:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

This very much adds a comment that looks like the content of the second paragraph of my reply, see below.

It is a good thing you mention the aforementioned patch, since exactly one line past the changes you implemented is the following piece of code:

https://source.denx.de/u-boot/u-boot/-/blob/master/common/spl/spl_mmc.c#L382

"
int default_spl_mmc_emmc_boot_partition(struct mmc *mmc)
...
part = (mmc->part_config >> 3) & PART_ACCESS_MASK; if (part == 7)

    part = 0;

"

Which maps 7 to 0 .

Quoted 6 lines
Quoted 6 lines

This kind of screaming feedback with zero additional information is worthless, sorry. Before you proceed with any further replies, please have a look at JEDEC JESD84-B51 section 7.4.69 PARTITION_CONFIG Bit[5:3] BOOT_PARTITION_ENABLE , this is what is being discussed here. Value 1/2 is either BOOT HW partition, value 0/7 is treated as USER HW partition by the boot code.

Please read the paragraph above, I do not see any reply to it and I think that might put the conversation back on track.

#6 lore raw

Re: [PATCH v3 2/2] spl: mmc: Pass eMMC HW partition 7 through

Quoted 38 lines · On Wednesday 05 April 2023 00:33:02 Marek Vasut wrote:
Quoted 11 lines · Pali Rohár
Quoted 7 lines · On Wednesday 05 April 2023 00:11:17 Marek Vasut wrote:
Quoted 4 lines · Pali Rohár
Quoted 1 line · On Tuesday 04 April 2023 20:05:15 Marek Vasut wrote:

The eMMC HW partition 0 and 7 both mean USER HW partition.

This is not truth!

Can you please provide further details to back your claim ?

Yes, see a patch with explanation which I meanwhile sent:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

This very much adds a comment that looks like the content of the second paragraph of my reply, see below.

It is a good thing you mention the aforementioned patch, since exactly one line past the changes you implemented is the following piece of code:

https://source.denx.de/u-boot/u-boot/-/blob/master/common/spl/spl_mmc.c#L382

"
int default_spl_mmc_emmc_boot_partition(struct mmc *mmc)
...
part = (mmc->part_config >> 3) & PART_ACCESS_MASK; if (part == 7)

    part = 0;

"

Which maps 7 to 0 .

Quoted 6 lines
Quoted 6 lines

This kind of screaming feedback with zero additional information is worthless, sorry. Before you proceed with any further replies, please have a look at JEDEC JESD84-B51 section 7.4.69 PARTITION_CONFIG Bit[5:3] BOOT_PARTITION_ENABLE , this is what is being discussed here. Value 1/2 is either BOOT HW partition, value 0/7 is treated as USER HW partition by the boot code.

Quoted 2 lines

Please read the paragraph above, I do not see any reply to it and I think that might put the conversation back on track.

I have read it and the reply with explanation is already there in my first email and also in the linked email.

What you have written above in not truth.

#7 lore raw

Re: [PATCH v3 2/2] spl: mmc: Pass eMMC HW partition 7 through

Quoted 39 lines · Pali Rohár
Quoted 38 lines · On Wednesday 05 April 2023 00:33:02 Marek Vasut wrote:
Quoted 11 lines · Pali Rohár
Quoted 7 lines · On Wednesday 05 April 2023 00:11:17 Marek Vasut wrote:
Quoted 4 lines · Pali Rohár
Quoted 1 line · On Tuesday 04 April 2023 20:05:15 Marek Vasut wrote:

The eMMC HW partition 0 and 7 both mean USER HW partition.

This is not truth!

Can you please provide further details to back your claim ?

Yes, see a patch with explanation which I meanwhile sent:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

This very much adds a comment that looks like the content of the second paragraph of my reply, see below.

It is a good thing you mention the aforementioned patch, since exactly one line past the changes you implemented is the following piece of code:

https://source.denx.de/u-boot/u-boot/-/blob/master/common/spl/spl_mmc.c#L382

"
int default_spl_mmc_emmc_boot_partition(struct mmc *mmc)
...
part = (mmc->part_config >> 3) & PART_ACCESS_MASK; if (part == 7)

     part = 0;

"

Which maps 7 to 0 .

Quoted 6 lines
Quoted 6 lines

This kind of screaming feedback with zero additional information is worthless, sorry. Before you proceed with any further replies, please have a look at JEDEC JESD84-B51 section 7.4.69 PARTITION_CONFIG Bit[5:3] BOOT_PARTITION_ENABLE , this is what is being discussed here. Value 1/2 is either BOOT HW partition, value 0/7 is treated as USER HW partition by the boot code.

Quoted 7 lines
Quoted 2 lines

Please read the paragraph above, I do not see any reply to it and I think that might put the conversation back on track.

I have read it and the reply with explanation is already there in my first email and also in the linked email.

What you have written above in not truth.

Very well, I think I will defer further judgement to the MMC maintainer and stop participating in this thread. Constructive feedback is welcome.

#8 lore raw

Re: [PATCH v3 2/2] spl: mmc: Pass eMMC HW partition 7 through

Quoted 43 lines · On Wednesday 05 April 2023 01:03:49 Marek Vasut wrote:
Quoted 42 lines · Pali Rohár
Quoted 40 lines · On Wednesday 05 April 2023 00:33:02 Marek Vasut wrote:
Quoted 11 lines · Pali Rohár
Quoted 7 lines · On Wednesday 05 April 2023 00:11:17 Marek Vasut wrote:
Quoted 4 lines · Pali Rohár
Quoted 1 line · On Tuesday 04 April 2023 20:05:15 Marek Vasut wrote:

The eMMC HW partition 0 and 7 both mean USER HW partition.

This is not truth!

Can you please provide further details to back your claim ?

Yes, see a patch with explanation which I meanwhile sent:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

This very much adds a comment that looks like the content of the second paragraph of my reply, see below.

It is a good thing you mention the aforementioned patch, since exactly one line past the changes you implemented is the following piece of code:

https://source.denx.de/u-boot/u-boot/-/blob/master/common/spl/spl_mmc.c#L382

"
int default_spl_mmc_emmc_boot_partition(struct mmc *mmc)
...
part = (mmc->part_config >> 3) & PART_ACCESS_MASK; if (part == 7)

     part = 0;

"

Which maps 7 to 0 .

Quoted 6 lines
Quoted 6 lines

This kind of screaming feedback with zero additional information is worthless, sorry. Before you proceed with any further replies, please have a look at JEDEC JESD84-B51 section 7.4.69 PARTITION_CONFIG Bit[5:3] BOOT_PARTITION_ENABLE , this is what is being discussed here. Value 1/2 is either BOOT HW partition, value 0/7 is treated as USER HW partition by the boot code.

Please read the paragraph above, I do not see any reply to it and I think that might put the conversation back on track.

Quoted 7 lines
Quoted 4 lines

I have read it and the reply with explanation is already there in my first email and also in the linked email.

What you have written above in not truth.

Very well, I think I will defer further judgement to the MMC maintainer and stop participating in this thread. Constructive feedback is welcome.

I see that this is your standard trolling reaction for a very long time if you do not have any relevant argument; or when you are lazy to read replies from other people.

#9 lore raw

Re: [PATCH v3 2/2] spl: mmc: Pass eMMC HW partition 7 through

Quoted 7 lines · Pali Rohár
Quoted 6 lines · On Wednesday 05 April 2023 01:03:49 Marek Vasut wrote:
Quoted 5 lines · Pali Rohár
Quoted 4 lines · On Wednesday 05 April 2023 00:33:02 Marek Vasut wrote:
Quoted 3 lines · Pali Rohár
Quoted 2 lines · On Wednesday 05 April 2023 00:11:17 Marek Vasut wrote:
Quoted 1 line · Pali Rohár

On Tuesday 04 April 2023 20:05:15 Marek Vasut wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

The eMMC HW partition 0 and 7 both mean USER HW partition.

This is not truth!

Can you please provide further details to back your claim ?

Yes, see a patch with explanation which I meanwhile sent:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Please note that I'm not sure the comments in this patch are a correct reflection of what the code does, or is supposed to be doing. I need to go and study everything there again.

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 25 lines

This very much adds a comment that looks like the content of the second paragraph of my reply, see below.

It is a good thing you mention the aforementioned patch, since exactly one line past the changes you implemented is the following piece of code:

https://source.denx.de/u-boot/u-boot/-/blob/master/common/spl/spl_mmc.c#L382

"
int default_spl_mmc_emmc_boot_partition(struct mmc *mmc)
...
part = (mmc->part_config >> 3) & PART_ACCESS_MASK; if (part == 7)

     part = 0;

"

Which maps 7 to 0 .

Quoted 6 lines
Quoted 6 lines

This kind of screaming feedback with zero additional information is worthless, sorry. Before you proceed with any further replies, please have a look at JEDEC JESD84-B51 section 7.4.69 PARTITION_CONFIG Bit[5:3] BOOT_PARTITION_ENABLE , this is what is being discussed here. Value 1/2 is either BOOT HW partition, value 0/7 is treated as USER HW partition by the boot code.

Quoted 2 lines

Please read the paragraph above, I do not see any reply to it and I think that might put the conversation back on track.

I have read it and the reply with explanation is already there in my first email and also in the linked email.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What you have written above in not truth.

Very well, I think I will defer further judgement to the MMC maintainer and stop participating in this thread. Constructive feedback is welcome.

I see that this is your standard trolling reaction for a very long time if you do not have any relevant argument; or when you are lazy to read replies from other people.

That's uncalled for and rude, Pali. If you don't have anything further to add, technically, there's no need nor justification for such language.

Signature · 1 line
Tom