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