diff --git a/src/platform/silabs/CHIPDevicePlatformConfig.h b/src/platform/silabs/CHIPDevicePlatformConfig.h index d8c58a9368..eace18141e 100644 --- a/src/platform/silabs/CHIPDevicePlatformConfig.h +++ b/src/platform/silabs/CHIPDevicePlatformConfig.h @@ -138,11 +138,7 @@ #endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE #ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE -#if defined(EFR32MG21) -#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (2 * 1024) -#else #define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE (8 * 1024) -#endif #endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0 diff --git a/src/platform/silabs/OTAImageProcessorImpl.h b/src/platform/silabs/OTAImageProcessorImpl.h index 5598b67d4b..d79be006a1 100644 --- a/src/platform/silabs/OTAImageProcessorImpl.h +++ b/src/platform/silabs/OTAImageProcessorImpl.h @@ -50,6 +50,8 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface static void HandleApply(intptr_t context); static void HandleAbort(intptr_t context); static void HandleProcessBlock(intptr_t context); + static void LockRadioProcessing(); + static void UnlockRadioProcessing(); CHIP_ERROR ProcessHeader(ByteSpan & block); /** diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 846d4f720a..11921d86f3 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -30,6 +30,20 @@ extern "C" { #include +#ifdef _SILICON_LABS_32B_SERIES_2 +// Series 2 bootloader_ api calls must be called from a critical section context for thread safeness +#define WRAP_BL_DFU_CALL(code) \ + { \ + CORE_CRITICAL_SECTION(code;) \ + } +#else +// series 3 bootloader_ calls uses rtos mutex for thread safety. Cannot be called within a critical section +#define WRAP_BL_DFU_CALL(code) \ + { \ + code; \ + } +#endif + /// No error, operation OK #define SL_BOOTLOADER_OK 0L @@ -144,7 +158,15 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload: started"); - CORE_CRITICAL_SECTION(bootloader_init();) +#ifdef _SILICON_LABS_32B_SERIES_2 + // TODO sl-temp: bootloader_init is called previously sl_platform_init(). Recalling it for series3 causes a crash. + WRAP_BL_DFU_CALL(err = bootloader_init()) + if (err != SL_BOOTLOADER_OK) + { + ChipLogProgress(SoftwareUpdate, "bootloader_init Failed error: %ld", err); + } +#endif + mSlotId = 0; // Single slot until we support multiple images writeBufOffset = 0; mWriteOffset = 0; @@ -186,7 +208,8 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) return; } #endif // SL_BTLCTRL_MUX - CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);) + WRAP_BL_DFU_CALL(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes)) + #if SL_BTLCTRL_MUX err = sl_wfx_host_post_bootloader_spi_transfer(); if (err != SL_STATUS_OK) @@ -208,11 +231,27 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully"); } +// TODO: SE access is not thread safe. It assert if other tasks accesses it during bootloader_verifyImage or +// bootloader_setImageToBootload steps - MATTER-4155 - PLATFORM_HYD-3235 +void OTAImageProcessorImpl::LockRadioProcessing() +{ +#if !SL_WIFI + DeviceLayer::ThreadStackMgr().LockThreadStack(); +#endif // SL_WIFI +} + +void OTAImageProcessorImpl::UnlockRadioProcessing() +{ +#if !SL_WIFI + DeviceLayer::ThreadStackMgr().UnlockThreadStack(); +#endif // SL_WIFI +} + void OTAImageProcessorImpl::HandleApply(intptr_t context) { uint32_t err = SL_BOOTLOADER_OK; - ChipLogProgress(SoftwareUpdate, "HandleApply: started"); + ChipLogProgress(SoftwareUpdate, "HandleApply: verifying image"); // Force KVS to store pending keys such as data from StoreCurrentUpdateInfo() chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave(); @@ -224,7 +263,13 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) return; } #endif // SL_BTLCTRL_MUX - CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);) + +#if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING + osDelay(100); // sl-temp: delay for uart print before verifyImage +#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING + LockRadioProcessing(); + WRAP_BL_DFU_CALL(err = bootloader_verifyImage(mSlotId, NULL)) + UnlockRadioProcessing(); if (err != SL_BOOTLOADER_OK) { ChipLogError(SoftwareUpdate, "bootloader_verifyImage() error: %ld", err); @@ -235,13 +280,14 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) if (err != SL_STATUS_OK) { ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err); - return; } #endif // SL_BTLCTRL_MUX return; } - - CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);) + ChipLogProgress(SoftwareUpdate, "Image verified, Set image to bootload"); + LockRadioProcessing(); + WRAP_BL_DFU_CALL(err = bootloader_setImageToBootload(mSlotId)) + UnlockRadioProcessing(); if (err != SL_BOOTLOADER_OK) { ChipLogError(SoftwareUpdate, "bootloader_setImageToBootload() error: %ld", err); @@ -252,7 +298,6 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) if (err != SL_STATUS_OK) { ChipLogError(SoftwareUpdate, "sl_wfx_host_post_bootloader_spi_transfer() error: %ld", err); - return; } #endif // SL_BTLCTRL_MUX return; @@ -266,8 +311,15 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) return; } #endif // SL_BTLCTRL_MUX + + ChipLogProgress(SoftwareUpdate, "Reboot and install new image..."); +#if defined(_SILICON_LABS_32B_SERIES_3) && CHIP_PROGRESS_LOGGING + osDelay(100); // sl-temp: delay for uart print before reboot +#endif // _SILICON_LABS_32B_SERIES_3 && CHIP_PROGRESS_LOGGING + LockRadioProcessing(); // This reboots the device - CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) + WRAP_BL_DFU_CALL(bootloader_rebootAndInstall()) + UnlockRadioProcessing(); // Unneccessay but for good measure } void OTAImageProcessorImpl::HandleAbort(intptr_t context) @@ -326,7 +378,8 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) return; } #endif // SL_BTLCTRL_MUX - CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes);) + WRAP_BL_DFU_CALL(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, kAlignmentBytes)) + #if SL_BTLCTRL_MUX err = sl_wfx_host_post_bootloader_spi_transfer(); if (err != SL_STATUS_OK)