From: Jo-Philipp Wich Date: Sat, 22 Oct 2011 14:16:45 +0000 (+0000) Subject: [packages] mtd-utils: add a bad block counter to mtd_debug, based on patch from http... X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fsvn-archive%2Farchive.git;a=commitdiff_plain;hb=3afe300984b683c4b7edc750aea767d3fe4662b0 [packages] mtd-utils: add a bad block counter to mtd_debug, based on patch from dev.laptop.org/~martin/mtd_debug.patch SVN-Revision: 28520 --- diff --git a/utils/mtd-utils/patches/100-mtd-debug-add-bad-block-counter.patch b/utils/mtd-utils/patches/100-mtd-debug-add-bad-block-counter.patch new file mode 100644 index 0000000000..191a7d07a6 --- /dev/null +++ b/utils/mtd-utils/patches/100-mtd-debug-add-bad-block-counter.patch @@ -0,0 +1,73 @@ +--- a/mtd_debug.c ++++ b/mtd_debug.c +@@ -236,6 +236,7 @@ int showinfo (int fd) + int i,err,n; + struct mtd_info_user mtd; + static struct region_info_user region[1024]; ++ int iNumOfBadBlocks = 0; + + err = getmeminfo (fd,&mtd); + if (err < 0) +@@ -328,6 +329,11 @@ int showinfo (int fd) + printf ("\nmtd.oobsize = "); + printsize (mtd.oobsize); + ++ printf ("\nmtd.badblockscount = "); ++ iNumOfBadBlocks = get_bb_number(fd, &mtd); ++ if (iNumOfBadBlocks > -1) ++ printf ("%d", iNumOfBadBlocks); ++ + printf ("\n" + "regions = %d\n" + "\n", +@@ -347,6 +353,50 @@ int showinfo (int fd) + return (0); + } + ++int get_bb_number(int fd, struct mtd_info_user *meminfo) ++{ ++ int isNAND = (meminfo->type == MTD_NANDFLASH); ++ int ibbCounter = 0; ++ /* Last 4 blocks of any MTD device are protected and ++ MTD reports them as badblocks. */ ++ int usablesize = meminfo->size - (4 * meminfo->erasesize); ++ erase_info_t erase; ++ erase.length = meminfo->erasesize; ++ ++ for (erase.start = 0; ++ erase.start < usablesize; ++ erase.start += meminfo->erasesize) ++ { ++ loff_t offset = erase.start; ++ int ret = ioctl(fd, MEMGETBADBLOCK, &offset); ++ ++ if (ret > 0) ++ { ++ ibbCounter++; ++ continue; ++ } ++ else if (ret < 0) ++ { ++ if (errno == EOPNOTSUPP) ++ { ++ if (isNAND) ++ { ++ printf("Bad block check not available"); ++ return -1; ++ } ++ } ++ else ++ { ++ printf("MTD get bad block failed: %s", ++ strerror(errno)); ++ return -1; ++ } ++ } ++ } ++ ++ return ibbCounter; ++} ++ + void showusage (const char *progname) + { + fprintf (stderr,