bmt.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef __BMT_H__
  2. #define __BMT_H__
  3. #include <linux/mtd/mtd.h>
  4. #include <linux/mtd/nand.h>
  5. #include <mtk_nand.h>
  6. #define MAX_BMT_SIZE (0x200) /* 0x80 */
  7. #define BMT_VERSION (1) /* initial version */
  8. #define MAIN_SIGNATURE_OFFSET (0)
  9. #define OOB_SIGNATURE_OFFSET (1)
  10. #define OOB_INDEX_OFFSET (29)
  11. #define OOB_INDEX_SIZE (2)
  12. #define FAKE_INDEX (0xAAAA)
  13. typedef struct _bmt_entry_ {
  14. u16 bad_index; /* bad block index */
  15. u16 mapped_index; /* mapping block index in the replace pool */
  16. } bmt_entry;
  17. typedef enum {
  18. UPDATE_ERASE_FAIL,
  19. UPDATE_WRITE_FAIL,
  20. UPDATE_UNMAPPED_BLOCK,
  21. UPDATE_REASON_COUNT,
  22. } update_reason_t;
  23. typedef struct {
  24. bmt_entry table[MAX_BMT_SIZE];
  25. u8 version;
  26. u8 mapped_count; /* mapped block count in pool */
  27. u8 bad_count; /* bad block count in pool. Not used in V1 */
  28. } bmt_struct;
  29. /***************************************************************
  30. * *
  31. * Interface BMT need to use *
  32. * *
  33. ***************************************************************/
  34. /* extern bool mtk_nand_exec_read_page(struct mtd_info *mtd, u32 row, u32 page_size, u8 * dat, u8 * oob); */
  35. extern int mtk_nand_exec_read_page(struct mtd_info *mtd, u32 u4RowAddr, u32 u4PageSize,
  36. u8 *pPageBuf, u8 *pFDMBuf);
  37. extern int mtk_nand_block_bad_hw(struct mtd_info *mtd, loff_t ofs);
  38. extern int mtk_nand_erase_hw(struct mtd_info *mtd, int page);
  39. extern int mtk_nand_block_markbad_hw(struct mtd_info *mtd, loff_t ofs);
  40. extern int mtk_nand_exec_write_page(struct mtd_info *mtd, u32 row, u32 page_size, u8 *dat,
  41. u8 *oob);
  42. /***************************************************************
  43. * *
  44. * Different function interface for preloader/uboot/kernel *
  45. * *
  46. ***************************************************************/
  47. void set_bad_index_to_oob(u8 *oob, u16 index);
  48. bmt_struct *init_bmt(struct nand_chip *nand, int size);
  49. bool update_bmt(u64 offset, update_reason_t reason, u8 *dat, u8 *oob);
  50. unsigned short get_mapping_block_index(int index);
  51. #endif /* #ifndef __BMT_H__ */