Compiling application in SRAM using SAMV71 SRAM Linker Script

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm working at the moment to get my application code to be compiled into the SRAM on the SAMV71 Xplained ULTRA board. I am using the Atmel linker script (see attached) to run the application in SRAM but I'm not having any success. 

 

Can someone outline the procedures for using the linker script with Atmel Studio 7.0 and getting an application into sram? My application runs fine in flash when booting from flash and using the flash.ld script provided by Atmel but I can't get the application to load into sram. Do I need to use SAM-BA at all? 

 

Cheers,

Sophie 

Attachment(s): 

Last Edited: Mon. Oct 14, 2019 - 04:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No I don't think you need SAM-BA for that.

 

Maybe this part from the GNU LD documentation (http://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html) helps? The main point is that you need to modify the run-time initialization code to load the code into SRAM.

 

I am guessing that you could even do that in C code residing in flash and then do a jump to the start address in SRAM.

 

Quote:
Every section has a virtual address (VMA) and a load address (LMA); see section Basic Linker Script Concepts. The address expression which may appear in an output section description sets the VMA (see section Output section address).

The linker will normally set the LMA equal to the VMA. You can change that by using the AT keyword. The expression lma that follows the AT keyword specifies the load address of the section.

 

This feature is designed to make it easy to build a ROM image. For example, the following linker script creates three output sections: one called `.text', which starts at 0x1000, one called `.mdata', which is loaded at the end of the `.text' section even though its VMA is 0x2000, and one called `.bss' to hold uninitialized data at address 0x3000. The symbol _data is defined with the value 0x2000, which shows that the location counter holds the VMA value, not the LMA value.

SECTIONS
  {
  .text 0x1000 : { *(.text) _etext = . ; }
  .mdata 0x2000 :
    AT ( ADDR (.text) + SIZEOF (.text) )
    { _data = . ; *(.data); _edata = . ;  }
  .bss 0x3000 :
    { _bstart = . ;  *(.bss) *(COMMON) ; _bend = . ;}
}

The run-time initialization code for use with a program generated with this linker script would include something like the following, to copy the initialized data from the ROM image to its runtime address. Notice how this code takes advantage of the symbols defined by the linker script.

extern char _etext, _data, _edata, _bstart, _bend;
char *src = &_etext;
char *dst = &_data;

/* ROM has data at end of text; copy it. */
while (dst < &_edata) {
  *dst++ = *src++;
}

/* Zero bss */
for (dst = &_bstart; dst< &_bend; dst++)
  *dst = 0;

/Jakob Selbing

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

there are several things at once:

 

a) one basic part of your code will be in flash (in order to perform the memcpy from flash to sram of the "sram code", etc.)

b) explicitly create a "sram code" section in the linker script

c) mark the code that should be placed in "sram code section" by adding attributes e.g. __attribute__ ((section(".sramcode")))

d) copy the "sram code" from flash to your "sramcode" section