- 若该文为原创文章,未经允许不得转载
- 风释雪
- QQ:627833006
- E-mail:hn.cy@foxmail.com
- CSDN博客地址:https://blog.csdn.net/weixin_46718879
1.版本说明
Data | Author | Version Revision |
---|---|---|
2021/12/21 | abner | 1.0 初定版本 |
2.目标
传统嵌入式方法从源码编译移植U-BOOT,Linux,设备树.
解决PetaLinux编译缓慢,出错不容易排查的问题。
PetaLinux主要用于编译rootfs,后期根据需要可以使用PetaLinux的文件系统来开发。
3.源码
- DeviceTree xilinx v2020.1
- u-boot xilinx v2020.1
- kernel xilinx v2020.1
4.输出文件
bootgen.bif (用于产生BOOT.bin的描述文件)
system.bit
system.dtb
Image (zynqmp对应内核镜像)
rootfs.cpio.gz
5.编译u-boot
export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=aarch64
make distclean
make xilinx_zynqmp_virt_defconfig
make menuconfig
make
6.编译kernel
export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64
make xilinx_zynqmp_defconfig
make menuconfig
make
7.uboot DHCP
替代TFTP从服务器上下载所需要的文件,
格式:dhcp [内存地址] [TFTP服务器地址]:[文件名]
例如:
dhcp 0x00200000 192.168.2.172:Image
dhcp 0x00100000 192.168.2.172:system.dtb
dhcp 0x04000000 192.168.2.172:rootfs.cpio.gz.u-boot
验证:
booti 0x00200000 0x04000000 0x00100000
8.设置环境变量
setenv dhcpboot ‘dhcp 0x00200000 192.168.2.172:Image; dhcp 0x00100000 192.168.2.172:system.dtb; dhcp 0x04000000 192.168.2.172:rootfs.cpio.gz.u-boot ; booti 0x00200000 0x04000000 0x00100000;’
setenv bootcmd 'run dhcpboot ’
saveenv
9.实际应用
- 调试阶段:BOOT.bin(SD卡) + TFTP(system.bit + system.dtb + NFS文件系统)
- SD启动:BOOT.bin + system.bit + system.dtb + 文件系统
- FLASH启动:BOOT.bin + system.bit + system.dtb + 文件系统
- 安全备份模式:FLASH + SD, FLASH上电先检测SD卡是否满足启动要求,然后启动SD,否则回退到FLASH启动
10.默认boot.scr
boot.scr 有助于理解启动时,文件从SD/FLASH拷贝到内存,最终运行的流程
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
/* devtype = mmc devnum = 0/1 distro_bootpart = 1 */
fatload ${devtype} ${devnum}:${distro_bootpart} 0x10000000 image.ub;
bootm 0x10000000;
exit;
fi
if test -e ${devtype} ${devnum}:${distro_bootpart} /Image; then
/* devtype = mmc devnum = 0/1 distro_bootpart = 1 */
/* 如果没有找到 image.ub 就找 Image */
fatload ${devtype} ${devnum}:${distro_bootpart} 0x00200000 Image;;
fi
if test -e ${devtype} ${devnum}:${distro_bootpart} /system.dtb; then
/* devtype = mmc devnum = 0/1 distro_bootpart = 1 */
/* 找 system.dtb */
fatload ${devtype} ${devnum}:${distro_bootpart} 0x00100000 system.dtb;
fi
if test -e ${devtype} ${devnum}:${distro_bootpart} /rootfs.cpio.gz.u-boot; then
/* devtype = mmc devnum = 0/1 distro_bootpart = 1 */
/* 找 rootfs.cpio.gz.u-boot */
/* 如果找到就指定地址启动 */
/* 启动 并 退出 */
fatload ${devtype} ${devnum}:${distro_bootpart} 0x04000000 rootfs.cpio.gz.u-boot;
booti 0x00200000 0x04000000 0x00100000
exit;
fi
/* 如果没有找到 rootfs.cpio.gz.u-boot 启动 并 退出 该模式用于 nfs文件系统,或者SD卡分区作为文件系统 */
booti 0x00200000 - 0x00100000
exit;
fi
/* 和 SD卡操作相同 */
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 0xA10000 0x1D00000;
sf read 0x04000000 0x4000000 0x4000000
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
nand read 0x04000000 0x7800000 0x3200000;
booti 0x00200000 0x04000000 0x00100000
exit;
fi
fi
done