bmt.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2015 MediaTek Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef __BMT_H__
  14. #define __BMT_H__
  15. #define MAX_BMT_SIZE (0x200)
  16. #define BMT_VERSION (1) /* initial version */
  17. #define MAIN_SIGNATURE_OFFSET (0)
  18. #define OOB_SIGNATURE_OFFSET (1)
  19. #define OOB_INDEX_OFFSET (29)
  20. #define OOB_INDEX_SIZE (2)
  21. #define FAKE_INDEX (0xAAAA)
  22. typedef struct _bmt_entry_ {
  23. u16 bad_index; /* bad block index */
  24. u16 mapped_index; /* mapping block index in the replace pool */
  25. } bmt_entry;
  26. typedef enum {
  27. UPDATE_ERASE_FAIL,
  28. UPDATE_WRITE_FAIL,
  29. UPDATE_UNMAPPED_BLOCK,
  30. UPDATE_REASON_COUNT,
  31. } update_reason_t;
  32. typedef struct {
  33. bmt_entry table[MAX_BMT_SIZE];
  34. u8 version;
  35. u8 mapped_count; /* mapped block count in pool */
  36. u8 bad_count; /* bad block count in pool. Not used in V1 */
  37. } bmt_struct;
  38. /***************************************************************
  39. * *
  40. * Interface BMT need to use *
  41. * *
  42. ***************************************************************/
  43. extern int mtk_nand_exec_read_page(struct mtd_info *mtd, u32 u4RowAddr, u32 u4PageSize,
  44. u8 *pPageBuf, u8 *pFDMBuf);
  45. extern int mtk_nand_block_bad_hw(struct mtd_info *mtd, loff_t ofs);
  46. extern int mtk_nand_erase_hw(struct mtd_info *mtd, int page);
  47. extern int mtk_nand_block_markbad_hw(struct mtd_info *mtd, loff_t ofs);
  48. extern int mtk_nand_exec_write_page(struct mtd_info *mtd, u32 row, u32 page_size, u8 *dat,
  49. u8 *oob);
  50. #if defined(CONFIG_MTK_TLC_NAND_SUPPORT)
  51. extern bool mtk_is_normal_tlc_nand(void);
  52. extern u32 mtk_nand_page_transform(struct mtd_info *mtd, struct nand_chip *chip, u32 page,
  53. u32 *blk, u32 *map_blk);
  54. #endif
  55. /***************************************************************
  56. * *
  57. * Different function interface for preloader/uboot/kernel *
  58. * *
  59. ***************************************************************/
  60. void set_bad_index_to_oob(u8 *oob, u16 index);
  61. bmt_struct *init_bmt(struct nand_chip *nand, int size);
  62. bool update_bmt(u64 offset, update_reason_t reason, u8 *dat, u8 *oob);
  63. unsigned short get_mapping_block_index(int index);
  64. #endif /* #ifndef __BMT_H__ */