Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 KiB
type, tags, updated
| type | tags | updated | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| concept |
|
2026-09-27 |
OTA Firmware Updates
How Controller A updates itself from this repo's Gitea releases, why each piece is the way it is, and what is still to do (Controller B). Built 2026-09-26. Design decisions by the user are marked (decision).
The pipeline
git push tag vX.Y.Z ──► Gitea Actions (.gitea/workflows/firmware.yml, runner ubuntu-latest)
pio run (-DFW_VERSION="vX.Y.Z")
sign "patrol-a|vX.Y.Z|<sha256>" with secret BMW_NISSAN_FIRMWARE_SIGNING_KEY
release vX.Y.Z: firmware.bin + firmware.elf + manifest.txt
│ public repo, HTTPS, no token
Controller A Settings → Updates → Install ◄──┘ (or `ota install`; parked, Wi-Fi joined)
GET /api/v1/repos/art/ESP32-S3-Touch-LCD-5B/releases/latest → tag
GET /releases/download/<tag>/manifest.txt → verify signature FIRST
GET /releases/download/<tag>/firmware.bin → idle slot, hashed while streaming
sha256 == signed sha256 → esp_ota_end → parked again? → switch slot → reboot
new image PENDING_VERIFY → confirmed after 30 s uptime, else bootloader rolls back
To release: git tag -a vX.Y.Z -m "..." && git push --follow-tags origin main — a plain git push sends the commit but not the tag, so only main-latest gets built and the board keeps offering the previous release (happened with v0.1.5, 2026-09-27; fixed with git push origin vX.Y.Z) — one push, one (tag) build: a main push skips itself when its commit already has a v* tag, and when it only changes wiki/** or *.md (checked inside the job, so a tag build is never skipped by a path filter).
Push to main (no tag) builds a rolling pre-release main-latest — unsigned, no manifest, for bench/USB testing. /releases/latest skips pre-releases, so the car is never offered it (repo).
Status: VERIFIED end-to-end (verified 2026-09-26, bench, USB power, Wi-Fi Personal1)
| Cycle (performed by the running firmware) | Result |
|---|---|
dev (USB-flashed) → v0.1.1, into app1 |
✅ 1.65 MB in ~60 s (~27 KB/s), confirmed after 30 s; v0.1.1 then passed ota check itself |
v0.1.1 → v0.1.2, into app0 |
✅ slots alternate as designed |
v0.1.2 → v0.1.2 (ota install force), attempt 1 |
❌ download aborted at 570 B — the loop treated a momentary TLS connected()==false as a drop. The failure path worked: aborted cleanly, "Update failed / still running v0.1.2" notice, stayed on v0.1.2 |
| same, attempt 2 | ✅ into app1, confirmed — first install run by the dark-screen code |
| v0.1.3 (published 2026-09-26) | fixes the 570 B abort (a drop only counts after 2 s of silence); installed, ran until 2026-09-27 |
dev → v0.1.4, from the screen (2026-09-27) |
✅ first install driven by the user from Settings → Updates (Check → Install → confirm): dark ~1 min, restart, version label A v0.1.4. v0.1.4 still had the old Wi-Fi code, so it came back disconnected and the flickering dots returned — see esp32-s3-touch-lcd-5b |
dev → v0.1.5, from the screen (2026-09-27) |
✅ user: "All good" — new Settings/Tuning screens, Wi-Fi rejoined by itself after the restart, no dots |
Always remember: an install is performed by the firmware that is already running, so a fix to the install path only takes effect on the update after the one that delivers it (v0.1.1 → v0.1.2 still flickered because v0.1.1 did the writing).
Dark-screen writes (v0.1.2+). Flash writes flicker the PSRAM-fed panel (cause below, and esp32-s3-touch-lcd-5b), so the backlight is off while the image is written: a full-screen notice "Updating to vX — the screen goes dark for about a minute — do not switch off" shows for 3 s first, then "Installed vX / Restarting…" or "Update failed / Still running vY". Seen by the user on the 2026-09-27 screen installs: dark for about a minute, then the restart. The running version is always shown bottom-right on every screen (A v0.1.2).
Known quirk: ota status shows the other slot's "built" date from the framework's precompiled app descriptor (e.g. "Nov 4 2025"), not our build time — ignore it.
Decisions and why
- Manual trigger only (decision, 2026-09-26). An install ends in a reboot, which blanks Controller B's gauges; nothing checks or installs in the background.
- On the Settings screen, behind a confirm dialog (decision, 2026-09-27) — replacing the earlier plan to put it on the password-gated Diagnostics screen. Settings → Updates shows installed vs latest and a Check for updates button; Install vX appears only when the latest release differs and asks "Install vX? The screen goes dark for about a minute… only while parked". The user chose a confirm dialog over a PIN: the parked gate and the signature already guard the dangerous parts; a PIN can come with the Diagnostics screen (open-questions #12). The
otaconsole stays for bench work androllback. - Parked gate
(repo): refused if engine rpm > 0 / run state running or starting, output shaft turning, or lever in a drive gear. A silent bus (>2 s no frames: ignition off, bench) counts as parked. Checked before the download and again before the slot switch.ota checkis exempt (read-only). - HTTPS pull from a public repo (decision). Both repos were made public 2026-09-26 so the device needs no token — the same reasoning as
parking_solution's public releases mirror: a read token in shipped firmware leaks with the device. History was scanned before/after going public: no secrets, no full VIN (only the 10-char prefix in ident logs), no SSIDs(verified 2026-09-26). - Signed images (decision). HTTPS only proves the file came from the server; the ECDSA P-256 signature proves it came from our CI key. The signed statement is
target|version|sha256, so a Controller B image can't be installed on A even with a shared key, and the manifest version can't be swapped. The firmware contains no secrets, so public binaries are fine — keep it that way: the future Diagnostics-screen password must be a salted hash in NVS, never a literal in source. - TLS trust = Let's Encrypt roots, not the leaf
(verified 2026-09-26): the server chain is leaf (SANgit.infra.msai.al) → YR2 → Root YR (cross-signed by ISRG Root X1). Both ISRG Root X1 (to 2035) and Root YR (to 2045) are embedded ininclude/config/ota_config.h, and each verifies the chain alone. Leaf certs rotate ~90 days — never pin them. The framework's mbedtls hasMBEDTLS_HAVE_TIME_DATEoff, so no NTP is needed (and cert dates aren't checked; the signature is the real guarantee). - Rollback: the framework bootloader has
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y, but Arduino'sinitArduino()marks a new image valid beforesetup().ota_update.cppoverridesverifyRollbackLater()→ the image stays PENDING_VERIFY untilOta::tick()confirms it after 30 s. Consequence: power off within 30 s of an update's first boot = back to the old version (by design).
Memory: why jobs run in the loop task (verified 2026-09-26)
With the display, Wi-Fi and all tasks up, internal RAM is nearly exhausted: 15.9 KB free, largest block 7.6 KB (PSRAM: 7.1 MB free). Two consequences, both handled in ota_update.cpp:
- This framework's mbedtls is built with
CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y(~40 KB internal per TLS session → impossible). During a job,mbedtls_platform_set_calloc_free()routes TLS to PSRAM, and restores it after (both sides free withheap_caps_free, so the swap is safe). - No room for a dedicated 10–16 KB task stack, and a PSRAM stack is forbidden because
esp_ota_write()disables the flash cache. So jobs run inside the Arduino loop task (8 KB internal stack):ota checkpeaked leaving 3.6 KB headroom. The console and screen value ticks pause while a job runs.
Update 2026-09-27: with LVGL's pool moved to PSRAM, internal free is 69 KB (largest block 31.7 KB); jobs still run in the loop task (it works, 3.6 KB headroom). The low internal heap was a system-wide risk beyond OTA (the LVGL 60-line DMA draw buffer alone is ~120 KB of internal SRAM) — see open-questions.
Partition table (changed 2026-09-26)
| Name | Offset | Size |
|---|---|---|
| nvs | 0x9000 | 20 KB — unchanged offset, settings survive |
| otadata | 0xE000 | 8 KB |
| app0 (ota_0) | 0x10000 | 7.9 MB |
| app1 (ota_1) | 0x800000 | 7.9 MB |
| coredump | 0xFF0000 | 64 KB |
SPIFFS (3.4 MB, unused by any code) was dropped. Firmware is ~1.65 MB (19.8 % of a slot). Moving to this layout needed one USB flash (done 2026-09-26 on COM10; tunables v150 survived — (verified)).
Console
| Command | What |
|---|---|
ota status |
version, build time, running slot + state, other slot's image |
ota check |
latest release vs running, signature checked (Wi-Fi only, no parked gate) |
ota install [force] |
full install; force reinstalls the same version |
ota rollback |
boot the other slot (or reject an unconfirmed image) — parked only |
Wi-Fi must be joined first — Settings → Wi-Fi (remembered from then on) or wifi join <ssid> [pass] on the console (wifi status | forget | scan | on | off). Do not install v0.1.0: it predates the loop-task/PSRAM-TLS fix, so once installed it can't run OTA again (it boots fine, so rollback won't save it — USB only). Joining an AP moves the radio channel; the ESP-NOW link to B follows it (B hops). diag raw off first keeps CANRAW from burying the progress lines.
- Wi-Fi is remembered (v0.1.5+): one network, saved after a successful join, rejoined ~3 s after boot — including the boot that ends an update
(verified 2026-09-27). Before v0.1.5 every boot needed a new join. - Open the console without resetting the board:
pio device monitor -p COM10 -b 115200 --dtr 0 --rts 0 --echo(pio lives at%USERPROFILE%\.platformio\penv\Scripts\pio.exe). Opening the port with default DTR/RTS resets it (rst:0x15 USB_UART_CHIP_RESET), which drops the Wi-Fi join(verified 2026-09-26). - Flicker cause
(verified 2026-09-26): flash and PSRAM share the MSPI cache; every flash write stalls the PSRAM framebuffer the RGB panel streams from (no bounce buffer). Hence the dark screen above.
Secrets and keys
BMW_NISSAN_FIRMWARE_SIGNING_KEY— Gitea repo secret (Settings → Actions → Secrets), the EC P-256 private key PEM. Generated 2026-09-26; keep an offline backup. Losing it means devices only accept updates after one USB flash with a new public key.- Public key: compiled in (
OTA_SIGNING_PUBKEY_PEM) and intools/ota/firmware_signing_pub.pem(CI self-checks each signature against it before publishing). - Rotating the key: new keypair → update both public-key copies → USB-flash once (a device only trusts the key it was built with).
Bugs found while bringing it up (2026-09-26)
- Settings Wi-Fi switch was disabled since the first SquareLine export (
LV_STATE_DISABLED) — the Wi-Fi UI had never worked. Re-enabled at runtime inUIStateManager(survives re-exports; untick "Disabled" in the SquareLine project too). - Joining Wi-Fi killed ESP-NOW: the Wi-Fi task used
WiFi.disconnect(true)(true = radio off), which drops ESP-NOW; B then ran on the wire only. NowWiFi.disconnect(), andEspNowLink::send()re-initialises ESP-NOW if the driver ever drops it. Verified: joined Personal1 (channel 9), ESP-NOW 195 sent / 0 failed. showConnectionResult()took the LVGL lock with a 0 ms try-lock, ignored the result, and touched widgets that are NULL off the Settings screen — now waits for the lock and null-checks. It still showed no success feedback on screen (user: "a disaster UX") — resolved by the hand-coded Settings screen in v0.1.5 (open-questions #14).
Controller B (not built yet)
Plan agreed 2026-09-26: B is updated by A over ESP-NOW, not by the RS485 wire (the wire is one-way A→B; ESP-NOW is bidirectional and faster). A downloads B's signed image (target patrol-b) from B's repo releases, sends it with acks, B verifies the signature and swaps slots with the same rollback scheme. Prerequisites: B moves off the stock default.csv (1.25 MB slots, 1.07 MB firmware → too tight) to a 16 MB layout (confirm B's flash size first; one USB flash); ESP-NOW pairing/encryption so only A can talk to B; protocol frames for the transfer (shared automotive_data.h → version bump in both repos). B's repo is public since 2026-09-27 (anonymous API 200). Wire stays for gauge-data redundancy.
Related
dual-controller-architecture · esp32-s3-touch-lcd-5b · open-questions · obd-diagnostic-polling