Skip to content

Commit

Permalink
[nrfconnect] Splitted building with Matter OTA and DFU over SMP
Browse files Browse the repository at this point in the history
Currently when enabling Matter OTA DFU, the another DFU over
Bluetooth LE using SMP configuration is also enabled. It should
be available to enable independently.

* Enabled Matter OTA by default for lighting-app
* Modified cmake BUILD_WITH_DFU option to allow disabling DFU
support, enabling Matter OTA DFU and enabling Matter OTA DFU
+ DFU over Bluetooth LE
* Splitted config overlays to extract common DFU parts
from SMP specific ones.
* Updated examples documentation
  • Loading branch information
kkasperczyk-no committed Jan 20, 2022
1 parent 150c479 commit 6029a0e
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 51 deletions.
22 changes: 22 additions & 0 deletions config/nrfconnect/app/overlay-mcuboot_qspi_nor_support.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

CONFIG_BOOTLOADER_MCUBOOT=y

# QSPI configuration
CONFIG_NORDIC_QSPI_NOR=y
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE=16
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Project CHIP Authors
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,14 +14,8 @@
# limitations under the License.
#

CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_UPDATEABLE_IMAGE_NUMBER=2

# QSPI configuration
CONFIG_NORDIC_QSPI_NOR=y
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE=16

# MCU Manager and SMP configuration
CONFIG_MCUMGR=y
CONFIG_MCUMGR_CMD_IMG_MGMT=y
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Project CHIP Authors
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions config/nrfconnect/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ config CHIP_NFC_COMMISSIONING
config CHIP_OTA_REQUESTOR
bool
imply DFU_TARGET
imply IMG_MANAGER
imply STREAM_FLASH
imply STREAM_FLASH_ERASE

Expand Down
26 changes: 21 additions & 5 deletions examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,32 @@ 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)
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")
message(BLE)
if(${BOARD} STREQUAL "nrf5340dk_nrf5340_cpuapp")
message(SMP_MULTI_IMAGE)
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_smp_dfu_support.conf)
else()
message(SMP_SINGLE_IMAGE)
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)
# Enable Matter OTA Requestor
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-ota_requestor.conf)

if(${BOARD} STREQUAL "nrf5340dk_nrf5340_cpuapp")
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_dfu_support.conf)
# 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_dfu_support.conf)
set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/configuration/mcuboot_single_image_dfu.conf CACHE INTERNAL "")
endif()

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

Expand Down Expand Up @@ -84,7 +100,7 @@ chip_configure_data_model(app
GEN_DIR ${GEN_DIR}/lighting-app/zap-generated
)

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

Expand Down
74 changes: 47 additions & 27 deletions examples/lighting-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,43 +98,50 @@ 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
[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.
The example supports over-the-air device firmware upgrade feature using one of the two available methods:
- Matter OTA update that is mandatory for Matter-compliant device 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 that is optional proprietary method and can be enabled to work alongside the default Matter OTA update. Note that this protocol is not a part of the Matter specification.

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

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.
#### Matter Over-the-Air Update

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.
The Matter over-the-air update distinguishes two types of devices, that are the OTA Provider and OTA Requestor.

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.
The OTA Provider is a node that hosts a new firmware image and is able to respond on the OTA Requestor's
queries. It may concern availability of new firmware images or requests to start sending the update packages.

The OTA Requestor is a node that wants to download new firmware image and sends requests to OTA Provider to start the update process.

#### Simple Management Protocol

Simple Management Protocol (SMP) is a basic transfer encoding that is used for
device management purposes, including application image management. SMP supports
using different transports, such as Bluetooth LE, UDP, or serial USB/UART.

In this example, the CHIP device runs the SMP Server to download the application
In this example, the Matter device runs the SMP Server to download the application
update image using the Bluetooth LE transport.

See the
[Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support)
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. The Nordic 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 @@ -209,7 +216,7 @@ following states are possible:
initiated.

- _Pressed for less than 3 s_ &mdash; Initiates the OTA software update
process. This feature is disabled by default, but can be enabled by
over Bluetooth LE process. This feature is disabled by default, but can be enabled by
following the
[Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support)
instruction.
Expand Down Expand Up @@ -384,11 +391,19 @@ Semiconductor's kit you own:

### Building with Device Firmware Upgrade support

To build the example with configuration that enables DFU, run the following
The DFU using Matter OTA method support 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's kit you own (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's kit you own (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 @@ -398,14 +413,19 @@ Semiconductor's kit you own (for example `nrf52840dk_nrf52840`):
> Multi-image mode allows to upgrade more firmware images and is suitable for
> upgrading the application core and network core firmware in two-core nRF5340
> DK devices.
>
> Currently the multi-image mode is available only for the DFU over Bluetooth LE method.

#### Changing Device Firmware Upgrade configuration

To change the default DFU configuration, edit the
`overlay-single_image_dfu_support.conf` or
`overlay-multi_image_dfu_support.conf` overlay files depending on whether the
build target device supports multi-image DFU (nRF5340 DK) or single-image DFU
(nRF52840 DK). The files are located in the `config/nrfconnect/app` directory.
To change the default DFU configuration, edit some of the following overlay files depending on selected configuration:
- `overlay-mcuboot_qspi_nor_support.conf` - generic 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.

#### Changing bootloader configuration
Expand Down
5 changes: 3 additions & 2 deletions examples/lock-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ 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_dfu_support.conf)
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_smp_dfu_support.conf)
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_dfu_support.conf)
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
11 changes: 6 additions & 5 deletions examples/lock-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,12 @@ Semiconductor's kit you own (for example `nrf52840dk_nrf52840`):
#### Changing Device Firmware Upgrade configuration

To change the default DFU configuration, edit the
`overlay-single_image_dfu_support.conf` or
`overlay-multi_image_dfu_support.conf` overlay files depending on whether the
build target device supports multi-image DFU (nRF5340 DK) or single-image DFU
(nRF52840 DK). The files are located in the `config/nrfconnect/app` directory.
To change the default DFU configuration, edit some of the following overlay files depending on selected configuration:
- `overlay-mcuboot_qspi_nor_support.conf` - generic 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

The files are located in the `config/nrfconnect/app` directory.
You can also define the desired options in your example's `prj.conf` file.

#### Changing bootloader configuration
Expand Down
5 changes: 3 additions & 2 deletions examples/pump-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ 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_dfu_support.conf)
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_smp_dfu_support.conf)
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_dfu_support.conf)
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
5 changes: 3 additions & 2 deletions examples/pump-controller-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ 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_dfu_support.conf)
list(INSERT OVERLAY_CONFIG 0 ${CHIP_ROOT}/config/nrfconnect/app/overlay-multi_image_smp_dfu_support.conf)
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_dfu_support.conf)
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

0 comments on commit 6029a0e

Please sign in to comment.