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

Ben Gardiner bengardiner at nanometrics.ca
Mon Jul 5 23:43:30 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>
CC: Wolfgang Denk <wd at denx.de>

---

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

V3:
 * rebased to 54841ab50c20d6fa6c9cc3eb826989da3a22d934 of
   git://git.denx.de/u-boot.git
 * fix line length over 80 chars
 * update copyright of cmd_mtdparts.c
---
 common/cmd_mtdparts.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index f1bed95..84acd62 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -15,6 +15,10 @@
  *   Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
  *   kernel tree.
  *
+ * (C) Copyright 2010
+ * Ben Gardiner, Nanometrics Inc., <bengardiner at nanometrics.ca>
+ *   Added net partition size output to mtdparts list command
+ *
  *   $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
  *   Copyright 2002 SYSGO Real-Time Solutions GmbH
  *
@@ -1213,6 +1217,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 +1250,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 +1261,34 @@ 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