fix(platformio): match partition table to already-deployed field devices

Pre-OTA sanity check ahead of pushing this firmware to 6-7 units still
running the pre-restructure firmware. All four PlatformIO environments
were building against min_spiffs.csv, but field devices were originally
flashed via Arduino IDE with PartitionScheme=no_fs — the two tables
disagree on app1's offset (0x200000 vs 0x1F0000) and both app slot
sizes, because min_spiffs.csv carves out an unused 128KB spiffs
partition this firmware never touches (SD-card only, zero SPIFFS/
LittleFS references anywhere in the codebase).

OTA cannot migrate a device from one partition table to another — the
bootloader and running app both resolve offsets from a boot-time
snapshot of the table at flash 0x8000, which OTA never reads or
writes. A device still on the old no_fs table has no partition entry
at 0x1F0000, so a min_spiffs-built OTA image can never land where it
needs to be; forcibly rewriting that sector via OTA is an unsupported,
unrecoverable-on-power-loss operation Espressif explicitly warns
against.

Added no_fs.csv (copied verbatim from the Arduino ESP32 core) and
switched every environment to it. Verified the built partitions.bin
decodes to a byte-for-byte match of what's already burned into field
devices. No functionality lost — each app slot actually gained ~64KB
by dropping the unused spiffs partition. OTA to existing field devices
is now safe without any USB/serial reflash.

Catalog entry: docs/features/feature-catalog.md F-059.
This commit is contained in:
2026-07-20 10:33:19 +03:00
parent 99ca468b54
commit 28b175b4fc
3 changed files with 44 additions and 6 deletions
+19
View File
@@ -68,6 +68,7 @@ Every feature — user-facing or significant internal mechanism — is listed he
| F-056 | Diagnostics report — CPU temperature, WiFi reconnects, OTA state, stack high-water mark, published automatically every 5 min + on-demand via `telemetry.get_diagnostics` | v2.1.5 | Stable | | F-056 | Diagnostics report — CPU temperature, WiFi reconnects, OTA state, stack high-water mark, published automatically every 5 min + on-demand via `telemetry.get_diagnostics` | v2.1.5 | Stable |
| F-057 | QA-to-shipping stats reset — `telemetry.reset_boot_data` (lifetime boot count + SD boot log) and `logs.clear` (SD debug logs) | v2.1.6 | Stable | | F-057 | QA-to-shipping stats reset — `telemetry.reset_boot_data` (lifetime boot count + SD boot log) and `logs.clear` (SD debug logs) | v2.1.6 | Stable |
| F-058 | Fix: NTP sync RTC corruption on flaky internet — de-dup guard, retry cooldown, large-jump consensus check | v2.1.7 | Stable | | F-058 | Fix: NTP sync RTC corruption on flaky internet — de-dup guard, retry cooldown, large-jump consensus check | v2.1.7 | Stable |
| F-059 | Fix: partition table mismatch blocking safe OTA to pre-restructure field devices | v2.1.7 | Stable |
--- ---
@@ -957,3 +958,21 @@ All four thresholds are `static constexpr` at the top of `TimeKeeper.cpp`. Conse
Full rationale documented in [TimeKeeper/README.md](../../src/TimeKeeper/README.md#ntp-sync-safety-bugfix). Full rationale documented in [TimeKeeper/README.md](../../src/TimeKeeper/README.md#ntp-sync-safety-bugfix).
Subsystem: `src/TimeKeeper/TimeKeeper.hpp`, `src/TimeKeeper/TimeKeeper.cpp` Subsystem: `src/TimeKeeper/TimeKeeper.hpp`, `src/TimeKeeper/TimeKeeper.cpp`
---
### F-059 — Fix: partition table mismatch blocking safe OTA to pre-restructure field devices
Pre-push sanity check ahead of rolling this firmware out to 6-7 units currently running the pre-restructure `vesper.ino` build (`Controller - Production FW/vesper`). Two things were checked: the NVS identity-key migration (F-014, confirmed correct — no changes needed) and whether OTA itself was safe to push. It was not, for a reason unrelated to any application code.
**Root cause.** `platformio.ini` had every environment building against PlatformIO's `min_spiffs.csv` partition table. Field devices were originally flashed via Arduino IDE with `PartitionScheme=no_fs` (confirmed byte-for-byte from `Controller - Production FW/vesper/build/esp32.esp32.esp32/build.options.json` and `partitions.csv`). The two tables disagree on `app1`'s offset (`0x200000` vs `min_spiffs.csv`'s `0x1F0000`) and both app slot sizes (`0x1F0000` vs `0x1E0000`), because `min_spiffs.csv` carves out a 128KB `spiffs` partition that `no_fs` doesn't have.
This matters because of how ESP32 OTA actually works: the bootloader and the running app both resolve partition offsets from a boot-time snapshot of the partition-table sector at flash offset `0x8000` — OTA (`Update.begin()`/`esp_ota_*`) never reads or writes that sector, it only writes app bytes into whichever slot the *currently burned* table already declares. A device still carrying the old `no_fs` table has no partition entry at `0x1F0000` (where `min_spiffs.csv` expects `app1` to live), so there is no way for a `min_spiffs`-built OTA image to ever land where the new firmware needs it to be. Rewriting the table itself via OTA to fix this is a separate, much riskier operation that Espressif's own team has stated they will never support ("highly dangerous, and will end up bricking some of your devices") — an interrupted write to that one sector has no redundancy and bricks the device, recoverable only via USB/serial.
**Fix.** Since this firmware is SD-card only and has zero SPIFFS/LittleFS references anywhere in the codebase, the `spiffs` partition was never actually used — it was pulled in incidentally as PlatformIO's default template, not a deliberate requirement. [no_fs.csv](../../no_fs.csv) (copied verbatim from the Arduino ESP32 core's own `tools/partitions/no_fs.csv`) was added to the repo root and all four environments (`vesper-std-v1`, `agnus-v1`, `agnus-mini-v1`, `bespoke-rs485-v1`) now build against it instead of `min_spiffs.csv`. Verified the resulting `partitions.bin` decodes to an exact byte-for-byte match of the table already burned into field devices (`app0`/`app1` offsets and sizes, `otadata`, `nvs`, `coredump` all identical). No functionality lost, and each app slot actually gained ~64KB of headroom (`0x1F0000` vs `0x1E0000`) as a side effect of dropping the unused `spiffs` partition.
With this in place, OTA to the existing field devices is safe going forward — no USB/serial reflash required for this release. `agnus-v1`/`agnus-mini-v1`/`bespoke-rs485-v1` were switched too for consistency even though they have no legacy install base, so the whole codebase can never regress into this mismatch again.
Verified: `pio run` (all four environments) + manual decode of `partitions.bin` against the field-device `partitions.csv`.
Subsystem: `platformio.ini`, `no_fs.csv` (new)
+6
View File
@@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x1F0000,
app1, app, ota_1, 0x200000,0x1F0000,
coredump, data, coredump,0x3F0000,0x10000,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x5000
3 otadata data ota 0xe000 0x2000
4 app0 app ota_0 0x10000 0x1F0000
5 app1 app ota_1 0x200000 0x1F0000
6 coredump data coredump 0x3F0000 0x10000
+19 -6
View File
@@ -78,9 +78,16 @@ monitor_speed = ${common.monitor_speed}
upload_speed = 921600 upload_speed = 921600
upload_protocol = esptool upload_protocol = esptool
; Partition table — 4MB with OTA support, larger app slots ; Partition table — MUST match the layout already burned into field devices
; min_spiffs.csv: ~1.8MB app + ~1.8MB OTA + 64KB NVS + 128KB SPIFFS ; running the pre-restructure firmware (Arduino IDE PartitionScheme=no_fs).
board_build.partitions = min_spiffs.csv ; No spiffs partition — this firmware is SD-card only and never used SPIFFS.
; Using min_spiffs.csv here would move app1's offset (0x1F0000 vs 0x200000)
; and shrink both app slots, which OTA cannot safely migrate on its own —
; the currently-burned partition table on those devices has no entry at the
; new offset, so pushing a min_spiffs-built binary via OTA leaves the
; bootloader unable to find a valid image after the slot flip. See
; docs/features/feature-catalog.md F-059 for the full writeup.
board_build.partitions = no_fs.csv
; Upgrade to C++14 so std::make_unique is available ; Upgrade to C++14 so std::make_unique is available
build_unflags = -std=gnu++11 build_unflags = -std=gnu++11
@@ -118,7 +125,9 @@ monitor_speed = ${common.monitor_speed}
upload_speed = 921600 upload_speed = 921600
upload_protocol = esptool upload_protocol = esptool
board_build.partitions = min_spiffs.csv ; Partition table — kept consistent with vesper-std-v1 (see that env's comment
; for the full rationale). No spiffs partition; SD-card only, no SPIFFS usage.
board_build.partitions = no_fs.csv
build_unflags = -std=gnu++11 build_unflags = -std=gnu++11
board_build.cmake_extra_args = -DCONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 board_build.cmake_extra_args = -DCONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096
@@ -145,7 +154,9 @@ monitor_speed = ${common.monitor_speed}
upload_speed = 921600 upload_speed = 921600
upload_protocol = esptool upload_protocol = esptool
board_build.partitions = min_spiffs.csv ; Partition table — kept consistent with vesper-std-v1 (see that env's comment
; for the full rationale). No spiffs partition; SD-card only, no SPIFFS usage.
board_build.partitions = no_fs.csv
build_unflags = -std=gnu++11 build_unflags = -std=gnu++11
board_build.cmake_extra_args = -DCONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 board_build.cmake_extra_args = -DCONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096
@@ -178,7 +189,9 @@ monitor_speed = ${common.monitor_speed}
upload_speed = 921600 upload_speed = 921600
upload_protocol = esptool upload_protocol = esptool
board_build.partitions = min_spiffs.csv ; Partition table — kept consistent with vesper-std-v1 (see that env's comment
; for the full rationale). No spiffs partition; SD-card only, no SPIFFS usage.
board_build.partitions = no_fs.csv
build_unflags = -std=gnu++11 build_unflags = -std=gnu++11
board_build.cmake_extra_args = -DCONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 board_build.cmake_extra_args = -DCONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096