mtd-abi.h 4.3 KB

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