[U-Boot] [RFC PATCH 3/5] cmd_ext2: use common get_device_and_partition function

Rob Herring robherring2 at gmail.com
Wed Mar 7 00:41:10 CET 2012


From: Rob Herring <rob.herring at calxeda.com>

Convert ext2ls and ext2load to use common device and partition parsing
function.

Signed-off-by: Rob Herring <rob.herring at calxeda.com>
---
 common/cmd_ext2.c |   71 ++++++++++++-----------------------------------------
 1 files changed, 16 insertions(+), 55 deletions(-)

diff --git a/common/cmd_ext2.c b/common/cmd_ext2.c
index 35fb361..84dafd6 100644
--- a/common/cmd_ext2.c
+++ b/common/cmd_ext2.c
@@ -59,34 +59,24 @@
 int do_ext2ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	char *filename = "/";
-	int dev=0;
-	int part=1;
+	int dev;
+	int part;
 	char *ep;
-	block_dev_desc_t *dev_desc=NULL;
+	block_dev_desc_t *dev_desc;
+	disk_partition_t info;
 	int part_length;
 
-	if (argc < 3)
+	if (argc < 2)
 		return cmd_usage(cmdtp);
 
-	dev = (int)simple_strtoul (argv[2], &ep, 16);
-	dev_desc = get_dev(argv[1],dev);
-
-	if (dev_desc == NULL) {
-		printf ("\n** Block device %s %d not supported\n", argv[1], dev);
+	part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info);
+	if (part < 0)
 		return 1;
-	}
-
-	if (*ep) {
-		if (*ep != ':') {
-			puts ("\n** Invalid boot device, use `dev[:part]' **\n");
-			return 1;
-		}
-		part = (int)simple_strtoul(++ep, NULL, 16);
-	}
 
 	if (argc == 4)
 		filename = argv[3];
 
+	dev = dev_desc->dev;
 	PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
 
 	if ((part_length = ext2fs_set_blk_dev(dev_desc, part)) == 0) {
@@ -126,11 +116,11 @@ int do_ext2load (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	char *filename = NULL;
 	char *ep;
-	int dev, part = 1;
+	int dev, part;
 	ulong addr = 0, part_length;
 	int filelen;
 	disk_partition_t info;
-	block_dev_desc_t *dev_desc = NULL;
+	block_dev_desc_t *dev_desc;
 	char buf [12];
 	unsigned long count;
 	char *addr_str;
@@ -171,43 +161,14 @@ int do_ext2load (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		return 1;
 	}
 
-	dev = (int)simple_strtoul (argv[2], &ep, 16);
-	dev_desc = get_dev(argv[1],dev);
-	if (dev_desc==NULL) {
-		printf ("** Block device %s %d not supported\n", argv[1], dev);
+	part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info);
+	if (part < 0)
 		return 1;
-	}
-	if (*ep) {
-		if (*ep != ':') {
-			puts ("** Invalid boot device, use `dev[:part]' **\n");
-			return 1;
-		}
-		part = (int)simple_strtoul(++ep, NULL, 16);
-	}
-
-	PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
-
-	if (part != 0) {
-		if (get_partition_info (dev_desc, part, &info)) {
-			printf ("** Bad partition %d **\n", part);
-			return 1;
-		}
-
-		if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
-			printf ("** Invalid partition type \"%.32s\""
-				" (expect \"" BOOT_PART_TYPE "\")\n",
-				info.type);
-			return 1;
-		}
-		printf ("Loading file \"%s\" "
-			"from %s device %d:%d (%.32s)\n",
-			filename,
-			argv[1], dev, part, info.name);
-	} else {
-		printf ("Loading file \"%s\" from %s device %d\n",
-			filename, argv[1], dev);
-	}
 
+	dev = dev_desc->dev;
+	printf("Loading file \"%s\" from %s device %d%c%c\n",
+		filename, argv[1], dev,
+		part ? ':' : ' ', part ? part + '0' : ' ');
 
 	if ((part_length = ext2fs_set_blk_dev(dev_desc, part)) == 0) {
 		printf ("** Bad partition - %s %d:%d **\n",  argv[1], dev, part);
-- 
1.7.5.4



More information about the U-Boot mailing list