Skip to content

Commit

Permalink
Switch to LittleFS as the main file system // Issue #173
Browse files Browse the repository at this point in the history
SPIFFS has been deprecated in the Arduino core v2.7.1
  • Loading branch information
valeros committed May 26, 2020
1 parent cbb04ee commit aa7ddb1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
50 changes: 27 additions & 23 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ def _parse_ld_sizes(ldscript_path):

appsize_re = re.compile(
r"irom0_0_seg\s*:.+len\s*=\s*(0x[\da-f]+)", flags=re.I)
spiffs_re = re.compile(
r"PROVIDE\s*\(\s*_SPIFFS_(\w+)\s*=\s*(0x[\da-f]+)\s*\)", flags=re.I)
filesystem_re = re.compile(
r"PROVIDE\s*\(\s*_%s_(\w+)\s*=\s*(0x[\da-f]+)\s*\)" % "FS"
if "arduino" in env.subst("$PIOFRAMEWORK")
else "SPIFFS",
flags=re.I,
)
with open(ldscript_path) as fp:
for line in fp.readlines():
line = line.strip()
Expand All @@ -71,9 +75,9 @@ def _parse_ld_sizes(ldscript_path):
if match:
result['app_size'] = _parse_size(match.group(1))
continue
match = spiffs_re.search(line)
match = filesystem_re.search(line)
if match:
result['spiffs_%s' % match.group(1)] = _parse_size(
result['fs_%s' % match.group(1)] = _parse_size(
match.group(2))
return result

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


def fetch_spiffs_size(env):
def fetch_fs_size(env):
ldsizes = _parse_ld_sizes(env.GetActualLDScript())
for key in ldsizes:
if key.startswith("spiffs_"):
if key.startswith("fs_"):
env[key.upper()] = ldsizes[key]

assert all([
k in env
for k in ["SPIFFS_START", "SPIFFS_END", "SPIFFS_PAGE", "SPIFFS_BLOCK"]
for k in ["FS_START", "FS_END", "FS_PAGE", "FS_BLOCK"]
])

# esptool flash starts from 0
for k in ("SPIFFS_START", "SPIFFS_END"):
for k in ("FS_START", "FS_END"):
_value = 0
if env[k] < 0x40300000:
_value = env[k] & 0xFFFFF
Expand All @@ -111,8 +115,8 @@ def fetch_spiffs_size(env):
env[k] = _value


def __fetch_spiffs_size(target, source, env):
fetch_spiffs_size(env)
def __fetch_fs_size(target, source, env):
fetch_fs_size(env)
return (target, source)


Expand Down Expand Up @@ -159,7 +163,7 @@ def get_esptoolpy_reset_flags(resetmethod):
# Misc
#

MKSPIFFSTOOL="mkspiffs",
MKFSTOOL="mklittlefs",

SIZEPROGREGEXP=r"^(?:\.irom0\.text|\.text|\.text1|\.data|\.rodata|)\s+([0-9]+).*",
SIZEDATAREGEXP=r"^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*",
Expand Down Expand Up @@ -194,14 +198,14 @@ def get_esptoolpy_reset_flags(resetmethod):
BUILDERS=dict(
DataToBin=Builder(
action=env.VerboseAction(" ".join([
'"$MKSPIFFSTOOL"',
'"$MKFSTOOL"',
"-c", "$SOURCES",
"-p", "$SPIFFS_PAGE",
"-b", "$SPIFFS_BLOCK",
"-s", "${SPIFFS_END - SPIFFS_START}",
"-p", "$FS_PAGE",
"-b", "$FS_BLOCK",
"-s", "${FS_END - FS_START}",
"$TARGET"
]), "Building SPIFFS image from '$SOURCES' directory to $TARGET"),
emitter=__fetch_spiffs_size,
]), "Building file system image from '$SOURCES' directory to $TARGET"),
emitter=__fetch_fs_size,
source_factory=env.Dir,
suffix=".bin"
)
Expand All @@ -210,21 +214,21 @@ def get_esptoolpy_reset_flags(resetmethod):


#
# Target: Build executable and linkable firmware or SPIFFS image
# Target: Build executable and linkable firmware or file system image
#

target_elf = env.BuildProgram()
if "nobuild" in COMMAND_LINE_TARGETS:
target_elf = join("$BUILD_DIR", "${PROGNAME}.elf")
if set(["uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
fetch_spiffs_size(env)
target_firm = join("$BUILD_DIR", "%s.bin" % env.get("SPIFFSNAME", "spiffs"))
fetch_fs_size(env)
target_firm = join("$BUILD_DIR", "%s.bin" % env.get("FSIMAGENAME", "fs"))
else:
target_firm = join("$BUILD_DIR", "${PROGNAME}.bin")
else:
if set(["buildfs", "uploadfs", "uploadfsota"]) & set(COMMAND_LINE_TARGETS):
target_firm = env.DataToBin(
join("$BUILD_DIR", env.get("SPIFFSNAME", "spiffs")), "$PROJECTDATA_DIR")
join("$BUILD_DIR", env.get("FSIMAGENAME", "fs")), "$PROJECTDATA_DIR")
AlwaysBuild(target_firm)
AlwaysBuild(env.Alias("buildfs", target_firm))
else:
Expand Down Expand Up @@ -255,7 +259,7 @@ def get_esptoolpy_reset_flags(resetmethod):
AlwaysBuild(target_size)

#
# Target: Upload firmware or SPIFFS image
# Target: Upload firmware or filesystem image
#

upload_protocol = env.subst("$UPLOAD_PROTOCOL")
Expand Down Expand Up @@ -313,7 +317,7 @@ def get_esptoolpy_reset_flags(resetmethod):
"--port", '"$UPLOAD_PORT"',
"--baud", "$UPLOAD_SPEED",
"write_flash",
"$SPIFFS_START"
"$FS_START"
],
UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $SOURCE',
)
Expand Down
5 changes: 5 additions & 0 deletions platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
"type": "uploader",
"optional": true,
"version": "~1.200.0"
},
"tool-mklittlefs": {
"type": "uploader",
"optional": true,
"version": "~1.203.0"
}
}
}

0 comments on commit aa7ddb1

Please sign in to comment.