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.

  • 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

  • Aren't you using SDK16? If so, you should use S140 version 7.0.1.

    Actually, it should work as long as you use S140 v 6 with the correct sd-id, but I believe something isn't right here. I suggest that you use the correct softdevice for SDK16, with sd-id 0xCA. If you use the latest version of nrfutil (v6.0.0) you can use "nrfutil --help" to see the softdevice IDs. 

  • 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

Related