0047-mtd-nand-Create-a-BBT-flag-to-access-bad-block-marke.patch 2.5 KB

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