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 <bengardi...@nanometrics.ca>
CC: Wolfgang Denk <w...@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

V4:
 * rebased to b417260d871d4d8d336c160d95ed40cc8c0fb0fa of
   git://git.denx.de/u-boot.git
 * removed copyright statement and changelog from file header
 * re-grouped list_partition #ifdefs into one
 * fixed multi-line comment style
---
 common/cmd_mtdparts.c |   70 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index 772ad54..500a38e 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -1215,18 +1215,65 @@ static int generate_mtdparts_save(char *buf, u32 buflen)
        return ret;
 }
 
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
 /**
- * Format and print out a partition list for each device from global device
- * list.
+ * 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 void list_partitions(void)
+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
+
+static void print_partition_table(void)
 {
        struct list_head *dentry, *pentry;
        struct part_info *part;
        struct mtd_device *dev;
        int part_num;
 
-       debug("\n---list_partitions---\n");
+#if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
+       list_for_each(dentry, &devices) {
+               struct mtd_info *mtd;
+
+               dev = list_entry(dentry, struct mtd_device, link);
+               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\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) {
+                       u32 net_size;
+                       char *size_note;
+
+                       part = list_entry(pentry, struct part_info, link);
+                       net_size = net_part_size(mtd, part);
+                       size_note = part->size == net_size ? " " : " (!)";
+                       printf("%2d: %-20s0x%08x\t0x%08x%s\t0x%08x\t%d\n",
+                                       part_num, part->name, part->size,
+                                       net_size, size_note, part->offset,
+                                       part->mask_flags);
+#else /* !defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
        list_for_each(dentry, &devices) {
                dev = list_entry(dentry, struct mtd_device, link);
                printf("\ndevice %s%d <%s>, # parts = %d\n",
@@ -1241,12 +1288,25 @@ static void list_partitions(void)
                        printf("%2d: %-20s0x%08x\t0x%08x\t%d\n",
                                        part_num, part->name, part->size,
                                        part->offset, part->mask_flags);
-
+#endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
                        part_num++;
                }
        }
+
        if (list_empty(&devices))
                printf("no partitions defined\n");
+}
+
+/**
+ * Format and print out a partition list for each device from global device
+ * list.
+ */
+static void list_partitions(void)
+{
+       struct part_info *part;
+
+       debug("\n---list_partitions---\n");
+       print_partition_table();
 
        /* current_mtd_dev is not NULL only when we have non empty device list 
*/
        if (current_mtd_dev) {
-- 
1.7.0.4

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to