]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_mtdparts.c
common/cmd_mtdparts.c: print ECC stats along with partition information
[karo-tx-uboot.git] / common / cmd_mtdparts.c
index 3cb0571df39a4dc0797f93df887dea76768f6484..33096c05b27942935dd5dc7d4d2ab1d594f145cd 100644 (file)
@@ -325,8 +325,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
                 */
                offset = part->offset;
                if (do_div(offset, mtd->erasesize)) {
-                       printf("%s%d: partition (%s) start offset"
-                              "alignment incorrect\n",
+                       printf("%s%d: partition (%s) start offset alignment incorrect\n",
                               MTD_DEV_TYPE(id->type), id->num, part->name);
                        return 1;
                }
@@ -862,7 +861,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
        debug("dev type = %d (%s), dev num = %d, mtd-id = %s\n",
                        id->type, MTD_DEV_TYPE(id->type),
                        id->num, id->mtd_id);
-       debug("parsing partitions %.*s\n", (pend ? pend - p : strlen(p)), p);
+       debug("parsing partitions %.*s\n", (int)(pend ? pend - p : strlen(p)), p);
 
 
        /* parse partitions */
@@ -1007,7 +1006,7 @@ static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_
        list_for_each(entry, &mtdids) {
                id = list_entry(entry, struct mtdids, link);
 
-               debug("entry: '%s' (len = %d)\n",
+               debug("entry: '%s' (len = %zu)\n",
                                id->mtd_id, strlen(id->mtd_id));
 
                if (mtd_id_len != strlen(id->mtd_id))
@@ -1234,6 +1233,18 @@ static uint64_t net_part_size(struct mtd_info *mtd, struct part_info *part)
 }
 #endif
 
+static void show_ecc_stats(struct mtd_device *dev)
+{
+       struct mtd_info *mtd;
+
+       if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
+               return;
+
+       printf("ECC stats for device %s:\n", mtd->name);
+       printf("  corrected bit flips:\t%4u\n", mtd->ecc_stats.corrected);
+       printf("  uncorrectable errors:\t%4u\n", mtd->ecc_stats.failed);
+}
+
 static void print_partition_table(void)
 {
        struct list_head *dentry, *pentry;
@@ -1281,6 +1292,7 @@ static void print_partition_table(void)
 #endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
                        part_num++;
                }
+               show_ecc_stats(dev);
        }
 
        if (list_empty(&devices))
@@ -1407,17 +1419,17 @@ static int delete_partition(const char *id)
                                part->name, part->size, part->offset);
 
                if (part_del(dev, part) != 0)
-                       return 1;
+                       return CMD_RET_FAILURE;
 
                if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
                        printf("generated mtdparts too long, resetting to null\n");
-                       return 1;
+                       return CMD_RET_FAILURE;
                }
-               return 0;
+               return CMD_RET_SUCCESS;
        }
 
        printf("partition %s not found\n", id);
-       return 1;
+       return CMD_RET_FAILURE;
 }
 
 #if defined(CONFIG_CMD_MTDPARTS_SPREAD)
@@ -1483,7 +1495,7 @@ static int spread_partitions(void)
                dev = list_entry(dentry, struct mtd_device, link);
 
                if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
-                       return 1;
+                       return CMD_RET_FAILURE;
 
                part_num = 0;
                cur_offs = 0;
@@ -1509,9 +1521,9 @@ static int spread_partitions(void)
 
        if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
                printf("generated mtdparts too long, resetting to null\n");
-               return 1;
+               return CMD_RET_FAILURE;
        }
-       return 0;
+       return CMD_RET_SUCCESS;
 }
 #endif /* CONFIG_CMD_MTDPARTS_SPREAD */
 
@@ -1898,15 +1910,15 @@ static int do_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        u8 pnum;
 
        if (mtdparts_init() !=0)
-               return 1;
+               return CMD_RET_FAILURE;
 
        if (argc < 2) {
                printf("no partition id specified\n");
-               return 1;
+               return CMD_RET_FAILURE;
        }
 
        if (find_dev_and_part(argv[1], &dev, &pnum, &part) != 0)
-               return 1;
+               return CMD_RET_FAILURE;
 
        current_mtd_dev = dev;
        current_mtd_partnum = pnum;
@@ -1915,7 +1927,7 @@ static int do_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        printf("partition changed to %s%d,%d\n",
                        MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum);
 
-       return 0;
+       return CMD_RET_SUCCESS;
 }
 
 /**
@@ -1946,17 +1958,18 @@ static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc,
                        setenv("mtdparts", NULL);
 
                        /* mtd_devices_init() calls current_save() */
-                       return mtd_devices_init();
+                       return mtd_devices_init() ? CMD_RET_FAILURE :
+                               CMD_RET_SUCCESS;
                }
        }
 
        /* make sure we are in sync with env variables */
        if (mtdparts_init() != 0)
-               return 1;
+               return CMD_RET_FAILURE;
 
        if (argc == 1) {
                list_partitions();
-               return 0;
+               return CMD_RET_SUCCESS;
        }
 
        /* mtdparts add <mtd-dev> <size>[@<offset>] <name> [ro] */
@@ -1974,11 +1987,11 @@ static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc,
                struct part_info *p;
 
                if (mtd_id_parse(argv[2], NULL, &type, &num) != 0)
-                       return 1;
+                       return CMD_RET_FAILURE;
 
                if ((id = id_find(type, num)) == NULL) {
                        printf("no such device %s defined in mtdids variable\n", argv[2]);
-                       return 1;
+                       return CMD_RET_FAILURE;
                }
 
                len = strlen(id->mtd_id) + 1;   /* 'mtd_id:' */
@@ -1989,14 +2002,14 @@ static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc,
 
                if (len >= PART_ADD_DESC_MAXLEN) {
                        printf("too long partition description\n");
-                       return 1;
+                       return CMD_RET_FAILURE;
                }
                sprintf(tmpbuf, "%s:%s(%s)%s",
                                id->mtd_id, argv[3], argv[4], argv[5] ? argv[5] : "");
                debug("add tmpbuf: %s\n", tmpbuf);
 
                if ((device_parse(tmpbuf, NULL, &dev) != 0) || (!dev))
-                       return 1;
+                       return CMD_RET_FAILURE;
 
                debug("+ %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
                                dev->id->num, dev->id->mtd_id);
@@ -2005,7 +2018,7 @@ static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc,
 
 #if defined(CONFIG_CMD_MTDPARTS_SPREAD)
                if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
-                       return 1;
+                       return CMD_RET_FAILURE;
 
                if (!strcmp(&argv[1][3], ".spread")) {
                        spread_partition(mtd, p, &next_offset);
@@ -2019,15 +2032,15 @@ static int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc,
                } else if (part_add(dev_tmp, p) != 0) {
                        /* merge new partition with existing ones*/
                        device_del(dev);
-                       return 1;
+                       return CMD_RET_FAILURE;
                }
 
                if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
                        printf("generated mtdparts too long, resetting to null\n");
-                       return 1;
+                       return CMD_RET_FAILURE;
                }
 
-               return 0;
+               return CMD_RET_SUCCESS;
        }
 
        /* mtdparts del part-id */