public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* execute code in ram, linker script
@ 2007-07-30 19:15 Klaus Rudolph
  2007-08-03  0:38 ` Erik Christiansen
  0 siblings, 1 reply; 4+ messages in thread
From: Klaus Rudolph @ 2007-07-30 19:15 UTC (permalink / raw)
  To: binutils

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.

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)

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

Please help!
  Klaus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: execute code in ram, linker script
  2007-07-30 19:15 execute code in ram, linker script Klaus Rudolph
@ 2007-08-03  0:38 ` Erik Christiansen
  2007-08-03  5:28   ` Klaus Rudolph
  0 siblings, 1 reply; 4+ messages in thread
From: Erik Christiansen @ 2007-08-03  0:38 UTC (permalink / raw)
  To: binutils

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: execute code in ram, linker script
  2007-08-03  0:38 ` Erik Christiansen
@ 2007-08-03  5:28   ` Klaus Rudolph
  0 siblings, 0 replies; 4+ messages in thread
From: Klaus Rudolph @ 2007-08-03  5:28 UTC (permalink / raw)
  To: Erik Christiansen, ramana.venkat83; +Cc: binutils

Thanks a lot for your help,

yes, in between I was able to found "my" problems.
I did not know that I had to have manually collect the sections .ctors 
.dtors in my rom section. I copied an available ld script from the net 
but this was wrong. The command (CONSTRUCTORS) was not made for my elf 
target. My mistake was to believe the constructors will catched by that 
command but this was not the reality :-)
And it was very misterious that a got a lot of "internal linker errors" 
   will digging through the writing of ld scripts.

And the trouble continous after linking some external libraries, because 
2 additional sections came into the build which I had also overseen :-)

But now it builds and the objdump -h looks well. But I have not tested 
the solution on the target. I will check for global constructors and my 
ram code. If it works, the work done! I hope it works :-)

Thanks
  Klaus





> 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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: execute code in ram, linker script
@ 2007-08-01 11:07 Ramana
  0 siblings, 0 replies; 4+ messages in thread
From: Ramana @ 2007-08-01 11:07 UTC (permalink / raw)
  To: lts-rudolph; +Cc: binutils

Hello Klaus,

    As far as i know, you can set the VMA as your RAM address and LMA
as your flash memory that will give your expected behavior.

 Here is how you can do that

PHDRS{
     -------------
     seg_flash PT_LOAD ;  /* if you want to specify the segment */
      --------------------
   }
MEMORY{
      -------------------
 ---------------------------
      ram_mem : ORIGIN = xxxxx, LENGTH = xxxxx
     flash_mem : ORIGIN = xxxxx, LENGTH = xxxxx
--------------
}

SECTIONS{
 -------------------------
----------------------
FLASH_RAM :{
               ---------------------
             -----------------------
          } >ram_mem AT>flash_mem :seg_flash
    ------------------
----------------------
}

Am I wrong?

Regards,
Ram

>---------- Forwarded message ----------
>From: "Klaus Rudolph" <lts-rudolph@gmx.de>
>To: binutils@sourceware.org
>Date: Mon, 30 Jul 2007 20:15:32 +0200
>Subject: execute code in ram, linker script
>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.
>
>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)
>
>Could someone give me an example. I also need the symbol definition
for the copy >routine.
>
>Please help!
> Klaus

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-08-03  5:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-30 19:15 execute code in ram, linker script Klaus Rudolph
2007-08-03  0:38 ` Erik Christiansen
2007-08-03  5:28   ` Klaus Rudolph
2007-08-01 11:07 Ramana

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).