概述
u_boot启动后,在倒计时结束后按照默认参数启动内核,默认参数其实是通过boot.scr向u-boot传参数的
1、boot.scr内容如下
for boot_target in ${boot_targets};
do
if test "${boot_target}" = "jtag" ; then
booti 0x00200000 0x04000000 0x00100000
exit;
fi
if test "${boot_target}" = "mmc0" || test "${boot_target}" = "mmc1" ; then
if test -e ${devtype} ${devnum}:${distro_bootpart} /image.ub; then
fatload ${devtype} ${devnum}:${distro_bootpart} 0x10000000 image.ub;
bootm 0x10000000;
exit;
fi
if test -e ${devtype} ${devnum}:${distro_bootpart} /Image; then
fatload ${devtype} ${devnum}:${distro_bootpart} 0x00200000 Image;;
fi
if test -e ${devtype} ${devnum}:${distro_bootpart} /system.dtb; then
fatload ${devtype} ${devnum}:${distro_bootpart} 0x00100000 system.dtb;
fi
if test -e ${devtype} ${devnum}:${distro_bootpart} /rootfs.cpio.gz.u-boot; then
fatload ${devtype} ${devnum}:${distro_bootpart} 0x04000000 rootfs.cpio.gz.u-boot;
booti 0x00200000 0x04000000 0x00100000
exit;
fi
booti 0x00200000 - 0x00100000
exit;
fi
if test "${boot_target}" = "xspi0" || test "${boot_target}" = "qspi" || test "${boot_target}" = "qspi0"; then
sf probe 0 0 0;
if test "image.ub" = "image.ub"; then
sf read 0x10000000 0xa10000 0x1500000;
bootm 0x10000000;
exit;
fi
if test "image.ub" = "Image"; then
sf read 0x00200000 0x3F00000 0x1D00000;
sf read 0x04000000 0x5D00000 0x1D00000
booti 0x00200000 0x04000000 0x00100000
exit;
fi
exit;
fi
if test "${boot_target}" = "nand" || test "${boot_target}" = "nand0"; then
nand info
if test "image.ub" = "image.ub"; then
nand read 0x10000000 0x4100000 0x6400000;
bootm 0x10000000;
exit;
fi
if test "image.ub" = "Image"; then
nand read 0x00200000 0x4100000 0x3200000;
nand read 0x04000000 0x7800000 0x3200000;
booti 0x00200000 0x04000000 0x00100000
exit;
fi
fi
done
- 1.1 首先查询boot_target(可以通过下述指令查看),例如我是从qsipflash启动的,且image.ub=image.ub
printenv
- 1.2 初始化qspi_flashsf probe 0 0 0,然后判断image.ub类型
if test "${boot_target}" = "xspi0" || test "${boot_target}" = "qspi" || test "${boot_target}" = "qspi0"; then
sf probe 0 0 0;
if test "image.ub" = "image.ub"; then
sf read 0x10000000 0xa10000 0x1500000;
bootm 0x10000000;
exit;
fi
if test "image.ub" = "Image"; then
XXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXX
fi
exit;
fi
-
1.3 从falsh读取kernel镜像,我的镜像位于flash地址0xa10000,长度为0x1500000,存于DDR 0x10000000
-
1.4 从DDR 0x10000000地址启动内核
2、boot.scr如何生成的?
2.1 mkimage可以用来生成boot.scr
- mkimage在制作映象文件的时候,是在原来的可执行映象文件的前面加上一个0x40字节的头,记录参数所指定的信息,这样uboot才能识别这个映象是针对哪个CPU体系结构的,哪个OS的,哪种类型,加载内存中的哪个位置, 入口点在内存的那个位置以及映象名是什么
./mkimage -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image
-A ==> set architecture to 'arch'
-O ==> set operating system to 'os'
-T ==> set image type to 'type'
-C ==> set compression type 'comp'
-a ==> set load address to 'addr' (hex)
-e ==> set entry point to 'ep' (hex)
-n ==> set image name to 'name'
-d ==> use image data from 'datafile'
-x ==> set XIP (execute in place)
2.2 mkimage位值(petalinux2021.2)
- mkimage位于prj_petalinux/build/tmp/sysroots-components/x86_64/u-boot-tools-native/usr/bin目录下
2.3 执行
./mkimage -c none -A arm -T script -d xxx./xxx./boot.cmd boot.scr
- 在2.2路径下执行上述指令即可生成boot.scr,其中xxx./xxx./boot.cmd代表boot.cmd的绝对路径,这里说通俗一点就是在boot.cmd前面加一个头,这样在u-boot读取该段内容时进行CRC校验,已确读取的内容正确。
3、image.ub
- image.ub, is a FIT image(https://blog.csdn.net/ee230/article/details/53318027)
- 在INITRAMFS模式下mpsoc中包含了rootfs.cpio文件系统和内核镜像
4、bootm bootz booti
- bootm和bootz的不同地方
- bootm用于加载uImage和ramdisk(rootfs.cpio)
bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address};
- bootz用于加载zImage和ext4文件系统
bootz ${kernel_load_address} - ${devicetree_load_address}
- zImage 是Image的压缩文件
- uImage U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40