Skip to content

Goodbye SPIFFS, Hello LittleFS! - #53

Open
bmorcelli wants to merge 1 commit into
0ct0sec:mainfrom
bmorcelli:main
Open

Goodbye SPIFFS, Hello LittleFS!#53
bmorcelli wants to merge 1 commit into
0ct0sec:mainfrom
bmorcelli:main

Conversation

@bmorcelli

Copy link
Copy Markdown

The Tale of the Overly Excited Porkchops

Once upon a time in the vast digital countryside, two neighboring farmers—Bruce and Meshtastic—shared a large, fertile plot of memory. Their fields were vast enough to cultivate all kinds of data and welcome new producers, provided everyone followed the same farming guidelines and land management system (the filesystem).

One day, a new farmer arrived at the estate with a lively herd of small pigs—the M5PORKCHOP project. The pigs were placed in their own corner of the farm (the SPIFFS partition), and quickly became a popular attraction. Visitors frequently toured the estate, stopping by the Bruce and Meshtastic fields before heading over to see the pigs.

The porkchops loved the attention. In fact, every time visitors arrived after exploring the rest of the farm, the pigs got so excited that they threw wild mud parties. They ran amok, knocked down fences, and inadvertently plowed over the entire shared estate—reformatting the land in such a chaotic way that neither Bruce nor Meshtastic could harvest their data anymore!

The farmers realized the problem wasn't the pigs—it was the fragile structure of the SPIFFS land management. To restore peace and ensure all producers could coexist safely, they decided to upgrade the entire estate to LittleFS. With LittleFS's sturdy fences and atomic land protection, even when the porkchops throw their wildest parties, the rest of the farm remains completely unharmed.

🚀 Why Switch from SPIFFS to LittleFS?

SPIFFS has served the ESP32 community well, but it has been officially deprecated in favor of LittleFS. Here is why this migration benefits M5PORKCHOP:

  • Power-Loss Resilience (Copy-on-Write): LittleFS uses atomic operations and a copy-on-write dynamic. If the device loses power or resets while writing a file, the filesystem rolls back to the last valid state instead of leaving a corrupted file behind.

  • Wear Leveling: LittleFS actively distributes write/erase cycles evenly across the flash memory sectors, significantly extending the lifespan of the onboard SPI flash chip.

  • Real Directory Support: Unlike SPIFFS, which simulates directories using flat filenames containing slashes (e.g., /folder/file.txt), LittleFS natively supports true directories and subdirectories, improving file lookup performance and structure.

  • Lower RAM Footprint: SPIFFS indexes the entire filesystem in RAM on mount, which grows with flash size. LittleFS utilizes dynamic indexing, keeping RAM usage much lower and predictable.

  • Faster Operations: Directory listings, file opens, and seeks are notably faster in LittleFS compared to SPIFFS on larger partition sizes.

And the most important thing.. While using Launcher, it won't lose data when moving back and forth from Meshtastic or Bruce, so nobody loses data. 😉

🛠️ Changes Included in this PR

Updated config.cpp and config.h to use LittleFSs instead of SPIFFS.

Updated file initialization and mounting logic.

Updated config.cpp and config.h to use LittleFSs instead of SPIFFS.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50004782ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/core/config.cpp
// Initialize LittleFS first (always available)
if (!LittleFS.begin(false)) {
Serial.println("[CONFIG] LittleFS mount failed, attempting format...");
if (!LittleFS.begin(true)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Migrate SPIFFS contents before formatting

On devices upgraded from an existing SPIFFS-based release, LittleFS.begin(false) will fail because the flash partition still contains a SPIFFS image; this new fallback immediately calls LittleFS.begin(true), which reformats that partition before loadPersonality() or the fallback config migration can read /personality.json, /porkchop.dat, or /porkchop.conf. Users without an SD copy, and all personality settings which are only stored in the internal FS, get reset to defaults on first boot, so the migration needs to read/copy the old SPIFFS data before enabling format-on-fail.

Useful? React with 👍 / 👎.

@bmorcelli

Copy link
Copy Markdown
Author

The tale is supposed to be funny, don't take me wrong 😄
You have made a great job with your firmware! I am happy to help!

@c0dedigger

c0dedigger commented Jul 30, 2026

Copy link
Copy Markdown

I've tried fresh install of this fork to Cardputer Adv and discovered that personality data don't save, all settings drops to default values after restart.
Here is an output via serial connection:

[boot] Turned on because (1= POWERON_RESET or 5==ESP_RST_DEEPSLEEP) (Other= Probably forced by launcher)--> 12
E (344) psram: PSRAM ID read error: 0x00ffffff, PSRAM chip not found or not supported, or wrong PSRAM line mode
E (986) esp_littlefs: partition "spiffs" could not be found
E (987) esp_littlefs: Failed to initialize LittleFS
[ 987][E][LittleFS.cpp:98] begin(): Mounting LittleFS failed! Error: 261
E (1004) esp_littlefs: partition "spiffs" could not be found
E (1004) esp_littlefs: Failed to initialize LittleFS
[ 1003][E][LittleFS.cpp:98] begin(): Mounting LittleFS failed! Error: 261
[ 1170][E][vfs_api.cpp:24] open(): File system is not mounted
[ 1177][E][vfs_api.cpp:24] open(): File system is not mounted
[ 1196][E][vfs_api.cpp:24] open(): File system is not mounted

UPD: the error has gone after manualy creation of spiffs partition via M5Launcher PM. But.
After installing and starting Bruce i've back to Porkchop and discovered that all settings back to default values again.

@bmorcelli

Copy link
Copy Markdown
Author

UPD: the error has gone after manualy creation of spiffs partition via M5Launcher PM. But. After installing and starting Bruce i've back to Porkchop and discovered that all settings back to default values again.

Launcher works better with merged binaries, so it can read the partition table and create whatever partition the firmware needs. As you used the "firmware.bin" to test, this partition wasn´t created, leading to that error you saw at first time

This latest version of Launcher (2.7.2) has an issue.. It is not reusing the pre-existent "spiffs" partition if its size is different from a pre-determined size (0x70000), and it probaly prompted you to remove data, or doing something before install.

So It has removed and recreated the "spiffs" partition if its size is not the predetermined size, not respecting the existent one, losing the config you made before. I have it fixed on Launcher Beta, for 2.8 that will come soon (today, I Hope)

To enhance your test, you can try the merged binary by:

pip install esptool
esptool --chip esp32s3 merge-bin -o cardputer-merged.bin 0x0 .pio/build/m5cardputer-debug/bootloader.bin 0x8000 .pio/build/m5cardputer-debug/partitions.bin 0x10000 .pio/build/m5cardputer-debug/firmware.bin

@c0dedigger

c0dedigger commented Jul 30, 2026

Copy link
Copy Markdown

This latest version of Launcher (2.7.2) has an issue.. It is not reusing the pre-existent "spiffs" partition if its size is different from a pre-determined size (0x70000), and it probaly prompted you to remove data, or doing something before install.

So It has removed and recreated the "spiffs" partition if its size is not the predetermined size, not respecting the existent one, losing the config you made before.

"spiffs" partition i've manually created was exactly 0x70000 size but you're right: when I was installed the Bruce, PManager asked me to remove some data and than performed "optimize flash" - presumably that’s when it recreated the "spiffs" partition.
Btw when i removed Bruce and then installed Meshtastic (without any partition optimization things) it didn't affected Porkchop's data anymore.
Thanks a lot man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants