spiffs_config.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * spiffs_config.h
  3. *
  4. * Created on: Jul 3, 2013
  5. * Author: petera
  6. */
  7. #ifndef SPIFFS_CONFIG_H_
  8. #define SPIFFS_CONFIG_H_
  9. // ----------- 8< ------------
  10. // Following includes are for the linux test build of spiffs
  11. // These may/should/must be removed/altered/replaced in your target
  12. #include "nodemcu_spiffs.h"
  13. // ----------- >8 ------------
  14. #include "user_config.h"
  15. // compile time switches
  16. // Set generic spiffs debug output call.
  17. #ifndef SPIFFS_DBG
  18. #define SPIFFS_DBG(...) //printf(__VA_ARGS__)
  19. #endif
  20. // Set spiffs debug output call for garbage collecting.
  21. #ifndef SPIFFS_GC_DBG
  22. #define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
  23. #endif
  24. // Set spiffs debug output call for caching.
  25. #ifndef SPIFFS_CACHE_DBG
  26. #define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
  27. #endif
  28. // Set spiffs debug output call for system consistency checks.
  29. #ifndef SPIFFS_CHECK_DBG
  30. #define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
  31. #endif
  32. // Enable/disable API functions to determine exact number of bytes
  33. // for filedescriptor and cache buffers. Once decided for a configuration,
  34. // this can be disabled to reduce flash.
  35. #ifndef SPIFFS_BUFFER_HELP
  36. #define SPIFFS_BUFFER_HELP 0
  37. #endif
  38. // Enables/disable memory read caching of nucleus file system operations.
  39. // If enabled, memory area must be provided for cache in SPIFFS_mount.
  40. #ifndef SPIFFS_CACHE
  41. #define SPIFFS_CACHE 1
  42. #endif
  43. #if SPIFFS_CACHE
  44. // Enables memory write caching for file descriptors in hydrogen
  45. #ifndef SPIFFS_CACHE_WR
  46. #define SPIFFS_CACHE_WR 1
  47. #endif
  48. // Enable/disable statistics on caching. Debug/test purpose only.
  49. #ifndef SPIFFS_CACHE_STATS
  50. #define SPIFFS_CACHE_STATS 1
  51. #endif
  52. #endif
  53. // Always check header of each accessed page to ensure consistent state.
  54. // If enabled it will increase number of reads, will increase flash.
  55. #ifndef SPIFFS_PAGE_CHECK
  56. #define SPIFFS_PAGE_CHECK 1
  57. #endif
  58. // Define maximum number of gc runs to perform to reach desired free pages.
  59. #ifndef SPIFFS_GC_MAX_RUNS
  60. #define SPIFFS_GC_MAX_RUNS 5
  61. #endif
  62. // Enable/disable statistics on gc. Debug/test purpose only.
  63. #ifndef SPIFFS_GC_STATS
  64. #define SPIFFS_GC_STATS 1
  65. #endif
  66. // Garbage collecting examines all pages in a block which and sums up
  67. // to a block score. Deleted pages normally gives positive score and
  68. // used pages normally gives a negative score (as these must be moved).
  69. // To have a fair wear-leveling, the erase age is also included in score,
  70. // whose factor normally is the most positive.
  71. // The larger the score, the more likely it is that the block will
  72. // picked for garbage collection.
  73. // Garbage collecting heuristics - weight used for deleted pages.
  74. #ifndef SPIFFS_GC_HEUR_W_DELET
  75. #define SPIFFS_GC_HEUR_W_DELET (5)
  76. #endif
  77. // Garbage collecting heuristics - weight used for used pages.
  78. #ifndef SPIFFS_GC_HEUR_W_USED
  79. #define SPIFFS_GC_HEUR_W_USED (-1)
  80. #endif
  81. // Garbage collecting heuristics - weight used for time between
  82. // last erased and erase of this block.
  83. #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
  84. #define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
  85. #endif
  86. // Object name maximum length. Note that this length include the
  87. // zero-termination character, meaning maximum string of characters
  88. // can at most be SPIFFS_OBJ_NAME_LEN - 1.
  89. #ifndef SPIFFS_OBJ_NAME_LEN
  90. #define SPIFFS_OBJ_NAME_LEN (FS_OBJ_NAME_LEN+1)
  91. #endif
  92. // Size of buffer allocated on stack used when copying data.
  93. // Lower value generates more read/writes. No meaning having it bigger
  94. // than logical page size.
  95. #ifndef SPIFFS_COPY_BUFFER_STACK
  96. #define SPIFFS_COPY_BUFFER_STACK (64)
  97. #endif
  98. // Enable this to have an identifiable spiffs filesystem. This will look for
  99. // a magic in all sectors to determine if this is a valid spiffs system or
  100. // not on mount point. If not, SPIFFS_format must be called prior to mounting
  101. // again.
  102. #ifndef SPIFFS_USE_MAGIC
  103. #define SPIFFS_USE_MAGIC (0)
  104. #endif
  105. #if SPIFFS_USE_MAGIC
  106. // Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is
  107. // enabled, the magic will also be dependent on the length of the filesystem.
  108. // For example, a filesystem configured and formatted for 4 megabytes will not
  109. // be accepted for mounting with a configuration defining the filesystem as 2
  110. // megabytes.
  111. #ifndef SPIFFS_USE_MAGIC_LENGTH
  112. #define SPIFFS_USE_MAGIC_LENGTH (0)
  113. #endif
  114. #endif
  115. // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
  116. // These should be defined on a multithreaded system
  117. // define this to enter a mutex if you're running on a multithreaded system
  118. #ifndef SPIFFS_LOCK
  119. #define SPIFFS_LOCK(fs)
  120. #endif
  121. // define this to exit a mutex if you're running on a multithreaded system
  122. #ifndef SPIFFS_UNLOCK
  123. #define SPIFFS_UNLOCK(fs)
  124. #endif
  125. // Enable if only one spiffs instance with constant configuration will exist
  126. // on the target. This will reduce calculations, flash and memory accesses.
  127. // Parts of configuration must be defined below instead of at time of mount.
  128. #ifndef SPIFFS_SINGLETON
  129. #define SPIFFS_SINGLETON 0
  130. #endif
  131. #if SPIFFS_SINGLETON
  132. // Instead of giving parameters in config struct, singleton build must
  133. // give parameters in defines below.
  134. #ifndef SPIFFS_CFG_PHYS_SZ
  135. #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2)
  136. #endif
  137. #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
  138. #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536)
  139. #endif
  140. #ifndef SPIFFS_CFG_PHYS_ADDR
  141. #define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
  142. #endif
  143. #ifndef SPIFFS_CFG_LOG_PAGE_SZ
  144. #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
  145. #endif
  146. #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
  147. #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536)
  148. #endif
  149. #endif
  150. // Enable this if your target needs aligned data for index tables
  151. #ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
  152. #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0
  153. #endif
  154. // Enable this if you want the HAL callbacks to be called with the spiffs struct
  155. #ifndef SPIFFS_HAL_CALLBACK_EXTRA
  156. #define SPIFFS_HAL_CALLBACK_EXTRA 0
  157. #endif
  158. // Enable this if you want to add an integer offset to all file handles
  159. // (spiffs_file). This is useful if running multiple instances of spiffs on
  160. // same target, in order to recognise to what spiffs instance a file handle
  161. // belongs.
  162. // NB: This adds config field fh_ix_offset in the configuration struct when
  163. // mounting, which must be defined.
  164. #ifndef SPIFFS_FILEHDL_OFFSET
  165. #define SPIFFS_FILEHDL_OFFSET 0
  166. #endif
  167. // Enable this to compile a read only version of spiffs.
  168. // This will reduce binary size of spiffs. All code comprising modification
  169. // of the file system will not be compiled. Some config will be ignored.
  170. // HAL functions for erasing and writing to spi-flash may be null. Cache
  171. // can be disabled for even further binary size reduction (and ram savings).
  172. // Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL.
  173. // If the file system cannot be mounted due to aborted erase operation and
  174. // SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be
  175. // returned.
  176. // Might be useful for e.g. bootloaders and such.
  177. #ifndef SPIFFS_READ_ONLY
  178. #define SPIFFS_READ_ONLY 0
  179. #endif
  180. // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
  181. // in the api. This function will visualize all filesystem using given printf
  182. // function.
  183. #ifndef SPIFFS_TEST_VISUALISATION
  184. #define SPIFFS_TEST_VISUALISATION 1
  185. #endif
  186. #if SPIFFS_TEST_VISUALISATION
  187. #ifndef spiffs_printf
  188. #define spiffs_printf(...) printf(__VA_ARGS__)
  189. #endif
  190. // spiffs_printf argument for a free page
  191. #ifndef SPIFFS_TEST_VIS_FREE_STR
  192. #define SPIFFS_TEST_VIS_FREE_STR "_"
  193. #endif
  194. // spiffs_printf argument for a deleted page
  195. #ifndef SPIFFS_TEST_VIS_DELE_STR
  196. #define SPIFFS_TEST_VIS_DELE_STR "/"
  197. #endif
  198. // spiffs_printf argument for an index page for given object id
  199. #ifndef SPIFFS_TEST_VIS_INDX_STR
  200. #define SPIFFS_TEST_VIS_INDX_STR(id) "i"
  201. #endif
  202. // spiffs_printf argument for a data page for given object id
  203. #ifndef SPIFFS_TEST_VIS_DATA_STR
  204. #define SPIFFS_TEST_VIS_DATA_STR(id) "d"
  205. #endif
  206. #endif
  207. // Types depending on configuration such as the amount of flash bytes
  208. // given to spiffs file system in total (spiffs_file_system_size),
  209. // the logical block size (log_block_size), and the logical page size
  210. // (log_page_size)
  211. // Block index type. Make sure the size of this type can hold
  212. // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
  213. typedef u16_t spiffs_block_ix;
  214. // Page index type. Make sure the size of this type can hold
  215. // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size
  216. typedef u16_t spiffs_page_ix;
  217. // Object id type - most significant bit is reserved for index flag. Make sure the
  218. // size of this type can hold the highest object id on a full system,
  219. // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2
  220. typedef u16_t spiffs_obj_id;
  221. // Object span index type. Make sure the size of this type can
  222. // hold the largest possible span index on the system -
  223. // i.e. (spiffs_file_system_size / log_page_size) - 1
  224. typedef u16_t spiffs_span_ix;
  225. #endif /* SPIFFS_CONFIG_H_ */