nRF51 SDK - S110 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Init packet handling

When updating the application on the chip, you can use an init packet in DFU to perform a safety check of the application image before it is transferred. This init packet provides a mechanism to include safety checks as part of the update procedure, so that a device accepts only compatible applications.

The init packet contains the following information that can be used for safety checks (see dfu_init_packet_t):

  • 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.0 and S110 v7.1.
  • Checksum: A 2-byte CRC-16-CCITT for the image to transfer.
dfu_init_packet.png
Figure 1: DFU Init packet

The nRF51 SDK provides a template, dfu_init_template.c, to perform safety checks of the init packet. This template can be used as starting point to develop procedures that increase the safety of DFU.

Device and revision type

The device and revision types can be stored in the user-reserved area of UICR (0x10001080) on the nRF51 chip. If this location is used for other purposes, update the offset UICR_CUSTOMER_DEVICE_INFO_OFFSET in dfu_init.h to match a free location in UICR.

#define UICR_CUSTOMER_DEVICE_INFO_OFFSET 0x0 /**< Device info offset inside the customer UICR reserved area. Customers may change this value to place the device information in a user-preferred location. */

The default value in UICR is 0xFFFF. If this value is present, any device and revision type provided in the init packet is accepted.

Application version

The DFU init packet supports checking the application version. The current Bootloader/DFU example does not use this feature. However, you should implement an application version check if required. Add this check to dfu_init_template.c.

If you add an application version check, every application must be compiled with a version ID. This version ID should be placed at a predefined location in the application image, for example at the application start address + 0x0100, similar to the principle used by Nordic SoftDevices.

See the following code snippet from dfu_init_template.c, which illustrates where to extend the DFU Init packet handling with an application version safety check:

// In order to support application versioning this check should be updated.
// This template allows for any application to be installed however customer could place a
// revision number at bottom of application to be verified by bootloader. This could be done at
// a relative location to this papplication for example Application start address + 0x0100.

SoftDevice list

Applications that are compiled for the nRF51 chip target a specific SoftDevice, for example S110 v7.1.0. Some applications might work with multiple SoftDevice versions if the API is backward compatible. For example, an application that is compiled for SoftDevice S110 v7.0.0 can also run on SoftDevice S110 v7.1.0.

You can provide a list of supported SoftDevices for the application that is to be installed in the DFU init packet. The DFU checks the list that is provided in the init packet against the currently installed SoftDevice on the chip and continues the update procedure only if a matching SoftDevice is installed.

A value of 0xFFFE indicates that the application should be installed regardless of the SoftDevice that is present. This feature can be helpful during development, but you should not use it in a product.

See the following table for the FWID values of current SoftDevices:

SoftDevice S110 FWID
S110 v7.0.0 0x004F
S110 v7.1.0 0x005A
Development/any 0xFFFE