From 65a0f69af66a78295a0bff5ea9f723e14c939a5a Mon Sep 17 00:00:00 2001 From: Andrey Tolstoy Date: Fri, 4 Dec 2020 22:08:49 +0700 Subject: [PATCH] [gen3] bootloader: add workaround for MODULE_DROP_MODULE_INFO module slot flag not being forward with Device OS versions < 2.0.0 --- platform/MCU/nRF52840/src/flash_mal.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/platform/MCU/nRF52840/src/flash_mal.c b/platform/MCU/nRF52840/src/flash_mal.c index 933b40335d..0080039de4 100644 --- a/platform/MCU/nRF52840/src/flash_mal.c +++ b/platform/MCU/nRF52840/src/flash_mal.c @@ -411,6 +411,25 @@ int FLASH_CopyMemory(flash_device_t sourceDeviceID, uint32_t sourceAddress, return FLASH_ACCESS_RESULT_BADARG; #endif // !HAS_COMPRESSED_OTA } else { + // XXX: Device OS versions < 2.0.0 may not be setting this flag in the module slots! + // Bootloader should rely on the actual flags within the module header! + if (!(flags & MODULE_DROP_MODULE_INFO) && (flags & MODULE_VERIFY_MASK)) { + // We may only check the module header if we've been asked to verify it + uint32_t infoOffset = 0; + const module_info_t* info = FLASH_ModuleInfo(sourceDeviceID, sourceAddress, &infoOffset); + if (info->flags & MODULE_INFO_FLAG_DROP_MODULE_INFO) { + // NB: We have corner cases where the module info is not located in the + // front of the module but for example after the vector table and we + // only want to enable this feature in the case it is in the front, + // hence the module_info_t located at the the source address check. + if (infoOffset == 0) { + // Skip module header + flags |= MODULE_DROP_MODULE_INFO; + } else { + return FLASH_ACCESS_RESULT_ERROR; + } + } + } if (flags & MODULE_DROP_MODULE_INFO) { // Skip the module info header if (length < sizeof(module_info_t)) { // Sanity check