Article Directory
related articles
1. "[Nordic] nRF52810 OTA upgrade (1)-DFU environment setup"
2. "[Nordic] nRF52810 OTA upgrade (2)-How to use DFU"
3. "[Nordic] nRF52810 OTA upgrade (3)-DFU theoretical analysis 》
1 Introduction
This article is based on "[Nordic] nRF52810 OTA Upgrade (1)-DFU Environment Setup" to implement the DFU OTA firmware upgrade function.
2. Generate micro_ecc_lib_nrf52.lib library
Nordic will use ECC to verify and authenticate firmware when using DFU for OTA upgrade, so it needs to be produced in the DFU project micro_ecc_lib_nrf52.lib
.
-
micro-ecc-master
Copy the source code downloaded in the previous article to the SDK directoryexternal\micro-ecc
and rename itmicro-ecc
-
Open the Cygwin command line
-
cd to the micro-ecc project directory:
nRF5_SDK_17.0.2_d674dde\external\micro-ecc\nrf52nf_keil\armgcc
-
Execute
make
command
here because there is no tool to find gcc error occurs, modify the file:nRF5_SDK_17.0.2_d674dde\components\toolchain\gcc\Makefile.windows
theGNU_INSTALL_ROOT := C:/Program Files (x86)/GNU Tools ARM Embedded/9 2019-q4-major/bin/ GNU_VERSION := 9.2.1 GNU_PREFIX := arm-none-eabi
Modify the actual installation directory of gcc:
GNU_INSTALL_ROOT := D:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/ GNU_VERSION := 10.2.1 GNU_PREFIX := arm-none-eabi
Execute again
make
and the compilation is successful.
3. Generate dfu_public_key.c and join
- Generate a private key
Create a new folder in the D drive, name it key, and enter the following in the cmd command:nrfutil keys generate D:\key\private.key
command, generate a private key file private.key
Note: To save the private key private.key, every new firmware upgrade in the future must be signed with this private key. Once lost, DFU will not be able to proceed.
- Generate public key
Enter the command to generate public key:nrfutil keys display --key pk --format code D:\key\private.key --out_file public_key.c
produce public key public_key.c on the desktop
- Add the public key to the project.
Rename the public key public_key.c to dfu_public_key.c, and replace the file withnRF5_SDK_17.0.2_d674dde\examples\dfu
dfu_public_key.c in thedirectory
4. Compile the bootloader
Because of the nRF52810 platform I use here , I choose the dfu bootloader path as follows:
nRF5_SDK_17.0.2_d674dde\examples\dfu\secure_bootloader\pca10040e_s112_ble\arm5_no_packs
Compilation is successful:
5. Burn bootloader and SoftDevice hex files
Use jlink to burn bootloader
and SoftDevice
:
- Burn bootloader
nRF5_SDK_17.0.2_d674dde\examples\dfu\secure_bootloader\pca10040e_s112_ble\arm5_no_packs\_build\nrf52810_xxaa_s112.hex
- Burn SoftDevice
nRF5_SDK_17.0.2_d674dde\components\softdevice\s112\hex\s112_nrf52_7.2.0_softdevice.hex
After burning, use the nRF Connect
APP installed on the phone to search for BLE, and DfuTarg appears to indicate that it has entered the bootloader mode. Because application hex is not burned, it directly enters the bootloader mode.
6.nRF Connect APP for OTA upgrade
Upgrade the application firmware to the firmware compiled in the previous project:nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_uart\pca10040e\s112\arm5_no_packs\_build
-
Make an OTA upgrade package
nrfutil pkg generate --hw-version 52 --application-version 1 --application nrf52810_xxaa.hex --sd-req 0x0103 --key-file D:\key\private.key dfufile.zip
-
Copy the OTA upgrade package
dfufile.zip
to the phone -
Connect BLE DfuTarg
-
Click the small DFU icon in the upper right corner and select the ZIP file
dfufile.zip
-
during upgrade…
-
The upgrade is successful, and the name Nordic_UART of application ble appears, as shown in the figure below:
7. Errors that occur
-
Error 1
..\..\..\..\..\components\libraries\crypto\backend\micro_ecc\micro_ecc_backend_ecc.h(52): error: #5: cannot open source input file "uECC.h": No such file or directory #include "uECC.h" ..\..\..\..\..\components\libraries\bootloader\dfu\nrf_dfu_validation.c: 0 warnings, 1 error
Error analysis:
Prompt that theuECC.h
header file isnot found.
Solution:
Refer to 2. Generate micro_ecc_lib_nrf52.lib library to solve the problem. -
Error 2
compiling dfu_public_key.c... ..\..\..\dfu_public_key.c(20): error: #35: #error directive: "Debug public key not valid for production. Please see https://github.com/NordicSemiconductor/pc-nrfutil/blob/master/README.md to generate it" #error "Debug public key not valid for production. Please see https://github.com/NordicSemiconductor/pc-nrfutil/blob/master/README.md to generate it" ..\..\..\dfu_public_key.c: 0 warnings, 1 error
Error analysis:
There is no valid dfu encryption public key.
Solution:
Refer to 3. Generate dfu_public_key.c and add it to solve the problem.