3fb47850fc48070e7619d4e93ded8c46e4119442
[openwrt/staging/zorun.git] /
1 Content-Type: text/plain; charset="utf-8"
2 MIME-Version: 1.0
3 Content-Transfer-Encoding: 7bit
4 Subject: [v3,
5 1/5] mtd: nand: Create a BBT flag to access bad block markers in raw
6 mode
7 From: Archit Taneja <architt@codeaurora.org>
8 X-Patchwork-Id: 6927081
9 Message-Id: <1438578498-32254-2-git-send-email-architt@codeaurora.org>
10 To: linux-mtd@lists.infradead.org, dehrenberg@google.com,
11 cernekee@gmail.com, computersforpeace@gmail.com
12 Cc: linux-arm-msm@vger.kernel.org, agross@codeaurora.org,
13 sboyd@codeaurora.org, linux-kernel@vger.kernel.org,
14 Archit Taneja <architt@codeaurora.org>
15 Date: Mon, 3 Aug 2015 10:38:14 +0530
16
17 Some controllers can access the factory bad block marker from OOB only
18 when they read it in raw mode. When ECC is enabled, these controllers
19 discard reading/writing bad block markers, preventing access to them
20 altogether.
21
22 The bbt driver assumes MTD_OPS_PLACE_OOB when scanning for bad blocks.
23 This results in the nand driver's ecc->read_oob() op to be called, which
24 works with ECC enabled.
25
26 Create a new BBT option flag that tells nand_bbt to force the mode to
27 MTD_OPS_RAW. This would result in the correct op being called for the
28 underlying nand controller driver.
29
30 Reviewed-by: Andy Gross <agross@codeaurora.org>
31 Signed-off-by: Archit Taneja <architt@codeaurora.org>
32
33 ---
34 drivers/mtd/nand/nand_base.c | 6 +++++-
35 drivers/mtd/nand/nand_bbt.c | 6 +++++-
36 include/linux/mtd/bbm.h | 7 +++++++
37 3 files changed, 17 insertions(+), 2 deletions(-)
38
39 --- a/drivers/mtd/nand/nand_base.c
40 +++ b/drivers/mtd/nand/nand_base.c
41 @@ -396,7 +396,11 @@ static int nand_default_block_markbad(st
42 } else {
43 ops.len = ops.ooblen = 1;
44 }
45 - ops.mode = MTD_OPS_PLACE_OOB;
46 +
47 + if (unlikely(chip->bbt_options & NAND_BBT_ACCESS_BBM_RAW))
48 + ops.mode = MTD_OPS_RAW;
49 + else
50 + ops.mode = MTD_OPS_PLACE_OOB;
51
52 /* Write to first/last page(s) if necessary */
53 if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
54 --- a/drivers/mtd/nand/nand_bbt.c
55 +++ b/drivers/mtd/nand/nand_bbt.c
56 @@ -423,7 +423,11 @@ static int scan_block_fast(struct mtd_in
57 ops.oobbuf = buf;
58 ops.ooboffs = 0;
59 ops.datbuf = NULL;
60 - ops.mode = MTD_OPS_PLACE_OOB;
61 +
62 + if (unlikely(bd->options & NAND_BBT_ACCESS_BBM_RAW))
63 + ops.mode = MTD_OPS_RAW;
64 + else
65 + ops.mode = MTD_OPS_PLACE_OOB;
66
67 for (j = 0; j < numpages; j++) {
68 /*
69 --- a/include/linux/mtd/bbm.h
70 +++ b/include/linux/mtd/bbm.h
71 @@ -116,6 +116,13 @@ struct nand_bbt_descr {
72 #define NAND_BBT_NO_OOB_BBM 0x00080000
73
74 /*
75 + * Force MTD_OPS_RAW mode when trying to access bad block markes from OOB. To
76 + * be used by controllers which can access BBM only when ECC is disabled, i.e,
77 + * when in RAW access mode
78 + */
79 +#define NAND_BBT_ACCESS_BBM_RAW 0x00100000
80 +
81 +/*
82 * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr
83 * was allocated dynamicaly and must be freed in nand_release(). Has no meaning
84 * in nand_chip.bbt_options.