DFU Target

This sample demonstrates the use of the Device Firmware Update (DFU) target functionality in the nRF Connect SDK. Currently, it only supports DFU targets for MCUboot.

Requirements

The sample supports the following development kit:

Hardware platforms

PCA

Board name

Board target

nRF7120 DK

nrf7120dk

nrf7120dk/nrf7120/cpuapp

nRF54L15 DK

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l15/cpuapp

nRF54H20 DK

PCA10175

nrf54h20dk

nrf54h20dk/nrf54h20/cpuapp

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

Overview

For simplicity, the sample does not include a transport layer for uploading a new image. Instead, a partition labeled dfu_target_helper is reserved in the board overlays.

Note

You must manually upload an image to this partition using nrfutil device.

Once the image has been uploaded, you can use the shell commands from the dfu_target group provided by this sample to test DFU target operations.

User interface

The sample’s interface is implemented using the shell, which is accessible via the serial port.

Building and running

This sample can be found under samples/dfu/dfu_target 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, perform the following steps:

  1. 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.

  2. Reset the development kit.

  3. Observe the following message on the terminal:

    ``Starting dfu_target sample, build time: <BUILD TIME>``
    

    <BUILD TIME> indicates the build time. It will be used later to verify the update.

  4. Build a second version of the sample. For simplicity, it is assumed to be built in the build_v2 directory.

  5. Use arm-zephyr-eabi-objcopy to link the contents of zephyr.signed.bin to the appropriate address:

    arm-zephyr-eabi-objcopy -I binary -O ihex --change-address <DFU_TARGET_HELPER_ADDRESS> build_v2/dfu_target/zephyr/zephyr.signed.bin  image_v2.hex
    

    Replace <DFU_TARGET_HELPER_ADDRESS> with the address of the dfu_target_helper partition, found in the board overlay file. Specifically, the address values are the following:

    Development Kit

    Address

    nRF52840 DK

    0xa8000

    nRF54H20 DK

    0xe092000

    nRF54L15 DK

    0xf2000

  6. Upload the second version of the image to the device using nrfutil device:

    nrfutil device program --firmware image_v2.hex  --options chip_erase_mode=ERASE_NONE
    
  7. Reset the development kit.

  8. Perform the update using one of the following methods:

    • Single-step update, running the following command:

      dfu_target full_update <image_size>
      

      <image_size> is the size, in bytes, of the file build_v2/dfu_target/zephyr/zephyr.signed.bin.

    • Step-by-step update:

      1. Get the image type:

        dfu_target image_type
        

        This command returns 1 for MCUBOOT.

      2. Initialize the image:

        dfu_target init <image_type> <image_size>
        

        <image_size> is the size, in bytes, of the file build_v2/dfu_target/zephyr/zephyr.signed.bin.

      3. Write the image either at once or in chunks:

        • To write the entire image at once, run:

          dfu_target write 0 <image_size>
          
        • To write the image in chunks, run the following commands as many times as there are chunks:

             dfu_target write <offset> <chunk_size>
          
          The ``<offset>`` is the offset in the ``dfu_target_helper`` partition from which to read the chunk.
          
      1. dfu_target done success.

      2. dfu_target schedule_update.

      3. Reboot the device.

  9. After the update completes, observe the following message on the terminal:

    ``Starting dfu_target sample, build time: <BUILD TIME>``
    

    The build time should reflect the new version.

  10. (Optional) To make the update permanent, use the dfu_target mcuboot_confirm command. Without this step, the device will revert to the previous image on the next reboot.

Dependencies

This sample uses the following nRF Connect SDK libraries: