nftl.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * File : nftl.h
  3. * COPYRIGHT (C) 2012-2014, Shanghai Real-Thread Electronic Technology Co.,Ltd
  4. *
  5. * Change Logs:
  6. * Date Author Notes
  7. * 2012-03-01 Bernard the first version
  8. * 2012-11-01 Bernard Add page mapping
  9. * 2012-12-28 Bernard Use log trace for NFTL log.
  10. * 2013-01-06 Bernard Fix oob issue when do a software page copy.
  11. * 2013-02-15 Bernard Reduce memory usage
  12. * 2013-06-10 Bernard Enable backup mapping block
  13. * 2013-09-18 Bernard Fix the quick search issue in mapping table initialization.
  14. * 2013-11-11 RealThread 1.0.13 version which supports none-os environment.
  15. * 2013-12-25 RealThread 1.0.14 version which optimizes for memory/stack usage.
  16. * 2014-01-20 RealThread 1.0.15 version which optimizes for the scan speed in boot.
  17. * 2015-01-05 RealThread 1.0.16 version which addes NFTL manargement block protect with MPU.
  18. * 2015-02-12 RealThread 1.0.17 version which fix the mapping block wear_leveling issue.
  19. */
  20. #ifndef __NAND_FTL_H__
  21. #define __NAND_FTL_H__
  22. #include <rtthread.h>
  23. #include <rtdevice.h>
  24. /* NFTL version information */
  25. #define NFTL_VERSION 1L /* major version number */
  26. #define NFTL_SUBVERSION 0L /* minor version number */
  27. #define NFTL_REVISION 17L /* revise version number */
  28. /* NFTL options */
  29. #define NFTL_BLOCKS_MAX 512 /* only 512 block for evaluation */
  30. #define NFTL_PAGE_MAX 2048
  31. #define NFTL_OOB_MAX 64
  32. #define NFTL_PAGE_IN_BLOCK_MAX 64
  33. #define NFTL_ERASE_BLANCE 10
  34. #define NFTL_PLANE_MAX 4
  35. #define NFTL_PM_CACHE_MAX 4
  36. #define NFTL_BLOCKS_RECENT_MAX 32
  37. #define NFTL_BACKUP_MAPPING_BLOCKS 4
  38. /* using backup register to save the block number of mapping table. */
  39. // #define NFTL_USING_BACKUP_MAPPING_BLOCK
  40. // #define NFTL_USING_COMPATIBLE
  41. /* using static memory for NFTl layer */
  42. // #define NFTL_USING_STATIC
  43. /* whether using MPU to protect NFTL core data */
  44. // #define NFTL_USING_MPU
  45. #define NFTL_MALLOC(sz) RT_KERNEL_MALLOC(sz)
  46. #define NFTL_FREE(ptr) RT_KERNEL_FREE(ptr)
  47. /* NFTL API for RT-Thread */
  48. rt_err_t nftl_attach(const char* mtd_device);
  49. /* NFTL API for diskio */
  50. rt_err_t nftl_read_page(struct rt_mtd_nand_device *device,
  51. rt_uint16_t block_offset,
  52. rt_uint16_t page_offset,
  53. rt_uint8_t *buffer);
  54. rt_err_t nftl_write_page(struct rt_mtd_nand_device *device,
  55. rt_uint16_t block_offset,
  56. rt_uint16_t page_offset,
  57. const rt_uint8_t *buffer);
  58. rt_err_t nftl_read_multi_page(struct rt_mtd_nand_device *device,
  59. rt_uint16_t block_offset,
  60. rt_uint16_t page_offset,
  61. rt_uint8_t *buffer,
  62. rt_size_t count);
  63. rt_err_t nftl_write_multi_page(struct rt_mtd_nand_device *device,
  64. rt_uint16_t block_offset,
  65. rt_uint16_t page_offset,
  66. const rt_uint8_t *buffer,
  67. rt_size_t count);
  68. rt_err_t nftl_erase_pages(struct rt_mtd_nand_device* device, rt_uint32_t page_begin, rt_uint32_t page_end);
  69. rt_err_t nftl_mapping_flush(struct rt_mtd_nand_device* device, rt_bool_t protect);
  70. rt_err_t nftl_layer_init(struct rt_mtd_nand_device* device);
  71. /* NFTL API for None-OS */
  72. rt_err_t nftl_layer_attach_nand(struct rt_mtd_nand_device* device);
  73. /* software ECC API */
  74. int nftl_ecc_verify256(rt_uint8_t *data, rt_uint32_t size, const rt_uint8_t *code);
  75. void nftl_ecc_compute256(const rt_uint8_t *data, rt_uint32_t size, rt_uint8_t *code);
  76. #endif