From 22484409b8bc402d45d934ee09691e3b53e37c8e Mon Sep 17 00:00:00 2001 From: Wang Qixiang <43193572+wqx6@users.noreply.github.com> Date: Tue, 17 Jan 2023 06:44:23 +0800 Subject: [PATCH] [ESP32] Add menuconfig options for reboot on OTA image apply (#24379) --- config/esp32/components/chip/Kconfig | 14 ++++++++++++++ src/platform/ESP32/OTAImageProcessorImpl.cpp | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index c5af3c66ad5d9c..dea6109649232f 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -171,6 +171,20 @@ menu "CHIP Core" help Enable this option to enable OTA Requestor for example + config OTA_AUTO_REBOOT_ON_APPLY + bool "Reboot the device after applying the OTA image" + depends on ENABLE_OTA_REQUESTOR + default y + help + Enable this option to reboot the device after applying the new image. + + config OTA_AUTO_REBOOT_DELAY_MS + int "OTA reboot delay time (ms)" + depends on OTA_AUTO_REBOOT_ON_APPLY + default 5000 + help + The delay time for OTA reboot on applying. + endmenu # "System Options" menu "Security Options" diff --git a/src/platform/ESP32/OTAImageProcessorImpl.cpp b/src/platform/ESP32/OTAImageProcessorImpl.cpp index ad93fa8e439238..ccf8c0498663bd 100644 --- a/src/platform/ESP32/OTAImageProcessorImpl.cpp +++ b/src/platform/ESP32/OTAImageProcessorImpl.cpp @@ -245,8 +245,12 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) PostOTAStateChangeEvent(DeviceLayer::kOtaApplyComplete); +#if CONFIG_OTA_AUTO_REBOOT_ON_APPLY // HandleApply is called after delayed action time seconds are elapsed, so it would be safe to schedule the restart - DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(2 * 1000), HandleRestart, nullptr); + DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(CONFIG_OTA_AUTO_REBOOT_DELAY_MS), HandleRestart, nullptr); +#else + ESP_LOGI(TAG, "Please reboot the device manually to apply the new image"); +#endif } CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block)