[U-Boot] [PATCH 2/2] disk: default to HW partition 0 if not specified

Stephen Warren swarren at wwwdotorg.org
Fri May 23 20:48:11 CEST 2014


From: Stephen Warren <swarren at nvidia.com>

Currently, get_device()/get_dev_hwpart() for MMC devices does not select
an explicit HW partition unless the user explicitly requests one, i.e. by
requesting device "mmc 0.0" rather than just "mmc 0". I think it makes
more sense if the default is to select HW partition 0 (main data area)
if the user didn't request a specific partition. Otherwise, the following
happens, which feels wrong:

Select HW partition 1 (boot0):
mmc dev 0 1

Attempts to access SW partition 1 on HW partition 1 (boot0), rather than
SW partition 1 on HW partition 0 (main data area):
ls mmc 0:1 /

With this patch, the second command above re-selects the main data area.

Many device types don't support HW partitions at all, so if HW partition
0 is selected (either explicitly or as the default) and there's no
select_hwpart function, we simply skip attempting to select a HW
partition.

Some MMC devices (i.e. SD cards) don't support HW partitions. However,
this patch still works, since mmc_start_init() sets the current
partition number to 0, and mmc_select_hwpart() succeeds if the requested
partition is already selected.

Signed-off-by: Stephen Warren <swarren at nvidia.com>
---
 disk/part.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index 2827089d8d5f..b3097e32f0eb 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -86,7 +86,7 @@ block_dev_desc_t *get_dev_hwpart(const char *ifname, int dev, int hwpart)
 			block_dev_desc_t *dev_desc = reloc_get_dev(dev);
 			if (!dev_desc)
 				return NULL;
-			if (hwpart == -1)
+			if (hwpart == 0 && !select_hwpart)
 				return dev_desc;
 			if (!select_hwpart)
 				return NULL;
@@ -102,7 +102,7 @@ block_dev_desc_t *get_dev_hwpart(const char *ifname, int dev, int hwpart)
 
 block_dev_desc_t *get_dev(const char *ifname, int dev)
 {
-	return get_dev_hwpart(ifname, dev, -1);
+	return get_dev_hwpart(ifname, dev, 0);
 }
 #else
 block_dev_desc_t *get_dev_hwpart(const char *ifname, int dev, int hwpart)
@@ -460,7 +460,7 @@ int get_device(const char *ifname, const char *dev_hwpart_str,
 		hwpart_str++;
 	} else {
 		dev_str = dev_hwpart_str;
-		hwpart = -1;
+		hwpart = 0;
 	}
 
 	dev = simple_strtoul(dev_str, &ep, 16);
-- 
1.8.1.5



More information about the U-Boot mailing list