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.

  • 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.

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

Related