text
[RRG-proxmark3.git] / armsrc / spiffs_config.h
blob85997903b6c303b405e449d24464243d5743ebd8
1 /*
2 * spiffs_config.h
4 * Created on: Jul 3, 2013
5 * Author: petera
6 */
8 #ifndef SPIFFS_CONFIG_H_
9 #define SPIFFS_CONFIG_H_
11 // ----------- 8< ------------
12 // Following includes are for the linux test build of spiffs
13 // These may/should/must be removed/altered/replaced in your target
14 //#include <stdio.h>
15 //#include <stdlib.h>
17 #include "printf.h"
18 #include "string.h"
19 #include "flashmem.h"
21 //#include <stddef.h>
22 //#include <unistd.h>
23 // ----------- >8 ------------
26 typedef int s32_t;
27 typedef uint32_t u32_t;
28 typedef int16_t s16_t;
29 typedef uint16_t u16_t;
30 typedef int8_t s8_t;
31 typedef uint8_t u8_t;
33 // compile time switches
35 // Set generic spiffs debug output call.
36 #ifndef SPIFFS_DBG
37 #define SPIFFS_DBG(_f, ...) //Dbprintf(_f, ## __VA_ARGS__)
38 #define SPIFFS_DBGF(str) SPIFFS_DBG(str,NULL)
39 #endif
40 // Set spiffs debug output call for garbage collecting.
41 #ifndef SPIFFS_GC_DBG
42 #define SPIFFS_GC_DBG(_f, ...) //Dbprintf(_f, ## __VA_ARGS__)
43 #define SPIFFS_GC_DBGF(str) SPIFFS_GC_DBG(str,NULL)
44 #endif
45 // Set spiffs debug output call for caching.
46 #ifndef SPIFFS_CACHE_DBG
47 #define SPIFFS_CACHE_DBG(_f, ...) //Dbprintf(_f, ## __VA_ARGS__)
48 #define SPIFFS_CACHE_DBGF(str) SPIFFS_CACHE_DBG(str,NULL)
49 #endif
50 // Set spiffs debug output call for system consistency checks.
51 #ifndef SPIFFS_CHECK_DBG
52 #define SPIFFS_CHECK_DBG(_f, ...) //Dbprintf(_f, ## __VA_ARGS__)
53 #define SPIFFS_CHECK_DBGF(str) SPIFFS_CHECK_DBG(str,NULL)
54 #endif
55 // Set spiffs debug output call for all api invocations.
56 #ifndef SPIFFS_API_DBG
57 #define SPIFFS_API_DBG(_f, ...) //Dbprintf(_f, ## __VA_ARGS__)
58 #define SPIFFS_API_DBGF(str) SPIFFS_API_DBG(str,NULL)
59 #endif
61 // Defines spiffs debug print formatters
62 // some general signed number
63 #ifndef _SPIPRIi
64 #define _SPIPRIi "%d"
65 #endif
66 // address
67 #ifndef _SPIPRIad
68 #define _SPIPRIad "%08x"
69 #endif
70 // block
71 #ifndef _SPIPRIbl
72 #define _SPIPRIbl "%04x"
73 #endif
74 // page
75 #ifndef _SPIPRIpg
76 #define _SPIPRIpg "%04x"
77 #endif
78 // span index
79 #ifndef _SPIPRIsp
80 #define _SPIPRIsp "%04x"
81 #endif
82 // file descriptor
83 #ifndef _SPIPRIfd
84 #define _SPIPRIfd "%d"
85 #endif
86 // file object id
87 #ifndef _SPIPRIid
88 #define _SPIPRIid "%04x"
89 #endif
90 // file flags
91 #ifndef _SPIPRIfl
92 #define _SPIPRIfl "%02x"
93 #endif
96 // Enable/disable API functions to determine exact number of bytes
97 // for filedescriptor and cache buffers. Once decided for a configuration,
98 // this can be disabled to reduce flash.
99 #ifndef SPIFFS_BUFFER_HELP
100 #define SPIFFS_BUFFER_HELP 0
101 #endif
103 // Enables/disable memory read caching of nucleus file system operations.
104 // If enabled, memory area must be provided for cache in SPIFFS_mount.
105 #ifndef SPIFFS_CACHE
106 #define SPIFFS_CACHE 1
107 #endif
108 #if SPIFFS_CACHE
109 // Enables memory write caching for file descriptors in hydrogen
110 #ifndef SPIFFS_CACHE_WR
111 #define SPIFFS_CACHE_WR 1
112 #endif
114 // Enable/disable statistics on caching. Debug/test purpose only.
115 #ifndef SPIFFS_CACHE_STATS
116 #define SPIFFS_CACHE_STATS 0
117 #endif
118 #endif
120 // Always check header of each accessed page to ensure consistent state.
121 // If enabled it will increase number of reads, will increase flash.
122 #ifndef SPIFFS_PAGE_CHECK
123 #define SPIFFS_PAGE_CHECK 0
124 #endif
126 // Define maximum number of gc runs to perform to reach desired free pages.
127 #ifndef SPIFFS_GC_MAX_RUNS
128 #define SPIFFS_GC_MAX_RUNS 5
129 #endif
131 // Enable/disable statistics on gc. Debug/test purpose only.
132 #ifndef SPIFFS_GC_STATS
133 #define SPIFFS_GC_STATS 0
134 #endif
136 // Garbage collecting examines all pages in a block which and sums up
137 // to a block score. Deleted pages normally gives positive score and
138 // used pages normally gives a negative score (as these must be moved).
139 // To have a fair wear-leveling, the erase age is also included in score,
140 // whose factor normally is the most positive.
141 // The larger the score, the more likely it is that the block will
142 // picked for garbage collection.
144 // Garbage collecting heuristics - weight used for deleted pages.
145 #ifndef SPIFFS_GC_HEUR_W_DELET
146 #define SPIFFS_GC_HEUR_W_DELET (5)
147 #endif
148 // Garbage collecting heuristics - weight used for used pages.
149 #ifndef SPIFFS_GC_HEUR_W_USED
150 #define SPIFFS_GC_HEUR_W_USED (-1)
151 #endif
152 // Garbage collecting heuristics - weight used for time between
153 // last erased and erase of this block.
154 #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
155 #define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
156 #endif
158 // Object name maximum length. Note that this length include the
159 // zero-termination character, meaning maximum string of characters
160 // can at most be SPIFFS_OBJ_NAME_LEN - 1.
161 #ifndef SPIFFS_OBJ_NAME_LEN
162 #define SPIFFS_OBJ_NAME_LEN (32)
163 #endif
165 // Maximum length of the metadata associated with an object.
166 // Setting to non-zero value enables metadata-related API but also
167 // changes the on-disk format, so the change is not backward-compatible.
169 // Do note: the meta length must never exceed
170 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64)
172 // This is derived from following:
173 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
174 // spiffs_object_ix_header fields + at least some LUT entries)
175 #ifndef SPIFFS_OBJ_META_LEN
176 #define SPIFFS_OBJ_META_LEN (0)
177 #endif
179 // Size of buffer allocated on stack used when copying data.
180 // Lower value generates more read/writes. No meaning having it bigger
181 // than logical page size.
182 #ifndef SPIFFS_COPY_BUFFER_STACK
183 #define SPIFFS_COPY_BUFFER_STACK (256)
184 #endif
186 // Enable this to have an identifiable spiffs filesystem. This will look for
187 // a magic in all sectors to determine if this is a valid spiffs system or
188 // not on mount point. If not, SPIFFS_format must be called prior to mounting
189 // again.
190 #ifndef SPIFFS_USE_MAGIC
191 #define SPIFFS_USE_MAGIC (0)
192 #endif
194 #if SPIFFS_USE_MAGIC
195 // Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is
196 // enabled, the magic will also be dependent on the length of the filesystem.
197 // For example, a filesystem configured and formatted for 4 megabytes will not
198 // be accepted for mounting with a configuration defining the filesystem as 2
199 // megabytes.
200 #ifndef SPIFFS_USE_MAGIC_LENGTH
201 #define SPIFFS_USE_MAGIC_LENGTH (0)
202 #endif
203 #endif
205 // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
206 // These should be defined on a multithreaded system
208 // define this to enter a mutex if you're running on a multithreaded system
209 #ifndef SPIFFS_LOCK
210 #define SPIFFS_LOCK(fs)
211 #endif
212 // define this to exit a mutex if you're running on a multithreaded system
213 #ifndef SPIFFS_UNLOCK
214 #define SPIFFS_UNLOCK(fs)
215 #endif
217 // Enable if only one spiffs instance with constant configuration will exist
218 // on the target. This will reduce calculations, flash and memory accesses.
219 // Parts of configuration must be defined below instead of at time of mount.
220 #ifndef SPIFFS_SINGLETON
221 #define SPIFFS_SINGLETON (1)
222 #endif
224 #if SPIFFS_SINGLETON
225 // Instead of giving parameters in config struct, singleton build must
226 // give parameters in defines below.
227 #ifndef SPIFFS_CFG_PHYS_SZ
228 #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*128)
229 #endif
230 #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
231 #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (4*1024)
232 #endif
233 #ifndef SPIFFS_CFG_PHYS_ADDR
234 #define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
235 #endif
236 #ifndef SPIFFS_CFG_LOG_PAGE_SZ
237 #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
238 #endif
239 #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
240 #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (4*1024)
241 #endif
242 #endif
244 // Enable this if your target needs aligned data for index tables
245 #ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
246 #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
247 #endif
249 // Enable this if you want the HAL callbacks to be called with the spiffs struct
250 #ifndef SPIFFS_HAL_CALLBACK_EXTRA
251 #define SPIFFS_HAL_CALLBACK_EXTRA 0
252 #endif
254 // Enable this if you want to add an integer offset to all file handles
255 // (spiffs_file). This is useful if running multiple instances of spiffs on
256 // same target, in order to recognise to what spiffs instance a file handle
257 // belongs.
258 // NB: This adds config field fh_ix_offset in the configuration struct when
259 // mounting, which must be defined.
260 #ifndef SPIFFS_FILEHDL_OFFSET
261 #define SPIFFS_FILEHDL_OFFSET 0
262 #endif
264 // Enable this to compile a read only version of spiffs.
265 // This will reduce binary size of spiffs. All code comprising modification
266 // of the file system will not be compiled. Some config will be ignored.
267 // HAL functions for erasing and writing to spi-flash may be null. Cache
268 // can be disabled for even further binary size reduction (and ram savings).
269 // Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL.
270 // If the file system cannot be mounted due to aborted erase operation and
271 // SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be
272 // returned.
273 // Might be useful for e.g. bootloaders and such.
274 #ifndef SPIFFS_READ_ONLY
275 #define SPIFFS_READ_ONLY 0
276 #endif
278 // Enable this to add a temporal file cache using the fd buffer.
279 // The effects of the cache is that SPIFFS_open will find the file faster in
280 // certain cases. It will make it a lot easier for spiffs to find files
281 // opened frequently, reducing number of readings from the spi flash for
282 // finding those files.
283 // This will grow each fd by 6 bytes. If your files are opened in patterns
284 // with a degree of temporal locality, the system is optimized.
285 // Examples can be letting spiffs serve web content, where one file is the css.
286 // The css is accessed for each html file that is opened, meaning it is
287 // accessed almost every second time a file is opened. Another example could be
288 // a log file that is often opened, written, and closed.
289 // The size of the cache is number of given file descriptors, as it piggybacks
290 // on the fd update mechanism. The cache lives in the closed file descriptors.
291 // When closed, the fd know the whereabouts of the file. Instead of forgetting
292 // this, the temporal cache will keep handling updates to that file even if the
293 // fd is closed. If the file is opened again, the location of the file is found
294 // directly. If all available descriptors become opened, all cache memory is
295 // lost.
296 #ifndef SPIFFS_TEMPORAL_FD_CACHE
297 #define SPIFFS_TEMPORAL_FD_CACHE 1
298 #endif
300 // Temporal file cache hit score. Each time a file is opened, all cached files
301 // will lose one point. If the opened file is found in cache, that entry will
302 // gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this
303 // value for the specific access patterns of the application. However, it must
304 // be between 1 (no gain for hitting a cached entry often) and 255.
305 #ifndef SPIFFS_TEMPORAL_CACHE_HIT_SCORE
306 #define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4
307 #endif
309 // Enable to be able to map object indices to memory.
310 // This allows for faster and more deterministic reading if cases of reading
311 // large files and when changing file offset by seeking around a lot.
312 // When mapping a file's index, the file system will be scanned for index pages
313 // and the info will be put in memory provided by user. When reading, the
314 // memory map can be looked up instead of searching for index pages on the
315 // medium. This way, user can trade memory against performance.
316 // Whole, parts of, or future parts not being written yet can be mapped. The
317 // memory array will be owned by spiffs and updated accordingly during garbage
318 // collecting or when modifying the indices. The latter is invoked by when the
319 // file is modified in some way. The index buffer is tied to the file
320 // descriptor.
321 #ifndef SPIFFS_IX_MAP
322 #define SPIFFS_IX_MAP 1
323 #endif
325 // By default SPIFFS in some cases relies on the property of NOR flash that bits
326 // cannot be set from 0 to 1 by writing and that controllers will ignore such
327 // bit changes. This results in fewer reads as SPIFFS can in some cases perform
328 // blind writes, with all bits set to 1 and only those it needs reset set to 0.
329 // Most of the chips and controllers allow this behavior, so the default is to
330 // use this technique. If your controller is one of the rare ones that don't,
331 // turn this option on and SPIFFS will perform a read-modify-write instead.
332 #ifndef SPIFFS_NO_BLIND_WRITES
333 #define SPIFFS_NO_BLIND_WRITES 0
334 #endif
336 // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
337 // in the api. This function will visualize all filesystem using given printf
338 // function.
339 #ifndef SPIFFS_TEST_VISUALISATION
340 #define SPIFFS_TEST_VISUALISATION 0
341 #endif
342 #if SPIFFS_TEST_VISUALISATION
343 #ifndef spiffs_printf
344 #define spiffs_printf(...) Dbprintf(__VA_ARGS__)
345 #endif
346 // spiffs_printf argument for a free page
347 #ifndef SPIFFS_TEST_VIS_FREE_STR
348 #define SPIFFS_TEST_VIS_FREE_STR "_"
349 #endif
350 // spiffs_printf argument for a deleted page
351 #ifndef SPIFFS_TEST_VIS_DELE_STR
352 #define SPIFFS_TEST_VIS_DELE_STR "/"
353 #endif
354 // spiffs_printf argument for an index page for given object id
355 #ifndef SPIFFS_TEST_VIS_INDX_STR
356 #define SPIFFS_TEST_VIS_INDX_STR(id) "i"
357 #endif
358 // spiffs_printf argument for a data page for given object id
359 #ifndef SPIFFS_TEST_VIS_DATA_STR
360 #define SPIFFS_TEST_VIS_DATA_STR(id) "d"
361 #endif
362 #endif
364 // Types depending on configuration such as the amount of flash bytes
365 // given to spiffs file system in total (spiffs_file_system_size),
366 // the logical block size (log_block_size), and the logical page size
367 // (log_page_size)
369 // Block index type. Make sure the size of this type can hold
370 // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
371 typedef u16_t spiffs_block_ix;
372 // Page index type. Make sure the size of this type can hold
373 // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size
374 typedef u16_t spiffs_page_ix;
375 // Object id type - most significant bit is reserved for index flag. Make sure the
376 // size of this type can hold the highest object id on a full system,
377 // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2
378 typedef u16_t spiffs_obj_id;
379 // Object span index type. Make sure the size of this type can
380 // hold the largest possible span index on the system -
381 // i.e. (spiffs_file_system_size / log_page_size) - 1
382 typedef u16_t spiffs_span_ix;
384 #endif /* SPIFFS_CONFIG_H_ */