Fill unused flash memory

Discussion around product based on ARM Cortex M4 core.
This forum will be discontinued soon.

Moderators: nferre, ncollot

cinterion
Posts: 2
Joined: Mon Nov 23, 2015 10:58 am

Fill unused flash memory

Tue Feb 21, 2017 12:10 pm

Hello,
i'm new to gcc and sam programming, so please excuse me if my question is quite obvious for you.
I want to fill my flash memory with a predefined pattern, and place in the last 4 bytes a crc32. Can I solve this problem with the flash.ld linker script ?
Regarding the first part (fill unused memory) I have read the documentation and some example but I can not understand why my script do not work. Here is my script:

Code: Select all


/* Memory Spaces Definitions */
MEMORY
{
  rom (rx)     : ORIGIN = 0x00400000, LENGTH = 0x00080000
  ram (rwx)    : ORIGIN = 0x20000000, LENGTH = 0x00020000
  BattRAM (rw) : ORIGIN = 0x60000000, LENGTH = 0x00080000
}

/* The stack size used by the application. NOTE: you need to adjust according to your application. */
__stack_size__ = DEFINED(__stack_size__) ? __stack_size__ : 0x3000;
__ram_end__ = ORIGIN(ram) + LENGTH(ram) - 4;

SECTIONS
{
    .text :
    {
        . = ALIGN(4);
        _sfixed = .;
        KEEP(*(.vectors .vectors.*))
        *(.text .text.* .gnu.linkonce.t.*)
        *(.glue_7t) *(.glue_7)
        *(.rodata .rodata* .gnu.linkonce.r.*)
        *(.ARM.extab* .gnu.linkonce.armextab.*)

        /* Support C constructors, and C destructors in both user code
           and the C library. This also provides support for C++ code. */
        . = ALIGN(4);
        KEEP(*(.init))
        . = ALIGN(4);
        __preinit_array_start = .;
        KEEP (*(.preinit_array))
        __preinit_array_end = .;

        . = ALIGN(4);
        __init_array_start = .;
        KEEP (*(SORT(.init_array.*)))
        KEEP (*(.init_array))
        __init_array_end = .;

        . = ALIGN(0x4);
        KEEP (*crtbegin.o(.ctors))
        KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
        KEEP (*(SORT(.ctors.*)))
        KEEP (*crtend.o(.ctors))

        . = ALIGN(4);
        KEEP(*(.fini))

        . = ALIGN(4);
        __fini_array_start = .;
        KEEP (*(.fini_array))
        KEEP (*(SORT(.fini_array.*)))
        __fini_array_end = .;

        KEEP (*crtbegin.o(.dtors))
        KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
        KEEP (*(SORT(.dtors.*)))
        KEEP (*crtend.o(.dtors))

        . = ALIGN(4);
        _efixed = .;            /* End of text section */
    } > rom 

    /* .ARM.exidx is sorted, so has to go in its own output section.  */

    PROVIDE_HIDDEN (__exidx_start = .);
    .ARM.exidx :
    {
      *(.ARM.exidx* .gnu.linkonce.armexidx.*)
    } > rom 
    PROVIDE_HIDDEN (__exidx_end = .);

    . = ALIGN(4);
    _etext = .;

/******* START SCRIPT THAT FILL MY FLASH *********************/
  .fini_array :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);

  } > rom
  
  .fill :
  {
    FILL(0xDEADBEEF);
    . = ORIGIN(rom) + LENGTH(rom) - 1;
    BYTE(0xAA)
    _etext = .;
  } > rom
/******* END SCRIPT THAT FILL MY FLASH *********************/

    .relocate : AT (_etext)
    {
        . = ALIGN(4);
        _srelocate = .;
        *(.ramfunc .ramfunc.*);
        *(.data .data.*);
        . = ALIGN(4);
        _erelocate = .;
    } > ram


    /* .bss section which is used for uninitialized data */
    .bss (NOLOAD) :
    {
        . = ALIGN(4);
        _sbss = . ;
        _szero = .;
        *(.bss .bss.*)
        *(COMMON)
        . = ALIGN(4);
        _ebss = . ;
        _ezero = .;
    } > ram


    /* stack section */
    .stack (NOLOAD):
    {
        . = ALIGN(8);
        _sstack = .;
        . = . + __stack_size__;
        . = ALIGN(8);
        _estack = .;
    } > ram


	/* External ram */
   .uninit (NOLOAD) : 
   { 
   } >BattRAM
    . = ALIGN(4);
    _end = . ;
}

I have defined a .fill section with the FILL command and I expect that this command fill all rom memory with the predefined pattern.
But what realy happen is that the flash memory is filled but a data memory overflow is generated! I can not understand the reason.
With this script I have the following warning:


Warning Program Memory Usage : 559060 bytes 106,6 % Full (Memory Overflow)
Data Memory Usage : 295596 bytes 225,5 % (Memory Overflow)


Also if I do not use only few bytes of data memory. Can someone help me to solve this problem ?
Thanks in advance.
tsvoipio
Posts: 54
Joined: Wed Aug 19, 2015 9:44 pm

Re: Fill unused flash memory

Tue Feb 21, 2017 8:47 pm

Your .relocate section is appended to the filled ROM image, creating the ROM overflow.

A link map is needed to see the cause of the data overflow.

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 3 guests