Build FileSystem Image fails for LittleFS partition

Hi,

TLDR;
I’m trying to move an esp32 project from using fatfs to littlefs… 'cos wear-levelling is a good thing, spiffs is deprecated, and it looks like Espressif have adopted littlefs as the filesystem of choice.
I get an error when building filesystem with littlefs partition for esp32.
Did much reading of esp-idf, esp-arduino, platformio, docs, blogs etc
Have found the problem, patched it on a fork, and tested that it works.

I could do with some guidance from those who know more about this stuff than I do, on two matters.

  1. I find it hard to believe that no-one else has had this problem.
    Am I missing some piece of historical detail about spiffs/littlefs and is there a better/preferred way to achieve what I’m trying to do, or a good reason why what I’ve done will not work?

  2. Assuming that what I’ve done is useful. How would you like me to upstream it? A PR? or shall I just be old-school about it and post a diff here ?

More details below
Many Thanks
Dariush

Details…

Environment:
Debian 12, VSC 1.91, PIO IDE 3.3.3
ESP32-[S3|C3|PICO] with 8MB Flash
PIO platform espressif32@6.7.0 with platform_packages arduino-esp32#3.0.2

Problem:
“pio run -t buildfs” fails with error “Could not find the any filesystem section in the partitions table ”
Failure occurs when using a custom partition table which defines a data partition of subtype “littlefs” and attempting to build a filesystem image (it all works fine if the subtype is ffat or spiffs)
It seems that the builder script at platform-espressif32/builder/main.py doesn’t check for the littlefs subtype when looking at the parsed the partition table config, so it doesn’t build the right string to execute the mklittlefs binary, it throws an error, and exits.

Fix:
I’ve created a minimal project to illustrate the problem, forked the platformio/platform-espressif32, fixed it in my fork, and can reliably reproduce the problem or fix by switching the platformio config back and forth between the platform:espressif32@6.7.0 and my fork. The filesystem image produced by the fixed version appears to work just fine when uploaded to a board.

Minimal project at https://github.com/dariush/esp32-littlefs-buildfs-fail
Forked platformio/platform-espressif32 at https://github.com/dariush/platform-espressif32

diff for the fix

$ git diff HEAD^..HEAD
diff --git a/builder/main.py b/builder/main.py
index 98ae155..2cb21d1 100644
--- a/builder/main.py
+++ b/builder/main.py
@@ -204,7 +204,7 @@ def _to_unix_slashes(path):
 def fetch_fs_size(env):
     fs = None
     for p in _parse_partitions(env):
-        if p["type"] == "data" and p["subtype"] in ("spiffs", "fat"):
+        if p["type"] == "data" and p["subtype"] in ("spiffs", "fat", "littlefs"):
             fs = p
     if not fs:
         sys.stderr.write(

Error run output:

$ pio run -t buildfs -v --environment adafruit_feather_esp32_v2
Processing adafruit_feather_esp32_v2 (board: adafruit_feather_esp32_v2; upload_speed: 921600; monitor_speed: 115200; build_flags: -DCORE_DEBUG_LEVEL=5; platform: espressif32@6.7.0; platform_packages: framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#3.0.2, framework-arduinoespressif32-libs@https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip; framework: arduino; board_build.filesystem: littlefs; board_build.partitions: partition_little.csv; monitor_filters: time, esp32_exception_decoder)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/adafruit_feather_esp32_v2.html
PLATFORM: Espressif 32 (6.7.0) > Adafruit Feather ESP32 V2
HARDWARE: ESP32 240MHz, 320KB RAM, 8MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.0.2+sha.65204d9 (git+https://github.com/espressif/arduino-esp32.git#3.0.2) 
 - framework-arduinoespressif32-libs @ 5.1.0+sha.bd2b9390ef (https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip) 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - tool-mklittlefs @ 1.203.210628 (2.3) 
 - toolchain-xtensa-esp32 @ 12.2.0+20230208
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 39 compatible libraries
Scanning dependencies...
Dependency Graph
|-- LittleFS @ 2.0.0 (License: Unknown, Path: /home/dariush/.platformio/packages/framework-arduinoespressif32@src-63eea845228ecc62b8fd85f819107145/libraries/LittleFS)
|   |-- FS @ 2.0.0 (License: Unknown, Path: /home/dariush/.platformio/packages/framework-arduinoespressif32@src-63eea845228ecc62b8fd85f819107145/libraries/FS)
Building in release mode
Could not find the any filesystem section in the partitions table /home/dariush/src/esp32-littlefs-buildfs-fail/partition_little.csv
======================================================================== [FAILED] Took 0.31 seconds ========================================================================

Successful run output:

$ pio run -t buildfs -v --environment adafruit_feather_esp32_v2
Processing adafruit_feather_esp32_v2 (board: adafruit_feather_esp32_v2; upload_speed: 921600; monitor_speed: 115200; build_flags: -DCORE_DEBUG_LEVEL=3; platform: https://github.com/dariush/platform-espressif32; platform_packages: framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#3.0.2, framework-arduinoespressif32-libs@https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip; framework: arduino; board_build.filesystem: littlefs; board_build.partitions: partition_little.csv; monitor_filters: time, esp32_exception_decoder)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/adafruit_feather_esp32_v2.html
PLATFORM: Espressif 32 (6.7.0+sha.bb3b90d) (git+https://github.com/dariush/platform-espressif32) > Adafruit Feather ESP32 V2
HARDWARE: ESP32 240MHz, 320KB RAM, 8MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.0.2+sha.65204d9 (git+https://github.com/espressif/arduino-esp32.git#3.0.2) 
 - framework-arduinoespressif32-libs @ 5.1.0+sha.bd2b9390ef (https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip) 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - tool-mklittlefs @ 1.203.210628 (2.3) 
 - toolchain-xtensa-esp32 @ 12.2.0+20230208
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 39 compatible libraries
Scanning dependencies...
Dependency Graph
|-- LittleFS @ 2.0.0 (License: Unknown, Path: /home/dariush/.platformio/packages/framework-arduinoespressif32@src-63eea845228ecc62b8fd85f819107145/libraries/LittleFS)
|   |-- FS @ 2.0.0 (License: Unknown, Path: /home/dariush/.platformio/packages/framework-arduinoespressif32@src-63eea845228ecc62b8fd85f819107145/libraries/FS)
Building in release mode
"mklittlefs" -c data -s 4194304 -p 256 -b 4096 .pio/build/adafruit_feather_esp32_v2/littlefs.bin
/chickens.txt
/somefile.txt
/someotherfile.txt
======================================================================== [SUCCESS] Took 0.33 seconds ========================================================================

When you look at the default partition table of the current Arduino-ESP32, for which LittleFS is indeed the first choice, you will see the subtype still being set to spiffs.

Probably a legacy thing. In fact, a total number of zero partition tables in Arduino-ESP32 use littlefs as their SubType.

So, your custom partition table is out-of-place in regards to the standard of still using the legacy name. Regardless of that, I do think that platform-espressif32 should recognize the littefs SubType as filesystem. So can you PR that change in?

Thanks,
I’ll raise a PR.

sidenote…
It makes me wonder what the difference between mkspiffs* and mklittlefs binaries is? :thinking: but I’m not going down that rabbit hole right now.

Please see add littlefs partition subtype by dariush · Pull Request #1426 · platformio/platform-espressif32 · GitHub