FwUpdate: format 2 delta packages (FwPatch in RAM), base checked with the manifest

This commit is contained in:
tth committed 2026-11-12 23:52:14 +01:00
1 parent 8d3e554ca3
commit aaca10958e
6 files changed
+225 -43

No files matched your search

+18 -2
View File
@@ -3,8 +3,14 @@
// CUSTOM (TeTeHacko): firmware update pushed by an admin, no bootloader change.
// Design and the reasons behind it: docs/ota-admin.md.
//
// The node stores a signed, deflate-compressed image in the free flash above the
// running one, checks it completely (signature, hashes, a dry-run inflate), and
// Two package formats, one signed 256 B manifest:
// 1 deflate-compressed full image, staged in the free flash above the running
// one, inflated over it by a RAM routine;
// 2 detools in-place DELTA against the running image (FwPatch.cpp), staged in
// the top FW_OTA_PATCH_AREA below InternalFS. The manifest names the base
// (sha256 of the running image) and the node refuses a package for another
// base as soon as the manifest chunks arrive.
// For both, the node checks it completely (signature, hashes, a dry-run inflate), and
// only then, on an explicit `fw apply`, disables the SoftDevice and runs a copy
// routine from RAM that inflates the image over itself. The bootloader settings
// page gets the CRC of the new image FIRST, so a power cut mid-copy leaves a
@@ -30,6 +36,10 @@
#define FW_OTA_MIN_MV 3800 // ~50 % of a Li-ion cell at rest
#endif
#ifndef FW_OTA_PATCH_AREA
#define FW_OTA_PATCH_AREA 0x10000 // delta packages (manifest + patch) up to 64 kB
#endif
#define FW_OTA_MANIFEST_SIZE 256
class FwUpdate {
@@ -52,6 +62,8 @@ private:
void cmdBootloader(char *reply);
uint16_t battMinMv();
uint32_t received() const;
bool checkManifest(); // signature, target, base; sets _err
const uint8_t *baseSha(); // sha256 of the running image, computed once
mesh::MainBoard &_board;
State _state = IDLE;
@@ -59,6 +71,10 @@ private:
uint32_t _total = 0; // package size (manifest + blob)
uint32_t _raw_size = 0;
uint16_t _crc = 0;
uint8_t _format = 0;
bool _manifest_ok = false;
bool _base_known = false;
uint8_t _base_sha[32];
char _version[48] = { 0 };
char _err[48] = { 0 };
unsigned long _apply_at = 0;