Simplify embedded bootloader updates and skip current versions
This commit is contained in:
1 parent
d0d32d7a31
commit
881d8e58a5
12 files changed
+456
-22
No files matched your search
@@ -68,6 +68,15 @@ void hash_region(uint32_t address, uint32_t size, uint8_t output[32]) {
|
||||
hash.finalize(output, 32);
|
||||
}
|
||||
|
||||
bool installed_up_to_date() {
|
||||
OtaBootloaderIdentity installed;
|
||||
return ota_bootloader_identity_from_image(
|
||||
reinterpret_cast<const uint8_t *>(migration::BOOT_BASE), migration::BOOT_SIZE, installed) &&
|
||||
migration::installed_up_to_date(installed, migration_board_id, migration_device_name,
|
||||
migration_boot_version, mota_nrf52_app_base(),
|
||||
migration_softdevice_fwid);
|
||||
}
|
||||
|
||||
uint8_t retained_result() {
|
||||
if (result_is_current) return last_result;
|
||||
uint8_t enabled = 0;
|
||||
@@ -186,20 +195,28 @@ void bootloader_migration_status(char *reply, size_t capacity) {
|
||||
char hash[17];
|
||||
hex8(migration_candidate_sha256, hash);
|
||||
snprintf(reply, capacity, "BL embedded 2.4.12: 40960 B; hash=%s; %s; last=%u", hash,
|
||||
pending ? "armed" : already_installed ? "already installed" : "idle", retained_result());
|
||||
pending ? "armed" : already_installed ? "already installed" :
|
||||
installed_up_to_date() ? "up to date" : "idle", retained_result());
|
||||
}
|
||||
|
||||
bool bootloader_migration_request(const char *confirmation, char *reply, size_t capacity) {
|
||||
char hash[17];
|
||||
hex8(migration_candidate_sha256, hash);
|
||||
if (pending) {
|
||||
snprintf(reply, capacity, "ERR bootloader migration is already armed");
|
||||
return false;
|
||||
}
|
||||
if (strcmp(confirmation, hash) != 0) {
|
||||
if (confirmation && strcmp(confirmation, hash) != 0) {
|
||||
snprintf(reply, capacity, "ERR confirm exact image: ota bootloader embedded install %s", hash);
|
||||
return false;
|
||||
}
|
||||
if (pending) {
|
||||
snprintf(reply, capacity, "OK bootloader update already armed");
|
||||
return true;
|
||||
}
|
||||
if (installed_up_to_date()) {
|
||||
already_installed = false;
|
||||
last_result = 0;
|
||||
result_is_current = true;
|
||||
snprintf(reply, capacity, "OK bootloader already up to date");
|
||||
return true;
|
||||
}
|
||||
// Bootloader diagnostics already read this memory-mapped region while
|
||||
// SoftDevice runs. Detect a no-op before stopping it so BLE stays usable.
|
||||
uint8_t digest[32];
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
namespace mesh {
|
||||
namespace ota {
|
||||
bool bootloader_migration_pending();
|
||||
// nullptr selects the pinned embedded image; a supplied hash must match exactly.
|
||||
bool bootloader_migration_request(const char *confirmation, char *reply, size_t capacity);
|
||||
void bootloader_migration_status(char *reply, size_t capacity);
|
||||
void bootloader_migration_audit(char *reply, size_t capacity);
|
||||
|
||||
@@ -101,6 +101,16 @@ inline bool installed_can_migrate(const OtaBootloaderIdentity &installed,
|
||||
140, fwid, app_base, 1) == OTA_BOOT_CONTINUITY_OK;
|
||||
}
|
||||
|
||||
inline bool installed_up_to_date(const OtaBootloaderIdentity &installed,
|
||||
uint32_t board_id, const char name[16],
|
||||
uint32_t version, uint32_t app_base, uint16_t fwid) {
|
||||
return installed.present && installed.crc_ok &&
|
||||
installed.image_start == BOOT_BASE && installed.image_size == BOOT_SIZE &&
|
||||
installed.board_id == board_id && memcmp(installed.device_name, name, 16) == 0 &&
|
||||
ota_bootloader_continuity_matches_runtime(installed, 140, fwid, app_base, 1) &&
|
||||
installed.boot_version >= version;
|
||||
}
|
||||
|
||||
} // namespace migration
|
||||
} // namespace ota
|
||||
} // namespace mesh
|
||||
@@ -1031,6 +1031,17 @@ static __attribute__((noinline)) bool handle_control_command(
|
||||
|
||||
} else if (is_cmd(a, "bootloader|blupdate", &rest)) {
|
||||
#if defined(OTA_BOOTLOADER_MIGRATION)
|
||||
const char* update_args = nullptr;
|
||||
if (is_cmd(rest, "update", &update_args)) {
|
||||
if (*update_args) {
|
||||
strcpy(reply, "ERR usage: ota bootloader update");
|
||||
} else if (!c.embeddedBootloaderIdle()) {
|
||||
strcpy(reply, "ERR another OTA operation is active");
|
||||
} else {
|
||||
bootloader_migration_request(nullptr, reply, 160);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const char* embedded = nullptr;
|
||||
if (is_cmd(rest, "embedded", &embedded)) {
|
||||
if (*embedded == 0 || strcmp(embedded, "status") == 0) {
|
||||
|
||||
Reference in new issue
Block a user