| Nordic Thingy:52 v2.0.0

OTA-DFU - Generating your own packages

The following procedures assume that you are working with your own custom firmware. You will need to do the following to generate your own packages:

1. Generate your own public and private key pair.
2. Generate a custom bootloader.
3. Generate custom bootloader settings.

To run these tasks, you will require nrfutil.

# Replacing the public key

Before you can generate DFU packages, you must first generate new keys. Cryptographic keys are required to sign and validate a Device Firmware Update package. Before running your own custom DFU, you must generate your own private-public key pair.

To generate a new private key, run the following command with nrfutil installed:

nrfutil keys generate private-key.pem

Make sure you keep this key secret. The command generates the new key file in the folder where you ran the command.

Now, generate a public key from the private one:

nrfutil keys display --key pk --format code private-key.pem --out_file dfu_public_key.c

Copy the public_key.c from where you generated it to `<InstallFolder>\project\bootloader_secure\dfu_public_key.c`.

# Generating the bootloader

To generate a new bootloader, compile the `Bootloader` project using either Keil μVision or GCC. Flash the compiled bootloader onto Thingy. Remember to flash the SoftDevice as well for the OTA-DFU to function properly.

# Generating a DFU package

Run `nrfutil pkg generate` to generate a ZIP file that you can later use with a mobile or desktop application to update the Thingy firmware, as described in nrfutil documentation. For example:

nrfutil pkg generate --application <path_to_hex_file> --application-version 0 --hw-version 52 --sd-req 0x98 --key-file private-key.pem dfu-app.zip

## Version requirements

This command contains essential information about the versions of the application and of the hardware. These versions determine whether it will be possible to perform a valid DFU process. DFU is only possible if:

- The application version is greater than or equal to the previous application version.
  Note
    If an existing app is replaced with a new one with a higher version number, Thingy will reinitialize parts of its flash storage, and BLE configurable settings will revert to default.
- The hw-version property is the same as in the previous version.
- The bootloader version is greater than the previous bootloader version (bootloader version is provided when you update the bootloader).

# Manual firmware assembly

A firmware package which supports OTA-DFU must consist of the following four elements:

- Application
- SoftDevice
- Bootloader
- Bootloader settings

## Bootloader settings

Bootloader settings is a special area in the bootloader that contains information about the DFU process, as well as information about the versions of the application and the bootloader. You must generate your own bootloader settings file for your custom application. See nrfutil documentation for information on how to generate the bootloader settings file. Refer to Version requirements and make sure that you set correct versions when generating the bootloader settings file.

# Running a DFU with a custom package

When your custom package is ready, follow the procedure in OTA-DFU with nRF Connect to run an OTA-DFU.