玩 Example - BLE Secure DFU Bootloader@nRF52832 - PCA10040 - S132 DK開發板

動機:要如何在 nRF52832 - PCA10040 S132 DK開發板上測試 BLE Secure DFU Bootloader 範例呢?!

準備環境
1.Windows10/MacBook筆電 (安裝VirtualBox 5.2.6 + Ubuntu 17.10虛擬機)
2.nRF52832 - S132 DK開發板(需連接USB數據線)
3.Using the GCC makefile of an example

Bootloader modules 如下圖

實作步驟
1.Configuration parameters
$ cd ~/opt/nRF5_SDK_14.2.0_17b948a/examples/dfu/bootloader_secure_ble/pca10040/config
$ nano sdk_config.h
增加內容如下
// BLE Secure DFU Bootloader
// To implement a bootloader with secure Device Firmware Update (DFU) functionality.
#ifndef NRF_DFU_INACTIVITY_TIMEOUT_MS
#define NRF_DFU_INACTIVITY_TIMEOUT_MS 120000
#endif

#ifndef NRF_DFU_POST_SD_BL_TIMEOUT_MS
#define NRF_DFU_POST_SD_BL_TIMEOUT_MS 10000
#endif

the source code and the project file目錄
~/opt/nRF5_SDK_14.2.0_17b948a/examples/dfu/bootloader_secure_ble

Button assignments
Button 4: Holding this button during startup makes the device enter DFU mode.
LED1, LED3會亮...

Working with keys
# Generate a private key in c:\vault\priv.pem
$ nrfutil keys generate priv.pem
# Display the generated private key (in little-endian format)
$ nrfutil keys display --key sk --format hex priv.pem
# Display the generated private key (in code format to be used with nrf_crypto)
$ nrfutil keys display --key sk --format code priv.pem
# Display the public key that corresponds to the generated private key (in little-endian format)
$ nrfutil keys display --key pk --format hex priv.pem
# Display the public key that corresponds to the generated private key (in code format to be used with nrf_crypto)
$ nrfutil keys display --key pk --format code priv.pem
# Write the public key that corresponds to the generated private key to the file public_key.c (in code format)
$ nrfutil keys display --key pk --format code priv.pem --out_file dfu_public_key.c

install micro-ecc
$ cd ~/opt/nRF5_SDK_14.2.0_17b948a/external/micro-ecc
$ git clone https://github.com/kmackay/micro-ecc.git
$ cd nrf52hf_armgcc/armgcc
$ make
$ cd ../..
$ cd nrf52hf_iar/armgcc
$ make
$ cd ../..
$ cd nrf52hf_keil/armgcc
$ make
$ cd ../..
$ cd nrf52nf_armgcc/armgcc
$ make
$ cd ../..
$ cd nrf52nf_iar/armgcc
$ make
$ cd ../..
$ cd nrf52nf_keil/armgcc
$ make
$ cd ../..

Testing
$ cd examples/dfu
$ mkdir ble_dfu_send_hex
$ cd dfu/ble_dfu_send_hex
$ nrfutil keys generate priv.pem
$ nrfutil keys display --key pk --format code priv.pem --out_file dfu_public_key.c

$ cp ../secure_dfu_test_images/ble/nrf52832/ble_app_buttonless_dfu_with_bonds_s132.zip .
$ cp ../secure_dfu_test_images/ble/nrf52832/ble_app_buttonless_dfu_with_bonds_s132_with_setting_page.hex .
$ cp ../secure_dfu_test_images/ble/nrf52832/softdevice_bootloader_secure_ble_debug_with_bonds_s132.* .

$ cd dfu_req_handling
nrfutil keys generate priv.pem
nrfutil keys display --key pk --format code priv.pem --out_file dfu_public_key.c

$ cd ../../dfu/bootloader_secure_ble/pca10040/armgcc/
$ make
如下圖

$ make flash
如下圖

With nrfutil:
$ cd ../../../ble_dfu_send_hex/
$ nrfutil dfu ble -ic NRF52 -f -pkg softdevice_bootloader_secure_ble_debug_with_bonds_s132.zip
會出現錯誤,如下圖

使用 nRF Toolbox app:
按下 DFU
按下 SELECT DEVICE (選 DfuTarg F6:88:DC:56:47:47)
按下 SELECT FILE (選 Distribution packet(ZIP), 按 OK, 選 雲端硬碟, 我的雲端硬碟, 選 softdevice.zip)
按下 UPLOAD...


1) Erase the device: nrfjprog -e --family NRF52
2) Generate the bootloader settings: nrfutil settings generate --family NRF52 --application pollen_device.hex --application-version 0x01 --bootloader-version 0 --bl-settings-version 1 bootloader_setting.hex
3) Upload the settings: nrfjprog --program bootloader_setting.hex --family NRF52
4) Upload the bootloader: nrfjprog --reset --program nrf52832_xxaa_s132.hex --family NRF52
5) Upload the softdevice: nrfjprog --reset --program s132_nrf52_4.0.2_softdevice.hex --family NRF52
6) Upload the app firmware: nrfjprog --reset --program s132_nrf52_4.0.2_softdevice.hex --family NRF52

參攷
1.BLE Secure DFU Bootloader, https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v14.2.0%2Fble_sdk_app_dfu_bootloader.html&cp=4_0_0_4_4_0
2.

留言