mtd-abi.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Portions of MTD ABI definition which are shared by kernel and user space
  3. */
  4. #ifndef __MTD_ABI_H__
  5. #define __MTD_ABI_H__
  6. struct erase_info_user {
  7. uint32_t start;
  8. uint32_t length;
  9. };
  10. struct mtd_oob_buf {
  11. uint32_t start;
  12. uint32_t length;
  13. unsigned char __user *ptr;
  14. };
  15. #define MTD_ABSENT 0
  16. #define MTD_RAM 1
  17. #define MTD_ROM 2
  18. #define MTD_NORFLASH 3
  19. #define MTD_NANDFLASH 4
  20. #define MTD_DATAFLASH 6
  21. #define MTD_UBIVOLUME 7
  22. #define MTD_WRITEABLE 0x400 /* Device is writeable */
  23. #define MTD_BIT_WRITEABLE 0x800 /* Single bits can be flipped */
  24. #define MTD_NO_ERASE 0x1000 /* No erase necessary */
  25. #define MTD_POWERUP_LOCK 0x2000 /* Always locked after reset */
  26. // Some common devices / combinations of capabilities
  27. #define MTD_CAP_ROM 0
  28. #define MTD_CAP_RAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
  29. #define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE)
  30. #define MTD_CAP_NANDFLASH (MTD_WRITEABLE)
  31. /* ECC byte placement */
  32. #define MTD_NANDECC_OFF 0 // Switch off ECC (Not recommended)
  33. #define MTD_NANDECC_PLACE 1 // Use the given placement in the structure (YAFFS1 legacy mode)
  34. #define MTD_NANDECC_AUTOPLACE 2 // Use the default placement scheme
  35. #define MTD_NANDECC_PLACEONLY 3 // Use the given placement in the structure (Do not store ecc result on read)
  36. #define MTD_NANDECC_AUTOPL_USR 4 // Use the given autoplacement scheme rather than using the default
  37. /* OTP mode selection */
  38. #define MTD_OTP_OFF 0
  39. #define MTD_OTP_FACTORY 1
  40. #define MTD_OTP_USER 2
  41. struct mtd_info_user {
  42. uint8_t type;
  43. uint32_t flags;
  44. uint32_t size; // Total size of the MTD
  45. uint32_t erasesize;
  46. uint32_t writesize;
  47. uint32_t oobsize; // Amount of OOB data per block (e.g. 16)
  48. /* The below two fields are obsolete and broken, do not use them
  49. * (TODO: remove at some point) */
  50. uint32_t ecctype;
  51. uint32_t eccsize;
  52. };
  53. struct region_info_user {
  54. uint32_t offset; /* At which this region starts,
  55. * from the beginning of the MTD */
  56. uint32_t erasesize; /* For this region */
  57. uint32_t numblocks; /* Number of blocks in this region */
  58. uint32_t regionindex;
  59. };
  60. struct otp_info {
  61. uint32_t start;
  62. uint32_t length;
  63. uint32_t locked;
  64. };
  65. #define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
  66. #define MEMERASE _IOW('M', 2, struct erase_info_user)
  67. #define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf)
  68. #define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf)
  69. #define MEMLOCK _IOW('M', 5, struct erase_info_user)
  70. #define MEMUNLOCK _IOW('M', 6, struct erase_info_user)
  71. #define MEMGETREGIONCOUNT _IOR('M', 7, int)
  72. #define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user)
  73. #define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo)
  74. #define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo)
  75. #define MEMGETBADBLOCK _IOW('M', 11, loff_t)
  76. #define MEMSETBADBLOCK _IOW('M', 12, loff_t)
  77. #define OTPSELECT _IOR('M', 13, int)
  78. #define OTPGETREGIONCOUNT _IOW('M', 14, int)
  79. #define OTPGETREGIONINFO _IOW('M', 15, struct otp_info)
  80. #define OTPLOCK _IOR('M', 16, struct otp_info)
  81. #define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout)
  82. #define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)
  83. #define MTDFILEMODE _IO('M', 19)
  84. /*
  85. * Obsolete legacy interface. Keep it in order not to break userspace
  86. * interfaces
  87. */
  88. struct nand_oobinfo {
  89. uint32_t useecc;
  90. uint32_t eccbytes;
  91. uint32_t oobfree[8][2];
  92. uint32_t eccpos[32];
  93. };
  94. struct nand_oobfree {
  95. uint32_t offset;
  96. uint32_t length;
  97. };
  98. #define MTD_MAX_OOBFREE_ENTRIES 8
  99. /*
  100. * ECC layout control structure. Exported to userspace for
  101. * diagnosis and to allow creation of raw images
  102. */
  103. struct nand_ecclayout {
  104. uint32_t eccbytes;
  105. uint32_t eccpos[64];
  106. uint32_t oobavail;
  107. struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
  108. };
  109. /**
  110. * struct mtd_ecc_stats - error correction stats
  111. *
  112. * @corrected: number of corrected bits
  113. * @failed: number of uncorrectable errors
  114. * @badblocks: number of bad blocks in this partition
  115. * @bbtblocks: number of blocks reserved for bad block tables
  116. */
  117. struct mtd_ecc_stats {
  118. uint32_t corrected;
  119. uint32_t failed;
  120. uint32_t badblocks;
  121. uint32_t bbtblocks;
  122. };
  123. /*
  124. * Read/write file modes for access to MTD
  125. */
  126. enum mtd_file_modes {
  127. MTD_MODE_NORMAL = MTD_OTP_OFF,
  128. MTD_MODE_OTP_FACTORY = MTD_OTP_FACTORY,
  129. MTD_MODE_OTP_USER = MTD_OTP_USER,
  130. MTD_MODE_RAW,
  131. };
  132. #endif /* __MTD_ABI_H__ */