@@ -119,34 +119,40 @@ def _update_max_upload_size(env):
119
119
120
120
121
121
def _to_unix_slashes (path ):
122
- return path .replace (' \\ ' , '/' )
122
+ return path .replace (" \\ " , "/" )
123
123
124
124
125
125
#
126
- # SPIFFS helpers
126
+ # Filesystem helpers
127
127
#
128
128
129
129
130
- def fetch_spiffs_size (env ):
131
- spiffs = None
130
+ def fetch_fs_size (env ):
131
+ fs = None
132
132
for p in _parse_partitions (env ):
133
- if p [' type' ] == "data" and p [' subtype' ] == "spiffs" :
134
- spiffs = p
135
- if not spiffs :
133
+ if p [" type" ] == "data" and p [" subtype" ] in ( "spiffs" , "fat" ) :
134
+ fs = p
135
+ if not fs :
136
136
sys .stderr .write (
137
- "Could not find the `spiffs` section in the partitions "
137
+ "Could not find the any filesystem section in the partitions "
138
138
"table %s\n " % env .subst ("$PARTITIONS_TABLE_CSV" )
139
139
)
140
140
env .Exit (1 )
141
141
return
142
- env ["SPIFFS_START " ] = _parse_size (spiffs [ ' offset' ])
143
- env ["SPIFFS_SIZE " ] = _parse_size (spiffs [ ' size' ])
144
- env ["SPIFFS_PAGE " ] = int ("0x100" , 16 )
145
- env ["SPIFFS_BLOCK " ] = int ("0x1000" , 16 )
142
+ env ["FS_START " ] = _parse_size (fs [ " offset" ])
143
+ env ["FS_SIZE " ] = _parse_size (fs [ " size" ])
144
+ env ["FS_PAGE " ] = int ("0x100" , 16 )
145
+ env ["FS_BLOCK " ] = int ("0x1000" , 16 )
146
146
147
+ # FFat specific offsets, see:
148
+ # https://github.com/lorol/arduino-esp32fatfs-plugin#notes-for-fatfs
149
+ if filesystem == "fatfs" :
150
+ env ["FS_START" ] += 4096
151
+ env ["FS_SIZE" ] -= 4096
147
152
148
- def __fetch_spiffs_size (target , source , env ):
149
- fetch_spiffs_size (env )
153
+
154
+ def __fetch_fs_size (target , source , env ):
155
+ fetch_fs_size (env )
150
156
return (target , source )
151
157
152
158
@@ -156,6 +162,7 @@ def __fetch_spiffs_size(target, source, env):
156
162
board = env .BoardConfig ()
157
163
mcu = board .get ("build.mcu" , "esp32" )
158
164
toolchain_arch = "xtensa-%s" % mcu
165
+ filesystem = board .get ("build.filesystem" , "spiffs" )
159
166
if mcu == "esp32c3" :
160
167
toolchain_arch = "riscv32-esp"
161
168
@@ -186,9 +193,25 @@ def __fetch_spiffs_size(target, source, env):
186
193
],
187
194
ERASECMD = '"$PYTHONEXE" "$OBJCOPY" $ERASEFLAGS erase_flash' ,
188
195
189
- MKSPIFFSTOOL = "mkspiffs_${PIOPLATFORM}_" + ("espidf" if "espidf" in env .subst (
190
- "$PIOFRAMEWORK" ) else "${PIOFRAMEWORK}" ),
191
- ESP32_SPIFFS_IMAGE_NAME = env .get ("ESP32_SPIFFS_IMAGE_NAME" , "spiffs" ),
196
+ # mkspiffs package contains two different binaries for IDF and Arduino
197
+ MKFSTOOL = "mk%s" % filesystem
198
+ + (
199
+ (
200
+ "_${PIOPLATFORM}_"
201
+ + (
202
+ "espidf"
203
+ if "espidf" in env .subst ("$PIOFRAMEWORK" )
204
+ else "${PIOFRAMEWORK}"
205
+ )
206
+ )
207
+ if filesystem == "spiffs"
208
+ else ""
209
+ ),
210
+ # Legacy `ESP32_SPIFFS_IMAGE_NAME` is used as the second fallback value for
211
+ # backward compatibility
212
+ ESP32_FS_IMAGE_NAME = env .get (
213
+ "ESP32_FS_IMAGE_NAME" , env .get ("ESP32_SPIFFS_IMAGE_NAME" , filesystem )
214
+ ),
192
215
ESP32_APP_OFFSET = "0x10000" ,
193
216
194
217
PROGSUFFIX = ".elf"
@@ -205,9 +228,9 @@ def __fetch_spiffs_size(target, source, env):
205
228
BUILDERS = dict (
206
229
ElfToBin = Builder (
207
230
action = env .VerboseAction (" " .join ([
208
- '"$PYTHONEXE" "$OBJCOPY"' ,
231
+ '"$PYTHONEXE" "$OBJCOPY"' ,
209
232
"--chip" , mcu ,
210
- "elf2image" ,
233
+ "elf2image" ,
211
234
"--flash_mode" , "$BOARD_FLASH_MODE" ,
212
235
"--flash_freq" , "${__get_board_f_flash(__env__)}" ,
213
236
"--flash_size" , board .get ("upload.flash_size" , "detect" ),
@@ -216,41 +239,51 @@ def __fetch_spiffs_size(target, source, env):
216
239
suffix = ".bin"
217
240
),
218
241
DataToBin = Builder (
219
- action = env .VerboseAction (" " .join ([
220
- '"$MKSPIFFSTOOL"' ,
221
- "-c" , "$SOURCES" ,
222
- "-p" , "$SPIFFS_PAGE" ,
223
- "-b" , "$SPIFFS_BLOCK" ,
224
- "-s" , "$SPIFFS_SIZE" ,
225
- "$TARGET"
226
- ]), "Building SPIFFS image from '$SOURCES' directory to $TARGET" ),
227
- emitter = __fetch_spiffs_size ,
242
+ action = env .VerboseAction (
243
+ " " .join (
244
+ ['"$MKFSTOOL"' , "-c" , "$SOURCES" , "-s" , "$FS_SIZE" ]
245
+ + (
246
+ [
247
+ "-p" ,
248
+ "$FS_PAGE" ,
249
+ "-b" ,
250
+ "$FS_BLOCK" ,
251
+ ]
252
+ if filesystem in ("spiffs" , "littlefs" )
253
+ else []
254
+ )
255
+ + ["$TARGET" ]
256
+ ),
257
+ "Building FS image from '$SOURCES' directory to $TARGET" ,
258
+ ),
259
+ emitter = __fetch_fs_size ,
228
260
source_factory = env .Dir ,
229
- suffix = ".bin"
230
- )
261
+ suffix = ".bin" ,
262
+ ),
231
263
)
232
264
)
233
265
234
266
if not env .get ("PIOFRAMEWORK" ):
235
267
env .SConscript ("frameworks/_bare.py" , exports = "env" )
236
268
237
269
#
238
- # Target: Build executable and linkable firmware or SPIFFS image
270
+ # Target: Build executable and linkable firmware or FS image
239
271
#
240
272
241
273
target_elf = None
242
274
if "nobuild" in COMMAND_LINE_TARGETS :
243
275
target_elf = join ("$BUILD_DIR" , "${PROGNAME}.elf" )
244
276
if set (["uploadfs" , "uploadfsota" ]) & set (COMMAND_LINE_TARGETS ):
245
- fetch_spiffs_size (env )
246
- target_firm = join ("$BUILD_DIR" , "${ESP32_SPIFFS_IMAGE_NAME }.bin" )
277
+ fetch_fs_size (env )
278
+ target_firm = join ("$BUILD_DIR" , "${ESP32_FS_IMAGE_NAME }.bin" )
247
279
else :
248
280
target_firm = join ("$BUILD_DIR" , "${PROGNAME}.bin" )
249
281
else :
250
282
target_elf = env .BuildProgram ()
251
283
if set (["buildfs" , "uploadfs" , "uploadfsota" ]) & set (COMMAND_LINE_TARGETS ):
252
284
target_firm = env .DataToBin (
253
- join ("$BUILD_DIR" , "${ESP32_SPIFFS_IMAGE_NAME}" ), "$PROJECT_DATA_DIR" )
285
+ join ("$BUILD_DIR" , "${ESP32_FS_IMAGE_NAME}" ), "$PROJECT_DATA_DIR"
286
+ )
254
287
env .NoCache (target_firm )
255
288
AlwaysBuild (target_firm )
256
289
else :
@@ -286,7 +319,7 @@ def __fetch_spiffs_size(target, source, env):
286
319
)
287
320
288
321
#
289
- # Target: Upload firmware or SPIFFS image
322
+ # Target: Upload firmware or FS image
290
323
#
291
324
292
325
upload_protocol = env .subst ("$UPLOAD_PROTOCOL" )
@@ -398,13 +431,13 @@ def __fetch_spiffs_size(target, source, env):
398
431
debug_tools .get (upload_protocol ).get ("server" ).get ("arguments" , []))
399
432
openocd_args .extend ([
400
433
"-c" , "adapter_khz %s" % env .GetProjectOption ("debug_speed" , "5000" ),
401
- "-c" ,
434
+ "-c" ,
402
435
"program_esp {{$SOURCE}} %s verify" %
403
436
board .get ("upload.offset_address" , "$ESP32_APP_OFFSET" ),
404
437
])
405
438
for image in env .get ("FLASH_EXTRA_IMAGES" , []):
406
439
openocd_args .extend ([
407
- "-c" ,
440
+ "-c" ,
408
441
'program_esp {{%s}} %s verify' %
409
442
(_to_unix_slashes (image [1 ]), image [0 ])
410
443
])
@@ -417,7 +450,7 @@ def __fetch_spiffs_size(target, source, env):
417
450
for f in openocd_args
418
451
]
419
452
env .Replace (UPLOADER = "openocd" ,
420
- UPLOADERFLAGS = openocd_args ,
453
+ UPLOADERFLAGS = openocd_args ,
421
454
UPLOADCMD = "$UPLOADER $UPLOADERFLAGS" )
422
455
upload_actions = [env .VerboseAction ("$UPLOADCMD" , "Uploading $SOURCE" )]
423
456
0 commit comments