Skip to contentSkip to conversation

Fix 'mbr' command with hybrid MBR/GPT

PATCH Superseded Joshua Watt 4 participants 23 messages Jun 24, 2023 – Jul 18, 2023

lore
Share & tools
lore
#5 lore raw

PATCH 2/2 cmd: mbr: Force DOS driver to be used for verify

In reply to Joshua Watt

Forces the DOS partition type driver to be used when verifying the MBR. This is particularly useful when using a hybrid MBR & GPT layout as otherwise MBR verification would mostly likely fail since the GPT partitions will be returned, even if the MBR is actually valid.

---
 cmd/mbr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/mbr.c +1 -1
index c269833eb8..ec99b66283 100644
@@ -244,7 +244,7 @@ static int do_verify_mbr(struct blk_desc *dev, const char *str)
 	for (i = 0; i < count; i++) {
 		struct disk_partition p;
 
-		if (part_get_info(dev, i + 1, &p))
+		if (part_get_info_by_type(dev, i + 1, PART_TYPE_DOS, &p))
 			goto fail;
 
 		if ((partitions[i].size && p.size != partitions[i].size) ||
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/2 disk: part: Add API to get partitions with specific driver

In reply to Joshua Watt

Adds part_driver_get_type() API which can be used to force a specific driver to be used when getting partition information instead of relying on auto detection.

---
 disk/part.c    | 38 +++++++++++++++++++++++++++++++-------
 include/part.h |  2 ++
 2 files changed, 33 insertions(+), 7 deletions(-)
disk/part.c +31 -7
index 35300df590..1f8c786ca5 100644
@@ -26,6 +26,22 @@
 /* Check all partition types */
 #define PART_TYPE_ALL		-1
 
+static struct part_driver *part_driver_get_type(int part_type)
+{
+	struct part_driver *drv =
+		ll_entry_start(struct part_driver, part_driver);
+	const int n_ents = ll_entry_count(struct part_driver, part_driver);
+	struct part_driver *entry;
+
+	for (entry = drv; entry != drv + n_ents; entry++) {
+		if (part_type == entry->part_type)
+			return entry;
+	}
+
+	/* Not found */
+	return NULL;
+}
+
 static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 {
 	struct part_driver *drv =
@@ -44,10 +60,7 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 			}
 		}
 	} else {
-		for (entry = drv; entry != drv + n_ents; entry++) {
-			if (dev_desc->part_type == entry->part_type)
-				return entry;
-		}
+		return part_driver_get_type(dev_desc->part_type);
 	}
 
 	/* Not found */
@@ -306,8 +319,8 @@ void part_print(struct blk_desc *dev_desc)
 		drv->print(dev_desc);
 }
 
-int part_get_info(struct blk_desc *dev_desc, int part,
-		       struct disk_partition *info)
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+			  struct disk_partition *info)
 {
 	struct part_driver *drv;
 
@@ -320,7 +333,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
 		info->type_guid[0] = 0;
 #endif
 
-		drv = part_driver_lookup_type(dev_desc);
+		if (part_type == PART_TYPE_UNKNOWN) {
+			drv = part_driver_lookup_type(dev_desc);
+		} else {
+			drv = part_driver_get_type(part_type);
+		}
+
 		if (!drv) {
 			debug("## Unknown partition table type %x\n",
 			      dev_desc->part_type);
@@ -340,6 +358,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
 	return -ENOENT;
 }
 
+int part_get_info(struct blk_desc *dev_desc, int part,
+		  struct disk_partition *info)
+{
+	return part_get_info_by_type(dev_desc, part, PART_TYPE_UNKNOWN, info);
+}
+
 int part_get_info_whole_disk(struct blk_desc *dev_desc,
 			     struct disk_partition *info)
 {
include/part.h +2 -0
index be75c73549..f150c84206 100644
@@ -106,6 +106,8 @@ struct blk_desc *blk_get_dev(const char *ifname, int dev);
 struct blk_desc *mg_disk_get_dev(int dev);
 
 /* disk/part.c */
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+			  struct disk_partition *info);
 int part_get_info(struct blk_desc *dev_desc, int part,
 		  struct disk_partition *info);
 /**
Signature · 1 line
2.33.0
#0 lore raw

cover Fix 'mbr' command with hybrid MBR/GPT

When dealing with a hybrid MBR/GPT partition table, the 'mbr' command would misbehave because it was reading the GPT partitions instead of reading from the MBR when verifying. Fix this by forcing 'mbr verify' to read MBR partitions.

Joshua Watt (2):
disk: part: Add API to get partitions with specific driver
cmd: mbr: Force DOS driver to be used for verify

 cmd/mbr.c      |  2 +-
 disk/part.c    | 38 +++++++++++++++++++++++++++++++-------
 include/part.h |  2 ++
 3 files changed, 34 insertions(+), 8 deletions(-)
Signature · 1 line
2.33.0
#2 lore raw

Re: [PATCH 1/2] disk: part: Add API to get partitions with specific driver

In reply to Joshua Watt

Hi Joshua,

Quoted 93 lines · Joshua Watt

Adds part_driver_get_type() API which can be used to force a specific driver to be used when getting partition information instead of relying on auto detection.

---
 disk/part.c    | 38 +++++++++++++++++++++++++++++++-------
 include/part.h |  2 ++
 2 files changed, 33 insertions(+), 7 deletions(-)
disk/part.c +31 -7
index 35300df590..1f8c786ca5 100644
@@ -26,6 +26,22 @@
 /* Check all partition types */
 #define PART_TYPE_ALL          -1
 
+static struct part_driver *part_driver_get_type(int part_type)
+{
+       struct part_driver *drv =
+               ll_entry_start(struct part_driver, part_driver);
+       const int n_ents = ll_entry_count(struct part_driver, part_driver);
+       struct part_driver *entry;
+
+       for (entry = drv; entry != drv + n_ents; entry++) {
+               if (part_type == entry->part_type)
+                       return entry;
+       }
+
+       /* Not found */
+       return NULL;
+}
+
 static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 {
        struct part_driver *drv =
@@ -44,10 +60,7 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
                        }
                }
        } else {
-               for (entry = drv; entry != drv + n_ents; entry++) {
-                       if (dev_desc->part_type == entry->part_type)
-                               return entry;
-               }
+               return part_driver_get_type(dev_desc->part_type);
        }
 
        /* Not found */
@@ -306,8 +319,8 @@ void part_print(struct blk_desc *dev_desc)
                drv->print(dev_desc);
 }
 
-int part_get_info(struct blk_desc *dev_desc, int part,
-                      struct disk_partition *info)
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+                         struct disk_partition *info)
 {
        struct part_driver *drv;
 
@@ -320,7 +333,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
                info->type_guid[0] = 0;
 #endif
 
-               drv = part_driver_lookup_type(dev_desc);
+               if (part_type == PART_TYPE_UNKNOWN) {
+                       drv = part_driver_lookup_type(dev_desc);
+               } else {
+                       drv = part_driver_get_type(part_type);
+               }
+
                if (!drv) {
                        debug("## Unknown partition table type %x\n",
                              dev_desc->part_type);
@@ -340,6 +358,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
        return -ENOENT;
 }
 
+int part_get_info(struct blk_desc *dev_desc, int part,
+                 struct disk_partition *info)
+{
+       return part_get_info_by_type(dev_desc, part, PART_TYPE_UNKNOWN, info);
+}
+
 int part_get_info_whole_disk(struct blk_desc *dev_desc,
                             struct disk_partition *info)
 {
include/part.h +0 -0
index be75c73549..f150c84206 100644

include/part.h struct blk_desc *blk_get_dev(const char *ifname, int dev); · line 110

Quoted 5 lines
include/part.h +2 -0
@@ -106,6 +106,8 @@ struct blk_desc *blk_get_dev(const char *ifname, int dev);
 struct blk_desc *mg_disk_get_dev(int dev);
 
 /* disk/part.c */
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+                         struct disk_partition *info);

Please can you add a full comment?

Also please add a test to test/dm/part.c for your new function[1]

Quoted 6 lines
include/part.h +0 -1
 int part_get_info(struct blk_desc *dev_desc, int part,
                  struct disk_partition *info);
 /**
--

2.33.0

Regards,
Simon

#3 lore raw

Re: [PATCH 1/2] disk: part: Add API to get partitions with specific driver

Quoted 99 lines · Simon Glass

Hi Joshua,

Quoted 95 lines · Joshua Watt

Adds part_driver_get_type() API which can be used to force a specific driver to be used when getting partition information instead of relying on auto detection.

---
 disk/part.c    | 38 +++++++++++++++++++++++++++++++-------
 include/part.h |  2 ++
 2 files changed, 33 insertions(+), 7 deletions(-)
disk/part.c +31 -7
index 35300df590..1f8c786ca5 100644
@@ -26,6 +26,22 @@
 /* Check all partition types */
 #define PART_TYPE_ALL          -1
 
+static struct part_driver *part_driver_get_type(int part_type)
+{
+       struct part_driver *drv =
+               ll_entry_start(struct part_driver, part_driver);
+       const int n_ents = ll_entry_count(struct part_driver, part_driver);
+       struct part_driver *entry;
+
+       for (entry = drv; entry != drv + n_ents; entry++) {
+               if (part_type == entry->part_type)
+                       return entry;
+       }
+
+       /* Not found */
+       return NULL;
+}
+
 static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 {
        struct part_driver *drv =
@@ -44,10 +60,7 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
                        }
                }
        } else {
-               for (entry = drv; entry != drv + n_ents; entry++) {
-                       if (dev_desc->part_type == entry->part_type)
-                               return entry;
-               }
+               return part_driver_get_type(dev_desc->part_type);
        }
 
        /* Not found */
@@ -306,8 +319,8 @@ void part_print(struct blk_desc *dev_desc)
                drv->print(dev_desc);
 }
 
-int part_get_info(struct blk_desc *dev_desc, int part,
-                      struct disk_partition *info)
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+                         struct disk_partition *info)
 {
        struct part_driver *drv;
 
@@ -320,7 +333,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
                info->type_guid[0] = 0;
 #endif
 
-               drv = part_driver_lookup_type(dev_desc);
+               if (part_type == PART_TYPE_UNKNOWN) {
+                       drv = part_driver_lookup_type(dev_desc);
+               } else {
+                       drv = part_driver_get_type(part_type);
+               }
+
                if (!drv) {
                        debug("## Unknown partition table type %x\n",
                              dev_desc->part_type);
@@ -340,6 +358,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
        return -ENOENT;
 }
 
+int part_get_info(struct blk_desc *dev_desc, int part,
+                 struct disk_partition *info)
+{
+       return part_get_info_by_type(dev_desc, part, PART_TYPE_UNKNOWN, info);
+}
+
 int part_get_info_whole_disk(struct blk_desc *dev_desc,
                             struct disk_partition *info)
 {
include/part.h +0 -0
index be75c73549..f150c84206 100644
@@ -106,6 +106,8 @@ struct blk_desc *blk_get_dev(const char *ifname, int dev);
 struct blk_desc *mg_disk_get_dev(int dev);
 
Quoted 7 lines

include/part.h struct blk_desc *blk_get_dev(const char *ifname, int dev); · line 110

Quoted 3 lines
include/part.h +2 -0
 /* disk/part.c */
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+                         struct disk_partition *info);

Please can you add a full comment?

Also please add a test to test/dm/part.c for your new function[1]

Any trick to getting the current test/dm/part.c tests to pass? When I run them they fail with ** No device specified ** errors, which doesn't give me hope that I can write tests that I could actually run locally.

Quoted 10 lines
Quoted 7 lines
include/part.h +0 -1
 int part_get_info(struct blk_desc *dev_desc, int part,
                  struct disk_partition *info);
 /**
--

2.33.0

Regards,
Simon

#4 lore raw

Re: [PATCH 1/2] disk: part: Add API to get partitions with specific driver

Hi Joshua,

Quoted 107 lines · Joshua Watt
Quoted 105 lines · Simon Glass

Hi Joshua,

Quoted 93 lines · Joshua Watt

Adds part_driver_get_type() API which can be used to force a specific driver to be used when getting partition information instead of relying on auto detection.

---
 disk/part.c    | 38 +++++++++++++++++++++++++++++++-------
 include/part.h |  2 ++
 2 files changed, 33 insertions(+), 7 deletions(-)
disk/part.c +31 -7
index 35300df590..1f8c786ca5 100644
@@ -26,6 +26,22 @@
 /* Check all partition types */
 #define PART_TYPE_ALL          -1
 
+static struct part_driver *part_driver_get_type(int part_type)
+{
+       struct part_driver *drv =
+               ll_entry_start(struct part_driver, part_driver);
+       const int n_ents = ll_entry_count(struct part_driver, part_driver);
+       struct part_driver *entry;
+
+       for (entry = drv; entry != drv + n_ents; entry++) {
+               if (part_type == entry->part_type)
+                       return entry;
+       }
+
+       /* Not found */
+       return NULL;
+}
+
 static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 {
        struct part_driver *drv =
@@ -44,10 +60,7 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
                        }
                }
        } else {
-               for (entry = drv; entry != drv + n_ents; entry++) {
-                       if (dev_desc->part_type == entry->part_type)
-                               return entry;
-               }
+               return part_driver_get_type(dev_desc->part_type);
        }
 
        /* Not found */
@@ -306,8 +319,8 @@ void part_print(struct blk_desc *dev_desc)
                drv->print(dev_desc);
 }
 
-int part_get_info(struct blk_desc *dev_desc, int part,
-                      struct disk_partition *info)
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+                         struct disk_partition *info)
 {
        struct part_driver *drv;
 
@@ -320,7 +333,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
                info->type_guid[0] = 0;
 #endif
 
-               drv = part_driver_lookup_type(dev_desc);
+               if (part_type == PART_TYPE_UNKNOWN) {
+                       drv = part_driver_lookup_type(dev_desc);
+               } else {
+                       drv = part_driver_get_type(part_type);
+               }
+
                if (!drv) {
                        debug("## Unknown partition table type %x\n",
                              dev_desc->part_type);
@@ -340,6 +358,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
        return -ENOENT;
 }
 
+int part_get_info(struct blk_desc *dev_desc, int part,
+                 struct disk_partition *info)
+{
+       return part_get_info_by_type(dev_desc, part, PART_TYPE_UNKNOWN, info);
+}
+
 int part_get_info_whole_disk(struct blk_desc *dev_desc,
                             struct disk_partition *info)
 {
include/part.h +0 -0
index be75c73549..f150c84206 100644

include/part.h struct blk_desc *blk_get_dev(const char *ifname, int dev); · line 110

Quoted 5 lines
include/part.h +2 -0
@@ -106,6 +106,8 @@ struct blk_desc *blk_get_dev(const char *ifname, int dev);
 struct blk_desc *mg_disk_get_dev(int dev);
 
 /* disk/part.c */
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+                         struct disk_partition *info);

Please can you add a full comment?

Quoted 6 lines
Quoted 1 line

Also please add a test to test/dm/part.c for your new function[1]

Any trick to getting the current test/dm/part.c tests to pass? When I run them they fail with ** No device specified ** errors, which doesn't give me hope that I can write tests that I could actually run locally.

Yes you probably need to run the ''test_ut_dm_init_bootstd' test first. This pytest is run automatically if you run everything, but otherwise is not. It sets up the mmc1.img file.

Regards,
Simon

#6 lore raw

v2 cover Fix 'mbr' command with hybrid MBR/GPT

In reply to Joshua Watt

When dealing with a hybrid MBR/GPT partition table, the 'mbr' command would misbehave because it was reading the GPT partitions instead of reading from the MBR when verifying. Fix this by forcing 'mbr verify' to read MBR partitions.

V2: Fixed up dm_test_part tests and added tests for new API

Joshua Watt (5):
dm: test: Fix partition test to use mmc2
dm: test: Improve partition test error output
disk: part: Add API to get partitions with specific driver
dm: test: Add test for part_get_info_by_type
cmd: mbr: Force DOS driver to be used for verify

 cmd/mbr.c                 |   2 +-
 configs/sandbox_defconfig |   2 +
 disk/part.c               |  38 ++++++++++---
 include/part.h            |  19 ++++++-
 test/dm/part.c            | 115 +++++++++++++++++++++++++++++++++-----
 5 files changed, 154 insertions(+), 22 deletions(-)
Signature · 1 line
2.33.0
#7 lore raw

PATCH v2 1/5 dm: test: Fix partition test to use mmc2

d94d9844bc ("dm: part: Update test to use mmc2") attempted to make the test use mmc2, but the change was incomplete in that it didn't also change the strings that reference a specific partition. Fix these so that the test passes again

---
 test/dm/part.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
test/dm/part.c +9 -9
index 35e99eeb01..d5c58d6e3f 100644
@@ -76,15 +76,15 @@ static int dm_test_part(struct unit_test_state *uts)
 	test(-EINVAL, "#test1", true);
 	test(1, "2", false);
 	test(1, "2", true);
-	test(-ENOENT, "1:0", false);
-	test(0, "1:0", true);
-	test(1, "1:1", false);
-	test(2, "1:2", false);
-	test(1, "1.0", false);
-	test(0, "1.0:0", true);
-	test(1, "1.0:1", false);
-	test(2, "1.0:2", false);
-	test(-EINVAL, "1#bogus", false);
+	test(-ENOENT, "2:0", false);
+	test(0, "2:0", true);
+	test(1, "2:1", false);
+	test(2, "2:2", false);
+	test(1, "2.0", false);
+	test(0, "2.0:0", true);
+	test(1, "2.0:1", false);
+	test(2, "2.0:2", false);
+	test(-EINVAL, "2#bogus", false);
 	test(1, "2#test1", false);
 	test(2, "2#test2", false);
 	ret = 0;
Signature · 1 line
2.33.0
#11 lore raw

PATCH v2 2/5 dm: test: Improve partition test error output

In reply to Joshua Watt

Improve the logging when the partition test fails so that it is clear what went wrong, shown with actual values.

---
 test/dm/part.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
test/dm/part.c +6 -4
index d5c58d6e3f..7dd8bc7a3c 100644
@@ -17,10 +17,12 @@ static int do_test(struct unit_test_state *uts, int expected,
 	struct blk_desc *mmc_dev_desc;
 	struct disk_partition part_info;
 
-	ut_asserteq(expected,
-		    part_get_info_by_dev_and_name_or_num("mmc", part_str,
-							 &mmc_dev_desc,
-							 &part_info, whole));
+	int ret = part_get_info_by_dev_and_name_or_num("mmc", part_str,
+						       &mmc_dev_desc,
+						       &part_info, whole);
+
+	ut_assertf(expected == ret, "test(%d, \"%s\", %d) == %d", expected,
+		   part_str, whole, ret);
 	return 0;
 }
 
Signature · 1 line
2.33.0
#14 lore raw

PATCH v2 3/5 disk: part: Add API to get partitions with specific driver

In reply to Joshua Watt

Adds part_driver_get_type() API which can be used to force a specific driver to be used when getting partition information instead of relying on auto detection.

---
 disk/part.c    | 38 +++++++++++++++++++++++++++++++-------
 include/part.h | 19 ++++++++++++++++++-
 2 files changed, 49 insertions(+), 8 deletions(-)
disk/part.c +31 -7
index 35300df590..1f8c786ca5 100644
@@ -26,6 +26,22 @@
 /* Check all partition types */
 #define PART_TYPE_ALL		-1
 
+static struct part_driver *part_driver_get_type(int part_type)
+{
+	struct part_driver *drv =
+		ll_entry_start(struct part_driver, part_driver);
+	const int n_ents = ll_entry_count(struct part_driver, part_driver);
+	struct part_driver *entry;
+
+	for (entry = drv; entry != drv + n_ents; entry++) {
+		if (part_type == entry->part_type)
+			return entry;
+	}
+
+	/* Not found */
+	return NULL;
+}
+
 static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 {
 	struct part_driver *drv =
@@ -44,10 +60,7 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 			}
 		}
 	} else {
-		for (entry = drv; entry != drv + n_ents; entry++) {
-			if (dev_desc->part_type == entry->part_type)
-				return entry;
-		}
+		return part_driver_get_type(dev_desc->part_type);
 	}
 
 	/* Not found */
@@ -306,8 +319,8 @@ void part_print(struct blk_desc *dev_desc)
 		drv->print(dev_desc);
 }
 
-int part_get_info(struct blk_desc *dev_desc, int part,
-		       struct disk_partition *info)
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+			  struct disk_partition *info)
 {
 	struct part_driver *drv;
 
@@ -320,7 +333,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
 		info->type_guid[0] = 0;
 #endif
 
-		drv = part_driver_lookup_type(dev_desc);
+		if (part_type == PART_TYPE_UNKNOWN) {
+			drv = part_driver_lookup_type(dev_desc);
+		} else {
+			drv = part_driver_get_type(part_type);
+		}
+
 		if (!drv) {
 			debug("## Unknown partition table type %x\n",
 			      dev_desc->part_type);
@@ -340,6 +358,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
 	return -ENOENT;
 }
 
+int part_get_info(struct blk_desc *dev_desc, int part,
+		  struct disk_partition *info)
+{
+	return part_get_info_by_type(dev_desc, part, PART_TYPE_UNKNOWN, info);
+}
+
 int part_get_info_whole_disk(struct blk_desc *dev_desc,
 			     struct disk_partition *info)
 {
include/part.h +18 -1
index be75c73549..8a0c8732a6 100644
@@ -105,7 +105,24 @@ struct blk_desc *blk_get_dev(const char *ifname, int dev);
 
 struct blk_desc *mg_disk_get_dev(int dev);
 
-/* disk/part.c */
+/**
+ * part_get_info_by_type() - Get partitions from a block device using a specific
+ * partition driver
+ *
+ * Each interface allocates its own devices and typically struct blk_desc is
+ * contained with the interface's data structure. There is no global
+ * numbering for block devices, so the interface name must be provided.
+ *
+ * @dev_desc:	Block device descriptor
+ * @part:	Partition number to read
+ * @part_type:	Partition driver to use, or PART_TYPE_UNKNOWN to automatically
+ *		choose a driver
+ * @info:	Returned partition information
+ *
+ * Return: 0 on success, negative errno on failure
+ */
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+			  struct disk_partition *info);
 int part_get_info(struct blk_desc *dev_desc, int part,
 		  struct disk_partition *info);
 /**
Signature · 1 line
2.33.0
#17 lore raw

PATCH v2 4/5 dm: test: Add test for part_get_info_by_type

In reply to Joshua Watt

Adds a test suite to ensure that part_get_info_by_type works correctly by creating a hybrid GPT/MBR partition table and reading both.

---
 configs/sandbox_defconfig |  2 +
 test/dm/part.c            | 87 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
configs/sandbox_defconfig +2 -0
index 1ec44d5b33..cbc5d5b895 100644
@@ -71,6 +71,7 @@ CONFIG_CMD_GPIO_READ=y
 CONFIG_CMD_PWM=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_GPT_RENAME=y
+CONFIG_CMD_MBR=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_LOADM=y
@@ -131,6 +132,7 @@ CONFIG_CMD_MTDPARTS=y
 CONFIG_CMD_STACKPROTECTOR_TEST=y
 CONFIG_MAC_PARTITION=y
 CONFIG_AMIGA_PARTITION=y
+CONFIG_DOS_PARTITION=y
 CONFIG_OF_CONTROL=y
 CONFIG_OF_LIVE=y
 CONFIG_ENV_IS_NOWHERE=y
test/dm/part.c +87 -0

90 lines not on this page · raw message

Signature · 1 line
2.33.0
#20 lore raw

PATCH v2 5/5 cmd: mbr: Force DOS driver to be used for verify

In reply to Joshua Watt

Forces the DOS partition type driver to be used when verifying the MBR. This is particularly useful when using a hybrid MBR & GPT layout as otherwise MBR verification would mostly likely fail since the GPT partitions will be returned, even if the MBR is actually valid.

---
 cmd/mbr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/mbr.c +1 -1
index c269833eb8..ec99b66283 100644
@@ -244,7 +244,7 @@ static int do_verify_mbr(struct blk_desc *dev, const char *str)
 	for (i = 0; i < count; i++) {
 		struct disk_partition p;
 
-		if (part_get_info(dev, i + 1, &p))
+		if (part_get_info_by_type(dev, i + 1, PART_TYPE_DOS, &p))
 			goto fail;
 
 		if ((partitions[i].size && p.size != partitions[i].size) ||
Signature · 1 line
2.33.0
Reviewed-by on v2 1/5
#8 lore raw

Re: [PATCH v2 1/5] dm: test: Fix partition test to use mmc2

In reply to Joshua Watt
Quoted 11 lines · Joshua Watt

d94d9844bc ("dm: part: Update test to use mmc2") attempted to make the test use mmc2, but the change was incomplete in that it didn't also change the strings that reference a specific partition. Fix these so that the test passes again

---
 test/dm/part.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
Fixes d94d9844bc ("dm: part: Update test to use mmc2")

Thanks.

Reviewed-by on v2 3/5
#15 lore raw

Re: [PATCH v2 3/5] disk: part: Add API to get partitions with specific driver

In reply to Joshua Watt
Quoted 2 lines · Joshua Watt

Adds part_driver_get_type() API which can be used to force a specific

Nit: Add

Quoted 8 lines

driver to be used when getting partition information instead of relying on auto detection.

---
 disk/part.c    | 38 +++++++++++++++++++++++++++++++-------
 include/part.h | 19 ++++++++++++++++++-
 2 files changed, 49 insertions(+), 8 deletions(-)
Reviewed-by on v2 5/5
#21 lore raw

Re: [PATCH v2 5/5] cmd: mbr: Force DOS driver to be used for verify

In reply to Joshua Watt
Quoted 10 lines · Joshua Watt

Forces the DOS partition type driver to be used when verifying the MBR. This is particularly useful when using a hybrid MBR & GPT layout as otherwise MBR verification would mostly likely fail since the GPT partitions will be returned, even if the MBR is actually valid.

---
 cmd/mbr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by on v2 4/5
#18 lore raw

Re: [PATCH v2 4/5] dm: test: Add test for part_get_info_by_type

In reply to Joshua Watt
Quoted 10 lines · Joshua Watt

Adds a test suite to ensure that part_get_info_by_type works correctly by creating a hybrid GPT/MBR partition table and reading both.

---
 configs/sandbox_defconfig |  2 +
 test/dm/part.c            | 87 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
Reviewed-by on v2 1/5
#9 lore raw

RE: [PATCH v2 1/5] dm: test: Fix partition test to use mmc2

In reply to Joshua Watt
Quoted 9 lines

-----Original Message-----
From: U-Boot <[email protected]> On Behalf Of Joshua Watt
Sent: Monday, July 3, 2023 10:40 PM
To: [email protected]
Cc: Joshua Watt <[email protected]>; Simon Glass <[email protected]>
Subject: [PATCH v2 1/5] dm: test: Fix partition test to use mmc2

Quoted 6 lines

d94d9844bc ("dm: part: Update test to use mmc2") attempted to make the test use mmc2, but the change was incomplete in that it didn't also change the strings that reference a specific partition. Fix these so that the test passes again

Best Regards,
Jaehoon Chung

Quoted 35 lines
---
 test/dm/part.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
test/dm/part.c +9 -10
index 35e99eeb01..d5c58d6e3f 100644
@@ -76,15 +76,15 @@ static int dm_test_part(struct unit_test_state *uts)
 	test(-EINVAL, "#test1", true);
 	test(1, "2", false);
 	test(1, "2", true);
-	test(-ENOENT, "1:0", false);
-	test(0, "1:0", true);
-	test(1, "1:1", false);
-	test(2, "1:2", false);
-	test(1, "1.0", false);
-	test(0, "1.0:0", true);
-	test(1, "1.0:1", false);
-	test(2, "1.0:2", false);
-	test(-EINVAL, "1#bogus", false);
+	test(-ENOENT, "2:0", false);
+	test(0, "2:0", true);
+	test(1, "2:1", false);
+	test(2, "2:2", false);
+	test(1, "2.0", false);
+	test(0, "2.0:0", true);
+	test(1, "2.0:1", false);
+	test(2, "2.0:2", false);
+	test(-EINVAL, "2#bogus", false);
 	test(1, "2#test1", false);
 	test(2, "2#test2", false);
 	ret = 0;
--

2.33.0

#10 lore raw

Re: [PATCH v2 1/5] dm: test: Fix partition test to use mmc2

In reply to Joshua Watt
Quoted 8 lines · Joshua Watt

d94d9844bc ("dm: part: Update test to use mmc2") attempted to make the test use mmc2, but the change was incomplete in that it didn't also change the strings that reference a specific partition. Fix these so that the test passes again

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#22 lore raw

Re: [PATCH v2 5/5] cmd: mbr: Force DOS driver to be used for verify

In reply to Joshua Watt
Quoted 7 lines · Joshua Watt

Forces the DOS partition type driver to be used when verifying the MBR. This is particularly useful when using a hybrid MBR & GPT layout as otherwise MBR verification would mostly likely fail since the GPT partitions will be returned, even if the MBR is actually valid.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom