DFU Multi-image
The DFU Multi-image sample demonstrates the use of the Device Firmware Update (DFU) multi-image functionality in the nRF Connect SDK. Currently, it only supports DFU targets for MCUboot as its backend.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
|
|---|---|---|---|
PCA10175 |
|
||
PCA10095 |
|
Overview
The sample does not include a transport layer for uploading a new image.
Instead, a partition labeled dfu_multi_image_helper is reserved in the board overlays.
Note
You must manually upload an image to this partition using nrfutil device command.
Once the image has been uploaded, you can use the shell commands from the dfu_multi_image group provided by this sample to test DFU multi image operations.
User interface
The sample’s interface is implemented using shell commands, which are accessible through the serial port.
Building and running
This sample can be found under samples/dfu/dfu_multi_image in the nRF Connect SDK folder structure.
To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.
Testing
After programming the sample to your development kit, complete the following steps to test it:
Connect to the kit that runs this sample with a terminal emulator (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.
Reset the development kit.
Observe the following message on the terminal of the application core:
Starting dfu_multi_image sample, build time: <BUILD TIME>And the following message on the terminal of the network core:
Network core build time: <BUILD_TIME><BUILD TIME>indicates the build time. It will be used later to verify the update.Build a second version of the sample. For simplicity, it is assumed to be built in the
build_v2directory.Use the
arm-zephyr-eabi-objcopycommand to link the contents of thedfu_multi_image.binfile to the appropriate address:arm-zephyr-eabi-objcopy -I binary -O ihex --change-address <DFU_MULTI_IMAGE_HELPER_ADDRESS> build_v2/dfu_multi_image.bin package_v2.hexReplace
<DFU_MULTI_IMAGE_HELPER_ADDRESS>with the address of thedfu_multi_image_helperpartition. Specifically, the address values are the following:Development kit
Address
nRF5340 DK
0xb8000nRF54H20 DK
0xe134000Upload the second version of the images to the device using
nrfutil device:nrfutil device program --firmware package_v2.hex --options chip_erase_mode=ERASE_NONEReset the development kit.
Perform the update using one of the following methods:
Single-step update, running the following command:
dfu_multi_image full_update <package_size>
<package_size>is the size, in bytes, of the filebuild_v2/dfu_multi_image.bin.Step-by-step update:
Write the image either at once or in chunks:
To write the entire image at once, run the following command:
dfu_multi_image write 0 0 <package_size><package_size>is the size, in bytes, of the filebuild_v2/dfu_multi_image.bin.To write the image in chunks, run the following commands as many times as there are chunks:
dfu_multi_image write <read_offset> <write_offset> <chunk_size>The
<read_offset>is the offset in thedfu_multi_image_helperpartition from which a chunk of data is read. The<write_offset>is the offset to pass to the DFU multi-image library, representing the offset in the package. This is useful when skipping some of the images. See the documentation of thedfu_multi_image_writefunction in thedfu_multi_image.hfile for more details.
If the write commands for all chunks complete without errors, finish writing with
dfu_multi_image done successcommand.Schedule the update for the next reboot using
dfu_multi_image schedule_updatecommand.Reboot the device.
After the update completes, observe the following message on the terminal of the application core:
Starting dfu_multi_image sample, build time: <BUILD TIME>Observe the following message on the terminal of the network core:
Network core build time: <BUILD_TIME>The build time should reflect the new version in both cases.
To make the update permanent, use the
dfu_multi_image mcuboot_confirm <image_number>command. This step is optional and not applicable to the nRF5340 DK.<image_number>is0for the application core and1for the network core. Without this step, any image that is not confirmed will revert to the previous image on the next reboot.
Dependencies
This sample uses the following nRF Connect SDK libraries: