Memory partition overflow detection in ld

I have a microcontroller project using the GCC toolchain.

gcc version 4.7.4 20130913 (release) [ARM/embedded-4_7-branch revision 202601]

The controller has a 512k flash memory. The first 64k are occupied by the bootloader and 448k remain for the project. I defined a script builder with dimensions for FLASH and RAM. I also added sections. Here is an excerpt:

MEMORY
{
  FLASH (rx)      : ORIGIN = 0x00010000, LENGTH = 448K
  RAM (xrw)       : ORIGIN = 0x10000000, LENGTH = 64K
}

SECTIONS
{
  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
  } > FLASH

  .fini_array :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);
    _eflash = .;
  } >FLASH

  /* used by the startup to initialize data */
  _sidata = .;

  .data : AT ( _sidata )
  {
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */
    _edata = .;        /* define a global symbol at data end */
  } >RAM
}

The component works great, placing all sections in their places. The problem is that the linker does not check if there is enough space for partitions .dataand .data*in FLASH in place _sidata. The result exceeds the memory size without warning.

How can I adapt the linker script so that ld uses initialization data (.data) in the size calculation?

Edit: is there a command line option to provide reasonable data placement?

+4
1

ASSERT:

  /* used by the startup to initialize data */
  _sidata = .;

  .data : AT ( _sidata )
  {
    _sdata = .;
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */
    _edata = .;        /* define a global symbol at data end */
  } >RAM

  /* verify that the initialization data fits in FLASH */
  ASSERT(
     (_sidata + (_edata - _sdata)) <= (ORIGIN(FLASH) + LENGTH(FLASH)),
     "Initialization Data blow up")
}
+3

Source: https://habr.com/ru/post/1536143/


All Articles