Skip to contentSkip to conversation

cmd: bcb: select user(0) hwpart in __bcb_load()

PATCH In review Mattijs Korpershoek 3 participants 3 messages Oct 13, 2022 – Oct 24, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cmd: bcb: select user(0) hwpart in __bcb_load()

For some blk operations, it's possible that a different hw partition gets selected via blk_dselect_hwpart().
In that case, only the region of the device covered by that partition is accessible.

This breaks "bcb load" which attempts to read the gpt and assumes it's on the user(0) hw partition:

=> bcb load 2 misc
GUID Partition Table Header signature is wrong: 0xDE7B17AD07D9E5D6 != 0x5452415020494645
find_valid_gpt: *** ERROR: Invalid GPT ***
GUID Partition Table Header signature is wrong: 0x0 != 0x5452415020494645
find_valid_gpt: *** ERROR: Invalid Backup GPT ***
Error: mmc 2:misc read failed (-2)

Add a fail-safe in __bcb_load() to ensure we will always read from the user(0) hwpartition.

This fixes the following fastboot sequence:

$ fastboot erase mmc2boot1    # switch to hwpart1
$ fastboot reboot bootloader  # switch to hwpart0, then reads GPT

---
Changes in v2:

* Move hwpart selection into the bcb command instead of fb_mmc.c
* Link to v1: https://lore.kernel.org/r/[email protected]

---
 cmd/bcb.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
cmd/bcb.c +11 -0
index 1622a90c97f0..02d0c70d87e2 100644
@@ -14,6 +14,7 @@
 #include <part.h>
 #include <malloc.h>
 #include <memalign.h>
+#include <linux/err.h>
 
 enum bcb_cmd {
 	BCB_CMD_LOAD,
@@ -128,6 +129,16 @@ static int __bcb_load(int devnum, const char *partp)
 		goto err_read_fail;
 	}
 
+	/*
+	 * always select the USER mmc hwpart in case another
+	 * blk operation selected a different hwpart
+	 */
+	ret = blk_dselect_hwpart(desc, 0);
+	if (IS_ERR_VALUE(ret)) {
+		ret = -ENODEV;
+		goto err_read_fail;
+	}
+
 	part = simple_strtoul(partp, &endp, 0);
 	if (*endp == '\0') {
 		ret = part_get_info(desc, part, &info);

---
base-commit: c4c32e359662aa95d9dbda2bd1272181bd9cb830
change-id: 20221011-usb-hwpart-599c278980b3

Best regards,

Signature · 1 line
Mattijs Korpershoek <[email protected]>
Reviewed-by on v2 1/1
#1 lore raw
Quoted 67 lines · Mattijs Korpershoek

For some blk operations, it's possible that a different hw partition gets selected via blk_dselect_hwpart().
In that case, only the region of the device covered by that partition is accessible.

This breaks "bcb load" which attempts to read the gpt and assumes it's on the user(0) hw partition:

=> bcb load 2 misc
GUID Partition Table Header signature is wrong: 0xDE7B17AD07D9E5D6 != 0x5452415020494645
find_valid_gpt: *** ERROR: Invalid GPT ***
GUID Partition Table Header signature is wrong: 0x0 != 0x5452415020494645
find_valid_gpt: *** ERROR: Invalid Backup GPT ***
Error: mmc 2:misc read failed (-2)

Add a fail-safe in __bcb_load() to ensure we will always read from the user(0) hwpartition.

This fixes the following fastboot sequence:

$ fastboot erase mmc2boot1    # switch to hwpart1
$ fastboot reboot bootloader  # switch to hwpart0, then reads GPT

---
Changes in v2:

* Move hwpart selection into the bcb command instead of fb_mmc.c
* Link to v1: https://lore.kernel.org/r/[email protected]

---
 cmd/bcb.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
cmd/bcb.c +11 -1
index 1622a90c97f0..02d0c70d87e2 100644
@@ -14,6 +14,7 @@
 #include <part.h>
 #include <malloc.h>
 #include <memalign.h>
+#include <linux/err.h>
 
 enum bcb_cmd {
 	BCB_CMD_LOAD,
@@ -128,6 +129,16 @@ static int __bcb_load(int devnum, const char *partp)
 		goto err_read_fail;
 	}
 
+	/*
+	 * always select the USER mmc hwpart in case another
+	 * blk operation selected a different hwpart
+	 */
+	ret = blk_dselect_hwpart(desc, 0);
+	if (IS_ERR_VALUE(ret)) {
+		ret = -ENODEV;
+		goto err_read_fail;
+	}
+
 	part = simple_strtoul(partp, &endp, 0);
 	if (*endp == '\0') {
 		ret = part_get_info(desc, part, &info);
 
---

base-commit: c4c32e359662aa95d9dbda2bd1272181bd9cb830
change-id: 20221011-usb-hwpart-599c278980b3

Quoted 2 lines

Best regards,

#2 lore raw
In reply to Mattijs Korpershoek
Quoted 18 lines · Mattijs Korpershoek

For some blk operations, it's possible that a different hw partition gets selected via blk_dselect_hwpart().
In that case, only the region of the device covered by that partition is accessible.

This breaks "bcb load" which attempts to read the gpt and assumes it's on the user(0) hw partition:

=> bcb load 2 misc
GUID Partition Table Header signature is wrong: 0xDE7B17AD07D9E5D6 != 0x5452415020494645
find_valid_gpt: *** ERROR: Invalid GPT ***
GUID Partition Table Header signature is wrong: 0x0 != 0x5452415020494645
find_valid_gpt: *** ERROR: Invalid Backup GPT ***
Error: mmc 2:misc read failed (-2)

Add a fail-safe in __bcb_load() to ensure we will always read from the user(0) hwpartition.

Quoted 7 lines

This fixes the following fastboot sequence:

$ fastboot erase mmc2boot1    # switch to hwpart1
$ fastboot reboot bootloader  # switch to hwpart0, then reads GPT

Applied to u-boot/master, thanks!

Signature · 1 line
Tom