Skip to content

Commit aa7ddb1

Browse files
committed
Switch to LittleFS as the main file system // Issue #173
SPIFFS has been deprecated in the Arduino core v2.7.1
1 parent cbb04ee commit aa7ddb1

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

builder/main.py

+27-23
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ def _parse_ld_sizes(ldscript_path):
6060

6161
appsize_re = re.compile(
6262
r"irom0_0_seg\s*:.+len\s*=\s*(0x[\da-f]+)", flags=re.I)
63-
spiffs_re = re.compile(
64-
r"PROVIDE\s*\(\s*_SPIFFS_(\w+)\s*=\s*(0x[\da-f]+)\s*\)", flags=re.I)
63+
filesystem_re = re.compile(
64+
r"PROVIDE\s*\(\s*_%s_(\w+)\s*=\s*(0x[\da-f]+)\s*\)" % "FS"
65+
if "arduino" in env.subst("$PIOFRAMEWORK")
66+
else "SPIFFS",
67+
flags=re.I,
68+
)
6569
with open(ldscript_path) as fp:
6670
for line in fp.readlines():
6771
line = line.strip()
@@ -71,9 +75,9 @@ def _parse_ld_sizes(ldscript_path):
7175
if match:
7276
result['app_size'] = _parse_size(match.group(1))
7377
continue
74-
match = spiffs_re.search(line)
78+
match = filesystem_re.search(line)
7579
if match:
76-
result['spiffs_%s' % match.group(1)] = _parse_size(
80+
result['fs_%s' % match.group(1)] = _parse_size(
7781
match.group(2))
7882
return result
7983

@@ -85,19 +89,19 @@ def _get_flash_size(env):
8589
return "%dM" % (ldsizes['flash_size'] / 1048576)
8690

8791

88-
def fetch_spiffs_size(env):
92+
def fetch_fs_size(env):
8993
ldsizes = _parse_ld_sizes(env.GetActualLDScript())
9094
for key in ldsizes:
91-
if key.startswith("spiffs_"):
95+
if key.startswith("fs_"):
9296
env[key.upper()] = ldsizes[key]
9397

9498
assert all([
9599
k in env
96-
for k in ["SPIFFS_START", "SPIFFS_END", "SPIFFS_PAGE", "SPIFFS_BLOCK"]
100+
for k in ["FS_START", "FS_END", "FS_PAGE", "FS_BLOCK"]
97101
])
98102

99103
# esptool flash starts from 0
100-
for k in ("SPIFFS_START", "SPIFFS_END"):
104+
for k in ("FS_START", "FS_END"):
101105
_value = 0
102106
if env[k] < 0x40300000:
103107
_value = env[k] & 0xFFFFF
@@ -111,8 +115,8 @@ def fetch_spiffs_size(env):
111115
env[k] = _value
112116

113117

114-
def __fetch_spiffs_size(target, source, env):
115-
fetch_spiffs_size(env)
118+
def __fetch_fs_size(target, source, env):
119+
fetch_fs_size(env)
116120
return (target, source)
117121

118122

@@ -159,7 +163,7 @@ def get_esptoolpy_reset_flags(resetmethod):
159163
# Misc
160164
#
161165

162-
MKSPIFFSTOOL="mkspiffs",
166+
MKFSTOOL="mklittlefs",
163167

164168
SIZEPROGREGEXP=r"^(?:\.irom0\.text|\.text|\.text1|\.data|\.rodata|)\s+([0-9]+).*",
165169
SIZEDATAREGEXP=r"^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*",
@@ -194,14 +198,14 @@ def get_esptoolpy_reset_flags(resetmethod):
194198
BUILDERS=dict(
195199
DataToBin=Builder(
196200
action=env.VerboseAction(" ".join([
197-
'"$MKSPIFFSTOOL"',
201+
'"$MKFSTOOL"',
198202
"-c", "$SOURCES",
199-
"-p", "$SPIFFS_PAGE",
200-
"-b", "$SPIFFS_BLOCK",
201-
"-s", "${SPIFFS_END - SPIFFS_START}",
203+
"-p", "$FS_PAGE",
204+
"-b", "$FS_BLOCK",
205+
"-s", "${FS_END - FS_START}",
202206
"$TARGET"
203-
]), "Building SPIFFS image from '$SOURCES' directory to $TARGET"),
204-
emitter=__fetch_spiffs_size,
207+
]), "Building file system image from '$SOURCES' directory to $TARGET"),
208+
emitter=__fetch_fs_size,
205209
source_factory=env.Dir,
206210
suffix=".bin"
207211
)
@@ -210,21 +214,21 @@ def get_esptoolpy_reset_flags(resetmethod):
210214

211215

212216
#
213-
# Target: Build executable and linkable firmware or SPIFFS image
217+
# Target: Build executable and linkable firmware or file system image
214218
#
215219

216220
target_elf = env.BuildProgram()
217221
if "nobuild" in COMMAND_LINE_TARGETS:
218222
target_elf = join("$BUILD_DIR", "${PROGNAME}.elf")
219223
if set(["uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
220-
fetch_spiffs_size(env)
221-
target_firm = join("$BUILD_DIR", "%s.bin" % env.get("SPIFFSNAME", "spiffs"))
224+
fetch_fs_size(env)
225+
target_firm = join("$BUILD_DIR", "%s.bin" % env.get("FSIMAGENAME", "fs"))
222226
else:
223227
target_firm = join("$BUILD_DIR", "${PROGNAME}.bin")
224228
else:
225229
if set(["buildfs", "uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
226230
target_firm = env.DataToBin(
227-
join("$BUILD_DIR", env.get("SPIFFSNAME", "spiffs")), "$PROJECTDATA_DIR")
231+
join("$BUILD_DIR", env.get("FSIMAGENAME", "fs")), "$PROJECTDATA_DIR")
228232
AlwaysBuild(target_firm)
229233
AlwaysBuild(env.Alias("buildfs", target_firm))
230234
else:
@@ -255,7 +259,7 @@ def get_esptoolpy_reset_flags(resetmethod):
255259
AlwaysBuild(target_size)
256260

257261
#
258-
# Target: Upload firmware or SPIFFS image
262+
# Target: Upload firmware or filesystem image
259263
#
260264

261265
upload_protocol = env.subst("$UPLOAD_PROTOCOL")
@@ -313,7 +317,7 @@ def get_esptoolpy_reset_flags(resetmethod):
313317
"--port", '"$UPLOAD_PORT"',
314318
"--baud", "$UPLOAD_SPEED",
315319
"write_flash",
316-
"$SPIFFS_START"
320+
"$FS_START"
317321
],
318322
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $SOURCE',
319323
)

platform.json

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
"type": "uploader",
7676
"optional": true,
7777
"version": "~1.200.0"
78+
},
79+
"tool-mklittlefs": {
80+
"type": "uploader",
81+
"optional": true,
82+
"version": "~1.203.0"
7883
}
7984
}
8085
}

0 commit comments

Comments
 (0)