nRF52840_Zigbee_OTA

Zigbee OTA Firmware Packaging

1. nRF52840 Feature list

1.1 Features

  • Bluetooth® 5, IEEE 802.15.4-2006, 2.4 GHz transceiver
    • -95 dBm sensitivity in 1 Mbps Bluetooth® low energy mode
    • -103 dBm sensitivity in 125 kbps Bluetooth® low energy mode (long range)
    • -20 to +8 dBm TX power, configurable in 4 dB steps
    • On-air compatible with nRF52, nRF51, nRF24L, and nRF24AP Series
    • Supported data rates:
      • Bluetooth® 5: 2 Mbps, 1 Mbps, 500 kbps, and 125 kbps
      • IEEE 802.15.4-2006: 250 kbps
      • Proprietary 2.4 GHz: 2 Mbps, 1 Mbps
    • Single-ended antenna output (on-chip balun)
    • 128-bit AES/ECB/CCM/AAR co-processor (on-the-fly packet encryption)
    • 4.8 mA peak current in TX (0 dBm)
    • 4.6 mA peak current in RX
    • RSSI (1 dB resolution)
  • ARM® Cortex® -M4 32-bit processor with FPU, 64 MHz
    • 212 EEMBC CoreMark score running from flash memory
    • 52 µA/MHz running CoreMark from flash memory
    • Watchpoint and trace debug modules (DWT, ETM, and ITM)
    • Serial wire debug (SWD)
  • Rich set of security features
    • ARM® TrustZone® Cryptocell 310 security subsystem
      • NIST SP800-90A and SP800-90B compliant random number generator
      • AES-128: ECB, CBC, CMAC/CBC-MAC, CTR, CCM/CCM*
      • Chacha20/Poly1305 AEAD supporting 128- and 256-bit key size
      • SHA-1, SHA-2 up to 256 bits
      • Keyed-hash message authentication code (HMAC)
      • RSA up to 2048-bit key size
      • SRP up to 3072-bit key size
      • ECC support for most used curves, among others P-256 (secp256r1) and Ed25519/Curve25519
      • Application key management using derived key model
    • Secure boot ready
      • Flash access control list (ACL)
      • Root-of-trust (RoT)
      • Debug control and configuration
      • Access port protection (CTRL-AP)
    • Secure erase
  • Flexible power management
    • 1.7 V to 5.5 V supply voltage range
    • On-chip DC/DC and LDO regulators with automated low current modes
    • 1.8 V to 3.3 V regulated supply for external components
    • Automated peripheral power management
    • Fast wake-up using 64 MHz internal oscillator
    • 0.4 µA at 3 V in System OFF mode, no RAM retention
    • 1.5 µA at 3 V in System ON mode, no RAM retention, wake on RTC
  • 1 MB flash and 256 kB RAM
  • Advanced on-chip interfaces
    • USB 2.0 full speed (12 Mbps) controller
    • QSPI 32 MHz interface
    • High-speed 32 MHz SPI
    • Type 2 near field communication (NFC-A) tag with wake-on field
      • Touch-to-pair support
    • Programmable peripheral interconnect (PPI)
    • 48 general purpose I/O pins
    • EasyDMA automated data transfer between memory and peripherals
  • Nordic SoftDevice ready with support for concurrent multiprotocol
  • 12-bit, 200 ksps ADC - 8 configurable channels with programmable gain
  • 64 level comparator
  • 15 level low-power comparator with wake-up from System OFF mode
  • Temperature sensor
  • 4x 4-channel pulse width modulator (PWM) unit with EasyDMA
  • Audio peripherals: I2S, digital microphone interface (PDM)
  • 5x 32-bit timer with counter mode
  • Up to 4x SPI master/3x SPI slave with EasyDMA
  • Up to 2x I2C compatible 2-wire master/slave
  • 2x UART (CTS/RTS) with EasyDMA
  • Quadrature decoder (QDEC)
  • 3x real-time counter (RTC)
  • Single crystal operation
  • Package variants
    • aQFN™ 73 package, 7 x 7 mm
    • WLCSP93 package, 3.544 x 3.607 mm

1.2 Applications

  • Advanced computer peripherals and I/O devices
    • Mouse
    • Keyboard
    • Multi-touch trackpad
  • Advanced wearables
    • Health/fitness sensor and monitor devices
    • Wireless payment enabled devices
  • Internet of things (IoT)
    • Smart home sensors and controllers
    • Industrial IoT sensors and controllers
  • Industrial IoT sensors and controllers
    • Remote controls
    • Gaming controllers

2. Memory layout

nRF52840

用途 地址範圍 大小 (KB)
Bootloader settings 0x000F_F000 - 0x0010_0000 4
MBR parameter storage 0x000F_E000 - 0x000F_F000 4
Bootloader 0x000F_8000 - 0x000F_E000 24
Zigbee settings 0x000E_C000 - 0x000F_8000 48
Application area (incl. free space) 0x0000_1000 - 0x000E_C000 940
Master Boot Record (MBR) 0x0000_0000 - 0x0000_1000 4

3. 工具安裝

4. Prepare Firmware

4.1 MBR setup

  • 打開命令窗口

    win + r

    cmd

  • 導航到 mbr.hex文件目錄

    1. 默認位置:$(nRF5_SDK_for_Thread_and_Zigbee_v3.2.0_9fade31)\components\softdevice\mbr\nrf52840\hex\mbr_nrf52_2.4.1_mbr.hex
  • 下載 mbr.hex

    nrfjprog -f nrf52 -r --program mbr_nrf52_2.4.1_mbr.hex --chiperase

4.2 Bootloader setup

  • 編譯 bootloader 工程

    1. 工程默認位置: $(nRF5_SDK_for_Thread_and_Zigbee_v3.2.0_9fade31)\examples\zigbee\ota\bootloader

    2. 下載 bootloader.hex(該文件位於工程目錄下的 _build目錄下)

      nrfjprog -f nrf52 -r --program nrf52840_xxaa_mbr.hex

4.3 OTA Upgrade Client setup

  • 編譯 app 工程
  1. 工程默認位置: $(nRF5_SDK_for_Thread_and_Zigbee_v3.2.0_9fade31)\examples\zigbee\ota\client
  2. 生成的文件 nrf52840_xxaa.hex位於工程目錄下的 _build目錄下

5. Firmware packaging

5.1 Make Firmware

  1. 產生公私鑰対,並將生成的公鑰添加到工程中的 dfu_public_key.c文件中,替換掉之前的公鑰。

    1. nrfutil keys generate priv.pem
    2. nrfutil keys display --key pk --format code priv.pem --out_file dfu_public_key.c
  2. 編譯 bootloader (詳見 Chapter 4.2)

  3. 編譯 app (詳見 Chapter 4.3) Note: 此時工程中的公鑰已替換爲第一步生成的公鑰

  4. 產生 bootloader配置文件

    1. nrfutil settings generate --family NRF52840 --application nrf52840_xxaa.hex --application-version 0x01010101 --bootloader-version 1 --bl-settings-version 2 --app-boot-validation VALIDATE_ECDSA_P256_SHA256 --key-file priv.pem settings.hex
  5. 合併 appbootloader 配置文件

    mergehex -m nrf52840_xxaa.hex settings.hex -o dfu_client.hex

5.2 Flash Firmware

  1. 通過 USB 連接 nRF52840 到電腦。

  2. 擦除全部 Flash

    nrfjprog -f nrf52 --eraseall

  3. 依次下載 MBR,Bootloader 和 merge 之後的 app 固件。(參見 Chapter 4)

    nrfjprog -f nrf52 -r --program mbr_nrf52_2.4.1_mbr.hex --chiperase

    nrfjprog -f nrf52 -r --program nrf52840_xxaa_mbr.hex

    nrfjprog -f nrf52 -r --program dfu_client.hex --sectorerase

5.3 Packaging New Firmware

nrfutil pkg generate --hw-version 52 --sd-req 0x00 --application-version 0x01020101 --application nrf52840_xxaa_new.hex --key-file priv.pem --app-boot-validation VALIDATE_ECDSA_P256_SHA256 app_dfu_package.zip --zigbee True --zigbee-manufacturer-id 123 --zigbee-image-type 321 --zigbee-comment good_image --zigbee-ota-hw-version 52 --zigbee-ota-fw-version 0x01020101

6. Processing Batch

6.1 Generate Key Pair

// 1. generate_key_pair.bat

cd %~dp0

:: 1. generate sm2 key-pair
nrfutil keys generate ./key/priv.pem

:: 2. generate pub_key code
nrfutil keys display --key pk --format code ./key/priv.pem --out_file ./key/dfu_public_key.c

echo finish !

pause

6.2 Signature Firmware

// 2. signature_firmware.bat

cd %~dp0

set firmware_version=0x00000001

set /p firmware_version=input packaging firmware version (default: 0x00000001):
echo %firmware_version%

:: 1. generate bootloader setting file:settings.hex
nrfutil settings generate --family NRF52840 --application ./firmware/nrf52840_xxaa.hex --application-version %firmware_version% --bootloader-version 1 --bl-settings-version 2 --app-boot-validation VALIDATE_ECDSA_P256_SHA256 --key-file ./key/priv.pem ./gen/settings.hex

:: 2. merge app and bootloader
mergehex -m ./firmware/nrf52840_xxaa.hex ./gen/settings.hex -o ./gen/dfu_client.hex


:: 3. program flash
:: 3.1 erase all flash
nrfjprog -f nrf52 --eraseall

:: 3.2 flash mbr
nrfjprog -f nrf52 -r --program ./firmware/mbr_nrf52_2.4.1_mbr.hex --chiperase

:: 3.3 flash bootloader
nrfjprog -f nrf52 -r --program ./firmware/nrf52840_xxaa_mbr.hex

:: 3.4 flash app
nrfjprog -f nrf52 -r --program ./gen/dfu_client.hex --sectorerase

echo finish !

pause

6.3 Pack OTA

// 3. pack_ota.bat

cd %~dp0

set firmware_version=0x00000002
set manufacturer_id=0x007B
set image_type=0x0141

set /p firmware_version=input ota firmware version (default: 0x00000002):
set /p manufacturer_id=input ota manufacturer id (default: 0x007B):
set /p image_type=input ota image type (default: 0x0141):
echo "firmware_version: %firmware_version%"
echo "manufacturer_id: %manufacturer_id%"
echo "image_type: %image_type%"

nrfutil pkg generate --hw-version 52 --sd-req 0x00 --application-version %firmware_version% --application ./firmware/nrf52840_xxaa_new.hex --key-file ./key/priv.pem --app-boot-validation VALIDATE_ECDSA_P256_SHA256 app_dfu_package.zip --zigbee True --zigbee-manufacturer-id %manufacturer_id% --zigbee-image-type %image_type% --zigbee-comment good_image --zigbee-ota-hw-version 52 --zigbee-ota-fw-version %firmware_version%


echo finish !

pause
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章