0
votes

I have a use-case where I want to reserve a configurable AREA of Flash for user-data at the end of the FLASH. I wan't the linker to produce an error (or at minimum a warning) if the code section overlap with the "user-data" area. Here is what I have defined in my linker script:

MEMORY
{
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 160K
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 512K
}

SECTIONS
{
    .text :
    {          
        *(.text)
        *(.text*)
        *(.glue_7)
        *(.glue_7t)
        *(.eh_frame)

        KEEP (*(.init))
        KEEP (*(.fini))
        _etext = .;
  } >FLASH

  /* Reserved FLASH area for user data (r/w data in Flash) */
  __flash_data_size__ = DEFINED(FLASH_DATA_SIZE) ? FLASH_DATA_SIZE : 0K;

  .flash_data  ORIGIN(FLASH) + LENGTH(FLASH) - __flash_data_size__ (NOLOAD) : 
  {
    . = ALIGN(2048);
    __flash_data_start__ = .;
    . = . + __flash_data_size__;
    __flash_data_end__ = .;
  } >FLASH
}

When I define the symbol FLASH_DATA_SIZE I can see that the elf file contains a NOLOAD section at the end of the Flash as expected. However if the section overlaps with the code section (.text) I don't get any linker error. Any idea why the linker does not complain about this?

Alternatively any other ideas how I can have a "compile time" configurable section of the Flash reserved for user data, which is checked against overlapping of code sections?

Thanks in advance, Thomas

1

1 Answers

0
votes

I managed to work out a solution that works and provided the errors I need with overlapping sections. I solved it, by creating another MEMORY region with configurable size. For those interested in the solution I have provided it below:

_FLASH_SIZE = 512K;
_FLASH_DATA_SIZE = (DEFINED(FLASH_DATA_SIZE) ? FLASH_DATA_SIZE : 0K);

MEMORY
{
  RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 160K
  FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = _FLASH_SIZE - _FLASH_DATA_SIZE
  FLASH_DATA (rw) : ORIGIN = 0x08000000 + _FLASH_SIZE - _FLASH_DATA_SIZE, LENGTH = _FLASH_DATA_SIZE
}

SECTIONS
{
  .text :
  {      
    *(.text)
    *(.text*)
    *(.glue_7)
    *(.glue_7t)
    *(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    _etext = .;
  } >FLASH

  .flash_data (NOLOAD) : 
  {
    . = ALIGN(2048);
    __flash_data_start__ = .;
    . = . + _FLASH_DATA_SIZE;
    __flash_data_end__ = .;
  } >FLASH_DATA
}