Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nrfconnect] Splitted building with Matter OTA and DFU over SMP #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 19 additions & 6 deletions examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,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)
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)
# 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)

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_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 +97,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
76 changes: 48 additions & 28 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 (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.

#### Bootloader
For both 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 nodes: 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.
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.

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

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. 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 @@ -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
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's kit you own (for example `nrf52840dk_nrf52840`):
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 @@ -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 only available 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 the following overlay files corresponding to the selected configuration:
- `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.

#### 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:
kkasperczyk-no marked this conversation as resolved.
Show resolved Hide resolved
- `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