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

  • 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

  • Hi Edvin,

    I arrive to flash all but my application never Start, there are just the two led of bootloader was light up.

    You have a solution ?

  • Can you describe what you did? If you are stuck, please try the pca10040_debug bootloader project, and monitor the RTT log. What does it say?

    Did you program all the 4 files: Bootloader, Softdevice, application and bootloader settings?

    Can you show me how you did it, and how you generated the bootloader settings?

    Edit: I just noticed that this question was from , and not the original poster. What did you do? What have you programmed on your DK? Are you using a DK? How do you perform the DFU? What is your DFU master? Are you using a phone, nRF Connect for iOS/Android? nRF Connect for Desktop? nrfutil?

    BR,

    Edvin

  • Hello Edvin,

    Thanks for your reply. I still have to test the script you attached. But I've read and analysed the rest of your reply and I have a few doubts and comments.

    Q: When you merged the bootloader settings and the bootloader, did you also program that application?
    A: I did in one of my trials. I also tried merging all my .hex files into one calling mergehex several times. These things didn't work, so I started from the beginning, trying to make the settings and bootloader work.

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

    I did replace the key. I'm using Segger Studio as my IDE.
    I created a new folder in which I only copied the softdevice.hex, bootloader.hex and application.hex. Is this a bad practice? Could this be my mistake?

    Where can I find the softdevice ID? I'm asking this because I'm still using sdk 17.0.0. I found this post and I've opened the 3 files I found on tesc's answer and wasn't able to find any code similar to the one you mentioned in your notes.

    Lastly, when you say
    "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."

    Do you specifically flash them in that order? Is the flashing or merging order relevant?

    Best regards,

    Pau

  • PauDC said:
    I created a new folder in which I only copied the softdevice.hex, bootloader.hex and application.hex. Is this a bad practice? Could this be my mistake?

     That is fine, as long as you remember to update them. Remember that whenever you change the smallest detail in the application, it results in a new .hex file, which you need to generate a new set of settings for. You can see in the script that I delete and always copy the latest application to be flashed into the folder "files".

    Please also note that you can flash the files using nrfjprog (the order doesn't matter). But if you try to debug in SES, then SES will upload a modified version of the .hex file, so the CRC will not match with the bootloader settings anymore. If you need to debug the application after you have programmed a bootloader, you should use the option: Target -> Attach Debugger:

    Which will hook onto the debugger without flashing anything. In order for this to work, you need to make sure that the nRF is manually flashed with the very latest application compile.

    But before you test the debugging part, make sure that you have uploaded the bootloader settings.

    BR,
    Edvin

Related