Skip to content

Commit

Permalink
[nrfconnect] Auto-reboot on firmware update (#14951)
Browse files Browse the repository at this point in the history
Automatically reboot the device when a firmware update
is applied.

Signed-off-by: Damian Krolik <[email protected]>
  • Loading branch information
Damian-Nordic authored and pull[bot] committed Jul 22, 2023
1 parent 8480523 commit 2513464
Show file tree
Hide file tree
Showing 3 changed files with 25 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 @@ -44,6 +44,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
11 changes: 10 additions & 1 deletion src/platform/nrfconnect/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <dfu/dfu_target.h>
#include <dfu/dfu_target_mcuboot.h>
#include <sys/reboot.h>

namespace chip {
namespace DeviceLayer {
Expand Down Expand Up @@ -56,7 +57,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 2513464

Please sign in to comment.