3 @@ -238,6 +238,7 @@ int showinfo (int fd)
5 struct mtd_info_user mtd;
6 static struct region_info_user region[1024];
7 + int iNumOfBadBlocks = 0;
9 err = getmeminfo (fd,&mtd);
11 @@ -330,6 +331,11 @@ int showinfo (int fd)
12 printf ("\nmtd.oobsize = ");
13 printsize (mtd.oobsize);
15 + printf ("\nmtd.badblockscount = ");
16 + iNumOfBadBlocks = get_bb_number(fd, &mtd);
17 + if (iNumOfBadBlocks > -1)
18 + printf ("%d", iNumOfBadBlocks);
23 @@ -349,6 +355,50 @@ int showinfo (int fd)
27 +int get_bb_number(int fd, struct mtd_info_user *meminfo)
29 + int isNAND = (meminfo->type == MTD_NANDFLASH);
31 + /* Last 4 blocks of any MTD device are protected and
32 + MTD reports them as badblocks. */
33 + int usablesize = meminfo->size - (4 * meminfo->erasesize);
35 + erase.length = meminfo->erasesize;
37 + for (erase.start = 0;
38 + erase.start < usablesize;
39 + erase.start += meminfo->erasesize)
41 + loff_t offset = erase.start;
42 + int ret = ioctl(fd, MEMGETBADBLOCK, &offset);
51 + if (errno == EOPNOTSUPP)
55 + printf("Bad block check not available");
61 + printf("MTD get bad block failed: %s",