深入浅析Linux下uboot之(四)-----------------------:链接脚本 u-boot.lds 分析

通过之前的 Makefile 的分析,可以知道 在Makefile 中 include $(obj)include/config.mk(133行),定位到跟 Makefile 同目录的 config.mk 里面的 144-148 行:

ifeq ($(CONFIG_NAND_U_BOOT),y)
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
else
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
endif

如果定义了 CONFIG_NAND_U_BOOT 宏,则链接脚本叫 u-boot-nand.lds,如果未定义这个宏则链接脚本叫 u-boot.lds 。我们在分析uboot的编译链接过程时就要分析这个链接脚本。u-boot.lds  脚本的内容如下:

/*
 * (C) Copyright 2002
 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
/*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/
OUTPUT_ARCH(arm)
ENTRY(_start)       //指定程序的入口点,在start.s中的_start。

SECTIONS
{
	. = 0x00000000;

	. = ALIGN(4);  //4个字节对齐
	.text      :       //文本段
	{
	  cpu/s5pc11x/start.o	(.text)
	  cpu/s5pc11x/s5pc110/cpu_init.o	(.text)
	  board/samsung/x210/lowlevel_init.o	(.text)
          cpu/s5pc11x/onenand_cp.o      (.text)                 
          cpu/s5pc11x/nand_cp.o (.text)                     
          cpu/s5pc11x/movi.o (.text) 
          common/secure_boot.o (.text) 
	  common/ace_sha1.o (.text)
	  cpu/s5pc11x/pmic.o (.text)
	  *(.text)
	}

	. = ALIGN(4);
	.rodata : { *(.rodata) }    //数据只读段

	. = ALIGN(4);
	.data : { *(.data) }  //指定读/写数据段

	. = ALIGN(4);
	.got : { *(.got) }  //指定got段,got段式是uboot自定义的一个段,非标准段

	__u_boot_cmd_start = .;  //把__u_boot_cmd_start赋值为当前位置,即起始位置
	.u_boot_cmd : { *(.u_boot_cmd) }  //uboot把所有的uboot命令放在该段
	__u_boot_cmd_end = .;  //赋值为当前位置,即结束位置

	. = ALIGN(4);
	.mmudata : { *(.mmudata) }

	. = ALIGN(4);
	__bss_start = .;
	.bss : { *(.bss) }  //__bss_start赋值为当前位置,即bss段得开始位置
	_end = .;  //把_end赋值为当前位置,即bss段得结束地址
}

ENTRY(_start)用来指定整个程序的入口地址。所谓入口地址就是整个程序的开头地址,可以认为就是整个程序的第一句指令。有点像C语言中的main。因此_start符号所在的文件就是整个程序的起始文件,_start所在处的代码就是整个程序的起始代码。用搜索代码工具搜索到一共7个_start,然后分析搜索出来的7处,发现有2个是api_example,2个是 onenand 相关的,都不是我们要找的。剩下3个都在 uboot/cpu/s5pc11x/start.S 文件中。因此 start.S 就是我们所要找的,也就是我们 uboot 启动第一阶段的代码的位置就在 start.S  

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值