execute code in ram, linker script

Erik Christiansen erik@dd.nec.com.au
Fri Aug 3 00:38:00 GMT 2007


On Mon, Jul 30, 2007 at 08:15:32PM +0200, Klaus Rudolph wrote:
> Hi again,
> 
> I need a section in a linker script which should put my code to the
> flash and give my the addresses like linked in ram. My startup code
> should move the code from flash to ram. Absolutly normal I hope.

Yes, if you look in some crt0.S (more generally crt[01].[Sc]), e.g. from
newlib (not so much ELDK, or the linux kernel), you can see an
elementary copy loop for .data, and zero initialisation loop for .bss.
But as you say, there's no magic at all.

> But I am not find the correct way to do it.
> 
> Please help!
> 
> 4 sections needed (.text, .data, .bss and my stupied Flash->RAM section)

Except that .bss is not copied, naturally.  :-)

> Could someone give me an example. I also need the symbol definition for the copy routine. 

OK, it looks like it's the symbol definitions which have you tricked, so
here's a quickly cobbled example:

MEMORY
{
   ROM :  org = 0x00100000, len = 0x00100000
   RAM :  org = 0x00000000, len = 0x00080000
}

SECTIONS
{
   VectorsInROM = 0x00140000 ;                  /* Just something to show a */
   .vectors 0x0 : AT (VectorsInROM) {           /* way to abut .data, below */
      *(.vectors)
   } > RAM

   __data_rom = VectorsInROM + SIZEOF(.vectors);   /* To abut sections in flash. */

   /*       RAM               Flash    */
   /*        |                  |      */
   .data 0x00012000 : AT (__data_rom) {         /* Terminology = VMA: AT LMA */ 
      __data_start = ABSOLUTE(.);               /* Symbol for copy loop. */
      *(.data*)
      /* More input sections, maybe. */
      __data_end = ABSOLUTE(.);                 /* Symbol for copy loop. */
   } > RAM
}

Obviously, if you use a symbol instead of 0x00012000 for VMA, then it's
easier to re-use for the copy loop destination.

But maybe you've managed to research as much by now?  :-)
("info ld" is a goldmine)

Good luck,

Erik



More information about the Binutils mailing list