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

Firmware on custom board (Application + Bootloader)

I've reached a critical point in the firmware development process where I need to start considering integrating a bootloader with the application code.

I have a custom board with an nrf52840 SoC. I have created a new bsp for the board and I'm able to execute code and run debugging on the board using Segger Embedded Studio. At some point, we'll have to integrate a bootloader in order to be able to create a release image.

Based on the requirements at my company, it has been decided to implement the application in two phases:

  • Phase 1 will include the application and bootloader
  • Phase 2 will include the application, bootloader and softdevice, once the BLE-related requirements have been locked.

I wish to implement phase 1 and as this is critical, I do not wish to get fragmented information.

My questions

  1.  Are there any ready-made bootloaders I can use?
  2. How do I go about combining the application and bootloader (without softdevice)
  3. How do I fragment the flash memory so that I can have the application, bootloader, and eventually softdevice?
  4. Are there any detailed tutorials explaining the integration processes?
  5. Eventually we'll implement FOTA over Bluetooth. Anything I should be specially aware of here?

Any link to documentation/tutorials will be very much appreciated. I apologize in advance if the questions seem a bit broad. I'm a bit new to this process of integrating application code and bootloaders.

Thanks,

/Tim

Parents
  • Hello Tim,

    1: Yes, there is a bootloader in the SDK. I don't know what SDK version you use (which one is it?)

    2: It is possible if you use the serial bootloader, but my impression is that the bootloader that uses BLE to transfer the application is the most used. If so, I would recommend going directly to phase 2.

    3: The bootloader will take care of this. You can use a tool called nrfutil to create the DFU(/FOTA) images, and there you will set what the image contains (Bootloader, softdevice or application (or a combination).

    4: Yes. Check out this tutorial, which will explain how to use the BLE bootloader. It is written for a fairly old SDK version (12.0.0), but you should be able to follow it using the latest SDK (SDK15.3.0) as well.

    5: As mentioned, I suggest that you do this directly. The blogpost in the link above will take you through this.

    I hope that clears up some of your questions. I suggest that you walk through the guide from the link (without your application, just use the examples from the SDK to get familiar with it), and then try to combine it with the example found in:

    SDK\examples\ble_peripheral\ble_app_buttonless_dfu

    And then move to including this in your application.

    Let me know if you are stuck somewhere in the testing.

    Best regards,

    Edvin

  • Thanks Edvin,

    • I use SDK 15.2.0
    • A little bit about your response in (2) - you mentioned a serial bootloader. How does this work? I'll have to use this for now, as we are working on optimizing the Bluetooth antenna for phase 2, which is why we split into two phases. Could you elaborate a bit on the serial bootloader.

    Thanks for the links and response. I'll check them out and reply in a few days,

    /Tim

  • Alright, so I tried merging in this order:

    1. Bootloader and bootloader settings => OK
    2. Merged bootloader and Application => OK
    3. Application (+Bootloader +Settings) and Softdevice => FAIL

    1. Do I have to change the start address of any of the components, or is this handled by the mergehex utility?

    2. Is the merge order relevant?

    3. My application currently doesn't include the SoftDevice. For now it's a completely "bluetooth-less" application. Could this be an issue?

    Here are my hex files:

    app.hex

    7043.bootloader_settings.hex

    secure_ble_s140_bootloader.hex

    s140_nrf52_6.1.0_softdevice.hex

    Thanks

    Tim

  • Hello Tim,

    Your app.hex looks a bit strange. 

    Does your app use the softdevice? 

    The app.hex, does that come from when you compiled the application, or did you do a flash dump after programming it? The reason I ask is that when I watch your app.hex with nRF Connect -> Programmer it looks like this:

    So the application has not put aside any space for the softdevice, which should be on the bottom/start. In addition, there is something in the top/end of the flash. what is that?

    Does your application work if you program only app.hex and softdevice? It probably will not, because it doesn't have space for the flash, but what I mean is that it will not work to merge them if you can't flash both simultaneously.

    So basically, you need to make your application work while you set aside space for the softdevice. Please refer to one of the ble_peripheral examples and the flash settings. If you are unsure on how to do that, please let me know what IDE you use, and I can give you some pointers.

    BR,

    Edvin

  • Well I think I almost figured it out. This  tutorial was super helpful:

    https://devzone.nordicsemi.com/nordic/short-range-guides/b/getting-started/posts/adjustment-of-ram-and-flash-memory

    I had to change the start address of the application and integrate the softdevice into my application.

    I managed to merge all files successfully, but the application still does not start. I used nRF Connect to watch my new image like you illustrated above and it looks as expected, based on the memory map described here: https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.2.0/lib_bootloader.html

    app_production_image.hex

    (See the attached hex file).

    Right now the softdevice is integrated in the application, but not initialized (as I mentioned in the beginning, we are not implementing any BLE features for now).

    • Any ideas on why the application still does not start?

    • Here are the contents of the bootloader settings:

    Bootloader DFU Settings:
    * File:                     ns_bootloader_setting.hex
    * Family:                   NRF52840
    * Start Address:            0x000FF000
    * CRC:                      0x48172AA9
    * Settings Version:         0x00000001 (1)
    * App Version:              0x00000000 (0)
    * Bootloader Version:       0x00000000 (0)
    * Bank Layout:              0x00000000
    * Current Bank:             0x00000000
    * Application Size:         0x0001F688 (128648 bytes)
    * Application CRC:          0x05F5197F
    * Bank0 Bank Code:          0x00000001
    * Softdevice Size:          0x00000000 (0 bytes)
    * Boot Validation CRC:      0x00000000
    * SD Boot Validation Type:  0x00000000 (0)
    * App Boot Validation Type: 0x00000000 (0)
    

    It says the sSoftDevice size is 0 bytes! I find that a bit odd. What do you think?

    Thanks

    Tim

  • Tim Adu said:
    It says the sSoftDevice size is 0 bytes! I find that a bit odd. What do you think?

     That should be fine. It says when I generate the bl_settings here as well.

    Does the application start if you flash only the bootloader + SD, and then you upload the application via DFU using nRF Connect?

    BR,

    Edvin

  • What I need now is for the bootloader to load the applicaton without having to do DFU/OTA update.

    I just read this thread:
    https://devzone.nordicsemi.com/f/nordic-q-a/19068/uploading-application-and-bootloader-application-not-starting

    So I'm guessing my device is stuck in bootloader mode.

    How can I force the bootloader to load the application?

    Also, I read this line in nrf_bootloader_app_start.c:

    uint32_t start_addr = MBR_SIZE; // Always boot from end of MBR. If a SoftDevice is present, it will boot the app.

    "if a softdevice is present, it will boot the app." How do we ensure that either the MBR or softdevice boots the application?

    Thanks

    Tim

Reply Children
  • Tim Adu said:
    What I need now is for the bootloader to load the applicaton without having to do DFU/OTA update.

     I understand, but I am trying to rule out mistakes. Maybe you have not generated the keys correctly.

    Let me try another way, then.

    Have you done any changes to the bootloader project? What bootloader project did you start with? the pca10056_ble_debug or pca10056_ble?

    What nrfutil command did you use to generate the bootloader settings?

    Did you use the corresponding public and private key in the bootloader and bootloader settings, respectively?

    1. I started with the pca10056_ble project. The only change I made was removing the dummy/default public_key.c and replacing with the one I generated using nrfutil
    2. Below is the shell script I made to generate the bootloader settings:

    ---------- Settings ----------------#
    device_family="NRF52840"
    app_image_path="../production/images/application_v2.hex"
    app_version="0"
    bl_version="0"
    bl_settings_version="1"
    output_file="../production/images/bootloader_settings.hex"
    #-----------------------------------#
    
    #Delete any existing bootloader settings image
    rm -f $output_file
    nrfutil settings generate --family $device_family --application $app_image_path --application-version $app_version --bootloader-version $bl_version --bl-settings-version $bl_settings_version $output_file

    (I am using the latest nrfutil version (5.2.0).

    3. I followed the guide here: https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/getting-started-with-nordics-secure-dfu-bootloader (steps A1 and A2) to generate the public and private keys.

    What exactly do you mean in your last question?

  • Did you use the corresponding public and private key in the bootloader and bootloader settings, respectively?

    Okay.. I think I see what you are referring to there. I just saw in the nrfutil settings generate help text that there is an option of validating the boot using the private key. Is that what you mean?

    If that's the case, then this was completely omitted from the tutorials. Can you describe exactly the syntax then for validating using the private key?

  • My last question

    Edvin said:
    Did you use the corresponding public and private key in the bootloader and bootloader settings, respectively?

     You don't use your key to sign off the application image when you create your bootloader settings? Can you try to add the following:

    "--key-file private.key" before $output_file

    That should create the correct signature for your file, so that the bootloader will accept the application if you flash it together with the BL + SD + app + BL_settings.

    Yes, unfortunately, the bootloader settings is not part of the guide. 

  • I tried it. It didn't work. My updated script:

    #---------- Settings ----------------#
    device_family="NRF52840"
    app_image_path="../path_to_production_app_hex/application.hex"
    app_version="0"
    bl_version="0"
    bl_settings_version="1"
    key_file="../path_to_generated_keys/private.key"
    output_file="../path_to_store_generated_bl_settings/bootloader_settings.hex"
    softdevice_file="../path_to_softdevice_image/s140_nrf52_6.1.0_softdevice.hex"
    #-----------------------------------#
    
    echo "---------------------------------------------------------------"
    
    #Delete any existing bootloader settings image
    rm -f $output_file
    nrfutil settings generate --family $device_family --application $app_image_path --application-version $app_version --bootloader-version $bl_version --bl-settings-version $bl_settings_version --softdevice $softdevice_file --key-file $key_file $output_file

    I read a thread with a similar problem: https://devzone.nordicsemi.com/f/nordic-q-a/19068/uploading-application-and-bootloader-application-not-starting.

    Is  there maybe an equivalent way to do it in SDK 15.2.0

Related