161-mtd-nand-Create-a-BBT-flag-to-access-bad-block-markers-in-raw-mode.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. Some controllers can access the factory bad block marker from OOB only
  17. when they read it in raw mode. When ECC is enabled, these controllers
  18. discard reading/writing bad block markers, preventing access to them
  19. altogether.
  20. The bbt driver assumes MTD_OPS_PLACE_OOB when scanning for bad blocks.
  21. This results in the nand driver's ecc->read_oob() op to be called, which
  22. works with ECC enabled.
  23. Create a new BBT option flag that tells nand_bbt to force the mode to
  24. MTD_OPS_RAW. This would result in the correct op being called for the
  25. underlying nand controller driver.
  26. Reviewed-by: Andy Gross <agross@codeaurora.org>
  27. Signed-off-by: Archit Taneja <architt@codeaurora.org>
  28. ---
  29. drivers/mtd/nand/nand_base.c | 6 +++++-
  30. drivers/mtd/nand/nand_bbt.c | 6 +++++-
  31. include/linux/mtd/bbm.h | 7 +++++++
  32. 3 files changed, 17 insertions(+), 2 deletions(-)
  33. --- a/drivers/mtd/nand/nand_base.c
  34. +++ b/drivers/mtd/nand/nand_base.c
  35. @@ -396,7 +396,11 @@ static int nand_default_block_markbad(st
  36. } else {
  37. ops.len = ops.ooblen = 1;
  38. }
  39. - ops.mode = MTD_OPS_PLACE_OOB;
  40. +
  41. + if (unlikely(chip->bbt_options & NAND_BBT_ACCESS_BBM_RAW))
  42. + ops.mode = MTD_OPS_RAW;
  43. + else
  44. + ops.mode = MTD_OPS_PLACE_OOB;
  45. /* Write to first/last page(s) if necessary */
  46. if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
  47. --- a/drivers/mtd/nand/nand_bbt.c
  48. +++ b/drivers/mtd/nand/nand_bbt.c
  49. @@ -423,7 +423,11 @@ static int scan_block_fast(struct mtd_in
  50. ops.oobbuf = buf;
  51. ops.ooboffs = 0;
  52. ops.datbuf = NULL;
  53. - ops.mode = MTD_OPS_PLACE_OOB;
  54. +
  55. + if (unlikely(bd->options & NAND_BBT_ACCESS_BBM_RAW))
  56. + ops.mode = MTD_OPS_RAW;
  57. + else
  58. + ops.mode = MTD_OPS_PLACE_OOB;
  59. for (j = 0; j < numpages; j++) {
  60. /*
  61. --- a/include/linux/mtd/bbm.h
  62. +++ b/include/linux/mtd/bbm.h
  63. @@ -116,6 +116,13 @@ struct nand_bbt_descr {
  64. #define NAND_BBT_NO_OOB_BBM 0x00080000
  65. /*
  66. + * Force MTD_OPS_RAW mode when trying to access bad block markes from OOB. To
  67. + * be used by controllers which can access BBM only when ECC is disabled, i.e,
  68. + * when in RAW access mode
  69. + */
  70. +#define NAND_BBT_ACCESS_BBM_RAW 0x00100000
  71. +
  72. +/*
  73. * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr
  74. * was allocated dynamicaly and must be freed in nand_release(). Has no meaning
  75. * in nand_chip.bbt_options.