diff --git a/config/nrfconnect/chip-module/Kconfig b/config/nrfconnect/chip-module/Kconfig index 6aecc3d070be2f..6e9214b93e37d2 100644 --- a/config/nrfconnect/chip-module/Kconfig +++ b/config/nrfconnect/chip-module/Kconfig @@ -43,6 +43,16 @@ config CHIP_OTA_REQUESTOR_BUFFER_SIZE Configures size of the buffer used by OTA Requestor when downloading and writing a new firmware image to flash. +config CHIP_OTA_REQUESTOR_REBOOT_ON_APPLY + bool "Auto-reboot when firmware update is applied" + default y + depends on CHIP_OTA_REQUESTOR + imply REBOOT + help + When a user consents to apply a firmware update, and the update package is + downloaded, reboot the device automatically to swap the old and the new + firmware images. + # See config/zephyr/Kconfig for full definition config CHIP_OTA_IMAGE_BUILD bool diff --git a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h index 60baa9424f4784..5aee8f4f27f71a 100644 --- a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h +++ b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h @@ -62,6 +62,11 @@ #define CHIP_DEVICE_CONFIG_SETTINGS_KEY "mt" #endif // CHIP_DEVICE_CONFIG_SETTINGS_KEY +#ifndef CHIP_DEVICE_CONFIG_OTA_REQUESTOR_REBOOT_DELAY_MS +/// Delay between completing a firmware update download and reboot to apply the update +#define CHIP_DEVICE_CONFIG_OTA_REQUESTOR_REBOOT_DELAY_MS 1000 +#endif // CHIP_DEVICE_CONFIG_OTA_REQUESTOR_REBOOT_DELAY_MS + // ========== Platform-specific Configuration Overrides ========= #ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY diff --git a/src/platform/nrfconnect/OTAImageProcessorImpl.cpp b/src/platform/nrfconnect/OTAImageProcessorImpl.cpp index c31f321a70872b..6659292dfec5be 100644 --- a/src/platform/nrfconnect/OTAImageProcessorImpl.cpp +++ b/src/platform/nrfconnect/OTAImageProcessorImpl.cpp @@ -25,6 +25,8 @@ #include #include +#include + namespace chip { namespace DeviceLayer { @@ -54,7 +56,15 @@ CHIP_ERROR OTAImageProcessorImpl::Abort() CHIP_ERROR OTAImageProcessorImpl::Apply() { - return System::MapErrorZephyr(dfu_target_done(true)); + ReturnErrorOnFailure(System::MapErrorZephyr(dfu_target_done(true))); + +#ifdef CONFIG_CHIP_OTA_REQUESTOR_REBOOT_ON_APPLY + return DeviceLayer::SystemLayer().StartTimer( + System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_OTA_REQUESTOR_REBOOT_DELAY_MS), + [](System::Layer *, void * /* context */) { sys_reboot(SYS_REBOOT_WARM); }, nullptr /* context */); +#else + return CHIP_NO_ERROR; +#endif } CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block)