FwUpdate: over the mesh only deltas, a full image only over USB / BLE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9080d8339d
commit
9165590d13
2 files changed
+24
-7
No files matched your search
@@ -548,6 +548,7 @@ int FwUpdate::handleBinary(const uint8_t *req, int len, uint8_t *reply, int repl
|
||||
return 0;
|
||||
}
|
||||
_w_bin++;
|
||||
_remote = true; // binary chunks are the mesh protocol (`fw bin` replays it on the bench)
|
||||
_mani_src = 'b';
|
||||
writeAt(off, &req[11], n); // errors show in the next 'm'
|
||||
return 0;
|
||||
@@ -635,6 +636,10 @@ bool FwUpdate::checkManifest() {
|
||||
strcpy(_err, "size mismatch");
|
||||
return false;
|
||||
}
|
||||
if (_remote && m->format != 2) {
|
||||
strcpy(_err, "full image not over the mesh (USB or BLE)");
|
||||
return false;
|
||||
}
|
||||
if (m->format == 2) {
|
||||
if (!deltaInRam()) {
|
||||
strcpy(_err, "no delta support in this build");
|
||||
@@ -690,10 +695,15 @@ void FwUpdate::cmdStatus(char *reply) {
|
||||
}
|
||||
}
|
||||
|
||||
void FwUpdate::cmdBegin(const char *arg, char *reply) {
|
||||
void FwUpdate::cmdBegin(uint32_t sender_timestamp, const char *arg, char *reply) {
|
||||
char *rest;
|
||||
uint32_t total = strtoul(arg, &rest, 10);
|
||||
uint32_t sid = strtoul(rest, NULL, 10); // optional transfer session (binary chunks)
|
||||
if (sender_timestamp != 0 && total > FW_OTA_PATCH_AREA) {
|
||||
sprintf(reply, "ERR: over the mesh only a delta (<= %u B); a full image goes over USB or BLE",
|
||||
(unsigned)FW_OTA_PATCH_AREA);
|
||||
return;
|
||||
}
|
||||
// small = delta: top of the free flash, out of reach of the in-place shift;
|
||||
// big = full image: right above the running one, as before
|
||||
uint32_t stage = total <= FW_OTA_PATCH_AREA ? PATCH_LO : (imageEnd() + PAGE - 1) & ~(PAGE - 1);
|
||||
@@ -708,6 +718,7 @@ void FwUpdate::cmdBegin(const char *arg, char *reply) {
|
||||
}
|
||||
_stage = stage;
|
||||
_total = total;
|
||||
_remote = sender_timestamp != 0;
|
||||
memset(_have, 0, sizeof(_have));
|
||||
_state = RECEIVING;
|
||||
_manifest_ok = false;
|
||||
@@ -724,7 +735,8 @@ void FwUpdate::cmdBegin(const char *arg, char *reply) {
|
||||
FW_OTA_CHUNK, (unsigned long)stage);
|
||||
}
|
||||
|
||||
void FwUpdate::cmdWrite(const char *arg, char *reply) {
|
||||
void FwUpdate::cmdWrite(uint32_t sender_timestamp, const char *arg, char *reply) {
|
||||
if (sender_timestamp != 0) _remote = true;
|
||||
if (_state == FAILED) {
|
||||
sprintf(reply, "ERR: %s", _err);
|
||||
return;
|
||||
@@ -1016,11 +1028,11 @@ bool FwUpdate::handleCommand(uint32_t sender_timestamp, const char *command, cha
|
||||
while (*arg == ' ')
|
||||
arg++;
|
||||
if (strncmp(arg, "w ", 2) == 0)
|
||||
cmdWrite(arg + 2, reply);
|
||||
cmdWrite(sender_timestamp, arg + 2, reply);
|
||||
else if (strcmp(arg, "status") == 0 || !*arg)
|
||||
cmdStatus(reply);
|
||||
else if (strncmp(arg, "begin ", 6) == 0)
|
||||
cmdBegin(arg + 6, reply);
|
||||
cmdBegin(sender_timestamp, arg + 6, reply);
|
||||
else if (strcmp(arg, "missing") == 0)
|
||||
cmdMissing(reply);
|
||||
else if (strcmp(arg, "verify") == 0)
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
// that jumps into half an image.
|
||||
//
|
||||
// fw status state, progress, battery
|
||||
// fw begin <bytes> start a transfer of a package (tools/ota_pack.py)
|
||||
// fw begin <bytes> start a transfer of a package (tools/ota_pack.py);
|
||||
// over the mesh only a delta (<= FW_OTA_PATCH_AREA)
|
||||
// fw w <offset> <base64> one chunk, offset a multiple of FW_OTA_CHUNK
|
||||
// fw missing first missing chunk offsets (for resending)
|
||||
// fw verify signature + hashes + dry-run inflate
|
||||
@@ -83,8 +84,8 @@ private:
|
||||
enum Job : uint8_t { JOB_NONE, JOB_MANIFEST, JOB_VERIFY };
|
||||
|
||||
void cmdStatus(char *reply);
|
||||
void cmdBegin(const char *arg, char *reply);
|
||||
void cmdWrite(const char *arg, char *reply);
|
||||
void cmdBegin(uint32_t sender_timestamp, const char *arg, char *reply);
|
||||
void cmdWrite(uint32_t sender_timestamp, const char *arg, char *reply);
|
||||
void cmdMissing(char *reply);
|
||||
void cmdVerify(char *reply);
|
||||
void doVerify();
|
||||
@@ -108,6 +109,10 @@ private:
|
||||
uint8_t _format = 0;
|
||||
Job _job = JOB_NONE;
|
||||
bool _manifest_ok = false;
|
||||
// Any part of the transfer came over the mesh (remote CLI or a binary
|
||||
// request). Then only a DELTA is accepted: a full image is ~300 kB, hours of
|
||||
// airtime on a shared channel -- it goes over USB or the BLE console.
|
||||
bool _remote = false;
|
||||
bool _base_known = false;
|
||||
uint8_t _base_sha[32];
|
||||
// The manifest is checked from this RAM copy, not from the stage in flash: three
|
||||
|
||||
Reference in new issue
Block a user