Merge branch 'feat/ota-branch-switch' into merge/ota-branch-into-observer-firmware-dev
# Conflicts: # .github/workflows/build-observer-firmwares.yml # examples/simple_repeater/MyMesh.cpp # examples/simple_room_server/MyMesh.cpp # src/helpers/ESP32Board.cpp # src/helpers/ESP32Board.h # test/test_config_serializer/test_config_serializer.cpp
This commit is contained in:
commit
ee88192acb
17 files changed
+383
-48
No files matched your search
+1
-1
@@ -75,7 +75,7 @@ public:
|
||||
// Pull-based OTA: fetch the firmware build for this variant from a baked-in manifest and flash it.
|
||||
// current_ver is the running firmware version string (used to skip if already up to date); when
|
||||
// dry_run is true the build is only reported, not flashed. Observer (ESP32+WiFi) builds only.
|
||||
virtual bool otaFromManifest(const char* current_ver, bool dry_run, char reply[]) { return false; }
|
||||
virtual bool otaFromManifest(const char* manifest_base, const char* current_ver, bool dry_run, char reply[]) { return false; }
|
||||
|
||||
// Power management interface (boards with power management override these)
|
||||
virtual bool isPwrMgtInitialised() const { return false; }
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
uint8_t path_hash_mode = 0; // which path mode to use when sending
|
||||
uint8_t loop_detect = 0;
|
||||
uint8_t cad_enabled = 0; // hardware Channel Activity Detection before TX (boolean)
|
||||
uint8_t ota_channel = 0; // OTA release channel selector: 0=native, 1=stable, 2=dev
|
||||
uint8_t extra_sf[4];
|
||||
|
||||
// NOTE: observer settings (MQTT/WiFi/timezone/SNMP/alert) are not in NodePrefs.
|
||||
@@ -221,6 +222,7 @@ protected:
|
||||
def("lat", node_lat);
|
||||
def("lon", node_lon);
|
||||
def("disc_mod", discovery_mod_timestamp); // gates 'since'-filtered DISCOVER replies
|
||||
def("ota_ch", ota_channel); // OTA release channel: 0=native, 1=stable, 2=dev
|
||||
def("radio", radio);
|
||||
def("bridge", bridge);
|
||||
def("gps", gps);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "CommonCLI.h"
|
||||
#include "OtaChannel.h"
|
||||
#include "TxtDataHelpers.h"
|
||||
#include "AlertReporter.h" // for alertReporterBannedChannelMatch[Hex]()
|
||||
#include "MQTTObserverValidation.h" // pure input validators (host-testable)
|
||||
@@ -1222,7 +1223,7 @@ bool CommonCLI::handleObserverCommand(uint32_t sender_timestamp, char* command,
|
||||
// MQTT bridge UP: the slim per-variant manifest is tiny, so the fetch only
|
||||
// costs a single TLS handshake (no large JSON doc) — which fits alongside
|
||||
// the live MQTT sessions even on no-PSRAM boards. No bridge bounce needed.
|
||||
_board->otaFromManifest(_callbacks->getFirmwareVer(), true, reply);
|
||||
_board->otaFromManifest(ota_resolve_base(_prefs->ota_channel), _callbacks->getFirmwareVer(), true, reply);
|
||||
} else {
|
||||
// `ota update`: cheap pre-check first (plain HTTP, bridge stays up). Only
|
||||
// schedule the real update — which tears the bridge down, flashes, and
|
||||
@@ -1230,7 +1231,7 @@ bool CommonCLI::handleObserverCommand(uint32_t sender_timestamp, char* command,
|
||||
// returns true iff so; otherwise it leaves the explanation (up to date /
|
||||
// cable flash / error) in reply, which we send without disturbing the
|
||||
// bridge or misleading the user with a "Beginning update..." that no-ops.
|
||||
if (_board->otaFromManifest(_callbacks->getFirmwareVer(), true, reply)) {
|
||||
if (_board->otaFromManifest(ota_resolve_base(_prefs->ota_channel), _callbacks->getFirmwareVer(), true, reply)) {
|
||||
// reply now holds "update available: <cur> -> <target> (N behind|new base)",
|
||||
// where <target> is "vX.Y.Z.B (hash)". Pull <target> out for a friendlier
|
||||
// start message. The "-> " ... trailing " (" framing is produced by
|
||||
@@ -1263,6 +1264,34 @@ bool CommonCLI::handleObserverCommand(uint32_t sender_timestamp, char* command,
|
||||
}
|
||||
#else
|
||||
strcpy(reply, "ERR: online OTA not supported on this build");
|
||||
#endif
|
||||
return true;
|
||||
} else if (memcmp(command, "ota branch", 10) == 0 && (command[10] == 0 || command[10] == ' ')) {
|
||||
// Switch (or report) the OTA release channel this device pulls from. The
|
||||
// selection is persisted (NodePrefs::ota_channel) and resolved to a baked-in
|
||||
// base URL by ota_resolve_base(); it changes only WHERE updates are fetched,
|
||||
// never the running image's reported version. Reachable from any admin path,
|
||||
// same as `ota update`.
|
||||
#if defined(WITH_MQTT_BRIDGE) && defined(OTA_MANIFEST_BASE)
|
||||
const char* arg = command + 10;
|
||||
while (*arg == ' ') arg++;
|
||||
if (*arg == 0) {
|
||||
snprintf(reply, 160, "channel: %s (build: %s), base %s",
|
||||
ota_channel_name(_prefs->ota_channel), ota_native_channel_name(),
|
||||
ota_resolve_base(_prefs->ota_channel));
|
||||
} else {
|
||||
uint8_t ch;
|
||||
if (!ota_parse_channel(arg, &ch)) {
|
||||
strcpy(reply, "ERR: usage ota branch [prod|beta|default] (aliases: stable, dev)");
|
||||
} else {
|
||||
_prefs->ota_channel = ch;
|
||||
savePrefs();
|
||||
snprintf(reply, 160, "channel set to %s, base %s; run ota update to switch",
|
||||
ota_channel_name(ch), ota_resolve_base(ch));
|
||||
}
|
||||
}
|
||||
#else
|
||||
strcpy(reply, "ERR: online OTA not supported on this build");
|
||||
#endif
|
||||
return true;
|
||||
} else if (memcmp(command, "start webconfig", 15) == 0 && (command[15] == 0 || command[15] == ' ')) {
|
||||
|
||||
+17
-10
@@ -270,6 +270,7 @@ static void ota_partitionSignature(char* out, size_t out_sz) {
|
||||
// which stays valid because that function blocks until the worker signals done.
|
||||
struct OtaTaskArgs {
|
||||
ESP32Board* self;
|
||||
const char* manifest_base;
|
||||
const char* current_ver;
|
||||
bool dry_run;
|
||||
char* reply;
|
||||
@@ -279,12 +280,12 @@ struct OtaTaskArgs {
|
||||
|
||||
static void ota_task_entry(void* param) {
|
||||
OtaTaskArgs* a = static_cast<OtaTaskArgs*>(param);
|
||||
a->result = a->self->otaFromManifestImpl(a->current_ver, a->dry_run, a->reply);
|
||||
a->result = a->self->otaFromManifestImpl(a->manifest_base, a->current_ver, a->dry_run, a->reply);
|
||||
a->done = true; // on a successful `ota update` we reboot before reaching here
|
||||
vTaskDelete(nullptr);
|
||||
}
|
||||
|
||||
bool ESP32Board::otaFromManifest(const char* current_ver, bool dry_run, char reply[]) {
|
||||
bool ESP32Board::otaFromManifest(const char* manifest_base, const char* current_ver, bool dry_run, char reply[]) {
|
||||
// The TLS handshake (cert-bundle verify) + JSON parse / HTTPUpdate use far more
|
||||
// stack than the ~8 KB loop task offers — especially when reached via the deep
|
||||
// mesh-receive call chain (it overflows the loopTask canary). Run the work in a
|
||||
@@ -292,7 +293,7 @@ bool ESP32Board::otaFromManifest(const char* current_ver, bool dry_run, char rep
|
||||
// freed when the task exits; on a successful update the chip reboots inside it.
|
||||
NetworkLink& network = activeNetworkLink();
|
||||
network.lockSwitching();
|
||||
OtaTaskArgs args = { this, current_ver, dry_run, reply, false, false };
|
||||
OtaTaskArgs args = { this, manifest_base, current_ver, dry_run, reply, false, false };
|
||||
TaskHandle_t handle = nullptr;
|
||||
BaseType_t ok = xTaskCreatePinnedToCore(ota_task_entry, "ota", 24576, &args, 5, &handle, 1);
|
||||
if (ok != pdPASS) {
|
||||
@@ -307,7 +308,7 @@ bool ESP32Board::otaFromManifest(const char* current_ver, bool dry_run, char rep
|
||||
return args.result;
|
||||
}
|
||||
|
||||
bool ESP32Board::otaFromManifestImpl(const char* current_ver, bool dry_run, char reply[]) {
|
||||
bool ESP32Board::otaFromManifestImpl(const char* manifest_base, const char* current_ver, bool dry_run, char reply[]) {
|
||||
#if !defined(OTA_MANIFEST_BASE) || !defined(OTA_VARIANT)
|
||||
strcpy(reply, "ERR: OTA not configured (build via build.sh)");
|
||||
return false;
|
||||
@@ -343,10 +344,10 @@ bool ESP32Board::otaFromManifestImpl(const char* current_ver, bool dry_run, char
|
||||
// and the handshake + the bridge both fail). This only reads version info; the
|
||||
// firmware download below (ota update) is always TLS-verified. Requires the
|
||||
// manifest host to serve /v over HTTP (no forced HTTPS redirect).
|
||||
if (strncmp(OTA_MANIFEST_BASE, "https://", 8) == 0) {
|
||||
snprintf(murl, sizeof(murl), "http://%s/%s.json", OTA_MANIFEST_BASE + 8, OTA_VARIANT);
|
||||
if (strncmp(manifest_base, "https://", 8) == 0) {
|
||||
snprintf(murl, sizeof(murl), "http://%s/%s.json", manifest_base + 8, OTA_VARIANT);
|
||||
} else {
|
||||
snprintf(murl, sizeof(murl), "%s/%s.json", OTA_MANIFEST_BASE, OTA_VARIANT);
|
||||
snprintf(murl, sizeof(murl), "%s/%s.json", manifest_base, OTA_VARIANT);
|
||||
}
|
||||
if (!http.begin(murl)) {
|
||||
strcpy(reply, "ERR: manifest connect failed");
|
||||
@@ -361,7 +362,7 @@ bool ESP32Board::otaFromManifestImpl(const char* current_ver, bool dry_run, char
|
||||
mclient.setCACertBundle(rootca_crt_bundle_start);
|
||||
#endif
|
||||
mclient.setTimeout(15000);
|
||||
snprintf(murl, sizeof(murl), "%s/%s.json", OTA_MANIFEST_BASE, OTA_VARIANT);
|
||||
snprintf(murl, sizeof(murl), "%s/%s.json", manifest_base, OTA_VARIANT);
|
||||
if (!http.begin(mclient, murl)) {
|
||||
strcpy(reply, "ERR: manifest connect failed");
|
||||
return false;
|
||||
@@ -446,10 +447,14 @@ bool ESP32Board::otaFromManifestImpl(const char* current_ver, bool dry_run, char
|
||||
bool same_base = (own_base[0] && avail_base[0] && strcmp(own_base, avail_base) == 0);
|
||||
bool have_builds = (own_build >= 0 && avail_build >= 0);
|
||||
bool diff_base = (own_base[0] && avail_base[0] && !same_base);
|
||||
// Build counters are per channel, so build numbers only compare within the native channel.
|
||||
bool cross_channel = (strcmp(manifest_base, OTA_MANIFEST_BASE) != 0);
|
||||
|
||||
int behind = 0;
|
||||
bool up_to_date;
|
||||
if (same_base && have_builds) {
|
||||
if (cross_channel) {
|
||||
up_to_date = hash_equal;
|
||||
} else if (same_base && have_builds) {
|
||||
behind = avail_build - own_build;
|
||||
up_to_date = (behind <= 0);
|
||||
} else if (diff_base) {
|
||||
@@ -474,6 +479,8 @@ bool ESP32Board::otaFromManifestImpl(const char* current_ver, bool dry_run, char
|
||||
if (dry_run) {
|
||||
if (up_to_date) {
|
||||
snprintf(reply, 160, "up to date: %s", avail_disp);
|
||||
} else if (cross_channel) {
|
||||
snprintf(reply, 160, "update available: %s -> %s (channel switch)%s", own_disp, avail_disp, pc_note);
|
||||
} else if (same_base && have_builds) {
|
||||
snprintf(reply, 160, "update available: %s -> %s (%d behind)%s", own_disp, avail_disp, behind, pc_note);
|
||||
} else if (diff_base) {
|
||||
@@ -530,7 +537,7 @@ bool ESP32Board::otaFromManifestImpl(const char* current_ver, bool dry_run, char
|
||||
#endif // OTA_MANIFEST_BASE && OTA_VARIANT
|
||||
}
|
||||
#else
|
||||
bool ESP32Board::otaFromManifest(const char* current_ver, bool dry_run, char reply[]) {
|
||||
bool ESP32Board::otaFromManifest(const char* manifest_base, const char* current_ver, bool dry_run, char reply[]) {
|
||||
strcpy(reply, "ERR: not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -161,11 +161,11 @@ public:
|
||||
bool stopOTAUpdate(char* reply) override;
|
||||
bool isOTAUpdateInProgress() const override;
|
||||
void maintainOTAUpdate(uint32_t now_ms) override;
|
||||
bool otaFromManifest(const char* current_ver, bool dry_run, char reply[]) override;
|
||||
bool otaFromManifest(const char* manifest_base, const char* current_ver, bool dry_run, char reply[]) override;
|
||||
// Heavy body (TLS + JSON / HTTPUpdate). Runs in a dedicated large-stack task
|
||||
// spawned by otaFromManifest() — public only so that task entry point can call
|
||||
// it; not meant to be invoked directly.
|
||||
bool otaFromManifestImpl(const char* current_ver, bool dry_run, char reply[]);
|
||||
bool otaFromManifestImpl(const char* manifest_base, const char* current_ver, bool dry_run, char reply[]);
|
||||
|
||||
void setInhibitSleep(bool inhibit) {
|
||||
inhibit_sleep = inhibit;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// OTA release-channel selector, persisted in NodePrefs::ota_channel.
|
||||
enum OtaChannel : uint8_t {
|
||||
OTA_CH_NATIVE = 0, // follow the channel this build was made for
|
||||
OTA_CH_STABLE = 1, // production
|
||||
OTA_CH_DEV = 2, // beta
|
||||
};
|
||||
|
||||
// Resolve the effective manifest base URL for a channel selector.
|
||||
// build.sh injects the three bases as compile-time macros:
|
||||
// OTA_MANIFEST_BASE = this build's native channel (defined on every OTA build)
|
||||
// OTA_MANIFEST_BASE_STABLE = stable (production) channel
|
||||
// OTA_MANIFEST_BASE_DEV = dev (beta) channel
|
||||
// stable/dev fall back to the native base when their macro is undefined (legacy/local
|
||||
// builds that only define OTA_MANIFEST_BASE), so this never returns nullptr on an
|
||||
// OTA-capable build. On a non-OTA build it returns nullptr.
|
||||
//
|
||||
// Each base is stored behind an "ota-base-<channel>:" tag so CI can read a binary's
|
||||
// channels back with `strings` (scripts/verify_ota_channel.sh). Returning a pointer
|
||||
// into the tagged array keeps the tag referenced, so the linker cannot drop it.
|
||||
#if defined(OTA_MANIFEST_BASE)
|
||||
#define OTA_BASE_TAG_NATIVE "ota-base-native:"
|
||||
#define OTA_BASE_TAG_STABLE "ota-base-stable:"
|
||||
#define OTA_BASE_TAG_DEV "ota-base-dev:"
|
||||
#if !defined(OTA_MANIFEST_BASE_STABLE)
|
||||
#define OTA_MANIFEST_BASE_STABLE OTA_MANIFEST_BASE
|
||||
#endif
|
||||
#if !defined(OTA_MANIFEST_BASE_DEV)
|
||||
#define OTA_MANIFEST_BASE_DEV OTA_MANIFEST_BASE
|
||||
#endif
|
||||
static const char ota_tagged_native[] = OTA_BASE_TAG_NATIVE OTA_MANIFEST_BASE;
|
||||
static const char ota_tagged_stable[] = OTA_BASE_TAG_STABLE OTA_MANIFEST_BASE_STABLE;
|
||||
static const char ota_tagged_dev[] = OTA_BASE_TAG_DEV OTA_MANIFEST_BASE_DEV;
|
||||
#endif
|
||||
|
||||
static inline const char* ota_resolve_base(uint8_t channel) {
|
||||
#if defined(OTA_MANIFEST_BASE)
|
||||
switch (channel) {
|
||||
case OTA_CH_STABLE: return ota_tagged_stable + sizeof(OTA_BASE_TAG_STABLE) - 1;
|
||||
case OTA_CH_DEV: return ota_tagged_dev + sizeof(OTA_BASE_TAG_DEV) - 1;
|
||||
case OTA_CH_NATIVE:
|
||||
default: return ota_tagged_native + sizeof(OTA_BASE_TAG_NATIVE) - 1;
|
||||
}
|
||||
#else
|
||||
(void)channel;
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Human label for a selector (for the `ota branch` report).
|
||||
static inline const char* ota_channel_name(uint8_t channel) {
|
||||
switch (channel) {
|
||||
case OTA_CH_STABLE: return "prod";
|
||||
case OTA_CH_DEV: return "beta";
|
||||
default: return "default";
|
||||
}
|
||||
}
|
||||
|
||||
// Label for the channel this build was made for, by matching its native base.
|
||||
static inline const char* ota_native_channel_name() {
|
||||
const char* native = ota_resolve_base(OTA_CH_NATIVE);
|
||||
if (native == nullptr) return "none";
|
||||
if (strcmp(native, ota_resolve_base(OTA_CH_STABLE)) == 0) return "prod";
|
||||
if (strcmp(native, ota_resolve_base(OTA_CH_DEV)) == 0) return "beta";
|
||||
return "custom";
|
||||
}
|
||||
|
||||
// Parse an `ota branch` argument. Returns true and sets *out on a known keyword
|
||||
// (prod|stable, beta|dev, default); returns false and leaves *out untouched otherwise.
|
||||
static inline bool ota_parse_channel(const char* arg, uint8_t* out) {
|
||||
if (strcmp(arg, "prod") == 0 || strcmp(arg, "stable") == 0) { *out = OTA_CH_STABLE; return true; }
|
||||
if (strcmp(arg, "beta") == 0 || strcmp(arg, "dev") == 0) { *out = OTA_CH_DEV; return true; }
|
||||
if (strcmp(arg, "default") == 0) { *out = OTA_CH_NATIVE; return true; }
|
||||
return false;
|
||||
}
|
||||
Reference in new issue
Block a user