本文共 2781 字,大约阅读时间需要 9 分钟。
FILENAME:/// /** * search_bbt - [GENERIC] scan the device for a specific bad block table * @mtd: MTD device structure * @buf: temporary buffer * @td: descriptor for the bad block table * * Read the bad block table by searching for a given ident pattern. Search is * preformed either from the beginning up or from the end of the device * downwards. The search starts always at the start of a block. If the option * NAND_BBT_PERCHIP is given, each chip is searched for a bbt, which contains * the bad block information of this chip. This is necessary to provide support * for certain DOC devices. * * The bbt ident pattern resides in the oob area of the first page in a block. */static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td){ struct nand_chip *this = mtd->priv; int i, chips; int bits, startblock, block, dir; int scanlen = mtd->writesize + mtd->oobsize; int bbtblocks; int blocktopage = this->bbt_erase_shift - this->page_shift; /* Search direction top -> down? */ if (td->options & NAND_BBT_LASTBLOCK) { startblock = (mtd->size >> this->bbt_erase_shift) - 1; dir = -1; } else { startblock = 0; dir = 1; } /* Do we have a bbt per chip? */ if (td->options & NAND_BBT_PERCHIP) { chips = this->numchips; bbtblocks = this->chipsize >> this->bbt_erase_shift; 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; td->pages[i] = -1; /* Scan the maximum number of blocks */ for (block = 0; block < td->maxblocks; block++) { int actblock = startblock + dir * block; loff_t offs = (loff_t)actblock << this->bbt_erase_shift; /* Read first page */ scan_read(mtd, buf, offs, mtd->writesize, td); if (!check_pattern(buf, scanlen, mtd->writesize, td)) { td->pages[i] = actblock << blocktopage; if (td->options & NAND_BBT_VERSION) { offs = bbt_get_ver_offs(mtd, td); td->version[i] = buf[offs]; } break; } } startblock += this->chipsize >> this->bbt_erase_shift; } /* Check, if we found a bbt for each requested chip */ for (i = 0; i < chips; i++) { if (td->pages[i] == -1) pr_warn("Bad block table not found for chip %d\n", i); else pr_info("Bad block table found at page %d, version " "0x%02X\n", td->pages[i], td->version[i]); } return 0;}
转载地址:http://vqsgi.baihongyu.com/