1 概述
PetaLinux 工具提供在 Xilinx 处理系统上定制、构建和调配嵌入式 Linux 解决方案所需的所有组件。该解决方案旨在提升设计生产力,可与 Xilinx 硬件设计工具配合使用,以简化针对 Versal、Zynq™ UltraScale+™ MPSoC、Zynq™ 7000 SoC、和 MicroBlaze™ 的 Linux 系统开发。
2 创建
2.1 启动PetaLinux
mkdir git
cd git/
source /opt/xilinx/petalinux/2020.1/settings.sh
PetaLinux environment set to '/opt/xilinx/petalinux/20.1'
WARNING: This is not a supported OS
INFO: Checking free disk space
INFO: Checking installed tools
INFO: Checking installed development libraries
INFO: Checking network and other services
2.2 新建工程
2.2.1 通过CPU类型创建工程
petalinux-create --type project --template zynqMP --name myproject
说明:
- type 类型为project说明创建的是工程,其它取值:apps/modules
- template 这里是CPU型号:microblaze/zynqMP/zynq/versal
准备vivado中生成的硬件描述文件:
/home/james/git/target/aaa.xsa
导入硬件描述文件:
- 方式1
cd /home/james/git/myproject
petalinux-config --get-hw-description=/home/james/git/target
方式2
cd /home/james/git/target/
petalinux-config --get-hw-description -p /home/james/git/myproject
``
方式3
```bash
petalinux-config --get-hw-description=/home/james/git/target -p /home/james/git/myproject
2.2.2 通过BSP工程创建工程
petalinux-create --type project -s aaa.bsp
说明:
- 通过BSP工程创建的工程不需要指定工程名称
3 配置
3.1 配置工程
cd /home/james/git/myproject
petalinux-config
3.2 配置u-boot
petalinux-config -c u-boot
配置过程中需要从官方网络上下载对应的u-boot源码
3.3 配置kernel
petalinux-config -c kernel
配置过程中需要从官方网络上下载对应的kernel源码
3.4 配置rootfs
petalinux-config -c rootfs
4 编译
4.1 全部编译
cd /home/james/git/myproject
petalinux-build
4.2 编译u-boot
petalinux-build -c u-boot
4.3 编译kernel
petalinux-build -c kernel
4.4 编译文件系统
petalinux-build -c rootfs
4.5 编译更新device tree
petalinux-build -c device-tree -x cleanall
petalinux-build -c device-tree
5 生成BOOT.BIN文件
5.1 FPGA Manager没使能
petalinux-package --boot --force --format BIN --fsbl images/linux/zynqmp_fsbl.elf --fpga images/linux/system.bit --u-boot
INFO: sourcing build tools
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/zynqmp_fsbl.elf"
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/pmufw.elf"
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/system.bit"
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/bl31.elf"
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/system.dtb"
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/u-boot.elf"
INFO: Generating zynqmp binary package BOOT.BIN...
****** Xilinx Bootgen v2020.1
**** Build date : May 26 2020-14:07:15
** Copyright 1986-2020 Xilinx, Inc. All Rights Reserved.
[INFO] : Bootimage generated successfully
INFO: Binary is ready.
BOOT.BIN文件路径
/home/james/git/myproject/images/linux/BOOT.BIN
5.2 FPGA Manager使能
petalinux-package --boot --force --format BIN --fsbl images/linux/zynqmp_fsbl.elf --u-boot
INFO: sourcing build tools
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/zynqmp_fsbl.elf"
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/pmufw.elf"
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/bl31.elf"
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/system.dtb"
INFO: File in BOOT BIN: "/home/james/git/rru/bz20rru/images/linux/u-boot.elf"
INFO: Generating zynqmp binary package BOOT.BIN...
****** Xilinx Bootgen v2020.1
**** Build date : May 26 2020-14:07:15
** Copyright 1986-2020 Xilinx, Inc. All Rights Reserved.
[INFO] : Bootimage generated successfully
INFO: Binary is ready.
参加后面10节手动加载FPGA目标文件。
6 制作启动SD卡
6.1 SD卡分区
为SD卡分区:
- 一个FAT32分区,分区Label:BOOT
- 一个EXT4分区,分区Label:ROOTFS
6.2 复制文件
- 复制到SD卡FAT32分区
rm /media/james/BOOT/BOOT.BIN
rm /media/james/BOOT/boot.scr
rm /media/james/BOOT/image.ub
cp images/linux/BOOT.BIN /media/james/BOOT/
cp images/linux/boot.scr /media/james/BOOT/
cp images/linux/image.ub /media/james/BOOT/
sync
- 复制到SD卡ext4分区
sudo rm /media/james/ROOTFS/* -rf
sudo tar zxvf images/linux/rootfs.tar.gz -C /media/james/ROOTFS/
sync
7 选择文件系统启动
7.1 通过kernel设备树
chosen {
bootargs = "earlycon=cdns,mmio,0xFF000000 console=ttyPS0,115200 clk_ignore_unused mem=512M uio_pdrv_genirq.of_id=generic-uio root=/dev/mmcblk1p2 rw rootfstype=ext4 rootwait";
stdout-path = "serial0:115200n8";
};
7.2 通过u-boot的bootargs参数
setenv bootargs "earlycon console=ttyPS0,115200 clk_ignore_unused uio_pdrv_genirq.of_id=generic-uio noinitrd root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait";
saveenv
8 添加APP
8.1 添加APP
petalinux-create -t apps --name myapp --enable
8.2 添加驱动
petalinux-create -t modules --name mymoudle --enable
8.3 指定使用语言
petalinux-create -t apps --template c++ --name myapp --enable
8.4 编译
petalinux-build -c myapp -x clean
petalinux-build -c myapp -x install
petalinux-build -c myapp -x build
9 生成SDK
上述步骤是基于Petalinux系统制作系统和驱动。开发应用其实不用基于Petalinux。可以通过生成SDK开发应用,SDK包括开发应用所需的编译器及其它开发库。
9.1 生成SDK
cd /home/james/git/myproject
petalinux-build --sdk
9.2 安装SDK
sudo /home/james/git/myproject/sdk.sh
9.3 配置SDK环境
source /opt/petalinux/2020.1/environment-setup-aarch64-xilinx-linux
10 手动加载FPGA目标文件
Kernel 启动之后手动加载FPGA:
echo 0 > /sys/class/fpga_manager/fpga0/flags
mkdir -p /lib/firmware
cp /media/mydevice.bin /lib/firmware/
echo /lib/firmware/mydevice.bin > /sys/class/fpga_manager/fpga0/firmware
加载完成后在串口打印:
fpga_manager fpga0: writing fpga_ntrru_top.bin to Xilinx ZynqMP FPGA Manager