nRF5 IoT SDK
v0.9.0
|
The firmware image has to be in a binary format, so Intel HEX files must be converted to the correct format.
One alternative is to use the hex2bin available from SourceForge. In addition, each part of the firmware has to be correctly aligned, which is detailed in the sections below.
We provide SoftDevice HEX files that are compiled. In order to prepare a SoftDevice to be upgraded, removing the MBR part of it is necessary. This part has several calls that are used by the bootloader to copy the new firmware (like a new SoftDevice or bootloader), and cannot be overwritten.
MBR for nRF52 consists of 0x3000 bytes. To convert softdevice.hex to softdevice.bin use the following commands:
For nRF52:
The application is usually aligned with the size of the SoftDevice. A simple conversion will result in huge padding (equal to the size of the SoftDevice) inside the binary file. To avoid that, removing the SoftDevice's memory space is needed. The actual size of the SoftDevice where the application runs can be found in related documentation, project settings, linker scripts, or retrieved from the HEX file.
Lines in Intel HEX have the following format:
where:
Each application (compiled to use a SoftDevice) starts with an address command.
Where XXXX is a starting point of addressing inside following HEX lines. To read it, multiply this value with 2^16:
is:
The next step is to get the start address (BBBB) from the first line with data and add the previous value to it. For example:
Which finally gives an address:
After obtaining the start address, the HEX file can be converted into binary form using the following command:
For the examples above this will be:
Bootloader conversion is similar to application conversion. After obtaining the correct start address, the following procedure works.
Example:
In order to create a binary file that consists of a SoftDevice and application binary files, execute the following commands:
To get the checksum of the binary file, our CRC16 library can be used. It can be found at SDK_PATH/components/libraries/crc16/crc16.c. The following code snippet shows how to use the crc16_compute
function and compile it on a computer:
The above program can be compiled using the following command:
The program reads an argument passed in the command line, treats it as a file path, calculates CRC16, and displays it in the standard output. Example usage: