How to define LittleFS partition, build image and flash it on ESP32?

For all those interested, I solved the problem. I am essentially creating a SPIFFS partition and load my own LittleFS image into it instead, fooling PlatformIO into thinking, it’s actually dealing with a SPIFFS image. I am doing this by overloading the MKSPIFFS command.

I created a Python script that I call from platformio.ini

extra_scripts = LittleFSBuilder.py

In this file I replace the MKSPIFFS tool command with my own like this

Import("env")
env.Replace( MKSPIFFSTOOL='python3" "' + env.get("PROJECT_DIR") + '/mklittlefs.py' )

My own tool now uses the command line arguments, builds the LittleFS bin image accordingly and saves it to where PlatformIO tells it to (the last argument in the mkspiffs call is the destination file name).

PlatformIO now believes it has actually created a SPIFFS.BIN file and proceeds to upload it to the device. Done!

3 Likes