Skip to content

Commit

Permalink
backport: [nrfconnect] Auto-reboot on firmware update project-chip#14951
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri Mizenko committed Feb 17, 2022
1 parent f3f994e commit 0f2ea43
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions config/nrfconnect/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/platform/nrfconnect/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/platform/nrfconnect/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <dfu/dfu_target.h>
#include <dfu/dfu_target_mcuboot.h>

#include <sys/reboot.h>

namespace chip {
namespace DeviceLayer {

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0f2ea43

Please sign in to comment.