在说u-boot之前大家想象一下windows上电启动:PC => BIOS => 引导操作系统 => 识别C、D盘... => 运行应用程序。通常在嵌入式系统中,系统的启动流程:载入系统 => bootloader => linux内核 => 挂载文件系统 => 应用程序。
一、首先从makefile的配置过程入手分析:make 100ask24x0_config,看看这个步骤具体做了什么事情
100ask24x0_config是makefile中的一个目标,它在makefile中对应的语句如下:
100ask24x0_config
: unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
($1-$6对应于:目标 ARCH CPU BOARD VENDOR SOC)
@echo "TEXT_BASE = 0x33F80000" => $(TOP)/board/100ask24x0/config.mk
step1:执行unconfig删除之前的配置和生成文件
step2:执行mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0配置u-boot工程
step2_1: 设置开发板
BOARD_NAME = 100ask24x0;
step2_2: echo "Configuring for ${BOARD_NAME} board..."
step2_3: 删除原来的ARCH链接,重新建立新的ARCH链接
cd ./include
rm -f asm
ln -s asm-$2 asm #建立asm链接目录,它指向asm-arm
step2_4: 删除原来的SOC链接,重新建立新的SOC链接
rm -f asm-$2/arch
ln -s ${LNPREFIX}arch-$6 asm-$2/arch =>
ln -s arch-s3c24x0 asm-arm/arch
step2_5:删除原来的proc链接,重新建立新的proc链接
rm -f asm-$2/proc
ln -s ${LNPREFIX}proc-armv asm-$2/proc => ln -s proc-armv
asm-arm/proc
step2_6:创建config.mk文件
#Create include file for Make
echo "ARCH = $2" > config.mk > :新建一个文件
echo "CPU = $3" >> config.mk >> :追加内容
echo "BOARD = $4" >> config.mk
echo "SOC = $6" >> config.mk
step2_7:创建config.h文件
# Create board specific header file
> config.h
echo "/* Automatically generated - do not edit */" >>config.h
echo "#include " >>config.h => echo "#include " >>config.h
二、然后分析make过程,看看这个步骤具体做了什么事情:
step1:加载配置过程生成的几个变量
# load ARCH, BOARD, and CPU configuration
include $(OBJTREE)/include/config.mk
export
ARCH CPU BOARD VENDOR SOC
step2:设置编译工具链
ifeq ($(ARCH),arm)
CROSS_COMPILE = arm-linux-
step3:设置第一个要编译链接的.o程序
OBJS = cpu/$(CPU)/start.o => OBJS = cpu/arm920t/start.o
step4:设置库文件
LIBS = lib_generic/libgeneric.a
LIBS += board/$(BOARDDIR)/lib$(BOARD).a => LIBS += board/100ask24x0/lib100ask24x0.a
LIBS += cpu/$(CPU)/lib$(CPU).a => LIBS += cpu/arm920t/libarm920t.a
......
step5:编译目标
ALL = $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND)
all:
$(ALL)
$(obj)u-boot.bin:$(obj)u-boot
$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
$(obj)u-boot:
depend version $(SUBDIRS) $(OBJS) $(LIBS) $(LDSCRIPT)
UNDEF_SYM=`$(OBJDUMP) -x $(LIBS) |sed -n
-e 's/.*(__u_boot_cmd_.*)/-u1/p'|sort|uniq`;
cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM
$(__OBJS)
--start-group $(__LIBS) --end-group $(PLATFORM_LIBS)
-Map u-boot.map -o u-boot
例:(我编译时的打印)
UNDEF_SYM=`arm-linux-objdump -x lib_generic/libgeneric.a board/100ask24x0/lib100ask24x0.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a
fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/nand/libnand.a drivers/nand_legacy/libnand_legacy.a
drivers/usb/libusb.a drivers/sk98lin/libsk98lin.a common/libcommon.a |sed -n -e 's/.*(__u_boot_cmd_.*)/-u1/p'|sort|uniq`;
cd /home/edu/JZ2440/u-boot工程/u-boot-1.1.6 && arm-linux-ld -Bstatic -T /home/edu/JZ2440/u-boot工程/u-boot-1.1.6/board/100ask24x0/u-boot.lds -Ttext 0x33F80000 $UNDEF_SYM cpu/arm920t/start.o
--start-group lib_generic/libgeneric.a board/100ask24x0/lib100ask24x0.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a
fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/nand/libnand.a drivers/nand_legacy/libnand_legacy.a drivers/usb/libusb.a drivers/sk98lin/libsk98lin.a common/libcommon.a --end-group
-L /home/edu/JZ2440/u-boot工程/gcc-3.4.5-glibc-2.3.6/bin/../lib/gcc/arm-linux/3.4.5 -lgcc
-Map u-boot.map -o u-boot
arm-linux-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec
arm-linux-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
step6:链接文件
SECTIONS
{
. = 0x00000000; //当前地址等于:0x0 + -Ttext 0x33F80000 = 0x33F80000
. = ALIGN(4);
.text :
{
cpu/arm920t/start.o(.text)
//第一个文件的代码段
board/100ask24x0/boot_init.o (.text)
//第二个文件的代码段
*(.text)
//其他所有文件的代码段
}
. = ALIGN(4);
.rodata : { *(.rodata) }
. = ALIGN(4);
.data : { *(.data) }
. = ALIGN(4);
.got : { *(.got) }
. = .;
__u_boot_cmd_start = .;
.u_boot_cmd : { *(.u_boot_cmd) }
__u_boot_cmd_end = .;
. = ALIGN(4);
__bss_start = .;
.bss : { *(.bss) }
_end = .;
}
step7:链接选项
TOP/config.mk(189) :
LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
#TEXT_BASE : TOP/board/100ask24x0/config.mk(25) : TEXT_BASE = 0x33F80000