[PATCH 5/9] part: Support string block devices in part_get_info_by_dev_and_name

Sean Anderson sean.anderson at seco.com
Thu Dec 31 23:48:48 CET 2020


This adds support for things like "#partname" and "0.1#partname". The block
device parsing is done like in blk_get_device_part_str.

Signed-off-by: Sean Anderson <sean.anderson at seco.com>
---

 disk/part.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index 39c6b00a59..e07dd67fd9 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -707,29 +707,31 @@ static int part_get_info_by_dev_and_name(const char *dev_iface,
 					 struct blk_desc **dev_desc,
 					 struct disk_partition *part_info)
 {
-	char *ep;
-	const char *part_str;
-	int dev_num, ret;
+	char *dup_str = NULL;
+	const char *dev_str, *part_str;
+	int ret;
 
+	/* Separate device and partition name specification */
 	part_str = strchr(dev_part_str, '#');
-	if (!part_str || part_str == dev_part_str)
-		return -EINVAL;
-
-	dev_num = simple_strtoul(dev_part_str, &ep, 16);
-	if (ep != part_str) {
-		/* Not all the first part before the # was parsed. */
+	if (part_str) {
+		dup_str = strdup(dev_part_str);
+		dup_str[part_str - dev_part_str] = 0;
+		dev_str = dup_str;
+		part_str++;
+	} else {
 		return -EINVAL;
 	}
-	part_str++;
 
-	*dev_desc = blk_get_dev(dev_iface, dev_num);
-	if (!*dev_desc) {
-		printf("Could not find %s %d\n", dev_iface, dev_num);
-		return -ENODEV;
-	}
+	ret = blk_get_device_by_str(dev_iface, dev_str, dev_desc);
+	if (ret)
+		goto cleanup;
+
 	ret = part_get_info_by_name(*dev_desc, part_str, part_info);
 	if (ret < 0)
 		printf("Could not find \"%s\" partition\n", part_str);
+
+cleanup:
+	free(dup_str);
 	return ret;
 }
 
-- 
2.25.1



More information about the U-Boot mailing list