2008年11月24日星期一

gcc链接脚本文件几个理解

1,运行时地址和装载时地址:
Another question, more conceptual. This ld uses named sections, using >
to say where it will be loaded, and AT> to say where it is at the moment
of reset. (I think, anyway). Let's say I also want to use
__attribute__ to define some functions in RAM, naming this ".ramtext" in
my C code. My guess is that this looks something like this:

prog : {
*(.text)
*(.rodata)
*(.rodata*)
*(.glue_7)
*(.glue_7t)
__end_of_prog__ = . ;
} >flash

.ramtext : {
__ramtext_beg__ = . ;
__ramtext_beg_src__ = __end_of_prog__ ;
*(.ramtext)
__ramtext_end__ = .;
} >ram AT>flash

And then my boot.s would just copy (__ramtext_end__ - __ramtext_beg__)
bytes from __ramtext_beg_src__ to __ramtext_beg__.

又例如:
SECTIONS {
firtst 0x00000000 : { head.o init.o }
second 0x30000000 : AT(0x100) { main.o }
}
对于第二个输出段,装载地址为0x100,运行地址为0x30000000,初始化文件需把该段从加载地址拷贝到运行地址处;


2,用户自定义输入段
例如:
volatile int buff1_app[1280] __attribute__((section(".sdram")));
void hello(int a) __attribute__((section(".sdram")));
声明了用户自定义输入段,在链接脚本文件中可以利用;函数声明到自定义段中,只是代码部分放到里面,其他部分被放到默认段中,如.data等;


3,分散加载

可以利用链接脚本文件实现分散加载,例如:
. = 0;
startup : { *(.startup)} >ram

/*接着放代码*/
prog :
{
*(.text)
*(.rodata)
*(.rodata*)
*(.glue_7)
*(.glue_7t)
} >ram

/*剩余代码放到外部RAM*/
prog2 :
{
*(.text)
*(.rodata)
*(.rodata*)
*(.glue_7)
*(.glue_7t)
} >eram

没有评论: