diff mbox series

[U-Boot,v2,1/2] disk: part: scan the disk if the part_type is unknown

Message ID 1518256538-28690-1-git-send-email-kever.yang@rock-chips.com
State Accepted
Delegated to: Tom Rini
Headers show
Series [U-Boot,v2,1/2] disk: part: scan the disk if the part_type is unknown | expand

Commit Message

Kever Yang Feb. 10, 2018, 9:55 a.m. UTC
If a DUT do not have partition table, and we write one with 'gpt write'
cmd, we should able to list the partition with 'part list' cmd.
It's reasonable to scan the disk again if the initial part_type is
unknown in case we just write a new one into disk.

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
---

Changes in v2:
- update commit message to make it more clear why we need this patch

 disk/part.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

Comments

Tom Rini March 14, 2018, 2:09 p.m. UTC | #1
On Sat, Feb 10, 2018 at 05:55:37PM +0800, Kever Yang wrote:

> If a DUT do not have partition table, and we write one with 'gpt write'
> cmd, we should able to list the partition with 'part list' cmd.
> It's reasonable to scan the disk again if the initial part_type is
> unknown in case we just write a new one into disk.
> 
> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/disk/part.c b/disk/part.c
index 66b8101..df0d50d 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -27,16 +27,28 @@ 
 DECLARE_GLOBAL_DATA_PTR;
 
 #ifdef HAVE_BLOCK_DEVICE
-static struct part_driver *part_driver_lookup_type(int part_type)
+static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 {
 	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;
+	if (dev_desc->part_type == PART_TYPE_UNKNOWN) {
+		for (entry = drv; entry != drv + n_ents; entry++) {
+			int ret;
+
+			ret = entry->test(dev_desc);
+			if (!ret) {
+				dev_desc->part_type = entry->part_type;
+				return entry;
+			}
+		}
+	} else {
+		for (entry = drv; entry != drv + n_ents; entry++) {
+			if (dev_desc->part_type == entry->part_type)
+				return entry;
+		}
 	}
 
 	/* Not found */
@@ -285,7 +297,7 @@  void part_print(struct blk_desc *dev_desc)
 {
 	struct part_driver *drv;
 
-	drv = part_driver_lookup_type(dev_desc->part_type);
+	drv = part_driver_lookup_type(dev_desc);
 	if (!drv) {
 		printf("## Unknown partition table type %x\n",
 		       dev_desc->part_type);
@@ -314,7 +326,7 @@  int part_get_info(struct blk_desc *dev_desc, int part,
 	info->type_guid[0] = 0;
 #endif
 
-	drv = part_driver_lookup_type(dev_desc->part_type);
+	drv = part_driver_lookup_type(dev_desc);
 	if (!drv) {
 		debug("## Unknown partition table type %x\n",
 		      dev_desc->part_type);