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

DFU gcc linker setting

Hi,

I have a question regarding linker file in case of gcc make. I need to create a DFU package and program the it on a bootloader.

Here is my linker file:

/* Linker script to configure memory regions. */

SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)

MEMORY
{
  FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x5a000
  RAM (rwx) :  ORIGIN = 0x20002bf0, LENGTH = 0xd410
}

SECTIONS
{
}

SECTIONS
{
  . = ALIGN(4);
  .mem_section_dummy_ram :
  {
  }
  .cli_sorted_cmd_ptrs :
  {
    PROVIDE(__start_cli_sorted_cmd_ptrs = .);
    KEEP(*(.cli_sorted_cmd_ptrs))
    PROVIDE(__stop_cli_sorted_cmd_ptrs = .);
  } > RAM
  .fs_data :
  {
    PROVIDE(__start_fs_data = .);
    KEEP(*(.fs_data))
    PROVIDE(__stop_fs_data = .);
  } > RAM
  .log_dynamic_data :
  {
    PROVIDE(__start_log_dynamic_data = .);
    KEEP(*(SORT(.log_dynamic_data*)))
    PROVIDE(__stop_log_dynamic_data = .);
  } > RAM
  .log_filter_data :
  {
    PROVIDE(__start_log_filter_data = .);
    KEEP(*(SORT(.log_filter_data*)))
    PROVIDE(__stop_log_filter_data = .);
  } > RAM

} INSERT AFTER .data;

SECTIONS
{
  .mem_section_dummy_rom :
  {
  }
  .sdh_soc_observers :
  {
    PROVIDE(__start_sdh_soc_observers = .);
    KEEP(*(SORT(.sdh_soc_observers*)))
    PROVIDE(__stop_sdh_soc_observers = .);
  } > FLASH
  .sdh_ble_observers :
  {
    PROVIDE(__start_sdh_ble_observers = .);
    KEEP(*(SORT(.sdh_ble_observers*)))
    PROVIDE(__stop_sdh_ble_observers = .);
  } > FLASH
  .pwr_mgmt_data :
  {
    PROVIDE(__start_pwr_mgmt_data = .);
    KEEP(*(SORT(.pwr_mgmt_data*)))
    PROVIDE(__stop_pwr_mgmt_data = .);
  } > FLASH
    .nrf_queue :
  {
    PROVIDE(__start_nrf_queue = .);
    KEEP(*(.nrf_queue))
    PROVIDE(__stop_nrf_queue = .);
  } > FLASH
  .sdh_req_observers :
  {
    PROVIDE(__start_sdh_req_observers = .);
    KEEP(*(SORT(.sdh_req_observers*)))
    PROVIDE(__stop_sdh_req_observers = .);
  } > FLASH
  .sdh_state_observers :
  {
    PROVIDE(__start_sdh_state_observers = .);
    KEEP(*(SORT(.sdh_state_observers*)))
    PROVIDE(__stop_sdh_state_observers = .);
  } > FLASH
  .sdh_stack_observers :
  {
    PROVIDE(__start_sdh_stack_observers = .);
    KEEP(*(SORT(.sdh_stack_observers*)))
    PROVIDE(__stop_sdh_stack_observers = .);
  } > FLASH
    .nrf_balloc :
  {
    PROVIDE(__start_nrf_balloc = .);
    KEEP(*(.nrf_balloc))
    PROVIDE(__stop_nrf_balloc = .);
  } > FLASH
    .cli_command :
  {
    PROVIDE(__start_cli_command = .);
    KEEP(*(.cli_command))
    PROVIDE(__stop_cli_command = .);
  } > FLASH
  .crypto_data :
  {
    PROVIDE(__start_crypto_data = .);
    KEEP(*(SORT(.crypto_data*)))
    PROVIDE(__stop_crypto_data = .);
  } > FLASH
  .log_const_data :
  {
    PROVIDE(__start_log_const_data = .);
    KEEP(*(SORT(.log_const_data*)))
    PROVIDE(__stop_log_const_data = .);
  } > FLASH
  .log_backends :
  {
    PROVIDE(__start_log_backends = .);
    KEEP(*(SORT(.log_backends*)))
    PROVIDE(__stop_log_backends = .);
  } > FLASH

} INSERT AFTER .text


INCLUDE "nrf_common.ld"

I know that I should define  the location where bootloader start address is stored in this file. But I have not found any example.

My second question is that how I can find this address in my bootloader file?

Thanks

Parents
  • Hi,

    I know that I should define  the location where bootloader start address is stored in this file. But I have not found any example.

    Take a look at the gcc linker setting in SDK_folder\examples\ble_peripheral\ble_app_buttonless_dfu\pca10040\s132\armgcc\ble_app_buttonless_dfu_gcc_nrf52.ld 

    My second question is that how I can find this address in my bootloader file?

    The bootloader linker script will write the bootloader start address to the UICR register. This value will be written in the bootloader HEX file and thus written to UICR when the bootloader is flashed into the chip. See the file nrf_bootloader_info.c

  • thanks for your reply.

    so if I replace the linker file by ble_app_buttonless_dfu_gcc_nrf52.ld and modify  FLASH (rx) and RAM (rwx) it should work?

Reply Children
  • Tai said:
    so if I replace the linker file by ble_app_buttonless_dfu_gcc_nrf52.ld and modify  FLASH (rx) and RAM (rwx) it should work?

     Yes, I think that should be enough. If you are using the bottonless DFU service, then you might need to call ble_dfu_buttonless_async_svci_init() in your main function as well.

  • I am going to try it.

    But know I have another question. I used hrs example and then I added ble_dfu_buttonless_async_svci_init() to it in Keil. DFU seems to work correctly. I wonder if there I correctly configured everything. For example Flash length is different in gcc linker file.

  • I tryed to change the flash and ram size to 

    MEMORY
    {
      FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x52000
      RAM (rwx) :  ORIGIN = 0x20002bf0, LENGTH = 0xd410
      uicr_bootloader_start_address (r) : ORIGIN = 0x10001014, LENGTH = 0x4
    }
    
    SECTIONS
    {
      . = ALIGN(4);
      .uicr_bootloader_start_address :
      {
        PROVIDE(__start_uicr_bootloader_start_address = .);
        KEEP(*(SORT(.uicr_bootloader_start_address*)))
        PROVIDE(__stop_uicr_bootloader_start_address = .);
      } > uicr_bootloader_start_address
    }

    I could compile and link and creat the package. But when I tryed to program the package via DFU, the connection stoped and the package did not upload.

  • Tai said:
    But when I tryed to program the package via DFU, the connection stoped and the package did not upload

     What SDK version are you using?

    Are you using the bootloader in examples\dfu\secure_bootloader\pca10040_s132_ble ?

    Can you post the command you used to create the DFU package?

  • It is 17.0.2 version.

    I am using hrs example and I added  ble_dfu_buttonless_async_svci_init() and other dfu codes to the example. When I use .hex created by keil it seems to be ok. But I can not use the package created by gcc.

    it is DFU package creator that I use:

    nrfutil pkg generate --hw-version 52 --application-version 0 --application ~\nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_habil_up\pca10040\s132\armgcc\_build\nrf52832_xxaa.hex --sd-req 0x0101 --key-file keys/private.key app_%1.zip

Related