mtd: nand: add ->badblockbits for minimum number of set bits in bad block byte
This can be used to protect against bitflips in that field, but now mostly for smartmedia. Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>hifive-unleashed-5.1
parent
b64d39d8b0
commit
e0b58d0a70
|
@ -364,14 +364,18 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
|
||||||
bad = cpu_to_le16(chip->read_word(mtd));
|
bad = cpu_to_le16(chip->read_word(mtd));
|
||||||
if (chip->badblockpos & 0x1)
|
if (chip->badblockpos & 0x1)
|
||||||
bad >>= 8;
|
bad >>= 8;
|
||||||
if ((bad & 0xFF) != 0xff)
|
else
|
||||||
res = 1;
|
bad &= 0xFF;
|
||||||
} else {
|
} else {
|
||||||
chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, page);
|
chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, page);
|
||||||
if (chip->read_byte(mtd) != 0xff)
|
bad = chip->read_byte(mtd);
|
||||||
res = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (likely(chip->badblockbits == 8))
|
||||||
|
res = bad != 0xFF;
|
||||||
|
else
|
||||||
|
res = hweight8(bad) < chip->badblockbits;
|
||||||
|
|
||||||
if (getchip)
|
if (getchip)
|
||||||
nand_release_device(mtd);
|
nand_release_device(mtd);
|
||||||
|
|
||||||
|
@ -2884,6 +2888,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
|
||||||
/* Set the bad block position */
|
/* Set the bad block position */
|
||||||
chip->badblockpos = mtd->writesize > 512 ?
|
chip->badblockpos = mtd->writesize > 512 ?
|
||||||
NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
|
NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
|
||||||
|
chip->badblockbits = 8;
|
||||||
|
|
||||||
/* Get chip options, preserve non chip based options */
|
/* Get chip options, preserve non chip based options */
|
||||||
chip->options &= ~NAND_CHIPOPTIONS_MSK;
|
chip->options &= ~NAND_CHIPOPTIONS_MSK;
|
||||||
|
|
|
@ -401,6 +401,7 @@ struct nand_chip {
|
||||||
int subpagesize;
|
int subpagesize;
|
||||||
uint8_t cellinfo;
|
uint8_t cellinfo;
|
||||||
int badblockpos;
|
int badblockpos;
|
||||||
|
int badblockbits;
|
||||||
|
|
||||||
flstate_t state;
|
flstate_t state;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue