ZCU106开发板实战:用PetaLinux 2019.2编译Vitis AI系统镜像的完整避坑指南
·
ZCU106开发板实战:用PetaLinux 2019.2编译Vitis AI系统镜像的完整避坑指南
在嵌入式AI开发领域,Xilinx Zynq UltraScale+ MPSoC系列凭借其强大的可编程逻辑与处理系统协同能力,成为边缘计算的热门选择。而ZCU106作为该系列的评估板,搭配Vitis AI工具链,能够快速部署计算机视觉和机器学习应用。本文将手把手带你完成从零开始的环境搭建、系统镜像编译到常见错误的完整解决方案,所有步骤均在Ubuntu 18.04.4 LTS和PetaLinux 2019.2环境下实测验证。
1. 环境准备与工具链配置
1.1 硬件与软件版本匹配原则
Xilinx工具链的版本兼容性至关重要,以下为经过验证的组合:
| 组件 | 推荐版本 | 官方下载源 |
|---|---|---|
| Vivado | 2019.2 | Xilinx官网需注册账户 |
| PetaLinux | 2019.2 | 需与Vivado版本严格一致 |
| Ubuntu | 18.04.4 LTS | 官方镜像 |
| Vitis AI | 1.1 | GitHub Xilinx官方仓库 |
注意:避免使用中文版文档,2019.2版本仅有英文手册完整。中文文档通常滞后且缺失关键细节。
1.2 系统依赖项安装
执行以下命令配置基础环境:
sudo apt-get install -y gcc g++ make python3-dev \
libncurses5-dev zlib1g-dev libssl-dev flex bison \
libselinux1 xterm autoconf libtool texinfo gawk
常见问题处理:
- Python版本冲突 :强制锁定python3为默认版本
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1 - 磁盘空间不足 :PetaLinux工程至少需要100GB空闲空间,建议使用
df -h检查
2. PetaLinux工程创建与配置优化
2.1 工程初始化步骤
source /opt/pkg/petalinux/2019.2/settings.sh
petalinux-create -t project --template zynqMP --name vitis_ai_zcu106
cd vitis_ai_zcu106
petalinux-config --get-hw-description=<Vivado导出目录>
关键配置项:
- Subsystem AUTO Hardware Settings → 确认PS端DDR型号为
MT40A256M16GE-075E - Image Packaging Configuration → 勾选
EXT4根文件系统格式 - u-boot Configuration → 禁用
CONFIG_NET_RANDOM_ETHADDR
2.2 加速编译的三大技巧
-
sstate-cache本地化 :
mkdir -p ./build/sstate_cache petalinux-config --component yocto在配置界面设置:
SSTATE_MIRRORS = "file://.* http://petalinux.xilinx.com/sswreleases/rel-v2019.2/sstate-cache/PATH"DL_DIR = "<本地下载缓存路径>"
-
并行编译设置 :
echo 'BB_NUMBER_THREADS = "8"' >> build/conf/local.conf echo 'PARALLEL_MAKE = "-j 8"' >> build/conf/local.conf -
离线包预下载 : 使用
petalinux-download工具提前获取所有依赖:petalinux-download --dir ./downloads --verbose
3. 关键依赖包问题解决方案
3.1 glog 0.3.5版本修复
当出现 fatal: Remote branch v35 not found 错误时,按以下步骤处理:
-
定位问题文件:
find ./ -name "glog_%.bbappend" -
替换为修正版配方:
SRC_URI = "git://github.com/google/glog.git;protocol=https;branch=master" SRCREV = "96a2f23dca4cc7180821ca5f32e526314395d1a5" PV = "0.3.5+git${SRCPV}" -
手动补丁应用:
wget https://patch-diff.githubusercontent.com/raw/google/glog/pull/263.patch quilt import ../263.patch quilt push
3.2 bind 9.11.3配置失败处理
针对 do_qa_configure 错误,推荐替换为稳定版本:
-
从Yocto仓库获取9.11.5版本配方:
wget http://git.yoctoproject.org/cgit.cgi/poky/plain/meta/recipes-connectivity/bind/bind_9.11.5.bb -
覆盖原文件:
cp bind_9.11.5.bb \ components/yocto/source/aarch64/layers/core/meta/recipes-connectivity/bind/ -
清理重建:
petalinux-build -c bind -x cleansstate petalinux-build -c bind
4. Vitis AI集成与镜像打包
4.1 DPU编译器集成
git clone https://github.com/Xilinx/Vitis-AI.git
cd Vitis-AI/setup/mpsoc
./install.sh /opt/vitis_ai/2019.2
环境变量配置示例:
export DPU_COMPILER=/opt/vitis_ai/2019.2/compiler
export PATH=$DPU_COMPILER/bin:$PATH
4.2 模型部署测试流程
-
编译ResNet50示例:
vai_c_tensorflow --arch /opt/vitis_ai/2019.2/arch/DPUCZDX8G/ZCU102/arch.json \ --model resnet50_keras_224.xmodel \ --output_dir ./output -
性能分析命令:
vai_c_profile --target dpuv2 --model resnet50.xmodel \ --output_dir profile_results
实测性能数据(ZCU106 @ 300MHz):
| 模型 | 吞吐量(FPS) | 功耗(W) | 延迟(ms) |
|---|---|---|---|
| ResNet50 | 142 | 5.3 | 7.04 |
| YOLOv3 | 58 | 6.1 | 17.24 |
| FPN | 89 | 5.8 | 11.23 |
4.3 最终镜像生成
petalinux-build
petalinux-package --boot --fsbl images/linux/zynqmp_fsbl.elf \
--u-boot images/linux/u-boot.elf \
--pmufw images/linux/pmufw.elf \
--fpga images/linux/system.bit \
--force
生成的 BOOT.BIN 和 image.ub 文件应复制到SD卡FAT32分区,根文件系统镜像 rootfs.ext4 需写入EXT4分区。首次启动建议通过串口终端观察启动日志,典型成功输出应包含:
[OK] Loaded DPU driver v1.4.0
[OK] DPU clock configured to 300MHz
更多推荐


所有评论(0)