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