nRF52 internal flash fills up and eeprom_begin() formats the filesystem (EEPROM and identities lost)
Board: Heltec Mesh Node T114 (nRF52840), env heltec_t114 from master.
Related: #109 (same setup, but this is a separate problem).
Summary
On boards that keep their stores on the internal flash (InternalFS, 28 KB),
the persistent stores fill the filesystem completely. When that happens,
eeprom_begin() cannot open the EEPROM file for writing and calls
InternalFS.format(): EEPROM, signature, firmware hash, LXMF identities and all
stores are erased. The device comes back with a red LED and
rnodeconf -i reports "EEPROM is invalid"; re-provisioning only works after
--eeprom-wipe.
Numbers
- InternalFS is 28672 bytes (128-byte blocks). Right after boot, with empty stores, about 17 KB are free (EEPROM file, time offset, filesystem overhead and app files take the rest).
- Defaults in microReticulum for the stores that are not overridden in the T114 env: known destinations 8 x 32 KB, packet hashlist 2 x 32 KB. Together with the path store (6 x 2 KB in the env) the nominal total is ~332 KB on a 17 KB budget.
- With RNS_DEBUG_MEMORY the
flash:value reaches 0 and then wraps (e.g. 4294966272 = -1024) within minutes under announce load (a nearby gateway rebroadcasting a TCP backbone over LoRa). - Even with all three stores reduced (path 4 x 2 KB, known destinations
2 x 2 KB, hashlist 2 x 1 KB = 14 KB nominal),
flash:still reaches 0, so the stores seem to use noticeably more than their nominal size (compaction/rewrite overhead?).
Why it is destructive
- The "FileSystem is full, clearing ..." checks in Transport only run when the stores are initialized at boot, not while the node is running.
- eeprom_begin() treats "cannot open for writing" as a corrupt filesystem and formats it, even when the filesystem is merely full.
Suggestions (any of these would avoid losing the device configuration)
- In eeprom_begin(), do not format when the filesystem is full: clear the path/hashlist stores first and retry, and only format as a last resort.
- Check free space at runtime and stop persisting (or clear) stores below a threshold, instead of only at boot.
- Smaller default store sizes for nRF52 boards without external flash, sized to the internal filesystem.
- Longer term for the T114: it has a 2 MB QSPI flash (MX25R1635F) that is currently unused, like the external flash RAK4631 already uses.
I can test any change on the T114.
Root cause of the full filesystem found, see #113: the FileStore stores keep appending to their last segment when rotation/compaction fails, so they grow far beyond their configured limits (known_store reached ~22 KB with a 2 KB limit). With the stores kept in RAM the filesystem no longer fills up. The risk described here (losing the EEPROM file once littlefs has no free blocks) still stands, so I'm leaving this open.