当前位置: 首页 > news >正文

PetaLinux的JTAG启动

相关文档 PetaLinux 使用技巧与缓存配置

PetaLinux 工具文档参考指南 (ug1144)

设备树配置文档

软硬件准备

分类项目说明/用途验证方法示例
硬件JTAG 线JTAG 下载、调试
UART 串口线查看 zynq 启动日志
网口线用于 TFTP 下载
软件TFTP 服务器用于下载各种启动文件systemctl status tftpd-hpa
Vivado (xsdb)使用 xsdb 命令通过 JTAG 下载 ELF/bitxsdb -version
PetaLinux构建和打包 Linux 镜像petalinux-create -h
mkimage 工具制作 boot.scr 文件,安装命令:sudo apt install u-boot-toolsmkimage -V

ubuntu环境变量 ~/.bashrc

alias sptl='source /opt/pkg/petalinux/2020.2/settings.sh'
alias svivado='source /opt/pkg/tools/Xilinx/Vivado/2020.2/settings64.sh'
alias svitis='source /opt/pkg/tools/Xilinx/Vitis/2020.2/settings64.sh'
alias ssdk='source  /opt/petalinux/2020.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi'
alias sclion='/opt/soft/clion-2023.3.4/bin/clion.sh'

vivado导出xsa文件给petalinux工程用

 scp system_wrapper.xsa minglie@192.168.1.104:~/petalinux/xsa_7010/

启动相关文件

文件名作用说明生成方式
system.bitFPGA 配置比特流文件,配置 PL 逻辑电路(JTAG/FSBL 下载到 FPGA)。petalinux-build
zynq_fsbl.elfFSBL(First Stage Boot Loader),初始化 PS/PL,加载 bitstream 和 U-Boot。petalinux-build
uboot.elf二级引导程序 U-Boot,可通过 SD/TFTP/Flash 加载内核和设备树。petalinux-build
uImage/zImageLinux 内核镜像petalinux-build
rootfs.cpio.gz.u-boot根文件系统(cpio+gzip 格式,适用于 initramfs)。petalinux-build
system.dtb设备树文件(Device Tree Blob),描述硬件结构,供内核识别外设。petalinux-build
boot.cmd.defaultboot.scr 的源码手写
boot.scrU-Boot 脚本文件(由 mkimage 生成),定义启动参数和加载流程。mkimage -c none -A arm -T script -d boot.cmd.default boot.scr
text.txt (xsdb 脚本)XSDB 命令脚本,定义通过 JTAG 下载 ELF/bitstream 的操作步骤。录制 petalinux-boot --jtag --prebuilt 3 --tcl test.txt

PetaLinux --prebuilt 等级对比表

预设等级加载 Bitstream加载 FSBL加载 U-Boot加载 Linux(内核 + rootfs)适用场景
--prebuilt 1✅ 是❌ 否❌ 否❌ 否只配置 PL(FPGA 逻辑),测试 FPGA
--prebuilt 2✅ 是✅ 是✅ 是❌ 否启动 U-Boot,进行手动加载或调试
--prebuilt 3✅ 是✅ 是✅ 是✅ 是一键启动 Linux 系统(推荐测试用)

操作步骤

使用 petalinux-boot 制作预建镜像

就是把 images/linux 里的文件复制到pre-built目录下,用于录制
xsdb 脚本, 后续我们从 images/linux/ 目录下载文件, 所以只制作一次

petalinux-package --prebuilt --fpga images/linux/system.bit
或
petalinux-package --prebuilt --force

录制 xsdb 脚本

执行前需重新上电,若不加 --tcl test.txt 则是jtag启动

petalinux-boot --jtag --prebuilt 3 --tcl test.txt

录制的text.txt

删除下载uImage和rootfs.cpio.gz.u-boot的部分,因为 boot.scr 通过tftp下载了
替换 /home/minglie/petalinux/antbase/pre-built/linux/images/ 为 /home/minglie/petalinux/antbase/images/linux/
这样重新build后,直接用 images/linux/里的文件

connect
puts stderr "INFO: Configuring the FPGA..."
puts stderr "INFO: Downloading bitstream: /home/minglie/petalinux/antbase/pre-built/linux/images/system.bit to the target."
fpga "/home/minglie/petalinux/antbase/pre-built/linux/images/system.bit"
after 2000
targets -set -nocase -filter {name =~ "arm*#0"}source /home/minglie/petalinux/antbase/project-spec/hw-description/ps7_init.tcl; ps7_post_config
catch {stop}
set mctrlval [string trim [lindex [split [mrd 0xF8007080] :] 1]]
puts "mctrlval=$mctrlval"
puts stderr "INFO: Downloading ELF file: /home/minglie/petalinux/antbase/pre-built/linux/images/zynq_fsbl.elf to the target."
dow  "/home/minglie/petalinux/antbase/pre-built/linux/images/zynq_fsbl.elf"
after 2000
con
after 3000; stop
targets -set -nocase -filter {name =~ "arm*#0"}
puts stderr "INFO: Downloading ELF file: /home/minglie/petalinux/antbase/pre-built/linux/images/u-boot.elf to the target."
dow  "/home/minglie/petalinux/antbase/pre-built/linux/images/u-boot.elf"
after 2000
con; after 1000; stop
targets -set -nocase -filter {name =~ "arm*#0"}
puts stderr "INFO: Loading image: /home/minglie/petalinux/antbase/pre-built/linux/images/system.dtb at 0x00100000"
dow -data  "/home/minglie/petalinux/antbase/pre-built/linux/images/system.dtb" 0x00100000
after 2000
targets -set -nocase -filter {name =~ "arm*#0"}
puts stderr "INFO: Loading image: /home/minglie/petalinux/antbase/pre-built/linux/images/uImage at 0x00200000"
dow -data  "/home/minglie/petalinux/antbase/pre-built/linux/images/uImage" 0x00200000
after 2000
targets -set -nocase -filter {name =~ "arm*#0"}
puts stderr "INFO: Loading image: /home/minglie/petalinux/antbase/pre-built/linux/images/rootfs.cpio.gz.u-boot at 0x04000000"
dow -data  "/home/minglie/petalinux/antbase/pre-built/linux/images/rootfs.cpio.gz.u-boot" 0x04000000
after 2000
targets -set -nocase -filter {name =~ "arm*#0"}
puts stderr "INFO: Loading image: /home/minglie/petalinux/antbase/pre-built/linux/images/boot.scr at 0x03000000"
dow -data  "/home/minglie/petalinux/antbase/pre-built/linux/images/boot.scr" 0x03000000
after 2000
con
exit
puts stderr "INFO: Saving XSDB commands to test.txt. You can run 'xsdb test.txt' to execute"

修改后的text.txt

connect
puts stderr "INFO: Configuring the FPGA..."
puts stderr "INFO: Downloading bitstream: /home/minglie/petalinux/antbase/images/linux/system.bit to the target."
fpga "/home/minglie/petalinux/antbase/images/linux/system.bit"
after 2000
targets -set -nocase -filter {name =~ "arm*#0"}source /home/minglie/petalinux/antbase/project-spec/hw-description/ps7_init.tcl; ps7_post_config
catch {stop}
set mctrlval [string trim [lindex [split [mrd 0xF8007080] :] 1]]
puts "mctrlval=$mctrlval"
puts stderr "INFO: Downloading ELF file: /home/minglie/petalinux/antbase/images/linux/zynq_fsbl.elf to the target."
dow  "/home/minglie/petalinux/antbase/images/linux/zynq_fsbl.elf"
after 2000
con
after 3000; stop
targets -set -nocase -filter {name =~ "arm*#0"}
puts stderr "INFO: Downloading ELF file: /home/minglie/petalinux/antbase/images/linux/u-boot.elf to the target."
dow  "/home/minglie/petalinux/antbase/images/linux/u-boot.elf"
after 2000con; after 1000; stop
targets -set -nocase -filter {name =~ "arm*#0"}
puts stderr "INFO: Loading image: /home/minglie/petalinux/antbase/images/linux/system.dtb at 0x00100000"
dow -data  "/home/minglie/petalinux/antbase/images/linux/system.dtb" 0x00100000
after 2000targets -set -nocase -filter {name =~ "arm*#0"}
puts stderr "INFO: Loading image: /home/minglie/petalinux/antbase/boot.scr at 0x03000000"
dow -data  "/home/minglie/petalinux/antbase/boot.scr" 0x03000000
after 2000
con
exit
puts stderr "INFO: Saving XSDB commands to test.txt. You can run 'xsdb test.txt' to execute"

生成自定义的boot.scr

加个echo “AAA” 确认这个boot.scr 是生效的

boot.cmd.default

echo "AAA"
setenv ipaddr   192.168.1.89
setenv serverip 192.168.1.104
pxe get
pxe boot

生成并拷贝boot.scr

mkimage -c none -A arm -T script -d boot.cmd.default boot.scr
cp boot.scr  /home/minglie/petalinux/antbase/boot.scr

xsdb执行脚本启动

xsdb text.txt

jtag 启动结束


qemu启动

petalinux-boot --qemu --kernel

u-boot 纯手动启动

>ZYNQ
tftpboot 0x00200000 zImage
tftpboot 0x00100000 system.dtb
# 加载bit文件
tftpboot 0x00800000 system.bit 
fpga load 0 0x00800000 $filesize
bootz 0x00200000 - 0x00100000

u-boot 手动执行boot.scr 启动

# 或制作ming_boot.scr
mkimage -A arm -T script -C none -n "Zynq Boot Script" -d boot.cmd ming_boot.scr
>ZYNQ
tftpboot 0x3000000 ming_boot.scr
source 0x3000000

u-boot 挂在nfs根文件系统启动

setenv ipaddr 192.168.1.89  
setenv serverip 192.168.1.104 
setenv gatewayip 192.168.1.1
setenv netmask 255.255.255.0setenv bootargs 'console=ttyPS0,115200 root=/dev/nfs rw nfsroot=192.168.1.104:/home/minglie/minglie/workspace/rootfs,nfsvers=3 ip=192.168.1.89:192.168.1.104:192.168.1.1:255.255.255.0::eth0:off'
saveenv
boot

petalinux 常用脚本

# 创建工程
petalinux-create -t project --template zynq -n antbase
cd antbase
# 导入硬件配置
petalinux-config --get-hw-description  ../xsa_7020/
petalinux-config --get-hw-description  ../xsa_7010/
# 配置 Linux 内核
petalinux-config -c kernel
# 配置 Linux 根文件系统
petalinux-config -c rootfs
# 编译
petalinux-build
petalinux-build -c device-tree -x clean
petalinux-build -c device-tree
# 制作BOOT.bin 启动文件并复制到 SD 卡
petalinux-package --boot --fsbl --fpga --u-boot --force
petalinux-package --boot  --u-boot --fsbl  --dtb no  --force
cd images/linux
cp BOOT.BIN image.ub boot.scr    /media/minglie/BOOT
# 修改xsa文件后,清理项目生成的中间文件,小改不用执行
petalinux-build -x mrproper -f
# 编译设备树
petalinux-build -c device-tree -x clean
petalinux-build -c device-tree

PetaLinux 清理命令

命令作用说明典型执行时机
petalinux-build -x clean删除临时文件和部分编译产物,保留配置文件和大部分构建结果,重新编译速度快。- 小范围修改(应用代码 / device tree / 配置等)出问题时尝试
- 编译失败怀疑是临时文件冲突时
petalinux-build -x mrproper -f删除项目生成的所有中间文件,包括内核、根文件系统的缓存和临时文件,但保留配置。相当于彻底重建。- 修改 XSA 硬件文件(新增/删除外设、更改地址映射)后必须执行
- BSP 结构发生变化
- 大规模修改导致编译异常时
petalinux-build -x distclean删除几乎所有构建产物,项目回到初始状态,仅保留工程配置文件。- 工程出现严重问题需要“重置”时
- 想把工程打包分享给别人,但不想带构建产物时

u-boot下载命令

# 从 TFTP 服务器上下载 PXE 配置文件(比如 pxelinux.cfg/default 或 pxelinux.cfg/<MAC>)
zynq>pxe get
# 在 pxe get 成功获取到 PXE 配置文件后,执行其中定义的启动流程:
## 下载内核镜像(zImage / uImage)
## 下载设备树(system.dtb)
## 下载 initrd(rootfs)
## 按配置的 bootargs 启动 Linux
zynq>pxe boot
http://www.dtcms.com/a/359689.html

相关文章:

  • Linux/UNIX系统编程手册笔记:用户和组、进程凭证、时间以及系统限制和选项
  • 创维LB2004_安装软件教程
  • vscode克隆远程代码步骤
  • MSVC---编译器工具链
  • 基于GA遗传优化的双向LSTM融合多头注意力(BiLSTM-MATT)时间序列预测算法matlab仿真
  • 【秋招笔试】2025.08.29阿里云秋招笔试题
  • 拉长视频时长的两种方法
  • 2023年IEEE IOTJ SCI1区TOP,动态环境下无人机目标覆盖任务路径规划,深度解析+性能实测
  • 腾讯浑元最新技术:具有表征对齐的多模态扩散,用于高保真拟音音频生成
  • 免税商品优选购物商城系统|java技术开发
  • 计算机网络总览
  • join怎么用
  • 性能测试工具-Slow Query Log
  • C/C++ 高阶数据结构 —— 二叉搜索树(二叉排序树)
  • 安装Android Studio
  • DVWA靶场通关笔记-SQL Injection (Impossible级别)
  • 【LeetCode - 每日1题】解数独
  • Tomcat 中部署 Web 应用
  • [灵动微电子 MM32BIN560CN MM32SPIN0280]读懂电机MCU 模拟输入运放放大
  • LangChain Prompt管理核心:PromptTemplate与ChatPromptTemplate全解析
  • 旦旦的农场打卡计划
  • 合约服务架构-OOP 方式
  • Linux系统比较两个​​已排序文件​​的实用工具之comm
  • R3:适用于 .NET 的新一代响应式扩展库,事件订阅流
  • HarmonyOS 应用开发:基于API 12及以上的新特性与实践
  • 视觉大模型与多模态理解
  • MySQL直接启动命令mysqld详解:从参数说明到故障排查
  • 容器seccomp配置文件在云服务器安全策略中的实施规范
  • 基于单片机老人防丢失防摔倒系统/老人健康状态检测系统
  • 神州数码VRRP 原理与配置篇