Creating zip package for DFU

Introduction

This blog will aim to give you an understanding of the zip package required to perform a Device Firmware Upgrade of your device. This blog will apply to the newest tools available to do this, including the SDK, the mobile app, or the master control panel for Windows.

This blog is based on this document on creating the INIT file for DFU found on github.

Required Tools

ZIP-file

With a bootloader in place, it is possible to perform a Device Firmware Upgrade of either the application, softdevice, or the bootloader itself. It is also possible to upgrade a combination of these at the same time. In order to do this, a common format has been adopted regarding the package used to perform the upgrade. This is done so that the same package can be used with any method, for example using the android app, or master control panel on Windows. Since it is also possible to upgrade several things at the same time, some additional meta-data about the package is required. This meta-data is in the form of an init file that is included in the same zip file with the binaries.

Hex file

When Keil successfully compiles your project a .hex and a .axf(ELF) image is created, these are typically located in the same folder as your µVision5 project, e.g. "..\pca10028\dual_bank_ble_s110\arm5_build".

New in Master Control Panel version 3.9.0 is the option of applying DFU directly from the .hex file of our application/bootloader/softdevice to the device with an automatically created init file. However if we want to update more than one of these at the same time we still have to use the .zip structure.

Binary file

We now have hex and AXF(ELF) versions of our application, however to create our ZIP-file we can also make a binary .bin version. This is done using the command line tool fromelf.exe. Make sure that you are running your command line with administrator privileges. This tool is located in the "KeilFolder\ARM\ARMCC\bin" folder. Call fromelf.exe to convert an AXF(ELF) image to a binary file like this(without quotations):

"Keil-folder"\ARM\ARMCC\bin\fromelf.exe --bin --output "outfile.bin" "infile.axf"

Successfull output, no errors, and .bin file has been generated in our folder.

image description

When doing this with a bootloader update, due to a UICR error the output from fromelf.exe will be a folder with two files in it, example shown below.

Working with our example a simple workaround is to rename the circled file to "mybinary.bin", and then use this file.

Init file

The init file is not only telling the bootloader what files are being updated, but it works as a safety mechanism to ensure that the transferred files are compatible, and have been received correctly. When performing a DFU, the init packet is transferred first, and the binary is then checked to see if it is correct. The contents of the init packet are presented below:

image description

  • Device type: A 2-byte value specified by the developer that identifies the device type, for example Heart Rate Belt.
  • Device revision: A 2-byte value that can be used to restrict the update to be accepted only on devices with a defined revision number.
  • Application version: A 4-byte value identifying the version of the application that is being transferred. This value can be used to allow only software upgrades and prevent downgrades. No example code is provided for this feature.
  • Supported SoftDevices: A list of 2-byte values identifying the SoftDevices that are compatible with the application, for example, S110 v7.1 or S110 v8.0.
  • Checksum: A 2-byte CRC-16-CCITT for the image to transfer.

Creating this init file can be difficult, but fortunately there is a tool that creates the entire zip package. the nrf.exe tool which comes with the master control panel can be used for this. The program is located in "C:\Program Files (x86)\Nordic Semiconductor\Master Control Panel\version\nrf" and its usage is explained here.

The input it takes is a binary or hex of the application, softdevice, or bootloader you wish to upgrade. Other parameters include the desired settings above. It will then calculate a CRC value, create an init file that matches the binary, and place the binary and the init file in a zip-file.

The init file, called manifest.json, will contain all the necessary meta-data for the bootloader. A typical file will look like this:

{
    "manifest": {
        "application": {
            "bin_file": "application.bin",
            "dat_file": "application.dat",
            "init_packet_data": {
                "application_version": 4294967295,
                "device_revision": 65535,
                "device_type": 65535,
                "firmware_crc16": 4837,
                "softdevice_req": [
                    65534
                ]
            }
        }
    }
}

Creating the ZIP-file

You can add the following firmware images in binary or hex format to the zip file:

  • application image.bin: a binary or hex image of an application
  • bootloader image.bin: a binary or hex image of a bootloader
  • softdevice image.bin: a binary or hex image of a SoftDevice

You can also combine several images in one zip file.

In addition to the images, you must specify the information that will be added to the init packet:

  • application-version version: the version of the application image, for example, 0xff
  • dev-revision version: the revision of the device that should accept the image, for example, 1
  • dev-type type: the type of the device that should accept the image, for example, 1
  • sd-req sd_list: a comma-separated list of FWID values of SoftDevices that are valid to be used with the new image, for example, 0x4f,0x5

Here is an example call of the nrf.exe ZIP-creating tool, with input and output files placed in the same folder nrf.exe as, note that you can also use pointers to different locations. Again, make sure that you are running your command line with administrator privileges.

\Nordic Semiconductor\Master Control Panel\"version"\nrf\nrf.exe dfu genpkg example.zip --bootloader ex_bootloaderimage.hex --application-version 0xff --dev-revision 1 --dev-type 1 --sd-req 0x4f,0x5

Command line success message: image description

Final notes

It is highly recommended to use the DFU from hex feature from Master Control Panel v. 3.9, as it significantly reduces the workload when working with your device.

Further reading

  • Hi,

    I have created dfu package using following command but not included init packet in 4744.sd_app_dfu_package_v3.zip file.

    nrfutil pkg generate --hw-version 2 --sd-req 0xAF --sd-id 0xAF --softdevice C:\nRF5_SDK_15.2.0_9412b96\nRF5_SDK_15.2.0_9412b96\components\softdevice\s132\hex\s132_nrf52_6.1.0_softdevice.hex --application-version 2 --application C:\nRF5_SDK_15.2.0_9412b96\nRF5_SDK_15.2.0_9412b96\examples\ble_central\test\pca10040\s132\arm5_no_packs\_build\nrf52832_xxaa.hex sd_app_dfu_package_v3.zip

  • hi i am using NRF52 SDK11 s132v2.0.0 and using command line tools to generate zip file for OTA. when i created zip and able to upload using NRFToolbox, the problem is after uploading to board using mobile app it is giving that upload success but the uploaded firmware on board is not running.

    i am using fallowing command to make zip file.

    nrfutil dfu genpkg --application Users/saiteja/Desktop/nRF5_SDK_11.0.0_89a8197/examples/ble_peripheral/ble_app_hrs/hex/ble_app_hrs_s132_pca10040.hex --application-version 0xff --dev-revision 0xff --dev-type 0xffff --sd-req 0x81 /Desktop/myAPp.zip

  • when you got an error like no such command "genpkg", you tried to reset your PC if it is the first time you install this control panel.

  • I used nrfutil.exe dfu genpkg, i am getting error (no such command "genpkg").

  • followed the instructions and it works but when i try to Load the DFUTarg example to nRF51DK from Keil why it never completes. although when i restart Kit it comes in search as DFUTarg. i used the blink example from my iphone App and it worked but only 1 LED was blinking. However if you load it from Keil all 4 LEDs blink repeatedly. do you think it has something to do with the DFUTarg App? I am using it on top of S130 thanks