09 uboot的配置编译主过程分析

时间:2022-07-27 16:36:05

在orangepi_sdk目录下:

//////////////////////////////////////
uboot的配置过程
make config_uboot //配置uboot

1). //当前目录的Makefile
26 PHONY += config_uboot
27 config_uboot :
28 @echo "+++++config uboot+++++"
29 @$(PWD)/script/config_uboot_source.sh

2). //当前目录下的script/config_uboot_source.sh
2 source $PWD/script/orangepi.conf //让orangepi.conf里的环境变量生效。如交叉编译器,uboot, kernel目录路径
3 source $PWD/script/common.sh //提供功能函数

11 message "entry u-boot source dir " && cd ${OPI_U_source} //进入uboot源码目录
12
13 if [ ! -f .config ] //判断uboot源码根目录下是否存在".config", ".config"用于指定uboot的编译配置
14 then //如没有.config文件
15 message "clear u-boot " && make distclean //清作编译生成的文件及配置文件
16 message "config u-boot " && make ${OPI_U_config} // make orangepi_linux_defconfig
17 fi

20 message "config u-boot" && make menuconfig //弹出一个配置界面

////////////////
总结下uboot的配置过程:
1). script/orangepi.conf里的环境变量生效, 及进入uboot源码目录
2). make distclean
3). make orangepi_linux_defconfig
4). make menuconfig
////////////////////////////////////////////////////////
uboot编译是通过命令:

make uboot
1). 当前目录下的Makefile
42 PHONY += uboot
43 PHONY += bootloader
44 uboot bootloader :
45 @echo "+++++build u-boot+++++" | tee $(OPI_OUTPUT_DIR)/build_uboot.log
46 @$(PWD)/script/make_uboot.sh 2>&1 | tee -a $(OPI_OUTPUT_DIR)/build_uboot.log

2). script/make_uboot.sh里的主要内容:
2 source $OPI_WORK_DIR/script/common.sh

10 message "entry u-boot source dir " && cd $OPI_U_source

20 message "build u-boot , Please wait some time." && make -j8

22 if [ -f u-boot-sunxi-with-spl.bin ]; then
23 # Copy u-boot-sunxi-with-spl.bin to output
24 cp u-boot-sunxi-with-spl.bin $OPI_UBOOT_OUTPUT_DIR
25 cp arch/arm/dts/*sun8i-h3* $OPI_DTB_OUTPUT_DIR
26 fi

// boot.scr文件的生成, boot.scr是uboot的环境变量存放文件
30 message "build u-boot boot.scr" && rm $OPI_UBOOT_OUTPUT_DIR/boot.scr
31 mkimage -C none -A arm -T script -d $OPI_source/u-boot-script/orangepi.cmd $OPI_UBOOT_O UTPUT_DIR/boot.scr

//由orangepi.fex生成script.bin, 文件里用于描述硬件相关的资源
34 message "build sunxi script.bin" && rm $OPI_UBOOT_OUTPUT_DIR/script.bin
35 fex2bin $OPI_source/sunxi-script/orangepi.fex $OPI_UBOOT_OUTPUT_DIR/script.bin
////////////
总结下编译主要过程:
1).进入uboot源码目录
2). make -j8
3). 生成boot.src环境变量文件
4). 生成script.bin文件
////////////////////////////////////////////////////
最后我们是用"make install_uboot sdcard=/dev/sdb"烧写到sd卡里

1). 当前目录里的Makefile:
63 PHONY += install_uboot
64 install_uboot :
65 @echo "Script run sudo , Please authorize :"
66 @sudo $(PWD)/script/install_uboot.sh $(sdcard)


2). script/install_uboot.sh的主要内容:
2 source $PWD/script/orangepi.conf
3 source $PWD/script/common.sh
4 sdcard=$1 // sdcard=/dev/sdb

18 echo "mount -t vfat $sdcard"1" $OPI_SDCARD_BOOT"
19 mount -t vfat $sdcard"1" $OPI_SDCARD_BOOT //挂载/dev/sdb1到目录里, sdb1是fat分区
20
21 cd ${OPI_UBOOT_OUTPUT_DIR}
23 cp boot.scr ${OPI_SDCARD_BOOT}/ //复制到挂载目录里,也就是存放到sd卡的fat分区
25 cp script.bin ${OPI_SDCARD_BOOT}/ //复制script.bin到sd卡的fat分区

27 cp u-boot-sunxi-with-spl.bin ${OPI_SDCARD_BOOT}/ //也复制uboot.bin到分区里

29 dd if=/dev/zero of=$sdcard bs=1k seek=8 count=1015 //从sd卡的第8个扇区(每个扇区512字节)开始,清零1015K字节空间
30 dd if=u-boot-sunxi-with-spl.bin of=$sdcard bs=1k seek=8 //把uboot.bin从sd卡的第8个扇区开始烧写进去