AnsweredAssumed Answered

Padding FLASH without overflowing memory

Question asked by Robert Poor on Aug 8, 2018
Latest reply on Aug 10, 2018 by Robert Poor

I'm using a flash-resident bootloader to load code into my KL27Z.  To reduce the chance of bricking the device, I'm using CRC on the image.  Consequently, I want to pad the image with 0xff so the checksum calculation will always be accurate.

 

Following Erich Styger's excellent blog post, I added the following to my MKL27Z64xxx4_flash.ld file (new code in bold face):

 

  .fini_array :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT(.fini_array.*)))
    KEEP (*(.fini_array*))
    PROVIDE_HIDDEN (__fini_array_end = .);
  } > m_text

 

  .filler :
  {
    FILL(0x5A);  /* for testing.  replace with 0xFF for production */
    . = ORIGIN(m_text) + LENGTH(m_text) - 1;
    BYTE(0xFF);
  } > m_text
 
  __etext = .;    /* define a global symbol at end of code */
  __DATA_ROM = .; /* Symbol is used by startup for data initialization */

 

My goal with this is to fill up all unused FLASH with a 0x5A pattern, and at the very last byte write 0xFF.  But when I link using this code, I get the error:

 

Invoking: Cross ARM GNU C++ Linker
arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -Og -fmessage-length=0 -fsigned-char ...
arm-none-eabi/bin/ld: region m_text overflowed with text and data
collect2: error: ld returned 1 exit status

 

I should mention that when I comment out the .filler {} section, the link process completes without error, and has ample room to spare:

 

Invoking: Cross ARM GNU Print Size
arm-none-eabi-size --format=berkeley "rex.elf"
   text       data        bss        dec        hex    filename
  37532       2404       3216      43152       a890    rex.elf
Finished building: rex.siz
Finished building: rex.srec

 

Any idea what's going on?

Outcomes