Skip to content

Commit 657937f

Browse files
authored
Merge pull request #2246 from particle-iot/fix/gen3-bootloader-softdevice-drop-module-info
[gen3] bootloader: add workaround for MODULE_DROP_MODULE_INFO
2 parents eae3cfe + 65a0f69 commit 657937f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

platform/MCU/nRF52840/src/flash_mal.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,25 @@ int FLASH_CopyMemory(flash_device_t sourceDeviceID, uint32_t sourceAddress,
411411
return FLASH_ACCESS_RESULT_BADARG;
412412
#endif // !HAS_COMPRESSED_OTA
413413
} else {
414+
// XXX: Device OS versions < 2.0.0 may not be setting this flag in the module slots!
415+
// Bootloader should rely on the actual flags within the module header!
416+
if (!(flags & MODULE_DROP_MODULE_INFO) && (flags & MODULE_VERIFY_MASK)) {
417+
// We may only check the module header if we've been asked to verify it
418+
uint32_t infoOffset = 0;
419+
const module_info_t* info = FLASH_ModuleInfo(sourceDeviceID, sourceAddress, &infoOffset);
420+
if (info->flags & MODULE_INFO_FLAG_DROP_MODULE_INFO) {
421+
// NB: We have corner cases where the module info is not located in the
422+
// front of the module but for example after the vector table and we
423+
// only want to enable this feature in the case it is in the front,
424+
// hence the module_info_t located at the the source address check.
425+
if (infoOffset == 0) {
426+
// Skip module header
427+
flags |= MODULE_DROP_MODULE_INFO;
428+
} else {
429+
return FLASH_ACCESS_RESULT_ERROR;
430+
}
431+
}
432+
}
414433
if (flags & MODULE_DROP_MODULE_INFO) {
415434
// Skip the module info header
416435
if (length < sizeof(module_info_t)) { // Sanity check

0 commit comments

Comments
 (0)