diff --git a/docs/features/feature-catalog.md b/docs/features/feature-catalog.md index 5a4ccd4..c6e113a 100644 --- a/docs/features/feature-catalog.md +++ b/docs/features/feature-catalog.md @@ -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-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-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). 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) diff --git a/no_fs.csv b/no_fs.csv new file mode 100644 index 0000000..a9078ee --- /dev/null +++ b/no_fs.csv @@ -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, diff --git a/platformio.ini b/platformio.ini index c39b477..46b7313 100644 --- a/platformio.ini +++ b/platformio.ini @@ -78,9 +78,16 @@ monitor_speed = ${common.monitor_speed} upload_speed = 921600 upload_protocol = esptool -; Partition table — 4MB with OTA support, larger app slots -; min_spiffs.csv: ~1.8MB app + ~1.8MB OTA + 64KB NVS + 128KB SPIFFS -board_build.partitions = min_spiffs.csv +; Partition table — MUST match the layout already burned into field devices +; running the pre-restructure firmware (Arduino IDE PartitionScheme=no_fs). +; 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 build_unflags = -std=gnu++11 @@ -118,7 +125,9 @@ monitor_speed = ${common.monitor_speed} upload_speed = 921600 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 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_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 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_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 board_build.cmake_extra_args = -DCONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096