一个可以执行的Image都会有一个入口点并且只有一个入口点,不管是WinCE还是Linux,都有唯一的一个入口,通常这个入口被放在Rom(flash)的0X0地址。例如在Uboot中:
输入:VIM /data/u-boot-1.1.6/cpu/s3c24xx/start.S
可见如下代码:
可见代码:
.globl_start
_start:
但是这个_start 入口又在何处呢?这个工作在linux中主要是由另一个关键的文件来实现。即链接器脚本文件。以后缀名.lds的文件。
gcc等编译器内置有缺省的链接器脚本。如果采用内置的缺省脚本,则生成的目标代码需要操作系统才能加载运行。为了能在嵌入式系统上直接运行,需要编写自己的链接生成脚本文件。编写链接脚本,首先要对目标文件的格式有一定的了解。GNU编译器生成的目标文件缺省为elf格式。elf文件由若干段(section)组成,如不特殊指明,又源程序生成的目标代码中包含如下的段:
.text(正文段)包含程序的指令代码;
.data(数据段)包含固定的数据,如常量、字符串等;
.bss(未初始化数据段)包含未初始化的变量、数组等。
C++源程序的目标代码中还包括.fini(析构函数代码)和.init(构造函数代码)等。
先来看看uboot内的u-boot.lds文件:
输入指令:VIM vim /data/u-boot-1.1.6/board/samsung/smdk2416/u-boot.lds
可得:
即:
/*
2 * (C) Copyright 2002
3 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24 OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
25 OUTPUT_ARCH(arm)
26 ENTRY(_start)
27 SECTIONS
28 {
29 . = 0x00000000;
30 . = ALIGN(4);
31 .text :
32 {
33 cpu/s3c24xx/start.o (.text)
34 cpu/s3c24xx/s3c2416/cpu_init.o (.text)
35 cpu/s3c24xx/onenand_cp.o (.text)
36 cpu/s3c24xx/nand_cp.o (.text)
37 cpu/s3c24xx/movi.o (.text)
38 *(.text)
39 }
40 . = ALIGN(4);
41 .rodata : { *(.rodata) }
42 . = ALIGN(4);
43 .data : { *(.data) }
44 . = ALIGN(4);
45 .got : { *(.got) }
46
47 . = .;
48 __u_boot_cmd_start = .;
49 .u_boot_cmd : { *(.u_boot_cmd) }
50 __u_boot_cmd_end = .;
51
52 . = ALIGN(4);
53 .mmudata : { *(.mmudata) }
54
55 . = ALIGN(4);
56 __bss_start = .;
57 .bss : { *(.bss) }
58 _end = .;
59 }
对以上代码做好好的分析:
额,好像一开始就看这个比较复杂了,先来看看GUN官网上的形式完整的描述:
SECTIOS{
...
secname start BLOCK(align)(NOLOAD):AT(ldadr)
{contents}>region:phdr = fill
...
}
准备下班,吃饭继续。。。。。。。