jz2440:
韦东山Linux视频第1期_裸板_UBoot_文件系统_驱动初步第09课第2节 u-boot分析之Makefile结构分析.WMV
《嵌入式linux完全开发手册》 15.2 U-Boot 分析与移植
1. uboot make编译过程:
cd u-boot-1.1.6
patch -p1 < ../u-boot-1.1.6_jz2440.patch
make 100ask24x0_config
make all
2. 分析make 100ask24x0_config
{
Makefile
mkconfig
include/asm
include/asm/arch
include/asm/proc
include/config.mk
include/config.h
include/configs/100ask24x0.h
}
vi Makefile
{
1886 100ask24x0_config : unconfig
1887 @$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
}
--> mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0
vi mkconfig
{
# Parameters: Target Architecture CPU Board [VENDOR] [SOC]
确定开发板名称:
{
23 [ "${BOARD_NAME}" ] || BOARD_NAME="$1"
}
创建到平台/开发板相关的头文件的链接
{
46 cd ./include
47 rm -f asm
48 ln -s asm-$2 asm
51 rm -f asm-$2/arch
56 ln -s ${LNPREFIX}arch-$6 asm-$2/arch
60 rm -f asm-$2/proc
61 ln -s ${LNPREFIX}proc-armv asm-$2/proc
}
为Make创建包含文件include/config.mk
{
67 echo "ARCH = $2" > config.mk
68 echo "CPU = $3" >> config.mk
69 echo "BOARD = $4" >> config.mk
71 [ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk
73 [ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk
}
创建开发板相关的头文件include/config.h
{
85 echo "#include " >>config.h
}
}
3. uboot的配置文件: include/configs/100ask24x0.h
修改这个配置文件来达到裁剪和设置uboot,类似于kernel的make menuconfig的效果。
主要有3类宏:
CONFIG_ 主要用来设置功能、使用文件中的哪一块这样的参数; CFG_ 主要用来设置一些更细节的参数; 另外还有些其他的定义。
原则上是这样的,实际上主要还是看代码。
{
36 #define CONFIG_ARM920T 1 /* This is an ARM920T Core */
45 #define USE_920T_MMU 1
56 #define MTDIDS_DEFAULT "nand0=nandflash0"
57 #define MTDPARTS_DEFAULT "mtdparts=nandflash0:256k@0(bootloader),"
58 "128k(params),"
59 "2m(kernel),"
60 "-(root)"
152 #define CFG_MEMTEST_START 0x30000000 /* memtest works on */
153 #define CFG_MEMTEST_END 0x33F00000 /* 63 MB in DRAM */
}
4. 分析make all
vi Makefile
{
116 # load ARCH, BOARD, and CPU configuration
117 include $(OBJTREE)/include/config.mk
118 export ARCH CPU BOARD VENDOR SOC
127 ifeq ($(ARCH),arm)
128 CROSS_COMPILE = arm-linux-
129 endif
163 # load other configuration
164 include $(TOPDIR)/config.mk
166 #########################################################################
167 # U-Boot objects....order is important (i.e. start must be first)
168
169 OBJS = cpu/$(CPU)/start.o //cpu/arm920t/start.o是第一个obj文件,先后顺序很重要
199 LIBS += lib_$(ARCH)/lib$(ARCH).a
200 LIBS += fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a
201 fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a
202 LIBS += net/libnet.a
203 LIBS += disk/libdisk.a
204 LIBS += rtc/librtc.a
205 LIBS += dtt/libdtt.a
206 LIBS += drivers/libdrivers.a
207 LIBS += drivers/nand/libnand.a
208 LIBS += drivers/nand_legacy/libnand_legacy.a
209 LIBS += drivers/usb/libusb.a
210 LIBS += drivers/sk98lin/libsk98lin.a
211 LIBS += common/libcommon.a
239 ALL = $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND)
240
241 all: $(ALL)
242
243 $(obj)u-boot.hex: $(obj)u-boot
244 $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@
245
246 $(obj)u-boot.srec: $(obj)u-boot
247 $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@
248
249 $(obj)u-boot.bin: $(obj)u-boot
250 $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
251
252 $(obj)u-boot.img: $(obj)u-boot.bin
253 ./tools/mkimage -A $(ARCH) -T firmware -C none
254 -a $(TEXT_BASE) -e 0
255 -n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) |
256 sed -e 's/"[ ]*$$/ for $(BOARD) board"/')
257 -d $< $@
258
259 $(obj)u-boot.dis: $(obj)u-boot
260 $(OBJDUMP) -d $< > $@
261
262 $(obj)u-boot: depend version $(SUBDIRS) $(OBJS) $(LIBS) $(LDSCRIPT)
263 UNDEF_SYM=`$(OBJDUMP) -x $(LIBS) |sed -n -e 's/.*(__u_boot_cmd_.*)/-u1/p'|sort|uniq`;
264 cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS)
265 --start-group $(__LIBS) --end-group $(PLATFORM_LIBS)
266 -Map u-boot.map -o u-boot
268 $(OBJS):
269 echo $(OBJS)
270 $(MAKE) -C cpu/$(CPU) $(if $(REMOTE_BUILD),$@,$(notdir $@))
271
272 $(LIBS):
273 $(MAKE) -C $(dir $(subst $(obj),,$@))
278 $(SUBDIRS):
279 $(MAKE) -C $@ all
}
分析 “ 164 include $(TOPDIR)/config.mk ” 相关文件
{
arm_config.mk
cpu/arm920t/config.mk
cpu/arm920t/s3c24x0/config.mk 没有这个文件,忽略
board/100ask24x0/config.mk //TEXT_BASE = 0x33F80000
}
vi config.mk
{
77 sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules
78 endif
79 ifdef CPU
80 sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules
81 endif
82 ifdef SOC
83 sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk # include SoC specific rules
84 endif
85 ifdef VENDOR
86 BOARDDIR = $(VENDOR)/$(BOARD)
87 else
88 BOARDDIR = $(BOARD)
89 endif
90 ifdef BOARD
91 sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
92 endif
117 # Include the make variables (CC, etc...)
118 #
119 AS = $(CROSS_COMPILE)as
120 LD = $(CROSS_COMPILE)ld
121 CC = $(CROSS_COMPILE)gcc
..........
}
继续分析Makefile
从199-211这些位置指定了生成LIBS变量就是平台、libasm、cpu、通用目录等下面的库。
OBJS和LIBS就是uboot的组成,它们再通过268-279这些代码生成。
声称以后,就剩下链接了。这由 262 - 266这些代码完成,其中,LDFLAGS指定了程序的布局和地址。
LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
-T board/100ask24x0/u-boot.lds -Ttext 0x33F80000
5.总结编译流程,对于100ask24x0.
(1)先编译cpu/arm920t/start.S
(2)对于平台、开发板、公共目录等各自调用他们的Makefile生成相应的库;
(3)将1,2两步生成的.o, .a文件按照-T board/100ask24x0/u-boot.lds -Ttext 0x33F80000 的布局链接起来。
(4)将第三步得到的uboot文件转换为二进制格式、s-record等格式。
同时也可以根据需要,得到uboot.dis反汇编文件。arm-linux-objdump -d u-boot > u-boot.dis