深入淺析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, <[email protected]>
 *
 * 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  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章