Bluetooth mesh: Device Firmware Update (DFU) target
The Bluetooth® mesh DFU target sample demonstrates how to update device firmware over Bluetooth mesh network. The sample implements the Target role of the Bluetooth mesh DFU subsystem.
The specification that the Bluetooth mesh DFU subsystem is based on is not adopted yet, and therefore this feature should be used for experimental purposes only.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Build target |
---|---|---|---|
PCA10056 |
|
For provisioning and configuring of the mesh model instances, the sample requires a smartphone with Nordic Semiconductor’s nRF Mesh mobile app installed in one of the following versions:
For uploading an image to the Distributor, this sample also requires a smartphone with Nordic Semiconductor’s nRF Connect Device Manager mobile app installed in one of the following versions:
Overview
This sample can be used as a base image or be transferred over Bluetooth mesh to update existing nodes.
To distribute this sample as a new image over Bluetooth mesh network, use the Bluetooth mesh: Device Firmware Update (DFU) distributor sample.
Provisioning
The sample supports provisioning over both the Advertising and the GATT Provisioning Bearers (i.e. PB-ADV and PB-GATT). The provisioning is handled by the Bluetooth mesh provisioning handler for Nordic DKs. It supports four types of out-of-band (OOB) authentication methods, and uses the Hardware Information driver to generate a deterministic UUID to uniquely represent the device.
Use nRF Mesh mobile app for provisioning and configuring of models supported by the sample.
Models
The following table shows the mesh composition data for this sample:
Element 1 |
---|
Config Server |
Health Server |
BLOB Transfer Server |
Firmware Update Server |
The models are used for the following purposes:
Config Server allows configurator devices to configure the node remotely.
Health Server provides
attention
callbacks that are used during provisioning to call your attention to the device. These callbacks trigger blinking of the LEDs.Binary Large Object (BLOB) Transfer models are the underlying transport mechanism for the mesh DFU feature. BLOB Transfer Server is instantiated on the primary element and used to receive the firmware image binary from the Distributor node.
The Firmware Update Server model is instantiated on the primary element. Together with the extended BLOB Transfer Server model, the Firmware Update Server model implements all the required functionality for receiving firmware updates over the mesh network.
Configuration
See Configuring your application for information about how to permanently or temporarily change the configuration.
Source file setup
This sample is split into the following source files:
A
main.c
file to handle Bluetooth mesh initialization, including the model handling for Device Composition Data, Health and Configuration Server models.File
dfu_target.c
with the Target role implementation.File
dfu_dist.c
with the Distributor role implementation.File
smp_bt.c
implementing SMP Bluetooth service advertisement.
Building and running
This sample can be found under samples/bluetooth/mesh/mesh_dfu/target
in the nRF Connect SDK folder structure.
To build the sample with Visual Studio Code, follow the steps listed on the How to build an application page in the nRF Connect for VS Code extension documentation. See Building and programming an application for other building and programming scenarios and Testing and debugging an application for general information about testing and debugging in the nRF Connect SDK.
Testing
This sample has been tested with the nRF52840 DK (nrf52840dk_nrf52840) board.
Provisioning the device
The provisioning assigns an address range to the device, and adds it to the mesh network. Complete the following steps in the nRF Mesh app:
Tap Add node to start scanning for unprovisioned mesh devices.
Select the Mesh DFU Target device to connect to it.
Tap Identify, and then Provision, to provision the device.
When prompted, select an OOB method and follow the instructions in the app.
Once the provisioning is complete, the app returns to the Network screen.
Configuring models
See Configuring mesh models using the nRF Mesh mobile app for details on how to configure the mesh models with the nRF Mesh mobile app.
Configure the BLOB Transfer Server model and the Firmware Update Server on the primary element on the Mesh DFU Target node:
Bind each model to Application Key 1.
Once the models are bound to the application key, together they implement all the required functionality for receiving firmware updates over the mesh network from the Distributor node.
Performing a Device Firmware Update
This sample can be transferred as a DFU over a mesh network to update the existing nodes. The sample can also be the Target node updated by any firmware image that is compiled as the MCUboot application and transferred over the mesh network. In both cases, the firmware needs to be signed and the firmware version increased to pass the validation when the MCUboot swaps the images.
To set a new version, alter the Kconfig option CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION
to a version that is higher than the default version of: "1.0.0+0"
.
Then, after rebuilding the sample, the binary of the updated sample can be found in samples/bluetooth/mesh_dfu/target/build/zephyr/app_update.bin
.
To perform a DFU with this sample, the following additional information is required:
- Firmware ID
Firmware ID used in this sample corresponds to the image version that is encoded in the format defined by the
mcuboot_img_sem_ver
structure. For example, when the new version is2.0.0+0
, the encoded value will be0200000000000000
.- Firmware metadata
This sample enables the
CONFIG_BT_MESH_DFU_METADATA
option and uses the format defined by the Bluetooth mesh DFU subsystem. How to generate valid metadata for this sample is described in Composing the firmware metadata.
The firmware distribution process starts on a target node with checking a metadata supplied with a new firmware. If the metadata data is decoded successfully, the following checks are performed in this sample:
That the new firmware version is higher than the existing one.
That the new firmware fits into the flash storage.
If the metadata check completes successfully, the sample selects a value from bt_mesh_dfu_effect
depending on whether the composition data changes after programming the new firmware or not.
This has an effect on the Distributor and the Target node.
Only 2 options are supported by this sample:
BT_MESH_DFU_EFFECT_NONE
This effect is chosen if the composition data of the new firmware doesn’t change. In this case the device will stay provisioned after the new firmware is programmed.
BT_MESH_DFU_EFFECT_UNPROV
This effect is chosen if the composition data in the new firmware changes. In this case, the device unprovisions itself before programming the new firmware. The unprovisioning happens before the device reboots, so if the MCUboot fails to validate the new firmware, the device will boot unprovisioned anyway.
In this sample, the device flash is split into fixed partitions using devicetree as defined in nrf52840dk_nrf52840.dts. When the DFU transfer starts, the sample stores the new firmware at slot-1 using Flash map.
When the DFU transfer ends, the sample requests the MCUboot to replace slot-0 with slot-1 and reboots the device. The MCUboot performs the validation of the image located at slot-1. Upon successful validation, the MCUboot replaces the old firmware with the new one and boots it. After booting, the sample confirms the image so the old image does not get reverted at the next reboot.
When the sample is used as a new firmware, independently of the provisioning state, it sets the Firmware Update Server model to Idle state after booting. If the device stays provisioned, it lets the Distributor successfully finalize the firmware distribution process. If the device is unprovisioned, it has no effect on the DFU Server. The firmware distribution process then succeeds on the Distributor side, if the Target node doesn’t respond to the Distributor after programming the new firmware.
For more information about the firmware distribution process, see Device Firmware Update (DFU).
Logging
In this sample, UART and SEGGER RTT are available as logging backends.
Dependencies
This sample uses the following nRF Connect SDK libraries:
It also requires MCUboot and MCUmgr.
In addition, it uses the following Zephyr libraries:
-
include/bluetooth/mesh.h