uffs_config.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. This file is part of UFFS, the Ultra-low-cost Flash File System.
  3. Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
  4. UFFS is free software; you can redistribute it and/or modify it under
  5. the GNU Library General Public License as published by the Free Software
  6. Foundation; either version 2 of the License, or (at your option) any
  7. later version.
  8. UFFS is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. or GNU Library General Public License, as applicable, for more details.
  12. You should have received a copy of the GNU General Public License
  13. and GNU Library General Public License along with UFFS; if not, write
  14. to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. As a special exception, if other files instantiate templates or use
  17. macros or inline functions from this file, or you compile this file
  18. and link it with other works to produce a work based on this file,
  19. this file does not by itself cause the resulting work to be covered
  20. by the GNU General Public License. However the source code for this
  21. file must still be made available in accordance with section (3) of
  22. the GNU General Public License v2.
  23. This exception does not invalidate any other reasons why a work based
  24. on this file might be covered by the GNU General Public License.
  25. */
  26. /**
  27. * \file uffs_config.h
  28. * \brief basic configuration of uffs
  29. * \author Ricky Zheng
  30. */
  31. #ifndef _UFFS_CONFIG_H_
  32. #define _UFFS_CONFIG_H_
  33. /**
  34. * \def UFFS_MAX_PAGE_SIZE
  35. * \note maximum page size UFFS support
  36. */
  37. #define UFFS_MAX_PAGE_SIZE 2048
  38. /**
  39. * \def UFFS_MAX_SPARE_SIZE
  40. */
  41. #define UFFS_MAX_SPARE_SIZE ((UFFS_MAX_PAGE_SIZE / 256) * 8)
  42. /**
  43. * \def UFFS_MAX_ECC_SIZE
  44. */
  45. #define UFFS_MAX_ECC_SIZE ((UFFS_MAX_PAGE_SIZE / 256) * 5)
  46. /**
  47. * \def MAX_CACHED_BLOCK_INFO
  48. * \note uffs cache the block info for opened directories and files,
  49. * a practical value is 5 ~ MAX_OBJECT_HANDLE
  50. */
  51. #define MAX_CACHED_BLOCK_INFO 50
  52. /**
  53. * \def MAX_PAGE_BUFFERS
  54. * \note the bigger value will bring better read/write performance.
  55. * but few writing performance will be improved when this
  56. * value is become larger than 'max pages per block'
  57. */
  58. #define MAX_PAGE_BUFFERS 40
  59. /**
  60. * \def CLONE_BUFFER_THRESHOLD
  61. * \note reserve buffers for clone. 1 or 2 should be enough.
  62. */
  63. #define CLONE_BUFFERS_THRESHOLD 2
  64. /**
  65. * \def MAX_SPARE_BUFFERS
  66. * \note spare buffers are used for lower level flash operations,
  67. * 5 should be enough.
  68. */
  69. #define MAX_SPARE_BUFFERS 5
  70. /**
  71. * \def MAX_DIRTY_PAGES_IN_A_BLOCK
  72. * \note this value should be between '2' and the lesser of
  73. * 'max pages per block' and (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD - 1).
  74. *
  75. * the smaller the value the frequently the buffer will be flushed.
  76. */
  77. #define MAX_DIRTY_PAGES_IN_A_BLOCK 32
  78. /**
  79. * \def MAX_DIRTY_BUF_GROUPS
  80. */
  81. #define MAX_DIRTY_BUF_GROUPS 3
  82. /**
  83. * \def CONFIG_ENABLE_UFFS_DEBUG_MSG
  84. * \note Enable debug message output. You must call uffs_InitDebugMessageOutput()
  85. * to initialize debug apart from enable debug feature.
  86. */
  87. #define CONFIG_ENABLE_UFFS_DEBUG_MSG
  88. /**
  89. * \def CONFIG_USE_GLOBAL_FS_LOCK
  90. * \note use global lock instead of per-device lock.
  91. * this is required if you use fd APIs in multi-thread environment.
  92. */
  93. #define CONFIG_USE_GLOBAL_FS_LOCK
  94. /**
  95. * \def CONFIG_USE_PER_DEVICE_LOCK
  96. * \note use per-device lock.
  97. * this is required if you use fs APIs in multi-thread environment.
  98. */
  99. //#define CONFIG_USE_PER_DEVICE_LOCK
  100. /**
  101. * \def CONFIG_USE_STATIC_MEMORY_ALLOCATOR
  102. * \note uffs will use static memory allocator if this is defined.
  103. * to use static memory allocator, you need to provide memory
  104. * buffer when creating uffs_Device.
  105. *
  106. * use UFFS_STATIC_BUFF_SIZE() to calculate memory buffer size.
  107. */
  108. #define CONFIG_USE_STATIC_MEMORY_ALLOCATOR 0
  109. /**
  110. * \def CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR
  111. * \note using system platform's 'malloc' and 'free'.
  112. */
  113. #define CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR 1
  114. /**
  115. * \def CONFIG_FLUSH_BUF_AFTER_WRITE
  116. * \note UFFS will write all data directly into flash in
  117. * each 'write' call if you enable this option.
  118. * (which means lesser data lost when power failure but
  119. * poorer writing performance).
  120. * It's not recommended to open this define for normal applications.
  121. */
  122. #define CONFIG_FLUSH_BUF_AFTER_WRITE
  123. /**
  124. * \def CONFIG_UFFS_AUTO_LAYOUT_MTD_COMP
  125. * \note Use Linux MTD compatiable spare placement for UFFS_LAYOUT_AUTO,
  126. * only valid for page data size 512 or 2048.
  127. */
  128. //#define CONFIG_UFFS_AUTO_LAYOUT_USE_MTD_SCHEME
  129. /**
  130. * \def MAX_OBJECT_HANDLE
  131. * maximum number of object handle
  132. */
  133. #define MAX_OBJECT_HANDLE 50
  134. #define FD_SIGNATURE_SHIFT 6
  135. /**
  136. * \def MAX_DIR_HANDLE
  137. * maximum number of uffs_DIR
  138. */
  139. #define MAX_DIR_HANDLE 10
  140. /**
  141. * \def MINIMUN_ERASED_BLOCK
  142. * UFFS will not allow appending or creating new files when the free/erased block
  143. * is lower then MINIMUN_ERASED_BLOCK.
  144. */
  145. #define MINIMUN_ERASED_BLOCK 2
  146. /**
  147. * \def CONFIG_CHANGE_MODIFY_TIME
  148. * \note If defined, closing a file which is opened for writing/appending will
  149. * update the file's modify time as well. Disable this feature will save a
  150. * lot of writing activities if you frequently open files for write and close it.
  151. */
  152. //#define CONFIG_CHANGE_MODIFY_TIME
  153. /**
  154. * \def CONFIG_ENABLE_BAD_BLOCK_VERIFY
  155. * \note allow erase and verify block marked as 'bad' when format UFFS partition.
  156. * it's not recommended for most NAND flash.
  157. */
  158. #define CONFIG_ENABLE_BAD_BLOCK_VERIFY
  159. /**
  160. * \def CONFIG_ERASE_BLOCK_BEFORE_MARK_BAD
  161. * \note erase block again before mark bad block
  162. */
  163. //#define CONFIG_ERASE_BLOCK_BEFORE_MARK_BAD
  164. /**
  165. * \def CONFIG_PAGE_WRITE_VERIFY
  166. * \note verify page data after write, for extra safe data storage.
  167. */
  168. #define CONFIG_PAGE_WRITE_VERIFY
  169. /**
  170. * \def CONFIG_BAD_BLOCK_POLICY_STRICT
  171. * \note If this is enabled, UFFS will report the block as 'bad' if any bit-flips found;
  172. * otherwise, UFFS report bad block only when ECC failed or reported
  173. * by low level flash driver.
  174. *
  175. * \note Enable this will ensure your data always be stored on completely good blocks.
  176. */
  177. #define CONFIG_BAD_BLOCK_POLICY_STRICT
  178. /**
  179. * \def CONFIG_ENABLE_PAGE_DATA_CRC
  180. * \note If this is enabled, UFFS save page data CRC16 sum in mini header,
  181. * it provides extra protection for data integrity.
  182. */
  183. #define CONFIG_ENABLE_PAGE_DATA_CRC
  184. /** micros for calculating buffer sizes */
  185. /**
  186. * \def UFFS_BLOCK_INFO_BUFFER_SIZE
  187. * \brief calculate memory bytes for block info caches
  188. */
  189. #define UFFS_BLOCK_INFO_BUFFER_SIZE(n_pages_per_block) \
  190. ( \
  191. ( \
  192. sizeof(uffs_BlockInfo) + \
  193. sizeof(uffs_PageSpare) * n_pages_per_block \
  194. ) * MAX_CACHED_BLOCK_INFO \
  195. )
  196. /**
  197. * \def UFFS_PAGE_BUFFER_SIZE
  198. * \brief calculate memory bytes for page buffers
  199. */
  200. #define UFFS_PAGE_BUFFER_SIZE(n_page_size) \
  201. ( \
  202. ( \
  203. sizeof(uffs_Buf) + n_page_size \
  204. ) * MAX_PAGE_BUFFERS \
  205. )
  206. /**
  207. * \def UFFS_TREE_BUFFER_SIZE
  208. * \brief calculate memory bytes for tree nodes
  209. */
  210. #define UFFS_TREE_BUFFER_SIZE(n_blocks) (sizeof(TreeNode) * n_blocks)
  211. #define UFFS_SPARE_BUFFER_SIZE (MAX_SPARE_BUFFERS * UFFS_MAX_SPARE_SIZE)
  212. /**
  213. * \def UFFS_STATIC_BUFF_SIZE
  214. * \brief calculate total memory usage of uffs system
  215. */
  216. #define UFFS_STATIC_BUFF_SIZE(n_pages_per_block, n_page_size, n_blocks) \
  217. ( \
  218. UFFS_BLOCK_INFO_BUFFER_SIZE(n_pages_per_block) + \
  219. UFFS_PAGE_BUFFER_SIZE(n_page_size) + \
  220. UFFS_TREE_BUFFER_SIZE(n_blocks) + \
  221. UFFS_SPARE_BUFFER_SIZE \
  222. )
  223. /* config check */
  224. #if (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD) < 3
  225. #error "MAX_PAGE_BUFFERS is too small"
  226. #endif
  227. #if (MAX_DIRTY_PAGES_IN_A_BLOCK < 2)
  228. #error "MAX_DIRTY_PAGES_IN_A_BLOCK should >= 2"
  229. #endif
  230. #if (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD - 1 < MAX_DIRTY_PAGES_IN_A_BLOCK)
  231. #error "MAX_DIRTY_PAGES_IN_A_BLOCK should < (MAX_PAGE_BUFFERS - CLONE_BUFFERS_THRESHOLD)"
  232. #endif
  233. #if defined(CONFIG_PAGE_WRITE_VERIFY) && (CLONE_BUFFERS_THRESHOLD < 2)
  234. #error "CLONE_BUFFERS_THRESHOLD should >= 2 when CONFIG_PAGE_WRITE_VERIFY is enabled."
  235. #endif
  236. #if CONFIG_USE_STATIC_MEMORY_ALLOCATOR + CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR > 1
  237. #error "Please enable ONLY one memory allocator"
  238. #endif
  239. #if CONFIG_USE_STATIC_MEMORY_ALLOCATOR + CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR == 0
  240. #error "Please enable ONE of memory allocators"
  241. #endif
  242. #if defined(CONFIG_USE_GLOBAL_FS_LOCK) && defined(CONFIG_USE_PER_DEVICE_LOCK)
  243. #error "enable either CONFIG_USE_GLOBAL_FS_LOCK or CONFIG_USE_PER_DEVICE_LOCK, not both"
  244. #endif
  245. #if (MAX_OBJECT_HANDLE > (1 << FD_SIGNATURE_SHIFT))
  246. #error "Please increase FD_SIGNATURE_SHIFT !"
  247. #endif
  248. #ifdef WIN32
  249. # pragma warning(disable : 4996)
  250. # pragma warning(disable : 4244)
  251. # pragma warning(disable : 4214)
  252. # pragma warning(disable : 4127)
  253. # pragma warning(disable : 4389)
  254. # pragma warning(disable : 4100)
  255. #endif
  256. #endif