diff --git a/examples/lighting-app/bouffalolab/bl602/BUILD.gn b/examples/lighting-app/bouffalolab/bl602/BUILD.gn index d5233ec407fa46..125e9ea45a3e0f 100644 --- a/examples/lighting-app/bouffalolab/bl602/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl602/BUILD.gn @@ -41,7 +41,10 @@ declare_args() { chip_print_memory_usage = true # OTA periodic query timeout in seconds - ota_periodic_query_timeout = 86400 + ota_periodic_query_timeout_seconds = 86400 + + # reboot delay in seconds to apply new OTA image + ota_auto_reboot_delay_seconds = 5 enable_heap_monitoring = false @@ -66,7 +69,8 @@ bl_iot_sdk("sdk") { "INCLUDE_xSemaphoreGetMutexHolder=1", "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}", - "OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout}", + "OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout_seconds}", + "OTA_AUTO_REBOOT_DELAY=${ota_auto_reboot_delay_seconds}", "CHIP_UART_BAUDRATE=${baudrate}", "SYS_AOS_LOOP_ENABLE", ] diff --git a/examples/lighting-app/bouffalolab/bl702/BUILD.gn b/examples/lighting-app/bouffalolab/bl702/BUILD.gn index 4e6319dac88dc7..028a36f25cc0e7 100644 --- a/examples/lighting-app/bouffalolab/bl702/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl702/BUILD.gn @@ -41,7 +41,10 @@ declare_args() { chip_print_memory_usage = true # OTA periodic query timeout in seconds - ota_periodic_query_timeout = 86400 + ota_periodic_query_timeout_seconds = 86400 + + # reboot delay in seconds to apply new OTA image + ota_auto_reboot_delay_seconds = 5 config_cache_size = 8192 @@ -69,7 +72,8 @@ bl_iot_sdk("sdk") { "INCLUDE_xSemaphoreGetMutexHolder=1", "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}", - "OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout}", + "OTA_PERIODIC_TIMEOUT=${ota_periodic_query_timeout_seconds}", + "OTA_AUTO_REBOOT_DELAY=${ota_auto_reboot_delay_seconds}", "OPENTHREAD_CONFIG_PLATFORM_XTAL_ACCURACY=40", "PRINT_DEBUG=0", ] diff --git a/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld b/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld index cf9dce4d23430c..e432a4d7bd2ed8 100644 --- a/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld +++ b/examples/platform/bouffalolab/bl702/ldscripts/psram_flash.ld @@ -143,10 +143,6 @@ SECTIONS { *(.rsvd_data) *(.ble_rsvd_mem) - - KEEP(*AppTask.cpp.o(.bss.*appStack*)) - KEEP(*main.cpp.o(.bss.*TimerTaskStack*)) - } >hbnram .tcmcode : ALIGN(4) diff --git a/examples/platform/bouffalolab/common/plat/OTAConfig.cpp b/examples/platform/bouffalolab/common/plat/OTAConfig.cpp index fc9b18c3d2c450..ed5c6286178ef7 100644 --- a/examples/platform/bouffalolab/common/plat/OTAConfig.cpp +++ b/examples/platform/bouffalolab/common/plat/OTAConfig.cpp @@ -44,3 +44,12 @@ void OTAConfig::Init() gDownloader.SetImageProcessorDelegate(&gImageProcessor); // Initialize and interconnect the Requestor and Image Processor objects -- END } + +void OTAConfig::InitOTARequestorHandler(chip::System::Layer * systemLayer, void * appState) +{ + if (!chip::GetRequestorInstance()) + { + ChipLogProgress(NotSpecified, "Init OTA Requestor"); + OTAConfig::Init(); + } +} diff --git a/examples/platform/bouffalolab/common/plat/OTAConfig.h b/examples/platform/bouffalolab/common/plat/OTAConfig.h index 0aed631b16fff0..906b7f533709cc 100644 --- a/examples/platform/bouffalolab/common/plat/OTAConfig.h +++ b/examples/platform/bouffalolab/common/plat/OTAConfig.h @@ -30,4 +30,6 @@ class OTAConfig OTAConfig(){}; static void Init(); + static constexpr uint32_t kInitOTARequestorDelaySec = 3; + static void InitOTARequestorHandler(chip::System::Layer * systemLayer, void * appState); }; diff --git a/examples/platform/bouffalolab/common/plat/platform.cpp b/examples/platform/bouffalolab/common/plat/platform.cpp index 50ed0de9c19a4d..0c6f1912d3bb80 100644 --- a/examples/platform/bouffalolab/common/plat/platform.cpp +++ b/examples/platform/bouffalolab/common/plat/platform.cpp @@ -121,6 +121,10 @@ void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg) { GetAppTask().PostEvent(AppTask::APP_EVENT_SYS_PROVISIONED); GetAppTask().mIsConnected = true; +#ifdef OTA_ENABLED + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), + OTAConfig::InitOTARequestorHandler, nullptr); +#endif } break; #endif @@ -155,11 +159,14 @@ void ChipEventHandler(const ChipDeviceEvent * event, intptr_t arg) { ChipLogProgress(NotSpecified, "Initializing route hook..."); bl_route_hook_init(); + +#ifdef OTA_ENABLED + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), + OTAConfig::InitOTARequestorHandler, nullptr); +#endif } break; #endif - - break; default: break; } @@ -249,12 +256,6 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void) PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE)); PlatformMgr().AddEventHandler(ChipEventHandler, 0); -#ifdef OTA_ENABLED - chip::DeviceLayer::PlatformMgr().LockChipStack(); - OTAConfig::Init(); - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); -#endif // OTA_ENABLED - #if PW_RPC_ENABLED chip::rpc::Init(); #endif diff --git a/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp b/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp index a24d9316f6d5f7..97af465ef1fef3 100644 --- a/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp +++ b/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp @@ -135,7 +135,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) return; } - if (hosal_ota_finish(1, 0) < 0) + if (hosal_ota_check() < 0) { imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); ChipLogProgress(SoftwareUpdate, "OTA image verification error"); @@ -157,8 +157,9 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) return; } + hosal_ota_apply(0); DeviceLayer::SystemLayer().StartTimer( - System::Clock::Seconds32(4), + System::Clock::Seconds32(OTA_AUTO_REBOOT_DELAY), [](Layer *, void *) { ChipLogProgress(SoftwareUpdate, "Rebooting..."); hal_reboot(); @@ -174,7 +175,7 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) return; } - hosal_ota_finish(1, 0); + hosal_ota_abort(); imageProcessor->ReleaseBlock(); } diff --git a/src/platform/bouffalolab/BL702/OTAImageProcessorImpl.cpp b/src/platform/bouffalolab/BL702/OTAImageProcessorImpl.cpp index c59e34d366cfc2..1e49c74e4f9eb0 100644 --- a/src/platform/bouffalolab/BL702/OTAImageProcessorImpl.cpp +++ b/src/platform/bouffalolab/BL702/OTAImageProcessorImpl.cpp @@ -23,6 +23,8 @@ extern "C" { #include } +using namespace chip::System; + namespace chip { CHIP_ERROR OTAImageProcessorImpl::PrepareDownload() @@ -98,7 +100,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) return; } - if (hosal_ota_finish(1, 0) < 0) + if (hosal_ota_check() < 0) { imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); ChipLogProgress(SoftwareUpdate, "OTA image verification error"); @@ -120,7 +122,14 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) return; } - hal_reboot(); + hosal_ota_apply(0); + DeviceLayer::SystemLayer().StartTimer( + System::Clock::Seconds32(OTA_AUTO_REBOOT_DELAY), + [](Layer *, void *) { + ChipLogProgress(SoftwareUpdate, "Rebooting..."); + hal_reboot(); + }, + nullptr); } void OTAImageProcessorImpl::HandleAbort(intptr_t context) @@ -131,7 +140,7 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) return; } - hosal_ota_finish(1, 0); + hosal_ota_abort(); imageProcessor->ReleaseBlock(); } diff --git a/third_party/bouffalolab/bl602/bl_iot_sdk.gni b/third_party/bouffalolab/bl602/bl_iot_sdk.gni index ea44002bccf38d..b65371d55f88ac 100644 --- a/third_party/bouffalolab/bl602/bl_iot_sdk.gni +++ b/third_party/bouffalolab/bl602/bl_iot_sdk.gni @@ -608,6 +608,7 @@ template("bl_iot_sdk") { ":${sdk_target_name}_config_BSP_Driver", ":${sdk_target_name}_config_freertos", ":${sdk_target_name}_config_utils", + ":${sdk_target_name}_config_hosal", ] public_configs = [ ":${sdk_target_name}_config",