Skip to content

Commit

Permalink
[nrfconnect] Splitted building with Matter OTA and DFU over SMP (proj…
Browse files Browse the repository at this point in the history
…ect-chip#14144)

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

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

* Fixed spellcheck failures

* Added cbor module to requirements

* Disabled building target with DFU support for nRF52840 dongle

* Disabled nRF5340DK shell workflow

* Removed additional board check for building DFU target
  • Loading branch information
kkasperczyk-no authored Jan 26, 2022
1 parent 2e0f64d commit 1202bc7
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 68 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ RendezVousTest
repo
req
Requestor
Requestor's
Requestors
responder
retargeting
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/examples-nrfconnect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ jobs:
nrfconnect nrf5340dk_nrf5340_cpuapp lighting-app \
examples/lighting-app/nrfconnect/build/nrf5340dk_nrf5340_cpuapp/zephyr/zephyr.elf \
/tmp/bloat_reports/
- name: Build example nRF Connect SDK Shell on nRF5340 DK
timeout-minutes: 10
run: |
scripts/examples/nrfconnect_example.sh shell nrf5340dk_nrf5340_cpuapp
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
nrfconnect nrf5340dk_nrf5340_cpuapp shell \
examples/shell/nrfconnect/build/nrf5340dk_nrf5340_cpuapp/zephyr/zephyr.elf \
/tmp/bloat_reports/
- name: Build example nRF Connect SDK Pump App on nRF52840 DK
timeout-minutes: 10
run: |
Expand Down
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
30 changes: 24 additions & 6 deletions examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,34 @@ 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(NOT BOARD STREQUAL "nrf52840dongle_nrf52840")
set(BUILD_WITH_DFU "MATTER" CACHE STRING "Build target with Device Firmware Upgrade support")
else()
set(BUILD_WITH_DFU "OFF" CACHE STRING "Build target with Device Firmware Upgrade support")
endif()

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 +102,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
100 changes: 68 additions & 32 deletions examples/lighting-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,43 +98,61 @@ 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

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
update image using the Bluetooth LE transport.
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 @@ -208,9 +226,9 @@ following states are possible:
procedure. **LEDs 1-4** blink in unison when the factory reset procedure is
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
following the
- _Pressed for less than 3 s_ &mdash; Initiates the OTA software update 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 +402,19 @@ Semiconductor's kit you own:

### 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 @@ -398,15 +424,25 @@ 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.
You can also define the desired options in your example's `prj.conf` file.
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
18 changes: 12 additions & 6 deletions examples/lock-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,18 @@ 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.
You can also define the desired options in your example's `prj.conf` file.
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
4 changes: 3 additions & 1 deletion scripts/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ bitstring==3.1.7
# via -r requirements.esp32.txt
brotli==1.0.9
# via flask-compress
cbor==1.0.0
# via -r requirements.txt
certifi==2021.5.30
# via requests
cffi==1.14.5
Expand Down Expand Up @@ -287,7 +289,7 @@ wcwidth==0.2.5
# prompt-toolkit
werkzeug==0.16.1
# via flask
west==0.11.0
west==0.12.0
# via -r requirements.txt
wheel==0.36.2
# via -r requirements.txt
Expand Down
3 changes: 2 additions & 1 deletion scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ portpicker
mobly

# zephyr
west>=0.11.0
west>=0.12.0
intelhex
cbor

# happy tests
lockfile
Expand Down

0 comments on commit 1202bc7

Please sign in to comment.