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

Sequence for Bootloader to configure SoftDevice

Hi,

In our existing project, it has a Bootloader and MBR, but no SoftDevice. Transport is UART for DFU.

I need to port the Bootloader to work on another project that uses SoftDevice.

I read that Bootloader needs to configure SoftDevice by calling the APIs.

I have 2 questions:

1. What are the things in SoftDevice that need to be configured by the Bootloader? Or, what is the right sequence for Bootloader to initialize and configure SoftDevice?

2. In the Bootloader sct file, the start address is 0xD6000, and the size is 0x1A000. But when I checked the hex file, the address ended at 0xE7000, while according the sct file, it ends at 0xF0000. The Bootloader settings location is at 0xEF000. Should I move it to be higher than 0xF0000?

Thanks.

  • Hi,

    Are you using your own bootloader design or the bootloader from the nRF5 SDK (with or without modifications)? I am assuming that you use a nRF5 SDK bootloader variant for now.

    The bootloader in the nRF5 SDK is designed to work both with and without SoftDevice, and there are abstraction libraries that handle the differences between having a SoftDevice, so there should be very little modification needed.

    1. What are the things in SoftDevice that need to be configured by the Bootloader? Or, what is the right sequence for Bootloader to initialize and configure SoftDevice?

    If you refer to the nRF5 SDK 16 example bootloader, you will see that the main.c file is identical for all bootloader variants, both those using a SoftDevice and those not. That is because the difference in having a SoftDevice or not is handled by drivers and libraries, and of course by the transport layer implementation, where the BLE transport layer uses a lot of BLE features from the bootloader. The SoftDeice is initialized when the BLE transport layer is initialized. So, to add the SoftDevice to the bootloader project you need to do the following:

    • Add the BLE backed source files and dependencies to the project
    • Add relevant defines to the project (e.g. SOFTDEVICE_PRESENT, NRF_SD_BLE_API_VERSION=7, ...)
    • Add any missing configurations to the bootloader sdk_config.h.
    • Move the start address of the bootloader down and increase the size, so that it can fit even though it becomes larger.

    All of the above include a lot of details, so the easiest is to compare/diff your bootloader project /Makefile to an example project/Makefile using the SoftDevice to see what you need to add.

    2. In the Bootloader sct file, the start address is 0xD6000, and the size is 0x1A000. But when I checked the hex file, the address ended at 0xE7000, while according the sct file, it ends at 0xF0000. The Bootloader settings location is at 0xEF000. Should I move it to be higher than 0xF0000?

    I am not sure bout this scatter (.sct) file you are referring to. Can you clarify? Which toolchain do you use, and what does it say? In any case, the bootloader location is simply at the end of the flash, but not overlapping the two last pages. It can start further down, but then you will wast flash at the end. The bootloader start address is programmed to the UICR and/or the last word in the MBR page (depending on SDK version), and that is part of the bootloader .hex. This lets the MBR know where the bootloader is located. See Memory layout for details.

  • Hi Einar, thanks a lot for a quick response.

    Yes, I am using nRF5 SDK bootloader. (SDK 15.2 - S140 v6.1.1)

    All of the above include a lot of details, so the easiest is to compare/diff your bootloader project /Makefile to an example project/Makefile using the SoftDevice to see what you need to add.

    Where can I find the example project for Bootloader with SoftDevice? I couldn't find it under SDK 15.2. I don't need the OTA yet, for now I just need to make Bootloader coexists with SoftDevice - keep the UART as the DFU transfort.

    I am not sure bout this scatter (.sct) file you are referring to. Can you clarify? Which toolchain do you use, and what does it say?

    The scatter file I referred to was the Bootloader's. I use Keil toolchain. It says that in scatter file we define the start address and the size of the output. That's why I am confused, as if I add 0xD6000  with 0x1A000 = 0xF0000. While the actual hex file is smaller - ends at 0xE7000.

    We use the last address space, that's why everything became custom. The Bootloader shifted to 0xD6000, Bootloader settings was set at 0xEF000, and MBR Params at 0xEE000.

    Btw, I pick up this project from another team member.

  • Hi,

    Harry said:
    Where can I find the example project for Bootloader with SoftDevice?

    The BLE bootloader examples use the SoftDevice.

    Harry said:
    I don't need the OTA yet, for now I just need to make Bootloader coexists with SoftDevice - keep the UART as the DFU transfort.

    Then you can keep the serial bootloader as is. Whether the SoftDevice is present in flash or not has no impact as long as it is not used by the bootloader itself. (The nRF52840 dongle is an example of that, as it ships with a USB serial bootloader. The bootloader remains the same regardless of if you program a SoftDevice or not, and the bootloader never uses the SoftDevice in any case).

  • Ok, let me explain the background in more details.

    Project A - it has serial Bootloader, MBR, but no SoftDevice. Works fine.

    Project B - it has SoftDevice, but it doesn't have Bootloader yet.

    So, I want to implement serial Bootloader for Project B, by modifying the existing serial Bootloader from Project A.

    When I just simply load the Bootloader to Project B, the app doesn't run anymore.

    From what I read, when the MBR in Project B knows that there is a Bootloader, the MBR will not initialize the softdevice but forward all interrupt to the bootloader. And it's up to the bootloader to init the softdevice or not. Maybe by calling sd_softdevice_vector_table_base_set() and many others to initialize SoftDevice.

    I hope it's clear now.

    All I ask is, what changes I should make in the Bootloader so that it will work for Project B.

  • Hi,

    This makes it clearer. There is still no need to think about the SoftDvice. I will explain in details:

    Now Project B has a SoftDevice and application, but no bootloader. The SoftDevice includes the MBR, so that is already present. To get the bootloader working and starting the application, you need to do the following:

    • Program the bootloader. This will also program the bootloader start address to the UICR or the end of the MBR page (depending on SDK version), as that is part of the bootloader .hex file.
      • After doing this, the MBR will check and see that a bootloader is present, and will start it and enter DFU mode (unless the bootloader i knows that a valid application is present.
    • Generate and program a valid bootloader settings page. If you don't, the bootloader will not know that a valid application is present. If you do, and it is correctly generated, the bootloader will start the application (this is just half-true, see below for details*).

    *As you see, there is no need to handle the SoftDevice specifically. The reason for this is that the bootloader always forwards interrupts and jumps to whatever is on page 1 (0x1000). If you don't have a SoftDevice, then this will be the application. If you ave a SoftDevice, then this will forward interrupts to the application and branch to it.

Related