Files
ESP32-S3-Touch-LCD-5B/src/modules/ota_update.h
T

75 lines
2.6 KiB
C++

/**
* ota_update.h - pull firmware updates from this repo's Gitea releases.
*
* Manual only: nothing checks or installs by itself. Driven from the Settings
* screen (Updates section: check, then install behind a confirm dialog) and the
* `ota` serial console.
*
* ota status running version, slot, rollback state
* ota check ask Gitea for the latest release, compare versions
* ota install [force] download, verify signature, flash idle slot, reboot
* ota rollback boot the previous slot
*
* Safety:
* - refused unless the vehicle is parked (engine off, output shaft still, lever
* not in a drive gear) - checked before the download AND again before the
* boot slot is switched. Silent bus (bench / ignition off) counts as parked.
* - image must match the signed manifest (sha256 + ECDSA P-256 over
* "target|version|sha256"); otherwise the idle slot is never activated.
* - a new image must run OTA_CONFIRM_MS before it is marked valid; a reset
* or crash before that makes the bootloader fall back to the old slot.
*
* Needs Wi-Fi joined to a network with internet (Settings screen). Joining an
* AP moves the radio channel; the ESP-NOW link to Inst. Cluster follows it.
* See wiki/pages/ota-updates.md.
*/
#ifndef OTA_UPDATE_H
#define OTA_UPDATE_H
#include <Arduino.h>
namespace Ota {
/** Log version/slot; note if this boot is an unconfirmed new image. Call early in setup(). */
void init();
/** Confirms a freshly installed image once it has run long enough. Call from loop(). */
void tick();
/** Console entry point (`ota ...`). Returns false if the line isn't an ota command. */
bool handleCommand(const char* line);
/** Firmware version baked in at build time ("dev" for local builds). */
const char* version();
// ---- Settings screen -------------------------------------------------------
typedef enum {
PHASE_IDLE, // nothing asked yet this boot
PHASE_CHECKING,
PHASE_UP_TO_DATE, // latest == running
PHASE_AVAILABLE, // latest != running
PHASE_INSTALLING,
PHASE_FAILED // message says why
} phase_t;
typedef struct {
phase_t phase;
char latest[32]; // latest release tag, once known
char message[96]; // failure reason
} ui_status_t;
ui_status_t getStatus();
/** Queue a check / install (runs in the loop task). False + reason if refused now. */
bool requestCheck(char* why, size_t n);
bool requestInstall(char* why, size_t n);
/** The parking gate on its own (Inst. Cluster's install is guarded by it too). */
bool isParked(char* why, size_t n);
} // namespace Ota
#endif // OTA_UPDATE_H