This is the mail archive of the crossgcc@sourceware.cygnus.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: crossgcc: code wont run from ROM.


Brendan J Simon wrote:
> 
> Peter Popov wrote:
> 
> > > I just had a thought.  Maybe I need to copy the initialised data section from
> > > ROM to RAM ?
> > > I know that the DiabData startup files do this and I'm pretty sure I haven't done
> > > this in my gcc startup files.
> > > Does this sound plausable ?
> >
> > Sure, if you are not doing that, you'll have all sorts of problems.
> 
> I 've just had a look at the gcc linker command file and it is a bit of a mess.  What
> sections do I need to copy from ROM to RAM for powerpc-eabi format.  The ones that I
> think are canditdates are .rodata, .sdata2 and .data.
> 
> Do I need to copy all or just some of these sections ?
> Are there any others I've missed ?

You need to copy all of the "initialized" sections, and zero out the
.bss and .sbss sections.  If you don't zero those out, you'll be in
trouble.  Here's a portion of my script which works on my board (this is
work in progress). This script is for code which gets loaded by a boot
loader.  The boot loader moves everything out of flash, including the
text sections, and then zeros out the .bss and .sbss sections.

    .data :
    {
        . = ALIGN(32);
        _Bdata = .;
        *(.data)
        *(.sdata)
        *(.sdata2)
        _Edata = .;
    } > sdram
 
    .bss :
    {
        . = ALIGN(32);
        _Bbss = .;
        *(.bss)
        *(.sbss)
        _Ebss = .;
    } > sdram

The boot loader moves everything from _Bdata to _Edata from flash to
sdram.  You don't need a boot loader to do that thought; simply do it in
your init code *before* you access any variables which are in the .bss,
.sbss, or .data sections.  Also, I zero out everything from _Bbss to
_Ebss.  You can move the .rodata section to sdram as well, since the
access will be faster than that of flash.  Or, you can keep it in flash,
but make sure it's linked appropriately.

Finally, do a simple test to see if you've moved everything correctly. 
In your c code, *after* everything is initialized, print a few varibles
from the different sections to verify they are initialized properly:

int var_dsection = 0x5a5a5a5a; // this var will go in the .data or
.sdata section
int should_be_zero;              // this one is in the .bss or .sbss
section

Naturally, a printf of var_dsection should show 0x5a5a5a5a, and
should_be_zero should show zero.

Pete

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]