Skip to content

Commit

Permalink
[nrfconnect] Enable OTA over Matter in all examples by default (#15724)
Browse files Browse the repository at this point in the history
Build all nRF Connect examples except all-clusters-app with
the OTA requestor support by default. OTA can be disabled
by passing "-- -DBUILD_WITH_DFU=OFF" to the "west build"
command. Additionally, OTA over SMP/BLE can be enabled with
"-DBUILD_WITH_DFU=BLE" flag.
  • Loading branch information
Damian-Nordic authored Mar 2, 2022
1 parent 39795c1 commit 967d6fd
Show file tree
Hide file tree
Showing 28 changed files with 1,160 additions and 172 deletions.
27 changes: 20 additions & 7 deletions examples/lock-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,29 @@ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.conf)
list(APPEND CONF_FILE boards/${BOARD}.conf)
endif()

option(BUILD_WITH_DFU "Build target with Device Firmware Upgrade support" OFF)
if(BUILD_WITH_DFU)
if(${BOARD} STREQUAL "nrf5340dk_nrf5340_cpuapp")
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_smp_dfu_support.conf)
set(BUILD_WITH_DFU "MATTER" CACHE STRING "Build target with Device Firmware Upgrade support")

if(NOT BUILD_WITH_DFU STREQUAL "OFF")
if(BUILD_WITH_DFU STREQUAL "BLE")
if(BOARD STREQUAL "nrf5340dk_nrf5340_cpuapp")
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_smp_dfu_support.conf)
else()
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-single_image_smp_dfu_support.conf)
endif()
elseif(NOT BUILD_WITH_DFU STREQUAL "MATTER")
message(FATAL_ERROR "Selected invalid BUILD_WITH_DFU value: ${BUILD_WITH_DFU}")
endif()

list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-mcuboot_qspi_nor_support.conf)
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-ota_requestor.conf)

if(BOARD STREQUAL "nrf5340dk_nrf5340_cpuapp")
# DFU over Matter doesn't support multi-image update yet, but using this configs should not harm it anyway.
set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/configuration/mcuboot_multi_image_dfu.conf CACHE INTERNAL "")
else()
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-single_image_smp_dfu_support.conf)
set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/configuration/mcuboot_single_image_dfu.conf CACHE INTERNAL "")
endif()
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-mcuboot_qspi_nor_support.conf)

set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static.yml)
endif()

Expand Down Expand Up @@ -80,6 +93,6 @@ chip_configure_data_model(app
ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../lock-common/lock-app.zap
)

if(BUILD_WITH_DFU)
if(BUILD_WITH_DFU STREQUAL "BLE")
target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUOverSMP.cpp)
endif()
75 changes: 51 additions & 24 deletions examples/lock-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,31 @@ with other Thread devices in the network.

### Device Firmware Upgrade

The example allows enabling the over-the-air Device Firmware Upgrade feature. In
this process, the device hosting new firmware image sends the image to the
Matter device using Bluetooth LE transport and
[Simple Management Protocol](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/device_mgmt/index.html#device-mgmt).
The
The example supports over-the-air (OTA) device firmware upgrade (DFU) using one
of the two available methods:

- Matter OTA update that is mandatory for Matter-compliant devices and enabled
by default
- [Simple Management Protocol](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/device_mgmt/index.html#device-mgmt)
over Bluetooth LE, an optional proprietary method that can be enabled to
work alongside the default Matter OTA update. Note that this protocol is not
a part of the Matter specification.

For both methods, the
[MCUboot](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/index.html)
bootloader solution then replaces the old firmware image with the new one.
bootloader solution is used to replace the old firmware image with the new one.

#### Bootloader
#### Matter Over-the-Air Update

MCUboot is a secure bootloader used for swapping firmware images of different
versions and generating proper build output files that can be used in the device
firmware upgrade process.
The Matter over-the-air update distinguishes two types of nodes: OTA Provider
and OTA Requestor.

The bootloader solution requires an area of flash memory to swap application
images during the firmware upgrade. The Nordic devices use an external memory
chip for this purpose. The memory chip communicates with the microcontroller
through the QSPI bus.
An OTA Provider is a node that hosts a new firmware image and is able to respond
on an OTA Requestor's queries regarding availability of new firmware images or
requests to start sending the update packages.

See the
[Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support)
section to learn how to change MCUboot and flash configuration in this example.
An OTA Requestor is a node that wants to download a new firmware image and sends
requests to an OTA Provider to start the update process.

#### Simple Management Protocol

Expand All @@ -132,6 +135,21 @@ See the
section to learn how to enable SMP and use it for the DFU purpose in this
example.

#### Bootloader

MCUboot is a secure bootloader used for swapping firmware images of different
versions and generating proper build output files that can be used in the device
firmware upgrade process.

The bootloader solution requires an area of flash memory to swap application
images during the firmware upgrade. Nordic Semiconductor devices use an external
memory chip for this purpose. The memory chip communicates with the
microcontroller through the QSPI bus.

See the
[Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support)
section to learn how to change MCUboot and flash configuration in this example.

<hr>

<a name="requirements"></a>
Expand Down Expand Up @@ -380,11 +398,19 @@ For example, use the following command for `nrf52840dk_nrf52840`:

### Building with Device Firmware Upgrade support

To build the example with configuration that enables DFU, run the following
command with _build-target_ replaced with the build target name of the Nordic
Semiconductor's kit you own (for example `nrf52840dk_nrf52840`):
Support for DFU using Matter OTA is enabled by default.

To enable DFU over Bluetooth LE, run the following command with _build-target_
replaced with the build target name of the Nordic Semiconductor kit you are
using (for example `nrf52840dk_nrf52840`):

$ west build -b build-target -- -DBUILD_WITH_DFU=BLE

To completely disable support for both DFU methods, run the following command
with _build-target_ replaced with the build target name of the Nordic
Semiconductor kit you are using (for example `nrf52840dk_nrf52840`):

$ west build -b build-target -- -DBUILD_WITH_DFU=1
$ west build -b build-target -- -DBUILD_WITH_DFU=OFF

> **Note**:
>
Expand All @@ -397,15 +423,16 @@ Semiconductor's kit you own (for example `nrf52840dk_nrf52840`):
#### Changing Device Firmware Upgrade configuration

To change the default DFU configuration, edit some of the following overlay
files depending on selected configuration:
To change the default DFU configuration, edit the following overlay files
corresponding to the selected configuration:

- `overlay-mcuboot_qspi_nor_support.conf` - generic file enabling MCUboot and
- `overlay-mcuboot_qspi_nor_support.conf` - general file enabling MCUboot and
QSPI NOR support, used by all DFU configurations
- `overlay-single_image_smp_dfu_support.conf` - file enabling single-image DFU
over Bluetooth LE using SMP
- `overlay-multi_image_smp_dfu_support.conf` - file enabling multi-image DFU
over Bluetooth LE using SMP
- `overlay-ota_requestor.conf` - file enabling Matter OTA Requestor support.

The files are located in the `config/nrfconnect/app` directory. You can also
define the desired options in your example's `prj.conf` file.
Expand Down
49 changes: 39 additions & 10 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
#include <lib/support/ErrorStr.h>
#include <system/SystemClock.h>

#if CONFIG_CHIP_OTA_REQUESTOR
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <platform/GenericOTARequestorDriver.h>
#include <platform/nrfconnect/OTAImageProcessorImpl.h>
#endif

#include <dk_buttons_and_leds.h>
#include <logging/log.h>
#include <zephyr.h>
Expand All @@ -49,21 +56,31 @@ using namespace ::chip::DeviceLayer;
#define APP_EVENT_QUEUE_SIZE 10
#define BUTTON_PUSH_EVENT 1
#define BUTTON_RELEASE_EVENT 0

namespace {
constexpr EndpointId kLockEndpointId = 1;

LOG_MODULE_DECLARE(app);
K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent));
k_timer sFunctionTimer;

LEDWidget sStatusLED;
LEDWidget sLockLED;
LEDWidget sUnusedLED;
LEDWidget sUnusedLED_1;

bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sHaveBLEConnections = false;

#if CONFIG_CHIP_OTA_REQUESTOR
GenericOTARequestorDriver sOTARequestorDriver;
OTAImageProcessorImpl sOTAImageProcessor;
chip::BDXDownloader sBDXDownloader;
chip::OTARequestor sOTARequestor;
#endif

static LEDWidget sStatusLED;
static LEDWidget sLockLED;
static LEDWidget sUnusedLED;
static LEDWidget sUnusedLED_1;

static bool sIsThreadProvisioned = false;
static bool sIsThreadEnabled = false;
static bool sHaveBLEConnections = false;

static k_timer sFunctionTimer;
} // namespace

AppTask AppTask::sAppTask;

Expand Down Expand Up @@ -140,6 +157,7 @@ CHIP_ERROR AppTask::Init()

// Initialize CHIP server
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
InitOTARequestor();
ReturnErrorOnFailure(chip::Server::GetInstance().Init());
ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
Expand All @@ -158,6 +176,17 @@ CHIP_ERROR AppTask::Init()
return err;
}

void AppTask::InitOTARequestor()
{
#if CONFIG_CHIP_OTA_REQUESTOR
sOTAImageProcessor.SetOTADownloader(&sBDXDownloader);
sBDXDownloader.SetImageProcessorDelegate(&sOTAImageProcessor);
sOTARequestorDriver.Init(&sOTARequestor, &sOTAImageProcessor);
sOTARequestor.Init(&chip::Server::GetInstance(), &sOTARequestorDriver, &sBDXDownloader);
chip::SetRequestorInstance(&sOTARequestor);
#endif
}

CHIP_ERROR AppTask::StartApp()
{
ReturnErrorOnFailure(Init());
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AppTask
friend AppTask & GetAppTask(void);

CHIP_ERROR Init();
void InitOTARequestor();

static void ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(BoltLockManager::Action_t aAction, int32_t aActor);
Expand Down
25 changes: 19 additions & 6 deletions examples/pump-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,29 @@ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD}.conf)
list(APPEND CONF_FILE boards/${BOARD}.conf)
endif()

option(BUILD_WITH_DFU "Build target with Device Firmware Upgrade support" OFF)
if(BUILD_WITH_DFU)
if(${BOARD} STREQUAL "nrf5340dk_nrf5340_cpuapp")
set(BUILD_WITH_DFU "MATTER" CACHE STRING "Build target with Device Firmware Upgrade support")

if(NOT BUILD_WITH_DFU STREQUAL "OFF")
if(BUILD_WITH_DFU STREQUAL "BLE")
if(BOARD STREQUAL "nrf5340dk_nrf5340_cpuapp")
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_smp_dfu_support.conf)
else()
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-single_image_smp_dfu_support.conf)
endif()
elseif(NOT BUILD_WITH_DFU STREQUAL "MATTER")
message(FATAL_ERROR "Selected invalid BUILD_WITH_DFU value: ${BUILD_WITH_DFU}")
endif()

list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-mcuboot_qspi_nor_support.conf)
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-ota_requestor.conf)

if(BOARD STREQUAL "nrf5340dk_nrf5340_cpuapp")
# DFU over Matter doesn't support multi-image update yet, but using this configs should not harm it anyway.
set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/configuration/mcuboot_multi_image_dfu.conf CACHE INTERNAL "")
else()
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-single_image_smp_dfu_support.conf)
set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/configuration/mcuboot_single_image_dfu.conf CACHE INTERNAL "")
endif()
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-mcuboot_qspi_nor_support.conf)

set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static.yml)
endif()

Expand Down Expand Up @@ -80,6 +93,6 @@ chip_configure_data_model(app
ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../pump-common/pump-app.zap
)

if(BUILD_WITH_DFU)
if(BUILD_WITH_DFU STREQUAL "BLE")
target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUOverSMP.cpp)
endif()
Loading

0 comments on commit 967d6fd

Please sign in to comment.