[U-Boot] [PATCH 2/4] mtdparts: show net size in mtdparts list

Ben Gardiner bengardiner at nanometrics.ca
Tue Jun 1 22:23:45 CEST 2010


This patch adds an additional column to the output of list_partitions. The
additional column will contain the net size and a '(!)' beside it if the net
size is not equal to the partition size.

Signed-off-by: Ben Gardiner <bengardiner at nanometrics.ca>
---
 common/cmd_mtdparts.c |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index 7a9768f..24d27b9 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -1213,6 +1213,23 @@ static int generate_mtdparts_save(char *buf, u32 buflen)
 	return ret;
 }
 
+/** get the net size (w/o bad blocks) of the given partition
+ * @param mtd the mtd info
+ * @param part the partition
+ * @param net_size the calculated net size of this partition (output)
+ */
+static void net_part_size(struct mtd_info *mtd, struct part_info *part, u32 *net_size)
+{
+	u32 i, bb_delta = 0;
+
+	for(i = 0; i < part->size; i += mtd->erasesize) {
+		if(mtd->block_isbad(mtd, part->offset + i))
+			bb_delta += mtd->erasesize;
+	}
+
+	*net_size = part->size - bb_delta;
+}
+
 /**
  * Format and print out a partition list for each device from global device
  * list.
@@ -1222,7 +1239,9 @@ static void list_partitions(void)
 	struct list_head *dentry, *pentry;
 	struct part_info *part;
 	struct mtd_device *dev;
+	struct mtd_info *mtd;
 	int part_num;
+	u32 net_size;
 
 	debug("\n---list_partitions---\n");
 	list_for_each(dentry, &devices) {
@@ -1230,14 +1249,19 @@ static void list_partitions(void)
 		printf("\ndevice %s%d <%s>, # parts = %d\n",
 				MTD_DEV_TYPE(dev->id->type), dev->id->num,
 				dev->id->mtd_id, dev->num_parts);
-		printf(" #: name\t\tsize\t\toffset\t\tmask_flags\n");
+		printf(" #: name\t\tsize\t\tnet size\toffset\t\tmask_flags\n");
+
+		if(get_mtd_info(dev->id->type, dev->id->num, &mtd))
+			return;
 
 		/* list partitions for given device */
 		part_num = 0;
 		list_for_each(pentry, &dev->parts) {
 			part = list_entry(pentry, struct part_info, link);
-			printf("%2d: %-20s0x%08x\t0x%08x\t%d\n",
+			net_part_size(mtd,part,&net_size);
+			printf("%2d: %-20s0x%08x\t0x%08x%s\t0x%08x\t%d\n",
 					part_num, part->name, part->size,
+					net_size, part->size == net_size ? " " : " (!)",
 					part->offset, part->mask_flags);
 
 			part_num++;
-- 
1.7.0.4



More information about the U-Boot mailing list