目录
1.编译配置
2.u-boot.lds连接配置文件
3.Stage1之start.S
4.Stage2之入口start_armboot
1.编译配置
编译前先进行配置:make smdkv210single_config
其中,Makefile中make smdkv210single_config为:
- smdkv210single_config : unconfig
- @$(MKCONFIG) $(@:_config=) arm s5pc11x smdkc110 samsung s5pc110
- @echo "TEXT_BASE = 0xc3e00000" > $(obj)board/samsung/smdkc110/config.mk
这里使用了Makefile中的替换引用规则,类似常看到的例子 obj=$(srcfiles:%.c=%.o): 由.c得到对应的.o文件.
这里是一样的道理: $(@:_config=) ,@代表的是target smdkv210single_config, 那么$(@:_config=)就是将smdkv210single_config中的_config替换为空,
即得到smdkv210single。
这里$(@:_config=) arm s5pc11x smdkc110 samsung s5pc110都是mkconfig(即@$(MKCONFIG))的参数,mkconfig即根目录下的脚本文件。
执行这句命令后,在include/下生成config.mk和config.h。并且Makefile包含这个config.mk。
config.mk文件:
- ARCH = arm
- CPU = s5pc11x
- BOARD = smdkc110
- VENDOR = samsung
- SOC = s5pc110
它指定里CPU架构,CPU型号,板子型号,CPU厂商,SOC??(母鸡啦)
可以根据上面的这个信息找到对应的代码。比如说CPU代码在cpu/s5pc11x下,板子代码在board/samsung/smdkc110下。
2. u-boot.lds连接配置文件
对于.lds文件,它定义了整个程序编译之后的连接过程,决定了一个可执行程序的各个段的存储位置。u-boot.lds如何指定连接过程?首先它被根目录下config.mk引用,定义如下:LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds。根据这个路径,对于Android210而言,可以找到这个文件位于:board/samsung/smdkc110/u-boot.lds。其次,LDSCRIPT这个变量何时被用到?同样在config.mk中,可以找到:
LDFLAGS += -Bstatic -T $(LDSCRIPT) $(PLATFORM_LDFLAGS)
ifneq ($(TEXT_BASE),)
LDFLAGS += -Ttext $(TEXT_BASE)
endif
-T 参数指定生成可执行文件时ld连接器如何连接,TEXT_BASE是在make smdkv210single_config时写到board/samsung/smdkc110/config.mk中的,值为0xc3e00000。
- /*
- * (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");指定输出可执行文件是elf格式,32位ARM指令,小端
- /*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/
- OUTPUT_ARCH(arm);指定输出可执行文件的平台为ARM
- ENTRY(_start);指定输出可执行文件的起始代码段为_start
- SECTIONS
- {
- . = 0x00000000; ;从0x0位置开始
- . = ALIGN(4); ;代码以4字节对齐
- .text : ;指定代码段
- {
- cpu/s5pc11x/start.o (.text)
- cpu/s5pc11x/s5pc110/cpu_init.o (.text)
- board/samsung/smdkc110/lowlevel_init.o (.text)
- cpu/s5pc11x/onenand_cp.o (.text)
- cpu/s5pc11x/nand_cp.o (.text)
- cpu/s5pc11x/movi.o (.text)
- board/samsung/smdkc110/flash.o (.text)
- common/secure.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) } ;指定u_boot_cmd段, uboot把所有的uboot命令放在该段
- __u_boot_cmd_end = .; ;把__u_boot_cmd_end赋值为当前位置,即结束位置
- . = ALIGN(4);
- .mmudata : { *(.mmudata) } ;内存管理单元数据段
- . = ALIGN(4);
- __bss_start = .; ;把__bss_start赋值为当前位置,即bss段的开始位置
- .bss : { *(.bss) } ;指定bss段
- _end = .; ;把_end赋值为当前位置,即bss段的结束位置
- }
3.Stage1之start.S
uboot是典型的bootloader之一,大多数bootloader都分为stage1和stage2两部分,u-boot也不例外。依赖于CPU体系结构的代码(如设备初始化代码等)通常都放在stage1且可以用汇编语言来实现,而stage2则通常用C语言来实现,这样可以实现复杂的功能,而且有更好的可读性和移植性。u-boot的Stage1代码通常放在start.S文件中,他用汇编语言写成,其主要代码部分如下:
(1)定义入口。由于一个可执行的Image必须有一个入口点,并且只能有一个全局入口,通常这个入口放在ROM(Flash)的0x00000000地址,因此,必须通知编译器以使其知道这个入口,该工作可通过修改连接器脚本来完成。
(2)设置异常向量(Exception Vector)。
(3)设置CPU的速度、时钟频率及终端控制寄存器。
(4)初始化内存控制器。
(5)将ROM中的程序复制到RAM中。
(6)初始化堆栈。
(7)转到RAM中执行,该工作可使用指令ldr pc来完成。
根据config.mk中CPU的信息,找到对应的cpu目录为cpu/s5pc11x。首先看cpu/s5pc11x/start.S:
其中代码解释引自:http://www.cnblogs.com/Efronc/archive/2012/02/28/2371662.html
- /*
- * armboot - Startup Code for S5PC110/ARM-Cortex CPU-core
- *
- * Copyright (c) 2009 Samsung Electronics
- *
- *
- * 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
- *
- * Base codes by scsuh (sc.suh)
- */
- #include <config.h>
- #include <version.h>
- #if defined(CONFIG_ENABLE_MMU)