--- zzzz-none-000/linux-2.6.32.61/drivers/mtd/nand/nand_bbt.c 2013-06-10 09:43:48.000000000 +0000 +++ ar10-7272-687/linux-2.6.32.61/drivers/mtd/nand/nand_bbt.c 2014-08-06 15:52:06.000000000 +0000 @@ -374,6 +374,7 @@ int startblock; loff_t from; size_t readlen; + __u32 start_badblocks = mtd->ecc_stats.badblocks; printk(KERN_INFO "Scanning device for bad blocks\n"); @@ -428,14 +429,78 @@ if (ret) { this->bbt[i >> 3] |= 0x03 << (i & 0x6); - printk(KERN_WARNING "Bad eraseblock %d at 0x%012llx\n", - i >> 1, (unsigned long long)from); + printk(KERN_WARNING "Bad eraseblock %d at 0x%012llx (byte on oob[0-1]=0x%x)\n", + i >> 1, (unsigned long long)from, buf[0]); mtd->ecc_stats.badblocks++; } i += 2; from += (1 << this->bbt_erase_shift); } + + if(mtd->ecc_stats.badblocks - start_badblocks) { + int bad_printed = 0; + int bad_start = -1; + + printk(KERN_WARNING "badblock statistics:\n" + "--------------------\n" + " start block = %d\n" + " num blocks = %d\n" + " bad blocks = %u\n", + startblock, + numblocks>>1, + mtd->ecc_stats.badblocks - start_badblocks + ); + + for (i = startblock; i < numblocks;) { + if(this->bbt[i >> 3] & 0x03 << (i & 0x6)) { + if(bad_start == -1) + bad_start = i >> 1; + } else { + if(bad_start != -1) { + if(!bad_printed) { + bad_printed = 1; + + printk(KERN_WARNING "\n" + " >> The following table summarize all badblocks to visualize the distribution" + "\n" + " block [ start | count | size/kB ] (start block, number of blocks)\n" + " --------------------------------- \n"); + } + + printk(KERN_WARNING " block [ %5d | %5d | %7d ]\n", + bad_start, + (i>>1)-bad_start, + (mtd->erasesize/1024) * ((i>>1)-bad_start) + ); + + bad_start = -1; + } + } + + i += 2; + } + if(bad_start != -1) { + if(!bad_printed) { + printk(KERN_WARNING "\n" + " >> The following table summarize all badblocks to visualize the distribution" + "\n" + " block [ start | count | size/kB ] (start block, number of blocks)\n" + " --------------------------------- \n"); + } + + printk(KERN_WARNING " block [ %5d | %5d | %7d ]\n", + bad_start, (i>>1)-bad_start, + (mtd->erasesize/1024) * ((i>>1)-bad_start) + ); + } + + printk(KERN_WARNING " [ ======================= ]\n" + " [ >> %5d | %7d ]\n", + mtd->ecc_stats.badblocks - start_badblocks, + (mtd->erasesize/1024) * (mtd->ecc_stats.badblocks - start_badblocks) + ); + } return 0; } @@ -460,9 +525,8 @@ { struct nand_chip *this = mtd->priv; int i, chips; - int bits, startblock, block, dir; + int startblock, bbtblocks, block, dir; int scanlen = mtd->writesize + mtd->oobsize; - int bbtblocks; int blocktopage = this->bbt_erase_shift - this->page_shift; /* Search direction top -> down ? */ @@ -481,12 +545,8 @@ startblock &= bbtblocks - 1; } else { chips = 1; - bbtblocks = mtd->size >> this->bbt_erase_shift; } - /* Number of bits for each erase block in the bbt */ - bits = td->options & NAND_BBT_NRBITS_MSK; - for (i = 0; i < chips; i++) { /* Reset version information */ td->version[i] = 0;