본문으로 바로가기

[nrfutil ] 명령어 사용법

category Nordic_nRF52 2022. 4. 14. 15:31

 

 :  파이션으로 만들어지 앱으로 DFU  및 암호화를 지원하는 명령줄 유틸리티(command-line utility) 입니다.

 

목차

     

     

    0> Nordic Document 

    https://infocenter.nordicsemi.com/topic/ug_nrfutil/UG/nrfutil/nrfutil_intro.html

     

    nRF Util

    The nRF Util application is a Python package and command-line utility that supports Device Firmware Update (DFU) and cryptographic functionality. The nRF Util application and its library has the following features: DFU package generation Cryptographic key

    infocenter.nordicsemi.com

     

    1> 기능

      : DFU 패키지 생성하기

       개인키 생성/관리/저장하기

        Bootloader settings 생성하기

        지원하는 DFU 인터페이스

          ▶ BLE

          Serial ( UART or USB)

          ▶ Thread unicast

           Thread multicast

           Zigbee

          ANT™

     

    2> 이미지 조합 ( Bootloader , SoftDevice , Application )

        : BL + APP 만 안되고 나머지는 명령 조합으로 가능합니다.

      2-1> nrfutil pkg generate  --help 

    D:\Project\SES\nrfutil>nrfutil pkg generate --help
    Usage: nrfutil pkg generate [OPTIONS] ZIPFILE
    
      Generate a zip package for distribution to apps that support Nordic DFU
      OTA. The application, bootloader, and SoftDevice files are converted to
      .bin if supplied as .hex files. For more information on the generated
      package, see: http://developer.nordicsemi.com/nRF5_SDK/doc/
    
      The following combinations are supported by this command:
    
      * BL only: Supported.
    
      * SD only: Supported (SD of same Major Version).
    
      * APP only: Supported (external or internal).
    
      * BL + SD: Supported.
    
      * BL + APP: Not supported (use two packages instead).
    
      * BL + SD + APP: Supported.
    
      * SD + APP: Supported (SD of same Major Version).
    
    Options:
      --debug-mode                    Debug mode switch, enables version check
                                      skipping.
      --application TEXT              The application firmware file.
      --application-version INTEGER   The application version.
      --application-version-string TEXT
                                      The application version string, e.g.
                                      "2.7.31". Will be converted to an integer,
                                      e.g. 207031.
      --bootloader TEXT               The bootloader firmware file.
      --bootloader-version INTEGER    The bootloader version.
      --hw-version INTEGER            The hardware version.
      --sd-req TEXT                   The SoftDevice requirements. A comma-
                                      separated list of SoftDevice firmware IDs (1
                                      or more) of which one must be present on the
                                      target device. Each item on the list must be
                                      a two- or four-digit hex number prefixed
                                      with "0x" (e.g. "0x12", "0x1234").
                                      A non-
                                      exhaustive list of well-known values to use
                                      with this option follows:
                                      |s112_nrf52_6.0.0|0xA7|
                                      |s112_nrf52_6.1.0|0xB0|
                                      |s112_nrf52_6.1.1|0xB8|
                                      |s112_nrf52_7.0.0|0xC4|
                                      |s112_nrf52_7.0.1|0xCD|
                                      |s113_nrf52_7.0.0|0xC3|
                                      |s113_nrf52_7.0.1|0xCC|
                                      |s130_nrf51_1.0.0|0x67|
                                      |s130_nrf51_2.0.0|0x80|
                                      |s132_nrf52_2.0.0|0x81|
                                      |s130_nrf51_2.0.1|0x87|
                                      |s132_nrf52_2.0.1|0x88|
                                      |s132_nrf52_3.0.0|0x8C|
                                      |s132_nrf52_3.1.0|0x91|
                                      |s132_nrf52_4.0.0|0x95|
                                      |s132_nrf52_4.0.2|0x98|
                                      |s132_nrf52_4.0.3|0x99|
                                      |s132_nrf52_4.0.4|0x9E|
                                      |s132_nrf52_4.0.5|0x9F|
                                      |s132_nrf52_5.0.0|0x9D|
                                      |s132_nrf52_5.1.0|0xA5|
                                      |s132_nrf52_6.0.0|0xA8|
                                      |s132_nrf52_6.1.0|0xAF|
                                      |s132_nrf52_6.1.1|0xB7|
                                      |s132_nrf52_7.0.0|0xC2|
                                      |s132_nrf52_7.0.1|0xCB|
                                      |s140_nrf52_6.0.0|0xA9|
                                      |s140_nrf52_6.1.0|0xAE|
                                      |s140_nrf52_6.1.1|0xB6|
                                      |s140_nrf52_7.0.0|0xC1|
                                      |s140_nrf52_7.0.1|0xCA|
                                      |s212_nrf52_6.1.1|0xBC|
                                      |s332_nrf52_6.1.1|0xBA|
                                      |s340_nrf52_6.1.1|0xB9|
      --sd-id TEXT                    The new SoftDevice ID to be used as --sd-req
                                      for the Application update in case the ZIP
                                      contains a SoftDevice and an Application.
      --softdevice TEXT               The SoftDevice firmware file.  
      --sd-boot-validation [NO_VALIDATION|VALIDATE_GENERATED_CRC|VALIDATE_GENERATED_SHA256|VALIDATE_ECDSA_P256_SHA256]
                                      The method of boot validation for
                                      Softdevice.
      --app-boot-validation [NO_VALIDATION|VALIDATE_GENERATED_CRC|VALIDATE_GENERATED_SHA256|VALIDATE_ECDSA_P256_SHA256]
                                      The method of boot validation for
                                      application.
      --key-file FILE                 The private (signing) key in PEM format.
      --external-app                  Indicates that the FW upgrade is intended to
                                      be passed through (not applied on the
                                      receiving device)
      --zigbee BOOLEAN                Create an image and distribution package for
                                      Zigbee DFU server.
      --zigbee-manufacturer-id INTEGER
                                      Manufacturer ID to be used in Zigbee OTA
                                      header.
      --zigbee-image-type INTEGER     Image type to be used in Zigbee OTA header.
      --zigbee-comment TEXT           Firmware comment to be used in Zigbee OTA
                                      header.
      --zigbee-ota-hw-version INTEGER
                                      The zigbee OTA hw version.
      --zigbee-ota-fw-version INTEGER
                                      The zigbee OTA fw version.
      --zigbee-ota-min-hw-version INTEGER
                                      The zigbee OTA minimum hw version of Zigbee
                                      OTA Client.
      --zigbee-ota-max-hw-version INTEGER
                                      The zigbee OTA maximum hw version of Zigbee
                                      OTA Client.
      --help                          Show this message and exit.

     

      2-2> application dfu 패키지 만들기

        : nrf52832 chip 기준 명령어 예제

          application-version 은 적당히 알아서 넣으세요.

        nrfutil pkg generate --hw-version 52 --application-version 2 ^
           --application  app_name.hex ^
           --sd-req 0x101 --key-file private.key app_dfu_package.zip

     

     > bootloader dfu 패키지 만들기

        : bootloader-version 은 적당히 알아서 넣으세요.

    D:\Project\SES\nrfutil>nrfutil.exe pkg generate --hw-version 52 --bootloader-version 21 ^
              --bootloader secure_bootloader_ble_s132_pca10040_V021.hex ^
              --key-file private.key --sd-req 0x101 dfu_bl_v021.zip 
    
    --> 정상적 Output 메시지
    Zip created at dfu_bl_v021.zip

     

      2-3> bootloader + Softdevice + application 패키지 만들기

    nrfutil pkg generate --hw-version 52 --application-version 2 ^
       --application app_name.hex ^
       --sd-id 0x101 --softdevice s132_nrf52_7.2.0_softdevice.hex ^
       --bootloader-version  21 ^
       --bootloader secure_bootloader_ble_s132_pca10040_V021.hex ^
       --sd-req 0x101 --key-file private.key dfu_sd_bl_app_package.zip

      >> 위 명령 실행한  폴더 첨부합니다.

     

     

      위 파일중  s132_nrf52_7.2.0_softdevice.hex 파일의 오리지널 위치는 아래와 같습니다.

        <Install Dir>\components\softdevice\s132\hex\

     3> dfu 명령

    D:\Project\SES\nrfutil>nrfutil dfu --help
    Usage: nrfutil dfu [OPTIONS] COMMAND [ARGS]...
    
      This set of commands supports Device Firmware Upgrade procedures over both
      BLE and serial transports.
    
    Options:
      --help  Show this message and exit.
    
    Commands:
      ant         Update the firmware on a device over an ANT connection.
      ble         Update the firmware on a device over a BLE connection.
      serial      Update the firmware on a device over a UART serial connection.
                  The DFU target must be a chip using digital I/O pins as an UART.
      thread      Update the firmware on a device over a Thread connection.
      usb-serial  Update the firmware on a device over a USB serial connection.
                  The DFU target must be a chip with USB pins (i.e. nRF52840) and
                  provide a USB ACM CDC serial interface.
      zigbee      Update the firmware on a device over a Zigbee connection.

     

     3-1> dfu thread 

    D:\Project\SES\nrfutil>nrfutil dfu thread --help
    Usage: nrfutil dfu thread [OPTIONS]
    
      Perform a Device Firmware Update on a device that supports Thread DFU.
      This requires a second nRF device, connected to this computer, with Thread
      Network CoProcessor (NCP) firmware loaded. The NCP device will perform the
      DFU procedure onto the target device.
    
    Options:
      -pkg, --package FILE            Filename of the DFU package.  [required]
      -p, --port TEXT                 Serial port COM port to which the NCP is
                                      connected.
      -a, --address TEXT              Device IPv6 address. If address is not
                                      specified then perform DFU on all capable
                                      devices. If multicast address is specified
                                      (FF03::1), perform multicast DFU.
      -sp, --server_port INTEGER      UDP port to which the DFU server binds. If
                                      not specified the 5683 is used.
      --panid INTEGER                 802.15.4 PAN ID. If not specified then 1234
                                      is used as PAN ID.
      --channel INTEGER               802.15.4 Channel. If not specified then
                                      channel 11 is used.
      -snr, --jlink_snr TEXT          Jlink serial number.
      -f, --flash_connectivity        Flash NCP connectivity firmware
                                      automatically. Default: disabled.
      -s, --sim                       Use software NCP and connect to the OT
                                      simulator.
      -r, --rate FLOAT                Multicast upload rate in blocks per second.
      -rs, --reset_suppress <delay_in_ms>
                                      Suppress device reset after finishing DFU
                                      for a given number of milliseconds. If -1 is
                                      given then suppress indefinatelly.
      -m, --masterkey TEXT            Masterkey. If not specified then
                                      00112233445566778899aabbccddeeff is used
      --help                          Show this message and exit.

     

      3-2> dfu ble 

    D:\Project\SES\nrfutil>nrfutil dfu ble --help
    Usage: nrfutil dfu ble [OPTIONS]
    
      Perform a Device Firmware Update on a device with a bootloader that
      supports BLE DFU. This requires a second nRF device, connected to this
      computer, with connectivity firmware loaded. The connectivity device will
      perform the DFU procedure onto the target device.
    
    Options:
      -pkg, --package FILE            Filename of the DFU package.  [required]
      -ic, --conn-ic-id [NRF51|NRF52]
                                      Connectivity IC family: NRF51 or NRF52
                                      [required]
      -p, --port TEXT                 Serial port COM port to which the
                                      connectivity IC is connected.
      -cd, --connect-delay INTEGER    Delay in seconds before each connection to
                                      the target device during DFU. Default is 3.
      -n, --name TEXT                 Device name.
      -a, --address TEXT              BLE address of the DFU target device.
      -snr, --jlink_snr TEXT          Jlink serial number for the connectivity IC.
      -f, --flash_connectivity        Flash connectivity firmware automatically.
                                      Default: disabled.
      -mtu, --att-mtu INTEGER RANGE   ATT MTU. Maximum ATT packet size for BLE
                                      transfers. Accepted values in range [23,
                                      247]. Default is 247. Note: Failing DFU
                                      transmissions can in some cases be solved by
                                      setting a lower mtu.
      --help                          Show this message and exit.

     

     

      3-3> dfu serial

    $>nrfutil dfu serial --help
    Usage: nrfutil dfu serial [OPTIONS]
    
      Perform a Device Firmware Update on a device with a bootloader that
      supports UART serial DFU.
    
    Options:
      -pkg, --package FILE            Filename of the DFU package.  [required]
      -p, --port TEXT                 Serial port address to which the device is
                                      connected. (e.g. COM1 in windows systems,
                                      /dev/ttyACM0 in linux/mac)
      -cd, --connect-delay INTEGER    Delay in seconds before each connection to
                                      the target device during DFU. Default is 3.
      -fc, --flow-control BOOLEAN     To enable flow control set this flag to 1
      -prn, --packet-receipt-notification INTEGER
                                      Set the packet receipt notification value
      -b, --baud-rate INTEGER         Set the baud rate
      -snr, --serial-number TEXT      Serial number of the device. Ignored if
                                      --port is set.
      -t, --timeout INTEGER           Set the timeout in seconds for board to
                                      respond (default: 30 seconds)
      --help                          Show this message and exit.

     

     

     <기타 >

      A> settings.hex 만들기 

    nrfutil settings generate --family NRF52 --application app.hex 
         --application-version 2 --bootloader-version 2 --bl-settings-version 1 settings.hex
    
    Note: Generating a DFU settings page with backup page included.
    This is only required for bootloaders from nRF5 SDK 15.1 and newer.
    If you want to skip backup page generation, use --no-backup option.
    
    Generated Bootloader DFU settings .hex file and stored it in: settings.hex
    
    Bootloader DFU Settings:
    * File:                     settings.hex
    * Family:                   nRF52
    * Start Address:            0x0007F000
    * CRC:                      0x5FE1C288
    * Settings Version:         0x00000001 (1)
    * App Version:              0x00000002 (2)
    * Bootloader Version:       0x00000002 (2)
    * Bank Layout:              0x00000000
    * Current Bank:             0x00000000
    * Application Size:         0x0000FC38 (64568 bytes)
    * Application CRC:          0xA258AA1F
    * Bank0 Bank Code:          0x00000001
    * Softdevice Size:          0x00000000 (0 bytes)
    * Boot Validation CRC:      0x00000000
    * SD Boot Validation Type:  0x00000000 (0)
    * App Boot Validation Type: 0x00000000 (0)

     

     > settings.hex 내용 표시하기

    $>nrfutil settings display settings.hex
    
    Bootloader DFU Settings:
    * File:                     settings.hex
    * Family:                   nRF52
    * Start Address:            0x0007E000
    * CRC:                      0x5FE1C288
    * Settings Version:         0x00000001 (1)
    * App Version:              0x00000002 (2)
    * Bootloader Version:       0x00000002 (2)
    * Bank Layout:              0x00000000
    * Current Bank:             0x00000000
    * Application Size:         0x0000FC38 (64568 bytes)
    * Application CRC:          0xA258AA1F
    * Bank0 Bank Code:          0x00000001
    * Softdevice Size:          0x00000000 (0 bytes)
    * Boot Validation CRC:      0x00000000
    * SD Boot Validation Type:  0x00000000 (0)
    * App Boot Validation Type: 0x00000000 (0)

     

      B> version 읽기

    D:\Project\SES\nrfutil>nrfutil.exe version
    nrfutil version 6.1.0

     

     C> private.key 생성하기

     $> nrfutil keys generate private.key
     
     정상 출력 메시지
     Generated private key and stored it in: private.key

     

     D> private.key 를 사용해 public_key.c 만들기

     $> nrfutil keys display --key pk --format code private.key --out_file public_key.c
     
     >> help 표시
     D:\Project\SES\nrfutil>nrfutil keys display --help
    Usage: nrfutil keys display [OPTIONS] KEY_FILE
    
    Options:
      --key [pk|sk]                   (pk|sk) Display the public key (pk) or the
                                      private key (sk).  [required]
      --format [hex|code|pem|dbgcode]
                                      (hex|code|pem) Display the key in
                                      hexadecimal format (hex), C code (code), or
                                      PEM (pem) format.  [required]
      --out_file TEXT                 If provided, save the output in file
                                      out_file.
      --help                          Show this message and exit.

     

    E> dfu serial 를 통해 이미지 업그레이드 하기

       ▶ 아래 명령은 secure bootloader serial 버전이 올라간 경우 입니다.

    $>nrfutil.exe dfu serial -pkg dfu_app_pkg.zip -p COM4
      [####################################]  100%
    Device programmed.

      ▶ 로그를 출력 할려면 다음처럼 -v 옵션을 추가해 주면 됩니다.

        $>nrfutil.exe -vvvv dfu serial -pkg dfu_app_pkg.zip -p COM4

     

      ▶ 로그 데이타를 저장할려면 -o 옵션을 추가해 주면 됩니다.

       $>nrfutil.exe -vvvv -o dfu_serial.log dfu serial -pkg dfu_app_pkg.zip -p COM4

     

    참고용으로 로그파일도 첨부합니다.

    nrfutil_dfu_serial.log
    0.36MB

     

     

     

    그럼 오늘도 수고하세요.

     

     

    반응형