aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/nand_bbt.c
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2012-06-22 19:35:45 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2012-09-29 09:51:55 -0400
commita7e68834fc273930c17e3decaddc13acb87a7dce (patch)
tree010ed62d3b24099960ff5f52e0e79562ec2a6f20 /drivers/mtd/nand/nand_bbt.c
parent491ed06f334955578f0c43d298c46ea1a7ea9e1b (diff)
mtd: nand: use ECC, if present, when scanning OOB
scan_read_raw_oob() is used in only in places where the MTD_OPS_PLACE_OOB mode is preferable to MTD_OPS_RAW mode, so use MTD_OPS_PLACE_OOB instead. MTD_OPS_PLACE_OOB provides the same functionality with the potential[1] added bonus of error correction. This brings scan_block_full() in line with scan_block_fast() so that they both read bad block markers with MTD_OPS_PLACE_OOB. This can help in preventing 0xff markers (in good blocks) from being interpreted as bad block indicators in the presence of a single bitflip. Note that ECC error codes (EUCLEAN or EBADMSG) are already silently ignored in all users of scan_read_raw_oob(). [1] Few drivers perform proper error correction on OOB data. In those cases, the use of MTD_OPS_RAW vs. MTD_OPS_PLACE_OOB is not significant. Signed-off-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/nand/nand_bbt.c')
-rw-r--r--drivers/mtd/nand/nand_bbt.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index f5839f06cece..0e928f3efaa4 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -289,14 +289,24 @@ static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
289 return mtd_read(mtd, offs, len, &retlen, buf); 289 return mtd_read(mtd, offs, len, &retlen, buf);
290} 290}
291 291
292/* Scan read raw data from flash */ 292/**
293 * scan_read_raw_oob - [GENERIC] Scan data+OOB region to buffer
294 * @mtd: MTD device structure
295 * @buf: temporary buffer
296 * @offs: offset at which to scan
297 * @len: length of data region to read
298 *
299 * Scan read data from data+OOB. May traverse multiple pages, interleaving
300 * page,OOB,page,OOB,... in buf. Completes transfer and returns the "strongest"
301 * ECC condition (error or bitflip). May quit on the first (non-ECC) error.
302 */
293static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs, 303static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
294 size_t len) 304 size_t len)
295{ 305{
296 struct mtd_oob_ops ops; 306 struct mtd_oob_ops ops;
297 int res; 307 int res, ret = 0;
298 308
299 ops.mode = MTD_OPS_RAW; 309 ops.mode = MTD_OPS_PLACE_OOB;
300 ops.ooboffs = 0; 310 ops.ooboffs = 0;
301 ops.ooblen = mtd->oobsize; 311 ops.ooblen = mtd->oobsize;
302 312
@@ -306,15 +316,18 @@ static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
306 ops.oobbuf = buf + ops.len; 316 ops.oobbuf = buf + ops.len;
307 317
308 res = mtd_read_oob(mtd, offs, &ops); 318 res = mtd_read_oob(mtd, offs, &ops);
309 319 if (res) {
310 if (res) 320 if (!mtd_is_bitflip_or_eccerr(res))
311 return res; 321 return res;
322 else if (mtd_is_eccerr(res) || !ret)
323 ret = res;
324 }
312 325
313 buf += mtd->oobsize + mtd->writesize; 326 buf += mtd->oobsize + mtd->writesize;
314 len -= mtd->writesize; 327 len -= mtd->writesize;
315 offs += mtd->writesize; 328 offs += mtd->writesize;
316 } 329 }
317 return 0; 330 return ret;
318} 331}
319 332
320static int scan_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t offs, 333static int scan_read_raw(struct mtd_info *mtd, uint8_t *buf, loff_t offs,