记录下在ZCU106制作linuxSD卡启动文件
很多地方理解不是很深,只是摸索着最后能启动运行,可能流程并不是规范的,还请大佬们指导
-
使用环境
编译平台:vmware下ubuntu虚拟机;
交叉编译工具:gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz(https://www.linaro.org/downloads/)
uboot:u-boot-xlnx-master.zip (>= 2020.1 Release)(https://github.com/Xilinx/u-boot-xlnx )
kernel:linux-xlnx-master.zip(忘了在哪儿下的了。。。找到再补)
rootfs:linaro-precise-ubuntu-desktop-20120923-436.tar.gz(https://releases.linaro.org/archive/12.09/ubuntu/leb-panda/)
BL31.elf(BOOT.bin会用到):arm-trusted-firmware-master.zip(https://github.com/Xilinx/arm-trusted-firmware)
参考:很多流程其实在xilinx wiki上都写到了https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841973/Build+U-Boot
官网上也可以直接下载2021.2-zcu106-release.tar.xz里面有些自己不想编译的可以直接用
https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/2202763266/2021.2+Release后来发现我用的这个ubuntu的版本太老了,好多源都不提供更新,于是linaro官网找到了个这个根文件系统可以试试
linaro-vivid-developer-20150612-99.tar.gz
(https://releases.linaro.org/archive/15.06/ubuntu/vivid-images/developer-arm64/) -
配置交叉编译工具
参考:https://blog.csdn.net/innocentzhao/article/details/120477218
基本上就是tar解压缩后,把bin文件路径添加到PATH环境变量就可以了,前提是一些依赖需要已安装好export PATH=$PATH:/home/用户名/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin
-
编译生成uboot.elf文件
注意:我用的uboot版本大于2020.1 Release,版本小于2020的操作不适用本文
3.1 配置环境变量export CROSS_COMPILE=aarch64-linux-gnu- export ARCH=aarch64
3.2 在uboot目录下执行编译
make distclean make xilinx_zynqmp_virt_defconfig export DEVICE_TREE="zynqmp-zcu106-revA" make
3.3 在uboot目录下找到生成的u-boot.elf(红笔圈出)
我看网上有的说是将u-boot文件(篮圈)重命名为u-boot.elf,我试了好像反而不能正常启动,最后直接用了目录下生成的u-boot.elf反而成功启动了。(u-boot.elf红圈大小1.3M,u-boot蓝圈10.6M)
-
编译kernel,生成Image
4.1配置环境变量(主要是修改ARCH=arm64,因为交叉编译CROSS_COMPILE和上一节编译uboot时是一样的)make ARCH=arm64 xilinx_zynqmp_defconfig make ARCH=arm64 menuconfig
4.2编译kernel,生成Image以及设备树dtb
make ARCH=arm64
编译时间特别长,耐心等待
make -j8
选项表示并行编译,貌似是可以编译并行提高速度
完成之后,在arch–>arm64–>boot目录下可以看到生成的Image
在arch–>arm64–>boot–>dts–>xilnx路径下可以找到zynqmp-zcu106-revA.dtb重命名为system.dtb备用
-
制作BOOT.bin
我用的vivado下的sdk生成的,这里pmufw是电源模块管理,据说可以不要,bl31不是很清楚干什么用的,这两个我都是用的xilinx官网2021.1-zcu106-release内复制来的,网上说不要也可以运行。
u-boot.elf添加时选择el-2bif文件参考以下:
//arch = zynqmp; split = false; format = BIN
the_ROM_image:
{
[fsbl_config]a53_x64
[bootloader]d:\路径\zynqmp_fsbl.elf
[pmufw_image]d:\路径\pmufw.elf
[destination_device = pl]D:\路径\design_1_wrapper.bit
[destination_cpu = a53-0, exception_level = el-3, trustzone]d:\路径\bl31.elf
[destination_cpu = a53-0, exception_level = el-2]d:\路径\u-boot.elf
} -
制作SD卡
6.1 同步根文件系统到ext分区
在虚拟机中解压linaro-precise-ubuntu-desktop-20120923-436.tar.gz
并将解压后的文件全部同步到SD卡的ext分区中sudo tar zxvf linaro-precise-ubuntu-desktop-20120923-436.tar.gz cd binary/boot/filesystem.dir sudo rsync -a --progress ./ /media/innocent/rootfs
这里的“cd binary/boot/filesystem.dir”该地址为解压后的文件系统根目录地址,
此外 /media/innocent/rootfs是SD卡ext分区在虚拟机下挂载后的地址,该分区名称为rootfs6.2 复制文件到FAT分区
PC中新建uEnv.txt,此文件是为了写入环境变量bootargs
在txt文件中写入:bootargs=console=ttyPS0,115200n8 root=/dev/mmcblk0p2 rw noinitrd rootfstype=ext4 rootwait
将BOOT.bin、Image、system.dtb、uEnv.txt放入FAT分区内。
此外还有一个boot.scr文件,是我在xilinx官网2021.1-zcu106-release看到的,里面内容如下,可以看到这是一个启动时的脚本指令,可以根据boot方式执行对应操作,这里面也提到了uEnv.txt以及kernel文件类型image.ub或Image等。
for boot_target in ${boot_targets}; do echo "Trying to load boot images from ${boot_target}" if test "${boot_target}" = "jtag" ; then booti 0x00200000 0x04000000 0x00100000 fi if test "${boot_target}" = "mmc0" || test "${boot_target}" = "mmc1" ; then if test -e ${devtype} ${devnum}:${distro_bootpart} /uEnv.txt; then fatload ${devtype} ${devnum}:${distro_bootpart} 0x00200000 uEnv.txt; echo "Importing environment(uEnv.txt) from ${boot_target}..." env import -t 0x00200000 $filesize if test -n $uenvcmd; then echo "Running uenvcmd ..."; run uenvcmd; fi fi if test -e ${devtype} ${devnum}:${distro_bootpart} /image.ub; then fatload ${devtype} ${devnum}:${distro_bootpart} 0x10000000 image.ub; bootm 0x10000000; 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} /ramdisk.cpio.gz.u-boot && test "${skip_tinyramdisk}" != "yes"; then fatload ${devtype} ${devnum}:${distro_bootpart} 0x04000000 ramdisk.cpio.gz.u-boot; booti 0x00200000 0x04000000 0x00100000 fi if test -e ${devtype} ${devnum}:${distro_bootpart} /rootfs.cpio.gz.u-boot && test "${skip_ramdisk}" != "yes"; then fatload ${devtype} ${devnum}:${distro_bootpart} 0x04000000 rootfs.cpio.gz.u-boot; booti 0x00200000 0x04000000 0x00100000 fi booti 0x00200000 - 0x00100000 fi
-
完成,插入SD卡,拨码开关SW6改为SD卡启动,上电就可以了。
-
上电后有几次pl初始化失败还是什么反正就是有红灯亮,= =,重新上电好像又好了,对MPSOC理解还不是很深,暂时只是做到这里,待以后用多了再说吧。
-
关于BL31
这里提到了ATF的编译,https://blog.csdn.net/luhao806/article/details/77896771
下载后使用下列指令编译,在build/zynqmp/release/bl31中会找到bl31.elf文件
make PLAT=zynqmp RESET_TO_BL31=1 CROSS_COMPILE=aarch64-none-linux-gnu-