• AVR Freaks

LINKER: Memory-Usage Report and user defined memory region.

Author
ThierryV
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2014/11/27 01:18:29
  • Location: 0
  • Status: offline
2020/05/19 02:07:00 (permalink)
0

LINKER: Memory-Usage Report and user defined memory region.

Hello,
 
I'm using a custom linker script to put some codes on a custom memory region.
MEMORY
{
  ...
  my_mem_region (rx) : ORIGIN = 0x9D000000, LENGTH = 0x1000
  ...
}

SECTIONS
{
  ...
  .extension :
  {
    KEEP(*my_file1.o(.text .text*))
    KEEP(*my_file2.o(.text .text*))
    ...
  } >my_mem_region
  ...
}

 
But this memory usage is not reported on the Memory-Usage Report of the map file and the output window.
 
I've wasted an awful lot of time, because I thought that my linker script was wrong and my code was discarded, since the memoryfile.xml also told me that my program has been drastically reduced (memory name="program" -> used).
 
Finally, my codes are well mapped on the map file, and I find all my functions at the expected addresses, when I inspect the execution memory in debug.
But the linker memory-usage report and the memoryfile.xml are lying.
 
 
Any idea to update the memory report and the memory file with my custom regions?
 
 
Besides, I also noticed that, while the linker manual (DS50002186A) tells that orphean sections are allocated to any regions with suitable attributes, the Best-Fit allocator is actually using the kseg0_program_mem region statically (since I can't remove it or rename it without a linker error).
#1

1 Reply Related Threads

    ThierryV
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2014/11/27 01:18:29
    • Location: 0
    • Status: offline
    Re: LINKER: Memory-Usage Report and user defined memory region. 2020/05/23 04:17:43 (permalink)
    0
    I am working on a bootloader, but the flash size dedicated for it is not enough for my project.
    Fortunately, my MCU has a bug: when the Boot Flash memory is write protected (BWP=0), the protection overlaps the first page of the main flash memory.
    As this first page cannot be used for my main application (it cannot be written by my bootloader, for a firmware update), I wanted to use it to increase the space available for my bootloader.
    But this extended code was not take into account by the statistic tools of Microchip.
    They seem to consider only the three standard regions named 'kseg0_boot_mem', 'kseg1_boot_mem' and 'kseg0_program_mem'. Otherwise, the size of my bootloader is wrong (this info is important to know, because my code is very tight in this small space). And orphean codes can only be allocated (automatically) into the last one.
     
    So, I had to use 'kseg0_boot_mem' or 'kseg1_boot_mem', to name my extended region.
    Unfortunately, theses named regions seems to be reserved in debug (I have linker errors in debug, while this works in release).
     
    So, finaly, I'am using this custom linker script:
     
     
    MEMORY
    {
    #ifndef __DEBUG_D
      kseg0_program_mem (rx) : ORIGIN = 0xBFC00000, LENGTH = 0x2FF0 /* Main Bootloader code */
      kseg0_boot_mem (rx) : ORIGIN = 0xBD000000, LENGTH = 0x1000 /* Bootloader extension code */
    #else
      kseg0_boot_mem (rx) : ORIGIN = 0xBFC00000, LENGTH = 0x490
      debug_exec_mem : ORIGIN = 0xBFC02000, LENGTH = 0xFF0
      kseg2_boot_mem (rx) : ORIGIN = 0xBD000000, LENGTH = 0x1000 /* Bootloader extension code */
      kseg0_program_mem (rx) : ORIGIN = 0xBD003000, LENGTH = 0x2FF0 /* Main Bootloader code */
    #endif
      configsfrs : ORIGIN = 0xBFC02FF0, LENGTH = 0x10
      config3 : ORIGIN = 0xBFC02FF0, LENGTH = 0x4
      config2 : ORIGIN = 0xBFC02FF4, LENGTH = 0x4
      config1 : ORIGIN = 0xBFC02FF8, LENGTH = 0x4
      config0 : ORIGIN = 0xBFC02FFC, LENGTH = 0x4
      sfrs : ORIGIN = 0xBF800000, LENGTH = 0x100000
      kseg1_data_mem (w!x) : ORIGIN = 0xA0000000, LENGTH = 0x20000
    }
    SECTIONS
    {
      .config_BFC02FFx : { ... } > configx
    }
    SECTIONS
    {
      /*** Boot Sections ***/
      .reset _RESET_ADDR :
      {
        KEEP(*(.reset))
    #ifndef __DEBUG_D
      } >kseg0_program_mem
    #else
      } >kseg0_boot_mem
    #endif

      /*** Main Bootloader Code Section ***/
           /*This section is allocated*/
           /*by the Best-Fit allocator*/
           /* (>kseg0_program_mem) */

      /*** Extension Code Sections ***/
      .extension :
      {
        KEEP(*file1.o(.text .text*))
        KEEP(*file2.o(.text .text*))
        KEEP(*file3.o(.text .text*))
        KEEP(*file4.o(.text .text*))
    #ifndef __DEBUG_D
      } >kseg0_boot_mem
    #else
      } >kseg2_boot_mem
    #endif

      /DISCARD/ : { *(.gen_handler) }
      /DISCARD/ : { *(.vector_*) }
      /DISCARD/ : { *(.startup) }
     
     
     
    ...
     
     
     

     
    Do you have any advices to add?
     
    Ideally, I wished:
    -Use the same linker script in debug and release (without any '#defines')
    -Name the regions as I see fit (with coherent sizes report)
    -Let the linker script dispatching my codes between all the regions tagged 'rx' automatically (remove the '.extension' section)
     
    Regards.
    post edited by ThierryV - 2020/05/25 11:59:46
    #2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5