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

Ben Gardiner bengardiner at nanometrics.ca
Wed Jun 2 17:58:37 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>
---
Changes in v2:
 * formatting: spaces after 'if' and 'for'
 * the entire new feature is conditional on a macro, there is now a zero-byte
   binary size impact when the macro is not defined.
 * return the net parition size directly from net_part_size instead of using
   an output variable

---
 common/cmd_mtdparts.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index a6eeb41..b36aac2 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -1213,6 +1213,29 @@ static int generate_mtdparts_save(char *buf, u32 buflen)
 	return ret;
 }
 
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+/** get the net size (w/o bad blocks) of the given partition
+ * @param mtd the mtd info
+ * @param part the partition
+ * @return the calculated net size of this partition
+ */
+static u32 net_part_size(struct mtd_info *mtd, struct part_info *part)
+{
+	if (mtd->block_isbad) {
+		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;
+		}
+
+		return part->size - bb_delta;
+	} else {
+		return part->size;
+	}
+}
+#endif
+
 /**
  * Format and print out a partition list for each device from global device
  * list.
@@ -1223,6 +1246,10 @@ static void list_partitions(void)
 	struct part_info *part;
 	struct mtd_device *dev;
 	int part_num;
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+	struct mtd_info *mtd;
+	u32 net_size;
+#endif
 
 	debug("\n---list_partitions---\n");
 	list_for_each(dentry, &devices) {
@@ -1230,14 +1257,33 @@ 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\t"
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+		"net size\t"
+#endif
+		"offset\t\tmask_flags\n");
+
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+		if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
+			return;
+#endif
 
 		/* 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",
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+			net_size = net_part_size(mtd, part);
+#endif
+			printf("%2d: %-20s0x%08x\t"
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+					"0x%08x%s\t"
+#endif
+					"0x%08x\t%d\n",
 					part_num, part->name, part->size,
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+					net_size, part->size == net_size ? " " : " (!)",
+#endif
 					part->offset, part->mask_flags);
 
 			part_num++;
-- 
1.7.0.4



More information about the U-Boot mailing list