Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

[NRF52840] Changing Bootloader Size and need to change Linker Script to match

Hello all,

Environment: nRF52840-DK, NRF SDK V15.0.0, SoftDevice s140 v 6.0.0, ARMGCC building with Makefile

I am currently trying to combine the examples of the USB and BLE DFU bootloaders into one bootloader, and I have run into a problem at the linking stage. I have run into this problem multiple times, and more or less would just like some info on this part of the procedure.

I have started by copying the <SDK_ROOT>/examples/dfu/secure_bootloader/pca10056_ble example to another example called <SDK_ROOT>/examples/dfu/secure_bootloader/pca10056_ble_usb, and then added the appropriate source files and include files from the <SDK_ROOT>/examples/dfu/secure_bootloader/pca10056_usb example to the new example. I'm able to compile all the required files but at the linking step I get the following:

Linking target: _build/nrf52840_xxaa_s140.out
/usr/bin/gnu-arm-embedded-toolchain/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: _build/nrf52840_xxaa_s140.out section `.text' will not fit in region `FLASH'
/usr/bin/gnu-arm-embedded-toolchain/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: region FLASH overflowed with .data and user data
/usr/bin/gnu-arm-embedded-toolchain/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: section .bootloader_settings_page VMA [00000000000ff000,00000000000fffff] overlaps section .text VMA [00000000000f8000,000000000010170f]
/usr/bin/gnu-arm-embedded-toolchain/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 14260 bytes
collect2: error: ld returned 1 exit status
make: *** [../../../../components/toolchain/gcc/Makefile.common:294: _build/nrf52840_xxaa_s140.out] Error 1

I know I need to make changes to the bootloader flash section in the associated secure_bootloader_gcc_nrf52.ld example linker script, but this is not something I have really done before. I'd like to learn how to go about this as well as get some resources on how to understand and manipulate linker scripts.

I'm sure as I move forward I'll have more issues in regards to the proper building of this combined example, but I really want to get this fundamental understood first.

Thanks!

Parents
  • Realized I had a few extra errors from forgetting to include some settings. I fixed those issues and updated the above output message to reflect the current status (which is now more specific to my question).

  • Hello,

    The linker output shows that your bootloader has become too big to fit inside bootloader's FLASH area. So, as you indicated, the solution is to allocate more memory to it. You can do so by lowering the FLASH ORIGIN address and increase the LENGTH accordingly. 

    As an example, let's say you want to increase the bootloader size by 16K (0x4000 bytes). Then you would have to change the ORIGIN from 0xF8000 to 0xF4000 (0xF8000 - 0x4000) and the LENGTH to 0xA000 (0x6000+0x4000).

    +++ b/secure_bootloader_gcc_nrf52.ld
    @@ -5,7 +5,7 @@ GROUP(-lgcc -lc -lnosys)
     
     MEMORY
     {
    -  FLASH (rx) : ORIGIN = 0xf8000, LENGTH = 0x6000
    +  FLASH (rx) : ORIGIN = 0xf4000, LENGTH = 0xA000
       RAM (rwx) :  ORIGIN = 0x20005978, LENGTH = 0x3a688
       uicr_bootloader_start_address (r) : ORIGIN = 0x10001014, LENGTH = 0x4
       bootloader_settings_page (r) : ORIGIN = 0x000FF000, LENGTH = 0x1000
    

    Best regards,

    Vidar

Reply
  • Hello,

    The linker output shows that your bootloader has become too big to fit inside bootloader's FLASH area. So, as you indicated, the solution is to allocate more memory to it. You can do so by lowering the FLASH ORIGIN address and increase the LENGTH accordingly. 

    As an example, let's say you want to increase the bootloader size by 16K (0x4000 bytes). Then you would have to change the ORIGIN from 0xF8000 to 0xF4000 (0xF8000 - 0x4000) and the LENGTH to 0xA000 (0x6000+0x4000).

    +++ b/secure_bootloader_gcc_nrf52.ld
    @@ -5,7 +5,7 @@ GROUP(-lgcc -lc -lnosys)
     
     MEMORY
     {
    -  FLASH (rx) : ORIGIN = 0xf8000, LENGTH = 0x6000
    +  FLASH (rx) : ORIGIN = 0xf4000, LENGTH = 0xA000
       RAM (rwx) :  ORIGIN = 0x20005978, LENGTH = 0x3a688
       uicr_bootloader_start_address (r) : ORIGIN = 0x10001014, LENGTH = 0x4
       bootloader_settings_page (r) : ORIGIN = 0x000FF000, LENGTH = 0x1000
    

    Best regards,

    Vidar

Children
Related