--- type: concept tags: [ota, firmware, gitea, ci, security, signing, design-decision, controller-a] updated: 2026-09-26 --- # 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|" with secret FIRMWARE_SIGNING_KEY release vX.Y.Z: firmware.bin + firmware.elf + manifest.txt │ public repo, HTTPS, no token Controller A `ota install` ◄──────┘ (parked, Wi-Fi joined) GET /api/v1/repos/art/ESP32-S3-Touch-LCD-5B/releases/latest → tag GET /releases/download//manifest.txt → verify signature FIRST GET /releases/download//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 ``` 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)`. ## 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. Today the trigger is the `ota` serial console; the intended home is the password-gated **Diagnostics screen** ([[open-questions]] #12), the same gate as active CAN polling. - **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 check` is 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 (SAN `git.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 in `include/config/ota_config.h`, and each verifies the chain alone. Leaf certs rotate ~90 days — never pin them. The framework's mbedtls has `MBEDTLS_HAVE_TIME_DATE` off, 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's `initArduino()` marks a new image valid *before* `setup()`. `ota_update.cpp` overrides `verifyRollbackLater()` → the image stays PENDING_VERIFY until `Ota::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). ## 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 via the Settings screen first. 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. The screen may flicker while flash is written (RGB panel + flash cache) `(unverified)`. ## Secrets and keys - `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 in `tools/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). ## 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 still answered 404 anonymously on 2026-09-26 — check its visibility setting. Wire stays for gauge-data redundancy. ## Related [[dual-controller-architecture]] · [[esp32-s3-touch-lcd-5b]] · [[open-questions]] · [[obd-diagnostic-polling]]