同步于简书: https://www.jianshu.com/p/c60cf237ffd1
以及个人博客: https://hades2013.github.io
u-boot分析以ar9331和ar953x 的为例。
获取u-boot源码
git clone https://github.com/pepe2k/u-boot_mod.git
一般u-boot的初始化过程:
- 硬件设备初始化
- 加载U-Boot都RAM空间
- 设置好栈
- 跳转到C语言入口
LSDK中最后编译完成后生成的u-boot为tuboot,查看顶层Makefile :
ifdef COMPRESSED_UBOOT
all: $(ALL) tuboot.bin
else
all: $(ALL) u-boot.img
endif
最后生成的u-boot的压缩文件,到底如何压缩呢:
tuboot.bin: System.map bootstrap.bin u-boot.lzimg
@echo
$(call echo_green,Merging bootstrap.bin with u-boot.lzimg...)
$(call echo_size, Bootstrap size,bootstrap.bin)
$(call echo_size, LZMA image size,u-boot.lzimg)
@cat bootstrap.bin > $@
@cat u-boot.lzimg >> $@
$(call echo_size, Total image size,$@)
tuboot.bin依赖三个文件: System.map bootstrap.bin u-boot.lzimg
,并使用cat命令将bootstrap.bin与u-boot.lzimg拼接在一起生成tub-boot.bin
- System.map为编译生成的符号连接表
- bootstrap.bin 为bootstrap引导程序
- u-boot.lzimg 为u-boot的lzma压缩文件
编译信息如下:
rm -rf u-boot.bin.lzma
../../../util/lzma/bin/lzma --best --keep u-boot.bin
./tools/mkimage -A mips -T firmware -C lzma \
-a 0xffffffff80010000 \
-e 0xffffffff80010000 \
-n 'u-boot image' -d u-boot.bin.lzma u-boot.lzimg
Imag