This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Flashing bootloader, softdevice and application issue

Hello.
I'm having an issue with nrfjprog that has been discussed in this forum several times but I can't manage to get it working. I'll link some of mentioned posts at the end of this post.

My goal: I'd like to have a powershell script in which I can flash the softdevice, the bootloader and the application. And the device runs the application and doesn't get stuck in the bootloader. I don't mind if to merge all the .hex files into one .hex file as long as it works.

My setup: I have a nrf52832 custom board without any buttons that I'd like to be able to update the application via dfu. I'm using sdk 17.0 (this is working, I followed Getting started with Nordic's Secure DFU bootloader, a step by step guide).
My application is based on the template example and my bootloader is the secure bootloader example.

Things I've tried (besides other devzone posts answers):
1. My first approach was to flash the softdevice, bootloader and application in this order. When I scan using nrfConnect I don't see my device name I just see DfuTarg. Which means the application is not running and it's stuck in the bootloader. Note: When I connect the device to nRFgo Studio I can see that the bootloader, softdevice and application are all flashed into the device but the application is not starting. If using nrfConnect I upload via dfu the same application it runs flawlessly.

2. The most common answer I've found in the forums is that I need to merge the bootloader .hex with a settings .hex. As far as I understood, the first thing I tried didn't work because the CRC checking and this settings .hex for the bootloader will make it work.

I've tried the following piece of code:

nrfutil settings generate --family NRF52 --application application.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 settings.hex

mergehex -m settings.hex bootloader.hex -o bootloader_w_settings.hex

nrfjprog.exe --eraseall
nrfjprog.exe --program bootloader_w_settings.hex --verify 


As far as I know, I need to be using --bl-settings-version 2 because my sdk version is 17.0. And --application-version and --bootloader-version are values for me to increase.

After running the script, verifying says it's ok. Powershell output:

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:                      0x13EBFE1F
* Settings Version:         0x00000002 (2)
* App Version:              0x00000001 (1)
* Bootloader Version:       0x00000001 (1)
* Bank Layout:              0x00000000
* Current Bank:             0x00000000
* Application Size:         0x00010104 (65796 bytes)
* Application CRC:          0x335A336B
* Bank0 Bank Code:          0x00000001
* Softdevice Size:          0x00000000 (0 bytes)
* Boot Validation CRC:      0x9D257E79
* SD Boot Validation Type:  0x00000000 (0)
* App Boot Validation Type: 0x00000001 (1)

Parsing input hex files.
Merging files.
Storing merged file.
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.
Programing device.
Verifying programming.
Verified OK.


At this point I use nrfConnect to check if the bootloader is working and I'm unable to find the device. nRFgo Studio says the bootloader is flashed.

How can I make this work and reach my goal?
Is there any extra configuration to the bootloader or application that must be done for this to work?
Thanks.

Some of the devzone posts I've researched and couldn't make it work:
https://devzone.nordicsemi.com/f/nordic-q-a/10135/how-to-program-softdevice-and-firmware-with-new-nrfjprog
https://devzone.nordicsemi.com/f/nordic-q-a/24801/combining-bootloader-softdevice-and-application-in-single-hex
https://devzone.nordicsemi.com/f/nordic-q-a/27006/how-to-flash-the-softdevice-the-bootloader-and-the-application-at-once
https://devzone.nordicsemi.com/f/nordic-q-a/19502/flashing-sd-app-bl-sdk12-2/75758#75758
https://devzone.nordicsemi.com/f/nordic-q-a/46033/nrf51822-prepare-hex-file-for-mass-production-softdevice-application-bootloader-and-start-it-into-the-application
https://devzone.nordicsemi.com/f/nordic-q-a/53693/how-to-flash-application-after-dfu-bootloader
https://devzone.nordicsemi.com/f/nordic-q-a/51265/sdk-15-3-flash-application-does-not-run-after-flash-softdevice-and-bootloader-as-advised-on-devzone-topics
https://devzone.nordicsemi.com/f/nordic-q-a/50482/unable-to-flash-after-adding-bootloader
https://devzone.nordicsemi.com/f/nordic-q-a/58894/unable-to-merge-bootloader-softdevice-and-application
https://devzone.nordicsemi.com/f/nordic-q-a/57523/flash-the-softdevice-the-bootloader-bootloader-settings-and-the-application-at-once

Parents
  • Hello,

    Creating these scripts is a good idea when working with a bootloader, because the bootloader will reject applications that are flashed without the correct bootloader settings. 

    So you are on the track of something. And you may merge the bootloader with the settings hex file, but that is not necessary. Just make sure you program them all.

    Why your setup is currently not working, I am not sure. When you merged the bootloader settings and the bootloader, did you also program that application?

    Let us take it from the start

    Let us assume you have already:

    - Replaced the dfu_public_key.c in the original location in the sdk with your personal private key. 

    - installed the "make" toolchain. If you are using an IDE, please compile the projects up front, and change the paths in the attached scripts. 

    If you copy the attached script into a .bat file (e.g. name it test.bat), place it in SDK17.0.2\examples\dfu\secure_bootloader\pca10040_s132_ble\armgcc and run it from a power shell or a command line, I believe it should work.

    make -j9 
    make -j9 -C ..\..\..\..\ble_peripheral\ble_app_buttonless_dfu\pca10040\s132\armgcc
    
    set TARGET_SNR=682396787
    set CONNECTIVITY_SNR=683963588
    
    mkdir files
    
    del files\bl_settings.hex
    del files\buttonless_app.hex
    
    copy ..\..\..\..\ble_peripheral\ble_app_buttonless_dfu\pca10040\s132\armgcc\_build\nrf52832_xxaa.hex files\buttonless_app.hex
    nrfutil settings generate --family NRF52 --application files\buttonless_app.hex --application-version 1 --bootloader-version 1 --bl-settings-version 1 --key-file ..\..\..\private.key files\bl_settings.hex
    
    nrfjprog -e --snr %TARGET_SNR%
    nrfjprog --program ..\..\..\..\..\components\softdevice\s132\hex\s132_nrf52_7.2.0_softdevice.hex --verify --snr %TARGET_SNR%
    nrfjprog --program _build\nrf52832_xxaa_s132.hex --verify --snr %TARGET_SNR%
    nrfjprog --program files\buttonless_app.hex --verify --snr %TARGET_SNR%
    nrfjprog --program files\bl_settings.hex --verify --snr %TARGET_SNR%
    nrfjprog --reset --snr %TARGET_SNR%
    
    :: if you want to also perform a DFU from another DK, uncomment the lines below, and make sure to set the serial numbers correctly.
    
    
    ::TIMEOUT 5
    
    ::nrfutil pkg generate --application files\buttonless_app.hex --application-version 2 --sd-req 0x0101 --hw-version 52 --key-file ..\..\..\private.key files\dfu_image_v2.zip
    ::nrfutil pkg generate --application files\buttonless_app.hex --application-version 3 --sd-req 0x0101 --hw-version 52 --key-file ..\..\..\private.key files\dfu_image_v3.zip
    ::nrfutil pkg generate --application files\buttonless_app.hex --application-version 4 --sd-req 0x0101 --hw-version 52 --key-file ..\..\..\private.key files\dfu_image_v4.zip
    ::nrfutil pkg generate --application files\buttonless_app.hex --application-version 5 --sd-req 0x0101 --hw-version 52 --key-file ..\..\..\private.key files\dfu_image_v5.zip
    
    
    ::nrfutil dfu ble -pkg files\dfu_image_v2.zip -ic NRF52 -snr %CONNECTIVITY_SNR% -n "Nordic_Buttonless"
    ::TIMEOUT 10
    ::nrfutil dfu ble -pkg files\dfu_image_v3.zip -ic NRF52 -snr %CONNECTIVITY_SNR% -n "Nordic_Buttonless"
    
    

    Notes:

    - Set the serial number of the programmer on your DK. The TARGET_SNR refers to the nRF52832 DK with the bootloader, and the CONNECTIVITY_SNR refers to the other DK that you will use to update the nRF52832 over the air.

    - The softdevice ID of the S132 from SDK17.0.2 is 0x0101.

    - Useful nrfutil commands: 

    • nrfutil settings generate --help
    • nrfutil pkg generate --help
    • nrfutil dfu ble --help

    Please note that I flash all 4 .hex files: Softdevice, Bootloader, Application and Bootloader Settings. You can merge them and program them all in one, if you like.

    If you have reset the device after programming the bootloader but before programming the bootloader settings, add the flag --sectorerase to the nrfjprog command programming the bootloader settings.

    Let me know if it doesn't work.

    Best regards,

    Edvin

  • Hello Edvin,

    I was able to flash everything thanks to this answer.

    The main difference I see between what you posted and what I did is that when creating the bootloader settings I didn't add the private key.

    I will test more to see if this was the only reason my script was failing.

    Thank you very much,

    Best regards.

    Pau

Reply Children
  • I am not sure whether using the private key is actually necessary when generating bootloader settings with the default settings in the bootloader (but I tend to include it). When testing these things, I suggest using scripts like the one attached earlier. It saves you a lot of time, and it ensures that you are testing the same every time (it is very easy to forget a step or two). If you want to use Segger Embedded Studio instead of the armgcc makefile, just replace the application .hex file that I copied into files\buttonless_app.hex.

    Best regards,

    Edvin

Related