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

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

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

  • The difference between the serial and ble bootloader is that the serial bootloader uses UART instead of BLE to transfer the images.

    Serial bootloader is located in: SDK15.2.0\examples\dfu\secure_bootloader\pca10056_uart

    BLE bootloader is located in: SDK15.2.0\examples\dfu\secure_bootloader\pca10056_ble

    I would still recommend to test the ble bootloader, which you can do on a DK in the meantime while you work on the antenna.

    However, if you want to test the serial bootloader, you can do that as well. In that case, it is a quite similar approach.

    You can start off by using nrfutil (which is also linked in the getting started guide) to create the images and perform the serial DFU. 

    The nrfutil tool has a "guide" you can access by typing "nrfutil --help" after you have installed it and added it to your environment path. There is also a list over useful commands here, such as how to perform the serial DFU.

    Best regards,

    Edvin

  • Great! Thanks. I'll get back to you in a few days.

  • I had assumed that a custom board could be flashed with the final image (application + bootloader) using Segger Flasher, a 10 pin needle adapter, and the nrfjprog utility - this setup facilitates batch programming at the factory.
    I just discovered the mergehex utility.

    1. would this be fine to combine the application and bootloader, and then program a device using the setup above?
    2. Can  you confirm that this is not possible? If this is the case, can you suggest a way (if possible) to use the DFU utility to batch program devices?
    3. This guide mentions that the bootloader can be flashed directly. Where exactly in the SDK is the bootloader image located (I'm using SDK 15.2.0)?

    Thanks

    Tim

  • 1: Yes. You can merge the hex files and program them in one chunk, but it is also possible to program them separately. Note that the bootloader has a CRC check, so unless you program the bootloader settings generated with the correct application and private key, the bootloader will reject the application, and stay in bootloader mode.

    2: If you mean to use .bat scripts to program using nrfjprog and/or update the firmware via DFU using nrfutil, then yes. It is possible. (I usually do this to test DFU stuff).

    3: There are some precompiled bootloaders located in:

    SDK15.2.0\examples\dfu\secure_dfu_test_images.

    However, I really (!) recommend you to compile your own bootloaders with your own keys generated the way that is described in the tutorial that I linked to in the first reply.

    The reason for this is that I am not sure what sort of keys or bootloader's that are compiled in the precompiled .hex files and .zip files.

    The bat scripts that I usually use to test looks something like this:

    REM nrfutil keys generate private.key
    REM nrfutil keys display --key pk private.key --format code --out_file public_key.c
    
    nrfjprog -e --snr 123456789
    nrfjprog --program softdevice.hex --snr 123456789
    nrfjprog --program bootloader.hex --snr 123456789
    nrfjprog --reset --snr 123456789
    
    nrfutil pkg generate --application application.hex --application-version 1 --hw-version 52 --sd-req 0xB6 --key-file private.key dfu_test_image.hex
    
    nrfutil dfu serial -pkg dfu_test_image.zip -p COM4 -snr 123456789 -b 115200

    Just change the serial numbers after --snr or -snr to match the serial number of your debugger (or on the DK).

    Also, you need to use the correct names for the softdevice hex file, the bootloader.hex is the .hex file from bootloader that you compiled, the application is the hex file for an application that you want to flash, and so on...

    Best regards,

    Edvin

Related