ESP32 OTA updates: Deploying new SPIFFs and when things go wrong…

Three-act diagram of the OTA recovery: the SPIFFS deadlock trap, the partial garbage-collector fix, and the LittleFS reformat that healed the fleet

Engineering · Field postmortem

A filesystem 82 % full, 258 KB free, an update that couldn’t write 9 kilobytes — and why the first fix wasn’t enough.

Date
2026-07-10
Surfaced on
firmware 67
Root cause
SPIFFS cliff
Status
Fixed in fw 70

Our devices update themselves over the air. Every few hours they ask our server “is there anything newer?” — and if there is, they download a signed manifest, reconcile their files, and flash the new firmware. It has worked, quietly, thousands of times.

Then a handful of devices in the field started reporting the same failure. Over and over, every eight hours, identically:

 serial · ota_update_task
No update available, latest 66, current 67
SPIFFS write failed at 1024/9654 bytes of /spiffs/manifest.txt
SPIFFS at failure: 1180202 used / 1438481 total, 258279 free
Download incomplete: 1024 of 9654 bytes
Manifest download failed: http://update…/manifest.txt

Read that twice. The device failed to write a 9.6 KB file — and it had 258 KB free. There was, apparently, a quarter of a megabyte of nothing, and we couldn’t put nine kilobytes into it.

01 — Why nowIt worked until it didn’t

The devices keep their web interface, fonts, screen layouts and icons on a small on-flash filesystem — SPIFFS — about 1.44 MB in total. Firmware 67 introduced signed update manifests, which added files. And over the months since, we shipped more of everything: a new layout engine, weather graphs, integration screens. Every release nudged the filesystem a little fuller.

SPIFFS has a well-earned reputation for one thing: it gets fragile past roughly 75–80 % usage. Below that line, everything is fine. Above it, “free” space starts to lie. Much of what it reports as free is actually deleted-but-not-yet-erased pages — space that can’t be written to until garbage collection reclaims it. Growth pushed us over that line, and the field caught up with the math.

258 KB reported free — yet the very first kilobyte past the start of the write is where it failed. The free space was real on paper and unusable in practice.

02 — The trapA perfect deadlock

Here is the cruel part. The device can free space. It has a prune step that deletes obsolete files, and garbage collection that reclaims dead pages. But both of those run as part of applying an update — and to apply an update, the device must first download and write the manifest. Which is exactly the write that fails.

To free space, it needs to update.
To update, it needs free space.

And nothing else broke the tie. A factory reset only clears settings — it never reformats the filesystem, so the full files survive it. The server couldn’t reach in and fix it either: the update check carries only a version number, not a command. So a wedged device did the only thing it could. It retried every eight hours, failed in exactly the same way, and waited. Indefinitely.

03 — The first fixAn intermediate firmware

We needed to get new firmware onto a device that couldn’t write to its own filesystem. The realization that unlocked it: flashing firmware doesn’t touch SPIFFS at all. The firmware image streams to a separate application partition. Only the file-reconcile step writes to SPIFFS — and if there’s nothing to reconcile, there’s nothing to write.

So we built firmware 68 as a stepping stone: published with a ~350-byte signed bootstrap manifest (small enough to fit in the crippled free space) listing exactly one file the device already has — so reconcile skips it and writes nothing — followed by a normal firmware flash to the app partition. Firmware 68 carried a smarter garbage collector that runs whenever the filesystem is nearly full, not only when free bytes look low. From there, devices would hop to firmware 69, the full content release, and heal. Two hops, 67 → 68 → 69, and the device is whole again.

That was the theory. Two-thirds of the fleet agreed with it. The other third did not.

04 — But waitThe fleet had other plans

The rollout telemetry told a split story. Most of the fleet climbed both hops and healed. But dozens of devices took the bootstrap, landed on firmware 68 — now carrying the improved garbage collector — and then failed the second hop with the exact same error as before:

 update server · update_results
13:31  mac=…4D5C  fw=68  code=2  Failed to download release manifest
13:25  mac=…FA1C  fw=68  code=2  Failed to download release manifest
13:17  mac=…E6C8  fw=68  code=2  Failed to download release manifest
13:05  mac=…CE04  fw=68  code=2  Failed to download release manifest
— a third of the fleet in 24 h, retrying every 8 hours —
65%
healed to 69
GC found reclaimable pages, the 9.6 KB manifest fit, files reconciled.
23%
stuck on 68
Bootstrap worked; the full manifest write still failed.
12%
stuck on 67
Wedged before they could even take the first hop.

Why didn’t the garbage collector save them? Because GC can only reclaim a block that is entirely dead. On a filesystem that’s 82 % full of live data, nearly every block holds at least some current file content — there is no free block to consolidate into, so collection runs, finds nothing collectible, and returns. The dead pages stay dead. The write still fails at kilobyte one.

The only thing that frees a truly packed SPIFFS is deleting files.
And the delete step runs after the write that fails.

Garbage collection was necessary but not sufficient. We had rebuilt the same deadlock, one version further along.

05 — The real fixStop patching the filesystem. Replace it.

At some point the honest conclusion is that you’re not fighting a bug, you’re fighting a design. SPIFFS fails structurally at high utilization. So firmware 70 swaps it for LittleFS: copy-on-write, power-fail-safe, real directories — and crucially, it reclaims blocks as part of every allocation. There is no high-usage cliff, and no GC to fall behind.

The migration is where it gets elegant. Same partition, same mount path — but on the first boot of firmware 70, LittleFS finds SPIFFS data it can’t mount and formats the partition. That wipe, which sounds like the disaster case, is the rescue: an empty filesystem is writable again, no matter how wedged it was. User settings live in a separate flash partition and never notice. Everything on the filesystem is re-downloadable — so the device simply re-downloads it, verified against the signed manifest, rebuilding all 106 files in about two minutes:

 serial · bench device, first LittleFS boot
Manifest OK: version 70, generated …, 106 files
Self-heal: verifying 106 files against release 70
Reconcile done: 102 downloaded, 4 already current
Self-heal complete

One serving problem remained: a wedged legacy device can only swallow the ~350-byte bootstrap, while a freshly-formatted firmware-70 device needs the full 9.6 KB manifest — from the same URL. So every release is now published with two signed manifests. New firmware adds a marker (?fw=70) to its manifest request and receives the full set; anything older gets the tiny bootstrap, because that is all it can write. One release rescues and heals in a single version — no more stepping stones.

  • Legacy device (any version, however wedged): gets the tiny bootstrap → writes ~350 B (fits) → flashes firmware 70 to the app partition, filesystem untouched.
  • First boot on 70: mount fails → format → empty, healthy LittleFS → self-heal fetches the full manifest (?fw=70) and rebuilds every file.
  • Every release after: normal signed updates on a filesystem that doesn’t lie about free space.

The bench test found one delightful footgun: SPIFFS is flat — “css/style.css” was just a filename with a slash in it — but LittleFS has real directories, and thirty years of muscle memory forgot that fopen() won’t create them. The first post-format heal wrote every root file perfectly and failed every nested one until we taught the downloader to mkdir its parents. Migrations bite in the small places.

06 — What we changedThe lasting fixes

  • A filesystem without the failure mode. LittleFS reclaims space as it allocates — there is no state where “free” bytes exist but cannot be written.
  • Rescue and heal in one release. Dual-manifest publishing (tiny bootstrap + full set, chosen by the ?fw= marker) is now the standard for every release — the recovery path is permanent infrastructure, not a one-off.
  • Self-heal treats “empty” as a to-do, not a shrug. A missing manifest now triggers an immediate verified rebuild of the whole file set, retried until it lands.
  • Filesystem headroom is a release metric. LittleFS fills up too — it just fails honestly. We now watch usage per release instead of learning about it over a serial cable.
Three acts. The trap: firmware 67 can’t write the 9.6 KB manifest and loops forever. The first fix: the ~350-byte bootstrap flashes GC-fixed firmware 68 — enough for two-thirds of the fleet, but the rest were full of live data and GC had nothing to collect. The real fix: the firmware 70 bootstrap flashes LittleFS firmware (esp_ota_write, filesystem untouched); first boot reformats the partition, and self-heal rebuilds all 106 files from the full manifest served to the ?fw=70 marker.

The bug was never really the failed write. It was a system that could only rescue itself by doing the one thing it had become unable to do. The first fix taught it a smaller step. The real fix was admitting the ground it stood on had to go — and building the update path so that replacing the ground is just another update.


Frixos — firmware & fleetOTA / SPIFFS → LittleFS / recovery● shipped 67 → 68 → 69 → 70