Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF5 SDK16.0.0 bootloader issue

Hello,

I am trying to upload the firmware with secure DFU using following method:

  1. generated the dfu_public_key.c and private.pem pair
  2. copied the "dfu_public_key.c" into "\examples\dfu" folder
  3. Ran "build_all.bat" to create "micro_ecc_lib_nrf52.a" at "\nRF5_SDK_16.0.0_98a08e2\external\micro-ecc\nrf52hf_armgcc\armgcc"
  4. Compiled "secure_bootloader_ble_s140_pca10056.emProject" and copied "secure_bootloader_ble_s140_pca10056.hex" to the package folder as "bootloader.hex"
  5. Ran "02_flash_SD_and_bootloader.bat" to upload the bootloader
  6. FW.zip was created using "03_create_fw_zip_package.bat"

I can see DFUTarg when I search the devices but when try to upload the FW.zip, it prompts error: "When writing 'EXECUTE' command to Control Point Characteristic of DFU Target: Operation code 4 (EXECUTE) failed on DFU Target. Result code 5 (INVALID_OBJECT)". Please see the attached image of error.

I have been doing this for SDK15.0.0 and nRF52832 for several months. The only difference now is that the SDK is v16.0.0 and chip is nRF52840. I have paid attention when copied the bootloader (which is s140 for nRF52840). Also the DFU example is also for S140 and nRF840. The FW.zip compiled project is also for nRF52840 which, otherwise, works fine on chip. 

Please let me know why this error is happening.

Parents
  • Hello,

    I don't understand what scripts you refer to. Where did you find "02_flash_SD_and_bootloader.bat" and "03_create_fw_zip_package.bat"? What command was used to generate the packet?

    BR,

    Edvin

  • 01_generate_private_public_keys.bat

    
    @echo off
    
    :: # Check to make sure nrfutil is installed before moving on
    WHERE >nul 2>nul nrfutil
    IF %ERRORLEVEL% NEQ 0 (
    ECHO "nrfutil was not found in PATH, please install using pip install"
    goto :end
    )
    
    :: Generate private key - ref http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.tools/dita/tools/nrfutil/nrfutil_keys_generate_display.html?cp=5_5_5
    :: and http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/lib_bootloader_dfu_keys.html?cp=4_0_0_3_5_1_3
    echo Generate a private key in private.pem
    nrfutil keys generate private.pem
    
    ::echo Display the generated private key (in little-endian format)
    ::nrfutil keys display --key sk --format hex private.pem
    
    ::echo Display the public key that corresponds to the generated private key
    ::echo (in little-endian format)
    ::nrfutil keys display --key pk --format hex private.pem
    
    ::echo Display the public key that corresponds to the generated private key
    ::echo (in code format to be used with DFU)
    ::nrfutil keys display --key pk --format code private.pem
    
    echo Write the public key that corresponds to the generated private key
    echo to the file dfu_public_key.c (in code format)
    nrfutil keys display --key pk --format code private.pem --out_file dfu_public_key.c
    
    :end
    pause

    02_flash_SD_and_bootloader.bat

    @echo off
    
    :: # Check to make sure nrfjprog is installed before moving on
    WHERE >nul 2>nul nrfjprog
    IF %ERRORLEVEL% NEQ 0 (
    ECHO "nrfjprog was not found in PATH, please install using windows installed as found on nordicsemi.com"
    goto :end
    )
    WHERE >nul 2>nul mergehex
    IF %ERRORLEVEL% NEQ 0 (
    ECHO "mergehex was not found in PATH, please install using windows installed as found on nordicsemi.com"
    goto :end
    )
    
    SET S140=s140_nrf52_6.1.0_softdevice.hex
    SET BOOTLOADER=bootloader.hex
    
    echo "## Looking to make sure %S140% exists"
    if not exist %S140% (
    echo "#### s140 hex file does not exist! Make sure the softdevice is in the same folder as this script!"
    goto :end
    )
    echo.
    
    echo "## Looking to make sure %BOOTLOADER% exists"
    if not exist %BOOTLOADER% (
    echo "#### Bootloader hex file does not exist! Please make sure its compiled, copied, and renamed into this folder!"
    goto :end
    )
    echo.
    
    echo "## Merging S140 and bootloader, then flashing it to nRF52-DK; make sure the DK is powered on and connected to the PC"
    mergehex -m %S140% %BOOTLOADER% -o merged_SD_bootloader.hex
    nrfjprog --program merged_SD_bootloader.hex --chiperase
    echo.
    
    echo "## Please power cycle the DK and then with nRF Connect, make sure the board is in bootloader mode and ADV as DfuTarg"
    echo.
    
    :end
    pause

    03_create_fw_zip_package.bat

    
    @echo off
    
    :: # Check to make sure nrfutil is installed before moving on
    WHERE >nul 2>nul nrfutil
    IF %ERRORLEVEL% NEQ 0 (
    ECHO "nrfutil was not found in PATH, please install using pip install"
    goto :end
    )
    
    SET S140=s140_nrf52_6.1.0_softdevice.hex
    SET APPLICATION_HEX=app.hex
    
    echo "## Looking to make sure %S140% is present in folder"
    if not exist %S140% (
    echo "#### s140 hex file does not exist! Please copy this file into the folder and try again!"
    goto :end
    )
    echo.
    
    echo "## Looking to make sure %APPLICATION_HEX% is present in folder"
    if not exist %APPLICATION_HEX% (
    echo "#### app.hex file does not exist! Please copy a application .hex file into the folder, rename it, and try again!"
    goto :end
    )
    echo.
    
    echo "## Creating a FW.zip package that can be used to update the FW on the DK"
    nrfutil pkg generate --application app.hex --application-version 1 --application-version-string "1.0.0" --hw-version 52 --sd-req 0xA8 --sd-id 0xA8 --softdevice s140_nrf52_6.1.0_softdevice.hex --key-file private.pem FW_Hotshot_hv_fv.zip
    echo.
    
    :end
    pause

  • The "nrfutil --help" does not give soft device IDs as shown below. Also changing the soft device to s140_nrf52_7.0.1_softdevice.hex doesn't make any difference.

    C:\WINDOWS\system32>nrfutil --help
    Usage: nrfutil [OPTIONS] COMMAND [ARGS]...
    
    Options:
      -v, --verbose            Increase verbosity of output. Can be specified more
                               than once (up to -v -v -v -v).
      -o, --output <filename>  Log output to file
      --help                   Show this message and exit.
    
    Commands:
      dfu       Perform a Device Firmware Update over serial, BLE, Thread, Zigbee
                or ANT transport given a DFU package (zip file).
      keys      Generate and display private and public keys.
      pkg       Display or generate a DFU package (zip file).
      settings  Generate and display Bootloader DFU settings.
      version   Display nrfutil version.
      zigbee    Zigbee-related commands and utilities.
    
    C:\WINDOWS\system32>

    nrfutil version
    nrfutil version 6.0.0a1

  • If it doesn't show up in nrfutil, try to use the nrfutil version 6.0.0 (not alpha 1). It should look like this:

    If you program the bootloader and softdevice using a programmer, and generate a dfu packet using the same key set  as the bootloader, and with the softdevice requirement 0xCA, which is the softdevice ID for S140v7.0.1, then it should pass. 

    I am not sure I understand your scripts. I see that you generate a DFU image containing the softdevice. 

    Are you trying to update the application or the softdevice?

    Can you try to program the bootloader and the softdevice, and upload an application, just to make sure that you have everything up and running?

    BR,

    Edvin

  • If it doesn't show up in nrfutil, try to use the nrfutil version 6.0.0 (not alpha 1)

    Using 6.0.0 now.

    If you program the bootloader and softdevice using a programmer, and generate a dfu packet using the same key set  as the bootloader, and with the softdevice requirement 0xCA, which is the softdevice ID for S140v7.0.1, then it should pass. 

    Every thing is as above with softdevice 0xCA, v7.0.1 but the issue persists. Keyset is same, softdevice requirement in both my app and while creating final zip is 0xCA (see below nrfutil commands).

    I am not sure I understand your scripts. I see that you generate a DFU image containing the softdevice. 

    Here is the summary of nrfutil commands:

    :: #1 - create dfu_public_key.c and private.pem file
    nrfutil keys display --key pk --format code private.pem --out_file dfu_public_key.c
    
    :: #2 - dfu_public_key is copied to the examples/dfu/ folder and dfu\secure_bootloader\pca10056_s140_ble is compiled
    
    :: #3 - secure_bootloader_ble_s140_pca10056.hex is copied back as bootloader.hex in folder containing app.hex and softdevice file
    
    :: #4 - merge bootloader and s140 and download it to the device
    SET S140=s140_nrf52_7.0.1_softdevice.hex
    SET BOOTLOADER=bootloader.hex
    mergehex -m %S140% %BOOTLOADER% -o merged_SD_bootloader.hex
    nrfjprog --program merged_SD_bootloader.hex --chiperase
    
    :: #5 - create zip file from app.hex file, signed with private.pem and requires SD v7.0.1 (sd-id 0xCA)
    nrfutil pkg generate --application app.hex --application-version 1 --application-version-string "1.0.0" --hw-version 52 --sd-req 0xCA --sd-id 0xCA --softdevice s140_nrf52_7.0.1_softdevice.hex --key-file private.pem FW_Hotshot_hv_fv.zip
    

    Can you try to program the bootloader and the softdevice, and upload an application, just to make sure that you have everything up and running?

    I'm bundling both app.hex and softdevice but I have tried using app.hex only with same error as before.

  • You are using the bootloader project from SDK16.0.0 as well, right?

    Can you try the following script then?

    :: #1 - create dfu_public_key.c and private.pem file
    nrfutil keys display --key pk --format code private.pem --out_file dfu_public_key.c
    
    :: #2 - dfu_public_key is copied to the examples/dfu/ folder and dfu\secure_bootloader\pca10056_s140_ble is compiled
    
    :: #3 - secure_bootloader_ble_s140_pca10056.hex is copied back as bootloader.hex in folder containing app.hex and softdevice file
    
    :: #4 - merge bootloader and s140 and download it to the device
    ::SET S140=s140_nrf52_7.0.1_softdevice.hex
    ::SET BOOTLOADER=bootloader.hex
    ::mergehex -m %S140% %BOOTLOADER% -o merged_SD_bootloader.hex
    ::nrfjprog --program merged_SD_bootloader.hex --chiperase
    
    nrfjprog -e
    nrfjprog --program s140_nrf52_7.0.1_softdevice.hex --verify
    nrfjprog --program bootloader.hex --verify
    nrfjprog --reset
    
    
    :: #5 - create zip file from app.hex file, signed with private.pem and requires SD v7.0.1 (sd-id 0xCA)
    ::nrfutil pkg generate --application app.hex --application-version 1 --application-version-string "1.0.0" --hw-version 52 --sd-req 0xCA --sd-id 0xCA --softdevice s140_nrf52_7.0.1_softdevice.hex --key-file private.pem FW_Hotshot_hv_fv.zip
    
    nrfutil pkg generate --application app.hex --application-version 1 --hw-version 52 --sd-req 0xCA --key-file private.pem FW_Hotshot_hv_fv.zip
    

    There shouldn't be anything wrong with using merghex, but I am not sure exactly how nrfutil behaves when you use both application-version and application-version-string. Also, try the image generation from this file, which is only the app.

    I am not saying this is how it needs to be in the end, but I am trying to figure out why it isn't working on your side. I tested it now on my side with the nRF52840 DK and the bootloader and softdevice from SDK16.0.0 using this script:

    make -j9
    nrfjprog -e
    nrfjprog --program ..\..\..\..\..\components\softdevice\s140\hex\s140_nrf52_7.0.1_softdevice.hex --verify
    nrfjprog --program _build\nrf52840_xxaa_s140.hex --verify
    nrfjprog --reset
    
    del files\bootloader.hex
    del files\buttonless.hex
    del files\private.key
    
    copy ..\..\..\..\ble_peripheral\ble_app_buttonless_dfu\pca10056\s140\armgcc\_build\nrf52840_xxaa.hex files\buttonless.hex
    copy _build\nrf52840_xxaa_s140.hex files\bootloader.hex
    copy ..\..\..\private.key files\private.key
    
    
    nrfutil pkg generate --application files\buttonless.hex --application-version 1 --hw-version 52 --sd-req 0xCA --key-file files\private.key files\my_image.zip

    If you place this inside the SDK16.0.0\examples\dfu\secure_bootloader\pca10056_s140_ble\armgcc

    and create a folder called "files" inside the armgcc folder, it should program the DK and generate the DFU image "my_image.zip", which should work.

Reply
  • You are using the bootloader project from SDK16.0.0 as well, right?

    Can you try the following script then?

    :: #1 - create dfu_public_key.c and private.pem file
    nrfutil keys display --key pk --format code private.pem --out_file dfu_public_key.c
    
    :: #2 - dfu_public_key is copied to the examples/dfu/ folder and dfu\secure_bootloader\pca10056_s140_ble is compiled
    
    :: #3 - secure_bootloader_ble_s140_pca10056.hex is copied back as bootloader.hex in folder containing app.hex and softdevice file
    
    :: #4 - merge bootloader and s140 and download it to the device
    ::SET S140=s140_nrf52_7.0.1_softdevice.hex
    ::SET BOOTLOADER=bootloader.hex
    ::mergehex -m %S140% %BOOTLOADER% -o merged_SD_bootloader.hex
    ::nrfjprog --program merged_SD_bootloader.hex --chiperase
    
    nrfjprog -e
    nrfjprog --program s140_nrf52_7.0.1_softdevice.hex --verify
    nrfjprog --program bootloader.hex --verify
    nrfjprog --reset
    
    
    :: #5 - create zip file from app.hex file, signed with private.pem and requires SD v7.0.1 (sd-id 0xCA)
    ::nrfutil pkg generate --application app.hex --application-version 1 --application-version-string "1.0.0" --hw-version 52 --sd-req 0xCA --sd-id 0xCA --softdevice s140_nrf52_7.0.1_softdevice.hex --key-file private.pem FW_Hotshot_hv_fv.zip
    
    nrfutil pkg generate --application app.hex --application-version 1 --hw-version 52 --sd-req 0xCA --key-file private.pem FW_Hotshot_hv_fv.zip
    

    There shouldn't be anything wrong with using merghex, but I am not sure exactly how nrfutil behaves when you use both application-version and application-version-string. Also, try the image generation from this file, which is only the app.

    I am not saying this is how it needs to be in the end, but I am trying to figure out why it isn't working on your side. I tested it now on my side with the nRF52840 DK and the bootloader and softdevice from SDK16.0.0 using this script:

    make -j9
    nrfjprog -e
    nrfjprog --program ..\..\..\..\..\components\softdevice\s140\hex\s140_nrf52_7.0.1_softdevice.hex --verify
    nrfjprog --program _build\nrf52840_xxaa_s140.hex --verify
    nrfjprog --reset
    
    del files\bootloader.hex
    del files\buttonless.hex
    del files\private.key
    
    copy ..\..\..\..\ble_peripheral\ble_app_buttonless_dfu\pca10056\s140\armgcc\_build\nrf52840_xxaa.hex files\buttonless.hex
    copy _build\nrf52840_xxaa_s140.hex files\bootloader.hex
    copy ..\..\..\private.key files\private.key
    
    
    nrfutil pkg generate --application files\buttonless.hex --application-version 1 --hw-version 52 --sd-req 0xCA --key-file files\private.key files\my_image.zip

    If you place this inside the SDK16.0.0\examples\dfu\secure_bootloader\pca10056_s140_ble\armgcc

    and create a folder called "files" inside the armgcc folder, it should program the DK and generate the DFU image "my_image.zip", which should work.

Children
  • Yes. I usually call it private.key. That should work, but there isn't any problem to use private.pem either, I believe.

  • Hello ,

    I have copied exact script in the SDK16.0.0\examples\dfu\secure_bootloader\pca10056_s140_ble\armgcc

    make -j9
    nrfjprog -e
    nrfjprog --program ..\..\..\..\..\components\softdevice\s140\hex\s140_nrf52_7.0.1_softdevice.hex --verify
    nrfjprog --program _build\nrf52840_xxaa_s140.hex --verify
    nrfjprog --reset
    
    del files\bootloader.hex
    del files\buttonless.hex
    del files\private.key
    
    copy ..\..\..\..\ble_peripheral\ble_app_buttonless_dfu\pca10056\s140\armgcc\_build\nrf52840_xxaa.hex files\buttonless.hex
    copy _build\nrf52840_xxaa_s140.hex files\bootloader.hex
    copy ..\..\..\private.key files\private.key
    
    
    nrfutil pkg generate --application files\buttonless.hex --application-version 1 --hw-version 52 --sd-req 0xCA --key-file files\private.key files\my_image.zip

    Here is the result of the script when executed:

    DONE nrf52840_xxaa_s140
    Erasing user available code and UICR flash areas.
    Applying system reset.
    Parsing hex file.
    Reading flash area to program to guarantee it is erased.
    Checking that the area to write is not protected.
    Programming device.
    Verifying programming.
    Verified OK.
    Parsing hex file.
    Reading flash area to program to guarantee it is erased.
    Checking that the area to write is not protected.
    Programming device.
    Verifying programming.
    Verified OK.
    Applying system reset.
    Run.
            1 file(s) copied.
            1 file(s) copied.
            1 file(s) copied.
    Zip created at files\my_image.zip
    Press any key to continue . . .
    

    Before this, I had to compile the "nRF5_SDK_16.0.0_98a08e2\examples\ble_peripheral\ble_app_buttonless_dfu" project using following script:

    @ECHO OFF
    
    :: This script will use git (must be in %PATH%) and arm-none-eabi tools in combination with GNU Make
    :: to both fetch and compile all variants of micro-ecc for the nRF5 families
    
    WHERE >nul 2>nul git
    IF %ERRORLEVEL% NEQ 0 (
        ECHO "git is not installed. Please install and append to PATH."
    )
    
    IF NOT EXIST micro-ecc/uECC.c (
        ECHO "micro-ecc not found! Let's pull it from HEAD."
        git clone https://github.com/kmackay/micro-ecc.git
    )
    
    make -C pca10056/s140/armgcc
    ::make -C nrf51_iar/armgcc
    
    pause

    The "my_image.zip" was created in the "files folder".

    But when I try to upload the "my_image.zip" via DFU, exact same error is prompted as noted in the very first post of this ticket:

    When writing 'EXECUTE' command to Control Point Characteristic of DFU Target: Operation code 4 (EXECUTE) failed on DFU Target. Result code 5 (INVALID_OBJECT).

    About the following line in your script:

    copy ..\..\..\..\ble_peripheral\ble_app_buttonless_dfu\pca10056\s140\armgcc\_build\nrf52840_xxaa.hex files\buttonless.hex

    Are you sure it is ble_app_buttonless_dfu and not \examples\dfu\secure_bootloader\pca10056_s140_ble\armgcc\_build folder from where dfu file needs to be copied?

  • I used the buttonless example as an example of the application that I wanted to update to via DFU.

    What HW are you running on? A normal DK?

    Can you please try to unzip an unmodified version of the SDK and:

    1: generate private.key and dfu_public_key.c in SDK\examples\dfu.
    2: compile the bootloader, ble_app_buttonless_dfu.
    3: run the build_all.bat from SDK\external\micro-ecc, and run the script again? 

    It should work out of the box like that, if you are running on a DK. What DK version do you have?

    BR,

    Edvin

  • It's a 3rd party DK with nRF52840 module. So the pca10056 and S140 should work on it. 

Related