前言

本文主要说明petalinux从工程创建到加载xsa到编译启动的步骤,以及vitis软件开发步骤。
环境基于ZYNQ UltraScale+ MPSoc EG系列,默认petalinux及vitis已安装完毕。
本文示例版本:

Vitis:2020.2.0 version

OS: Ubuntu 18.04

基础知识介绍

vitis名词解释

Workspace:当打开Vitis软件平台时,创建workspace,用来存储工程数据。

Platform:是硬件部件(XSA)和软件部件(BSP,FSB等)的集合。

Application(Software Project):一个Software Project包含一个或多个源文件,和必要的头文件,编译和生成二进制输出文件(ELF)。System project可以包含多个application project。每一个software project必须有一个相应的domain。

XSA:包含硬件信息,例如处理器配置信息,外设连接信息和器件初始化代码。当创建Platform Project时需要提供XSA。

Domain:Domain时一个板级支持包(BSP)或者包含驱动的运行系统(OS),在这上面构建应用。创建好的软件镜像包含部分Xilinx库。可以在Domain中创建多个应用。Domain可以时一个处理器,也可以是多个。

板卡jtag 与 emmc启动方式切换
拨码开关如图所示,全为on时为jtag模式
在这里插入图片描述

petalinux构建linux镜像

环境变量配置

source ~/petalinux/settings.sh

创建一个新的petelinux工程

示例:
<plnx-proj-root> petalinux-create --type project --template zynqMP --name test_pro

导入硬件描述文件XSA

进入test_pro目录
<plnx-proj-root> petalinux-config --get-hw-description  [SRC]
示例:
petalinux-config --get-hw-description /home/server04/yongshuai/pc_prj/MEMORY_CONTROLER_release_20230319_diff_addr/system.xsa

参数SRC是文件所在“路径”

ps:tftp warning处理:
https://blog.csdn.net/qq_43102715/article/details/113662985

设置

(jtag模式保持默认配置,emmc模式待验证确认)
运行petalinux-config后出现配置界面

进入配置界面:
在DTG Settings中设置Kernel Bootargs:
earlycon clk_ignore_unused earlyprintkroot=/dev/mmcblk1p2 rootwait cma=1024M
在ImagePackaging Configuration中设置:
Device node of SD device :/dev/mmcblk1p2
配置SD卡ext文件系统启动:
在Rootfilesystem type中选择EXT

编译创建系统Image

<plnx-proj-root> petalinux-build 

生成启动镜像

petalinux-package --boot --format BIN --fsbl images/linux/zynqmp_fsbl.elf --u-boot images/linux/u-boot.elf --pmufw images/linux/pmufw.elf --fpga images/linux/*.bit --force

put the bitstream to the prebuilt directory

petalinux-package --prebuilt 

编译vitis相关功能

如果使用vitis开发,需要执行如下指令

<plnx-proj-root>cd images/linux
petalinux-build --sdk
petalinux-package --sysroot

emmc/SD启动

(jtag方式跳过,emmc启动模式待验证确认)
将 BOOT.BIN 和 image.ub 拷贝至 SD 卡的 BOOT 分区:

cp images/linux/BOOT.BIN /media/BOOT/

cp images/linux/image.ub /media/BOOT/

将rootfs.tar.gz 文件拷贝至 SD 卡的 RootFS 分区并提取文件系统

sudotar xvf rootfs.tar.gz -C /media/rootfs

设置emmc启动方式,上电启动

jtag启动

烧写并启动

petalinux-boot --jtag --prebuilt 3(LEVEL)

Level 1: Download the prebuilt FPGA bitstream.
Level 2: Download the prebuilt FPGA bitstream and boot the prebuilt U-Boot.
Level 3: Download and boot the prebuilt Linux

Vitis创建linux应用

在Vitis下创建Linux应用程序分三步:

1、使用XSA创建Platform Project;
2、在Platform Project加入Linux Domain;
3、创建Linux Application Project。

使用XSA创建Platform Project

  1. 选择一个目录作为workspace
    在这里插入图片描述

  2. 新建Platform Project

在这里插入图片描述

  1. 选择Create Plateform Project,指定之前所用的XSA文件
    在Operating system中指定linux,点击finish完成Platform Project创建
    在这里插入图片描述

在Platform Project加入Linux Domain

  1. 将petelinu生成的镜像文件放入vitis指定目录:
    在workspace目录中新建文件夹image,文件夹boot,将Petalinux工程image/linux文件夹下的image.ub、boot.scr 和 rootfs.cpio.gz 拷贝到image。
    将system.bit、bl31.elf、uboot.elf、zynqmp_fsbl、pmufw.elf 文件复制到boot。
<plnx-proj-root/images/linux/> 
cp system.bit bl31.elf u-boot.elf zynqmp_fsbl.elf pmufw.elf /home/server04/cau_vitis_project/boot
cp image.ub boot.scr rootfs.tar.gz /home/server04/cau_vitis_project/image
  1. 在boot中,新建文件linux.bif
the_ROM_image:
{
  [fsbl_config] a53_x64
  [bootloader] <zynqmp_fsbl.elf>
  [pmufw_image] <pmufw.elf>
  [destination_device=pl] <bitstream>
  [destination_cpu=a53-0, exception_level=el-3, trustzone] <bl31.elf>
  [destination_cpu=a53-0, exception_level=el-2]<u-boot.elf>
}
  1. 在vitis工程中进行如下图设置:
Bif file: /home/server04/cau_vitis_project/boot/linux.bif
boot components directory: /home/server04/cau_vitis_project/boot
Linux Image Directory: /home/server04/cau_vitis_project/image
Linux Rootfs:/home/server04/cau_vitis_project/image/rootfs.tar.gz
/home/server04/Project/SCSFV1.0.1Alpha03/images/linux/sdk/sysroots/aarch64-xilinx-linux

在这里插入图片描述

  1. 设置完成后,在工程右键选Build Project编译工程
    在这里插入图片描述

创建Linux Application Project

  1. 新建app工程

在工程右键选点击New->Application Project
在这里插入图片描述

  1. 指定platform
    在这里插入图片描述

  2. 设置app工程名及system projectname

Tips:
   System project:将同时运行在器件上的应用进行组合。两个独立运行在同一个处理器上的应用不能在一个System project里。一个workspace可以包含多个System project。

在这里插入图片描述

  1. 继续next
    在这里插入图片描述

  2. 选择应用工程,编写编译运行
    选择Linux Hello World进行测试
    在这里插入图片描述

  3. 选择应用右键build project
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-aI9qBEUx-1688436866997)(pic/0ee06c5ea68508def1bdf1f36fb04e7.png)]

  4. 可以在线执行
    在这里插入图片描述

  5. 也可以拷贝可执行文件到板上运行

    将项目文件夹下(/home/server04/cau_vitis_project/项目名称/Debug/)生成的可执行文件(elf文件)发送到FPGA的linux中运行
    
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐