Skip to content

Commit

Permalink
mtd: nand: add ->badblockbits for minimum number of set bits in bad b…
Browse files Browse the repository at this point in the history
…lock 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>
  • Loading branch information
Maxim Levitsky authored and David Woodhouse committed Feb 26, 2010
1 parent b64d39d commit e0b58d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions drivers/mtd/nand/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
if (chip->badblockpos & 0x1)
bad >>= 8;
if ((bad & 0xFF) != 0xff)
res = 1;
else
bad &= 0xFF;
} else {
chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, page);
if (chip->read_byte(mtd) != 0xff)
res = 1;
bad = chip->read_byte(mtd);
}

if (likely(chip->badblockbits == 8))
res = bad != 0xFF;
else
res = hweight8(bad) < chip->badblockbits;

if (getchip)
nand_release_device(mtd);

Expand Down Expand Up @@ -2884,6 +2888,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
/* Set the bad block position */
chip->badblockpos = mtd->writesize > 512 ?
NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS;
chip->badblockbits = 8;

/* Get chip options, preserve non chip based options */
chip->options &= ~NAND_CHIPOPTIONS_MSK;
Expand Down
1 change: 1 addition & 0 deletions include/linux/mtd/nand.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ struct nand_chip {
int subpagesize;
uint8_t cellinfo;
int badblockpos;
int badblockbits;

flstate_t state;

Expand Down

0 comments on commit e0b58d0

Please sign in to comment.