Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cb77251

Browse files
ochrindongheng
authored andcommitted
fix(spiffs): fix bugs of spiffs
1. fix debug macro and parameters error 2. fix data no-align load/store error 3. update other function for user to develop easily Merges espressif#729
1 parent 36d8b6c commit cb77251

File tree

9 files changed

+2097
-515
lines changed

9 files changed

+2097
-515
lines changed

include/spiffs/spiffs.h

Lines changed: 285 additions & 29 deletions
Large diffs are not rendered by default.

include/spiffs/spiffs_config.h

Lines changed: 175 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,79 @@
1111
// ----------- 8< ------------
1212
// Following includes are for the linux test build of spiffs
1313
// These may/should/must be removed/altered/replaced in your target
14-
#include <stdio.h>
15-
#include <stdlib.h>
16-
#include <string.h>
17-
#include <stddef.h>
18-
#include "freertos/FreeRTOS.h"
19-
#include "freertos/task.h"
20-
14+
//#include "params_test.h"
15+
//#include <stdio.h>
16+
//#include <stdlib.h>
17+
//#include <string.h>
18+
//#include <stddef.h>
19+
//#include <unistd.h>
20+
//#ifdef _SPIFFS_TEST
21+
//#include "testrunner.h"
22+
//#endif
2123
// ----------- >8 ------------
2224

25+
#include "freertos/FreeRTOS.h"
26+
2327
// compile time switches
2428

2529
// Set generic spiffs debug output call.
2630
#ifndef SPIFFS_DBG
27-
#define SPIFFS_DBG(...) //printf(__VA_ARGS__)
31+
#define SPIFFS_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
2832
#endif
2933
// Set spiffs debug output call for garbage collecting.
3034
#ifndef SPIFFS_GC_DBG
31-
#define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
35+
#define SPIFFS_GC_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
3236
#endif
3337
// Set spiffs debug output call for caching.
3438
#ifndef SPIFFS_CACHE_DBG
35-
#define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
39+
#define SPIFFS_CACHE_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
3640
#endif
3741
// Set spiffs debug output call for system consistency checks.
3842
#ifndef SPIFFS_CHECK_DBG
39-
#define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
43+
#define SPIFFS_CHECK_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
44+
#endif
45+
// Set spiffs debug output call for all api invocations.
46+
#ifndef SPIFFS_API_DBG
47+
#define SPIFFS_API_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
4048
#endif
4149

50+
51+
52+
// Defines spiffs debug print formatters
53+
// some general signed number
54+
#ifndef _SPIPRIi
55+
#define _SPIPRIi "%d"
56+
#endif
57+
// address
58+
#ifndef _SPIPRIad
59+
#define _SPIPRIad "%08x"
60+
#endif
61+
// block
62+
#ifndef _SPIPRIbl
63+
#define _SPIPRIbl "%04x"
64+
#endif
65+
// page
66+
#ifndef _SPIPRIpg
67+
#define _SPIPRIpg "%04x"
68+
#endif
69+
// span index
70+
#ifndef _SPIPRIsp
71+
#define _SPIPRIsp "%04x"
72+
#endif
73+
// file descriptor
74+
#ifndef _SPIPRIfd
75+
#define _SPIPRIfd "%d"
76+
#endif
77+
// file object id
78+
#ifndef _SPIPRIid
79+
#define _SPIPRIid "%04x"
80+
#endif
81+
// file flags
82+
#ifndef _SPIPRIfl
83+
#define _SPIPRIfl "%02x"
84+
#endif
85+
86+
4287
// Enable/disable API functions to determine exact number of bytes
4388
// for filedescriptor and cache buffers. Once decided for a configuration,
4489
// this can be disabled to reduce flash.
@@ -51,7 +96,6 @@
5196
#ifndef SPIFFS_CACHE
5297
#define SPIFFS_CACHE 1
5398
#endif
54-
5599
#if SPIFFS_CACHE
56100
// Enables memory write caching for file descriptors in hydrogen
57101
#ifndef SPIFFS_CACHE_WR
@@ -60,7 +104,7 @@
60104

61105
// Enable/disable statistics on caching. Debug/test purpose only.
62106
#ifndef SPIFFS_CACHE_STATS
63-
#define SPIFFS_CACHE_STATS 1
107+
#define SPIFFS_CACHE_STATS 0
64108
#endif
65109
#endif
66110

@@ -72,12 +116,12 @@
72116

73117
// Define maximum number of gc runs to perform to reach desired free pages.
74118
#ifndef SPIFFS_GC_MAX_RUNS
75-
#define SPIFFS_GC_MAX_RUNS 5
119+
#define SPIFFS_GC_MAX_RUNS 10
76120
#endif
77121

78122
// Enable/disable statistics on gc. Debug/test purpose only.
79123
#ifndef SPIFFS_GC_STATS
80-
#define SPIFFS_GC_STATS 1
124+
#define SPIFFS_GC_STATS 0
81125
#endif
82126

83127
// Garbage collecting examines all pages in a block which and sums up
@@ -102,11 +146,27 @@
102146
#define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
103147
#endif
104148

105-
// Object name maximum length.
149+
// Object name maximum length. Note that this length include the
150+
// zero-termination character, meaning maximum string of characters
151+
// can at most be SPIFFS_OBJ_NAME_LEN - 1.
106152
#ifndef SPIFFS_OBJ_NAME_LEN
107153
#define SPIFFS_OBJ_NAME_LEN (32)
108154
#endif
109155

156+
// Maximum length of the metadata associated with an object.
157+
// Setting to non-zero value enables metadata-related API but also
158+
// changes the on-disk format, so the change is not backward-compatible.
159+
//
160+
// Do note: the meta length must never exceed
161+
// logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64)
162+
//
163+
// This is derived from following:
164+
// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
165+
// spiffs_object_ix_header fields + at least some LUT entries)
166+
#ifndef SPIFFS_OBJ_META_LEN
167+
#define SPIFFS_OBJ_META_LEN (0)
168+
#endif
169+
110170
// Size of buffer allocated on stack used when copying data.
111171
// Lower value generates more read/writes. No meaning having it bigger
112172
// than logical page size.
@@ -122,6 +182,17 @@
122182
#define SPIFFS_USE_MAGIC (0)
123183
#endif
124184

185+
#if SPIFFS_USE_MAGIC
186+
// Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is
187+
// enabled, the magic will also be dependent on the length of the filesystem.
188+
// For example, a filesystem configured and formatted for 4 megabytes will not
189+
// be accepted for mounting with a configuration defining the filesystem as 2
190+
// megabytes.
191+
#ifndef SPIFFS_USE_MAGIC_LENGTH
192+
#define SPIFFS_USE_MAGIC_LENGTH (1)
193+
#endif
194+
#endif
195+
125196
// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
126197
// These should be defined on a multithreaded system
127198

@@ -134,7 +205,6 @@
134205
#define SPIFFS_UNLOCK(fs)
135206
#endif
136207

137-
138208
// Enable if only one spiffs instance with constant configuration will exist
139209
// on the target. This will reduce calculations, flash and memory accesses.
140210
// Parts of configuration must be defined below instead of at time of mount.
@@ -167,11 +237,98 @@
167237
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
168238
#endif
169239

240+
// Enable this if you want the HAL callbacks to be called with the spiffs struct
241+
#ifndef SPIFFS_HAL_CALLBACK_EXTRA
242+
#define SPIFFS_HAL_CALLBACK_EXTRA 0
243+
#endif
244+
245+
// Enable this if you want to add an integer offset to all file handles
246+
// (spiffs_file). This is useful if running multiple instances of spiffs on
247+
// same target, in order to recognise to what spiffs instance a file handle
248+
// belongs.
249+
// NB: This adds config field fh_ix_offset in the configuration struct when
250+
// mounting, which must be defined.
251+
#ifndef SPIFFS_FILEHDL_OFFSET
252+
#define SPIFFS_FILEHDL_OFFSET 0
253+
#endif
254+
255+
// Enable this to compile a read only version of spiffs.
256+
// This will reduce binary size of spiffs. All code comprising modification
257+
// of the file system will not be compiled. Some config will be ignored.
258+
// HAL functions for erasing and writing to spi-flash may be null. Cache
259+
// can be disabled for even further binary size reduction (and ram savings).
260+
// Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL.
261+
// If the file system cannot be mounted due to aborted erase operation and
262+
// SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be
263+
// returned.
264+
// Might be useful for e.g. bootloaders and such.
265+
#ifndef SPIFFS_READ_ONLY
266+
#define SPIFFS_READ_ONLY 0
267+
#endif
268+
269+
// Enable this to add a temporal file cache using the fd buffer.
270+
// The effects of the cache is that SPIFFS_open will find the file faster in
271+
// certain cases. It will make it a lot easier for spiffs to find files
272+
// opened frequently, reducing number of readings from the spi flash for
273+
// finding those files.
274+
// This will grow each fd by 6 bytes. If your files are opened in patterns
275+
// with a degree of temporal locality, the system is optimized.
276+
// Examples can be letting spiffs serve web content, where one file is the css.
277+
// The css is accessed for each html file that is opened, meaning it is
278+
// accessed almost every second time a file is opened. Another example could be
279+
// a log file that is often opened, written, and closed.
280+
// The size of the cache is number of given file descriptors, as it piggybacks
281+
// on the fd update mechanism. The cache lives in the closed file descriptors.
282+
// When closed, the fd know the whereabouts of the file. Instead of forgetting
283+
// this, the temporal cache will keep handling updates to that file even if the
284+
// fd is closed. If the file is opened again, the location of the file is found
285+
// directly. If all available descriptors become opened, all cache memory is
286+
// lost.
287+
#ifndef SPIFFS_TEMPORAL_FD_CACHE
288+
#define SPIFFS_TEMPORAL_FD_CACHE 1
289+
#endif
290+
291+
// Temporal file cache hit score. Each time a file is opened, all cached files
292+
// will lose one point. If the opened file is found in cache, that entry will
293+
// gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this
294+
// value for the specific access patterns of the application. However, it must
295+
// be between 1 (no gain for hitting a cached entry often) and 255.
296+
#ifndef SPIFFS_TEMPORAL_CACHE_HIT_SCORE
297+
#define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4
298+
#endif
299+
300+
// Enable to be able to map object indices to memory.
301+
// This allows for faster and more deterministic reading if cases of reading
302+
// large files and when changing file offset by seeking around a lot.
303+
// When mapping a file's index, the file system will be scanned for index pages
304+
// and the info will be put in memory provided by user. When reading, the
305+
// memory map can be looked up instead of searching for index pages on the
306+
// medium. This way, user can trade memory against performance.
307+
// Whole, parts of, or future parts not being written yet can be mapped. The
308+
// memory array will be owned by spiffs and updated accordingly during garbage
309+
// collecting or when modifying the indices. The latter is invoked by when the
310+
// file is modified in some way. The index buffer is tied to the file
311+
// descriptor.
312+
#ifndef SPIFFS_IX_MAP
313+
#define SPIFFS_IX_MAP 1
314+
#endif
315+
316+
// By default SPIFFS in some cases relies on the property of NOR flash that bits
317+
// cannot be set from 0 to 1 by writing and that controllers will ignore such
318+
// bit changes. This results in fewer reads as SPIFFS can in some cases perform
319+
// blind writes, with all bits set to 1 and only those it needs reset set to 0.
320+
// Most of the chips and controllers allow this behavior, so the default is to
321+
// use this technique. If your controller is one of the rare ones that don't,
322+
// turn this option on and SPIFFS will perform a read-modify-write instead.
323+
#ifndef SPIFFS_NO_BLIND_WRITES
324+
#define SPIFFS_NO_BLIND_WRITES 0
325+
#endif
326+
170327
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
171328
// in the api. This function will visualize all filesystem using given printf
172329
// function.
173330
#ifndef SPIFFS_TEST_VISUALISATION
174-
#define SPIFFS_TEST_VISUALISATION 0
331+
#define SPIFFS_TEST_VISUALISATION 1
175332
#endif
176333
#if SPIFFS_TEST_VISUALISATION
177334
#ifndef spiffs_printf

0 commit comments

Comments
 (0)