Print list of bad blocks in NAND flash from user space

Is there any user space tool that can retrieve and dump the list of bad blocks in a NAND flash device? I’ve checked the mtdinfo command line utility, and also searched /proc and /sys, but couldn’t find anything.

I am looking for something suitable for use from a shell script.

I could parse dmesg as the kernel prints bad block information on init, but I am hoping there will be a better way.

Asked By: Grodriguez


I have not been able to find any user space utility doing what I need. The closest I have found is the nanddump utility from mtd-utils, which can dump NAND contents, including bad blocks.

Answered By: Grodriguez

I met this problem recently, and I wrote the C codes by referring open-source of mtd-utils, the core part is as follows,

    offset = 0;
    while (1) {
        int rc = ioctl(fd, MEMGETBADBLOCK, &offset);
        if (rc < 0) {
            perror("Failed to check bad block");
            return 1;
        } else if (rc > 0) {
            // Block is bad, print the block information
            printf("Bad block at offset 0x%llx n", offset);

        offset += mtd_info.erasesize;
        if (offset > mtd_info.size)
Answered By: wangt13
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.