Skip to content

Commit d8ad6e4

Browse files
me-no-devigrr
authored andcommitted
Use SPIFFS as submodule, fix build for ESP32/ESP8266 (#31)
* Remove old spiffs and move config * Add spiffs submodule * Update test to not break the submodule and fix ESP8266 build * Init submodule for Travis and AppVeyor * Add missing includes causing build errors
1 parent 7fefeac commit d8ad6e4

15 files changed

+68
-7542
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "spiffs"]
2+
path = spiffs
3+
url = https://github.com/pellepl/spiffs.git

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ addons:
66
packages:
77
- g++-4.8
88
script:
9+
- git submodule update --init --recursive
910
- export CXX="g++-4.8" CC="gcc-4.8"
1011
# Build default configuration
1112
- make dist
1213
# Build configuration with SPIFFS_USE_MAGIC_LENGTH=0 (legacy version)
1314
- make clean
14-
- make dist BUILD_CONFIG_NAME="-no_magic_length" CFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0"
15+
- make dist BUILD_CONFIG_NAME="-no_magic_length" CFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0 -DSPIFFS_ALIGNED_OBJECT_INDEX_TABLES=1"
1516

1617
notifications:
1718
email:

Makefile

+24-23
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ endif
3939
VERSION ?= $(shell git describe --always)
4040

4141
OBJ := main.o \
42-
spiffs/spiffs_cache.o \
43-
spiffs/spiffs_check.o \
44-
spiffs/spiffs_gc.o \
45-
spiffs/spiffs_hydrogen.o \
46-
spiffs/spiffs_nucleus.o \
42+
spiffs/src/spiffs_cache.o \
43+
spiffs/src/spiffs_check.o \
44+
spiffs/src/spiffs_gc.o \
45+
spiffs/src/spiffs_hydrogen.o \
46+
spiffs/src/spiffs_nucleus.o \
4747

48-
INCLUDES := -Itclap -Ispiffs -I.
48+
INCLUDES := -Itclap -Iinclude -Ispiffs/src -I.
4949

5050
override CFLAGS := -std=gnu99 -Os -Wall $(TARGET_CFLAGS) $(CFLAGS)
5151
override CXXFLAGS := -std=gnu++11 -Os -Wall $(TARGET_CXXFLAGS) $(CXXFLAGS)
@@ -74,26 +74,27 @@ $(DIST_DIR):
7474
@mkdir -p $@
7575

7676
clean:
77-
@rm -f *.o
78-
@rm -f spiffs/*.o
79-
@rm -f $(TARGET)
77+
@rm -f $(TARGET) $(OBJ)
8078

8179
SPIFFS_TEST_FS_CONFIG := -s 0x100000 -p 512 -b 0x2000
8280

8381
test: $(TARGET)
84-
rm -rf spiffs/.git
85-
rm -f spiffs/.DS_Store
86-
ls -1 spiffs > out.list0
87-
touch spiffs/.DS_Store
88-
mkdir -p spiffs/.git
89-
touch spiffs/.git/foo
90-
./mkspiffs -c spiffs $(SPIFFS_TEST_FS_CONFIG) out.spiffs | sort | sed s/^\\/// > out.list1
91-
./mkspiffs -u spiffs_u $(SPIFFS_TEST_FS_CONFIG) out.spiffs | sort | sed s/^\\/// > out.list_u
92-
./mkspiffs -l $(SPIFFS_TEST_FS_CONFIG) out.spiffs | cut -f 2 | sort | sed s/^\\/// > out.list2
82+
mkdir -p spiffs_t
83+
cp spiffs/src/*.h spiffs_t/
84+
cp spiffs/src/*.c spiffs_t/
85+
rm -rf spiffs_t/.git
86+
rm -f spiffs_t/.DS_Store
87+
ls -1 spiffs_t > out.list0
88+
touch spiffs_t/.DS_Store
89+
mkdir -p spiffs_t/.git
90+
touch spiffs_t/.git/foo
91+
./mkspiffs -c spiffs_t $(SPIFFS_TEST_FS_CONFIG) out.spiffs_t | sort | sed s/^\\/// > out.list1
92+
./mkspiffs -u spiffs_u $(SPIFFS_TEST_FS_CONFIG) out.spiffs_t | sort | sed s/^\\/// > out.list_u
93+
./mkspiffs -l $(SPIFFS_TEST_FS_CONFIG) out.spiffs_t | cut -f 2 | sort | sed s/^\\/// > out.list2
9394
diff --strip-trailing-cr out.list0 out.list1
9495
diff --strip-trailing-cr out.list0 out.list2
95-
rm -rf spiffs/.git
96-
rm -f spiffs/.DS_Store
97-
diff spiffs spiffs_u
98-
rm -f out.{list0,list1,list2,list_u,spiffs}
99-
rm -R spiffs_u
96+
rm -rf spiffs_t/.git
97+
rm -f spiffs_t/.DS_Store
98+
diff spiffs_t spiffs_u
99+
rm -f out.{list0,list1,list2,list_u,spiffs_t}
100+
rm -R spiffs_u spiffs_t

appveyor.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ matrix:
1010
fast_finish: true
1111

1212
build_script:
13+
- git submodule update --init --recursive
1314
- SET PATH=C:\MinGW\bin;C:\MinGW\msys\1.0\bin;%PATH%
1415
# Build default configuration
1516
- make dist
1617
# Build configuration with SPIFFS_USE_MAGIC_LENGTH=0 (legacy version)
1718
- make clean
18-
- make dist BUILD_CONFIG_NAME="-no_magic_length" CFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0"
19+
- make dist BUILD_CONFIG_NAME="-no_magic_length" CFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0 -DSPIFFS_ALIGNED_OBJECT_INDEX_TABLES=1"
1920

2021
artifacts:
2122
- path: '*.zip'

spiffs/spiffs_config.h renamed to include/spiffs_config.h

+35-108
Original file line numberDiff line numberDiff line change
@@ -8,93 +8,65 @@
88
#ifndef SPIFFS_CONFIG_H_
99
#define SPIFFS_CONFIG_H_
1010

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>
16+
#include <string.h>
1117
#include <stddef.h>
1218
#include <stdint.h>
1319
#include <stdbool.h>
14-
#include <string.h>
15-
#include <stdio.h>
16-
17-
typedef int16_t file_t;
18-
typedef int32_t s32_t;
19-
typedef uint32_t u32_t;
20-
typedef int16_t s16_t;
21-
typedef uint16_t u16_t;
22-
typedef int8_t s8_t;
23-
typedef uint8_t u8_t;
24-
25-
#ifndef SEEK_SET
26-
#define SEEK_SET 0 /* set file offset to offset */
27-
#endif
28-
29-
#ifndef SEEK_CUR
30-
#define SEEK_CUR 1 /* set file offset to current plus offset */
31-
#endif
32-
33-
#ifndef SEEK_END
34-
#define SEEK_END 2 /* set file offset to EOF plus offset */
35-
#endif
36-
37-
#ifndef EOF
38-
#define EOF (-1)
39-
#endif
40-
41-
// compile time switches
20+
#include <unistd.h>
4221

4322
// Set generic spiffs debug output call.
4423
#ifndef SPIFFS_DBG
45-
#define SPIFFS_DBG(...) //printf(__VA_ARGS__)
24+
#define SPIFFS_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
4625
#endif
4726
// Set spiffs debug output call for garbage collecting.
4827
#ifndef SPIFFS_GC_DBG
49-
#define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
28+
#define SPIFFS_GC_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
5029
#endif
5130
// Set spiffs debug output call for caching.
5231
#ifndef SPIFFS_CACHE_DBG
53-
#define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
32+
#define SPIFFS_CACHE_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
5433
#endif
5534
// Set spiffs debug output call for system consistency checks.
5635
#ifndef SPIFFS_CHECK_DBG
57-
#define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
36+
#define SPIFFS_CHECK_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
5837
#endif
59-
6038
// Set spiffs debug output call for all api invocations.
6139
#ifndef SPIFFS_API_DBG
62-
#define SPIFFS_API_DBG(...) //printf(__VA_ARGS__)
40+
#define SPIFFS_API_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
6341
#endif
6442

43+
// needed types
44+
typedef int16_t file_t;
45+
typedef int32_t s32_t;
46+
typedef uint32_t u32_t;
47+
typedef int16_t s16_t;
48+
typedef uint16_t u16_t;
49+
typedef int8_t s8_t;
50+
typedef uint8_t u8_t;
51+
6552
// Defines spiffs debug print formatters
6653
// some general signed number
67-
#ifndef _SPIPRIi
6854
#define _SPIPRIi "%d"
69-
#endif
7055
// address
71-
#ifndef _SPIPRIad
7256
#define _SPIPRIad "%08x"
73-
#endif
7457
// block
75-
#ifndef _SPIPRIbl
7658
#define _SPIPRIbl "%04x"
77-
#endif
7859
// page
79-
#ifndef _SPIPRIpg
8060
#define _SPIPRIpg "%04x"
81-
#endif
8261
// span index
83-
#ifndef _SPIPRIsp
8462
#define _SPIPRIsp "%04x"
85-
#endif
8663
// file descriptor
87-
#ifndef _SPIPRIfd
8864
#define _SPIPRIfd "%d"
89-
#endif
9065
// file object id
91-
#ifndef _SPIPRIid
9266
#define _SPIPRIid "%04x"
93-
#endif
9467
// file flags
95-
#ifndef _SPIPRIfl
9668
#define _SPIPRIfl "%02x"
97-
#endif
69+
9870

9971
// Enable/disable API functions to determine exact number of bytes
10072
// for filedescriptor and cache buffers. Once decided for a configuration,
@@ -127,9 +99,7 @@ typedef uint8_t u8_t;
12799
#endif
128100

129101
// Define maximum number of gc runs to perform to reach desired free pages.
130-
#ifndef SPIFFS_GC_MAX_RUNS
131-
#define SPIFFS_GC_MAX_RUNS 5
132-
#endif
102+
#define SPIFFS_GC_MAX_RUNS 10
133103

134104
// Enable/disable statistics on gc. Debug/test purpose only.
135105
#ifndef SPIFFS_GC_STATS
@@ -145,23 +115,17 @@ typedef uint8_t u8_t;
145115
// picked for garbage collection.
146116

147117
// Garbage collecting heuristics - weight used for deleted pages.
148-
#ifndef SPIFFS_GC_HEUR_W_DELET
149118
#define SPIFFS_GC_HEUR_W_DELET (5)
150-
#endif
151119
// Garbage collecting heuristics - weight used for used pages.
152-
#ifndef SPIFFS_GC_HEUR_W_USED
153120
#define SPIFFS_GC_HEUR_W_USED (-1)
154-
#endif
155121
// Garbage collecting heuristics - weight used for time between
156122
// last erased and erase of this block.
157-
#ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
158123
#define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
159-
#endif
160124

161-
// Object name maximum length.
162-
#ifndef SPIFFS_OBJ_NAME_LEN
125+
// Object name maximum length. Note that this length include the
126+
// zero-termination character, meaning maximum string of characters
127+
// can at most be SPIFFS_OBJ_NAME_LEN - 1.
163128
#define SPIFFS_OBJ_NAME_LEN (32)
164-
#endif
165129

166130
// Maximum length of the metadata associated with an object.
167131
// Setting to non-zero value enables metadata-related API but also
@@ -173,15 +137,13 @@ typedef uint8_t u8_t;
173137
// This is derived from following:
174138
// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
175139
// spiffs_object_ix_header fields + at least some LUT entries)
176-
#ifndef SPIFFS_OBJ_META_LEN
177140
#define SPIFFS_OBJ_META_LEN (0)
178-
#endif
179141

180142
// Size of buffer allocated on stack used when copying data.
181143
// Lower value generates more read/writes. No meaning having it bigger
182144
// than logical page size.
183145
#ifndef SPIFFS_COPY_BUFFER_STACK
184-
#define SPIFFS_COPY_BUFFER_STACK (64)
146+
#define SPIFFS_COPY_BUFFER_STACK (256)
185147
#endif
186148

187149
// Enable this to have an identifiable spiffs filesystem. This will look for
@@ -207,50 +169,23 @@ typedef uint8_t u8_t;
207169
// These should be defined on a multithreaded system
208170

209171
// define this to enter a mutex if you're running on a multithreaded system
210-
#ifndef SPIFFS_LOCK
211172
#define SPIFFS_LOCK(fs)
212-
#endif
213173
// define this to exit a mutex if you're running on a multithreaded system
214-
#ifndef SPIFFS_UNLOCK
215174
#define SPIFFS_UNLOCK(fs)
216-
#endif
217-
218175

219176
// Enable if only one spiffs instance with constant configuration will exist
220177
// on the target. This will reduce calculations, flash and memory accesses.
221178
// Parts of configuration must be defined below instead of at time of mount.
222-
#ifndef SPIFFS_SINGLETON
223179
#define SPIFFS_SINGLETON 0
224-
#endif
225-
226-
#if SPIFFS_SINGLETON
227-
// Instead of giving parameters in config struct, singleton build must
228-
// give parameters in defines below.
229-
#ifndef SPIFFS_CFG_PHYS_SZ
230-
#define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2)
231-
#endif
232-
#ifndef SPIFFS_CFG_PHYS_ERASE_SZ
233-
#define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536)
234-
#endif
235-
#ifndef SPIFFS_CFG_PHYS_ADDR
236-
#define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
237-
#endif
238-
#ifndef SPIFFS_CFG_LOG_PAGE_SZ
239-
#define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
240-
#endif
241-
#ifndef SPIFFS_CFG_LOG_BLOCK_SZ
242-
#define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536)
243-
#endif
244-
#endif
245180

246181
// Enable this if your target needs aligned data for index tables
247182
#ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
248-
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
183+
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0
249184
#endif
250185

251186
// Enable this if you want the HAL callbacks to be called with the spiffs struct
252187
#ifndef SPIFFS_HAL_CALLBACK_EXTRA
253-
#define SPIFFS_HAL_CALLBACK_EXTRA 0
188+
#define SPIFFS_HAL_CALLBACK_EXTRA 0
254189
#endif
255190

256191
// Enable this if you want to add an integer offset to all file handles
@@ -260,7 +195,7 @@ typedef uint8_t u8_t;
260195
// NB: This adds config field fh_ix_offset in the configuration struct when
261196
// mounting, which must be defined.
262197
#ifndef SPIFFS_FILEHDL_OFFSET
263-
#define SPIFFS_FILEHDL_OFFSET 0
198+
#define SPIFFS_FILEHDL_OFFSET 0
264199
#endif
265200

266201
// Enable this to compile a read only version of spiffs.
@@ -274,7 +209,7 @@ typedef uint8_t u8_t;
274209
// returned.
275210
// Might be useful for e.g. bootloaders and such.
276211
#ifndef SPIFFS_READ_ONLY
277-
#define SPIFFS_READ_ONLY 0
212+
#define SPIFFS_READ_ONLY 0
278213
#endif
279214

280215
// Enable this to add a temporal file cache using the fd buffer.
@@ -296,7 +231,7 @@ typedef uint8_t u8_t;
296231
// directly. If all available descriptors become opened, all cache memory is
297232
// lost.
298233
#ifndef SPIFFS_TEMPORAL_FD_CACHE
299-
#define SPIFFS_TEMPORAL_FD_CACHE 1
234+
#define SPIFFS_TEMPORAL_FD_CACHE 1
300235
#endif
301236

302237
// Temporal file cache hit score. Each time a file is opened, all cached files
@@ -305,7 +240,7 @@ typedef uint8_t u8_t;
305240
// value for the specific access patterns of the application. However, it must
306241
// be between 1 (no gain for hitting a cached entry often) and 255.
307242
#ifndef SPIFFS_TEMPORAL_CACHE_HIT_SCORE
308-
#define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4
243+
#define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4
309244
#endif
310245

311246
// Enable to be able to map object indices to memory.
@@ -321,12 +256,12 @@ typedef uint8_t u8_t;
321256
// file is modified in some way. The index buffer is tied to the file
322257
// descriptor.
323258
#ifndef SPIFFS_IX_MAP
324-
#define SPIFFS_IX_MAP 1
259+
#define SPIFFS_IX_MAP 1
325260
#endif
326261

327262
// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
328263
// in the api. This function will visualize all filesystem using given printf
329-
// function.
264+
// function..
330265
#ifndef SPIFFS_TEST_VISUALISATION
331266
#define SPIFFS_TEST_VISUALISATION 1
332267
#endif
@@ -335,22 +270,14 @@ typedef uint8_t u8_t;
335270
#define spiffs_printf(...) printf(__VA_ARGS__)
336271
#endif
337272
// spiffs_printf argument for a free page
338-
#ifndef SPIFFS_TEST_VIS_FREE_STR
339273
#define SPIFFS_TEST_VIS_FREE_STR "_"
340-
#endif
341274
// spiffs_printf argument for a deleted page
342-
#ifndef SPIFFS_TEST_VIS_DELE_STR
343275
#define SPIFFS_TEST_VIS_DELE_STR "/"
344-
#endif
345276
// spiffs_printf argument for an index page for given object id
346-
#ifndef SPIFFS_TEST_VIS_INDX_STR
347277
#define SPIFFS_TEST_VIS_INDX_STR(id) "i"
348-
#endif
349278
// spiffs_printf argument for a data page for given object id
350-
#ifndef SPIFFS_TEST_VIS_DATA_STR
351279
#define SPIFFS_TEST_VIS_DATA_STR(id) "d"
352280
#endif
353-
#endif
354281

355282
// Types depending on configuration such as the amount of flash bytes
356283
// given to spiffs file system in total (spiffs_file_system_size),

0 commit comments

Comments
 (0)