FwUpdate: manifest check and verify run in loop(), not in the command handler

This commit is contained in:
tth committed 2026-11-13 00:23:05 +01:00
1 parent aaca10958e
commit 228e7a129b
2 files changed
+41 -12

No files matched your search

+33 -12
View File
@@ -562,6 +562,10 @@ void FwUpdate::cmdStatus(char *reply) {
}
break;
case RECEIVING:
if (_job == JOB_VERIFY) {
strcpy(reply, "> verifying");
break;
}
sprintf(reply, "> rx %lu/%lu chunks, batt %umV", (unsigned long)received(), (unsigned long)n, mv);
break;
case READY:
@@ -594,12 +598,17 @@ void FwUpdate::cmdBegin(const char *arg, char *reply) {
_state = RECEIVING;
_manifest_ok = false;
_format = 0;
_job = JOB_NONE;
_apply_at = 0;
sprintf(reply, "OK %lu chunks of %u at %05lX", (unsigned long)((total + FW_OTA_CHUNK - 1) / FW_OTA_CHUNK),
FW_OTA_CHUNK, (unsigned long)stage);
}
void FwUpdate::cmdWrite(const char *arg, char *reply) {
if (_state == FAILED) {
sprintf(reply, "ERR: %s", _err);
return;
}
if (_state != RECEIVING) {
strcpy(reply, "ERR: not receiving");
return;
@@ -625,15 +634,7 @@ void FwUpdate::cmdWrite(const char *arg, char *reply) {
bool all = true;
for (uint32_t i = 0; i * FW_OTA_CHUNK < FW_OTA_MANIFEST_SIZE; i++)
if (!(_have[i >> 3] & (1 << (i & 7)))) all = false;
if (all) {
flash_nrf5x_flush();
if (!checkManifest()) {
_state = FAILED;
sprintf(reply, "ERR: %s", _err);
return;
}
_manifest_ok = true;
}
if (all && _job == JOB_NONE) _job = JOB_MANIFEST; // loop() checks it
}
strcpy(reply, "ok");
}
@@ -656,7 +657,7 @@ void FwUpdate::cmdMissing(char *reply) {
}
void FwUpdate::cmdVerify(char *reply) {
if (_state == READY) {
if (_state == READY || _state == FAILED || _job == JOB_VERIFY) {
cmdStatus(reply);
return;
}
@@ -669,6 +670,11 @@ void FwUpdate::cmdVerify(char *reply) {
strcpy(reply, "ERR: incomplete, see fw missing");
return;
}
_job = JOB_VERIFY; // loop() runs it; poll `fw status`
strcpy(reply, "> verifying");
}
void FwUpdate::doVerify() {
flash_nrf5x_flush();
_state = FAILED;
@@ -763,10 +769,9 @@ void FwUpdate::cmdVerify(char *reply) {
strncpy(_version, m->version, sizeof(_version) - 1);
_version[sizeof(_version) - 1] = 0;
_state = READY;
cmdStatus(reply);
return;
fail:
sprintf(reply, "ERR: %s", _err);
_state = FAILED;
}
void FwUpdate::cmdBootloader(char *reply) {
@@ -810,6 +815,22 @@ void FwUpdate::cmdApply(uint32_t sender_timestamp, const char *arg, char *reply)
}
void FwUpdate::loop() {
if (_job == JOB_MANIFEST) {
_job = JOB_NONE;
flash_nrf5x_flush();
if (checkManifest()) {
_manifest_ok = true;
} else {
_state = FAILED;
}
} else if (_job == JOB_VERIFY) {
_job = JOB_NONE;
if (!_manifest_ok && !checkManifest()) {
_state = FAILED;
} else {
doVerify();
}
}
if (_apply_at == 0 || (long)(millis() - _apply_at) < 0) return;
_apply_at = 0;
if (_state != READY) return;