ZYNQ:使用 PetaLinux 构建Linux项目
参考文档:ug1144-petalinux-tools-reference-guide.pdf
环境安装
tofrodos iproute2 gawk gcc g++ git make net-tools libncurses5-dev tftpd zlib1g:i386 libssl-dev flex bison libselinux1 gnupg wget diffstat chrpath socat xterm autoconf libtool tar unzip texinfo zlib1g-dev gcc-multilib build-essential libsdl1.2-dev libglib2.0-dev screen pax gzip automake glib2-devel openssl openssl-devel xinetd tftp tftp-server redhat-lsb u-boot-tools(或 uboot-tools)
创建目录:
su root
mkdir /opt/env
chown -R huangshuchao:embd /opt/env/
#chown -R huangshuchao:embd /opt/env/
# 2016.4以后的petalinux不能以超级权限去安装,必须在$下安装petalinux。
安装
./petalinux-v2018.3-final-installer.run /opt/env/petalinux/2018.3
Ubuntu bash
dpkg-reconfigure dash
--> NO
使用
每次都需要:
source /opt/env/petalinux/2018.3/settings.sh
本文链接:https://www.cnblogs.com/schips/p/using-petalinux-build-linux-env.html
导入硬件
拷贝design_1_wrapper_hw_platform_0
到Linux
创建项目
petalinux-create --type project --template zynq --name 项目名称(目录)
INFO: Create project: ax_peta
INFO: New project successfully created in /home/huangshuchao/ax_peta
导入硬件信息
输入以下命令:
硬件信息包:
design_1_wrapper_hw_platform_0_test.tgz
(来自13_vdma_to_qspi_sd
)
petalinux-config --get-hw-description ~/hw-vivado/design_1_wrapper_hw_platform_0_test
配置优化
我们这里再做一些优化工作,以方便我们的使用:
离线编译
注意,修改镜像时,填入的路径是以file://
开头的。
-> Yocto Settings
## 设置缓存:SState cache
-> Local sstate feeds settings
-> local sstate feeds url ## 按 Enter
/home/xx/sstage_package_for_petalinux/arm
-> Yocto Settings
## 设置镜像:download mirror
-> Add pre-mirror url ## 按 Enter
file:///home/xx/sstage_package_for_petalinux/downloads
-> Yocto Settings
## 设置离线编译
[ ] Enable Network sstate feeds ## 按 N
[*] Enable BB NO NETWORK ## 按 Y
启动Linux时自动登录
避免输入账号密码。
-> Yocto Settings
[*] Enable Debug Tweaks ## 按 Y
不自动获取IP地址
如果网口存在时,可以考虑关闭自动获取IP地址(会造成开机过慢)
-> Subsystem AUTO Hardware Settings (SUBSYSTEM_HARDWARE_AUTO [=y])
-> Ethernet Settings
Primary Ethernet ((ps7_ethernet_0) # 确认 存在此项
[ ] Obtain IP address automatically # 按下空格键取消,并设置一个IP
(192.168.168.168) Static IP address
(255.255.255.0) Static IP netmask (NEW)
(192.168.168.1) Static IP gateway
u-boot Configuration --->
(192.168.168.1) TFTP Server IP addres # 设置TFTP服务器地址
修改文件系统类型(可选)
默认的文件系统类型会导致文件系统无法保存,一开始的时候可以保持默认,可以在后续修改为以下配置:
-> Image Packaging Configuration
-> Root filesystem type
-> Root filesystem type (SD card) --->
(/dev/mmcblk0p2) Device node of SD device (NEW)
保存退出,以下是提示信息:
INFO: Getting hardware description...
[INFO] generating Kconfig for project
[INFO] menuconfig project
*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.
[INFO] sourcing bitbake
[INFO] generating plnxtool conf
[INFO] generating meta-plnx-generated layer
[INFO] generating machine configuration
[INFO] generating bbappends for project . This may take time !
[INFO] generating u-boot configuration files
[INFO] generating kernel configuration files
[INFO] generating kconfig for Rootfs
[INFO] oldconfig rootfs
[INFO] generating petalinux-user-image.bb
配置保护
保留Linux和UBoot源代码
echo 'RM_WORK_EXCLUDE += "linux-xlnx"'>> project-spec/meta-user/conf/petalinuxbsp.conf
echo 'RM_WORK_EXCLUDE += "u-boot-xlnx"'>> project-spec/meta-user/conf/petalinuxbsp.conf
echo ''>> project-spec/meta-user/conf/petalinuxbsp.conf
原理:run.do_rm_work
中有对关键字进行解析,如果符合条件,那么不执行删除操作。
配置uboot
petalinux-config -c u-boot
进行如下配置:
配置项 | 值与说明 |
---|---|
Boot media | Boot介质,配置从SD卡启动 |
delay in seconds before automatically booting | Boot自启动时间,默认4s,可修改 |
Disable support for parallel NOR flash | NOR flash支持,无支持 |
add U-Boot environment variable vers | U-Boot环境变量添加,无 |
Display information about the CPU during start up | 启动阶段显示CPU信息,可选 |
Display information about the board during start up | 启动阶段显示板卡信息,可选 |
Command line interface | 命令行配置,用户可进一步配置 |
Device Tree Control | 设备树控制,保持默认配置(embeded) |
配置内核
输入:
petalinux-config -c kernel
以下是提示信息:
[INFO] generating Kconfig for project
[INFO] sourcing bitbake
[INFO] generating plnxtool conf
[INFO] generating meta-plnx-generated layer
[INFO] generating machine configuration
[INFO] configuring: kernel
[INFO] generating kernel configuration files
[INFO] bitbake virtual/kernel -c menuconfig
Parsing recipes: 100% |##########################################| ETA: 0:00:56
Parsing of 2569 .bb files complete (0 cached, 2569 parsed). 3445 targets, 149 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
很快就会弹出Menuconfig菜单,选择
CONFIG_MICREL_PHY:
-> Device Drivers
-> Network device support (NETDEVICES [=y])
-> PHY Device support and infrastructure (PHYLIB [=y])
[y] Micrel PHYs
保存,EXIT。
配置文件系统
petalinux-config -c rootfs
petalinux-config -c rootfs && petalinux-build
无更改,保存退出
编译 uboot、内核、文件系统、设备树
petalinux-build
此后,生成下面的文件
# ls image/linux
rootfs.cpio rootfs.cpio.gz.u-boot rootfs.ext4 rootfs.jffs2 rootfs.tar.gz system.dtb u-boot.elf zynq_fsbl.elf image.ub rootfs.cpio.bz2 rootfs.ext3 rootfs.ext4.gz rootfs.manifest rootfs.testdata.json System.map.linux vmlinux rootfs.bin rootfs.cpio.gz rootfs.ext3.bz2 rootfs.its rootfs.tar.bz2 system.bit u-boot.bin zImage
生成BOOT.BIN
执行下面的代码生成BOOT.BIN
petalinux-package --boot --fsbl ./images/linux/zynq_fsbl.elf --fpga ./images/linux/system.bit --u-boot --force
下面的是提示信息:
INFO: Getting system flash information...
INFO: File in BOOT BIN: "/home/huangshuchao/ax_peta2/images/linux/zynq_fsbl.elf"
INFO: File in BOOT BIN: "/home/huangshuchao/ax_peta2/images/linux/system.bit"
INFO: File in BOOT BIN: "/home/huangshuchao/ax_peta2/images/linux/u-boot.elf"
INFO: Generating Zynq binary package BOOT.BIN...
****** Xilinx Bootgen v2018.3
**** Build date : Nov 15 2018-19:22:29
** Copyright 1986-2018 Xilinx, Inc. All Rights Reserved.
INFO: Binary is ready.
生成image.ub
mkimage -f ./images/linux/rootfs.its image.ub
测试
从image/linux
中拷贝:BOOT.BIN
、image.ub
,到SD卡即可。
创建项目的脚本
##
# Copyright By Schips, All Rights Reserved
# https://gitee.com/schips/
#
# File Name: copy_petalinux_project_with_hw.sh
# Created : 2020-07-25 11:28:24
#
##
#!/bin/sh
# 项目工程常见参数设置
## sstage包下载后设置
SSTATE_LOCAL_PATH="/home/huangshuchao/sstage_package_for_petalinux/"
## IP地址设置
NET=192.168.1
IPADDR=$NET.100
help () {
echo "Error : need \$projectname \$hw_bsp"
echo " eg :"
echo " $0 ax_project ~/hw-vivado-bsp-for-petalinux/some_packakge"
exit 1
}
if [ -z "$1" ]; then
help
fi
if [ -z "$2" ]; then
help
fi
command -v petalinux-create >/dev/null 2>&1 || { echo >&2 "Aborted : Require \"petalinux-create\" but not found."; exit 1; }
command -v petalinux-config >/dev/null 2>&1 || { echo >&2 "Aborted : Require \"petalinux-config\" but not found."; exit 1; }
## 删除源目录
rm $1 -rf
## 创建项目
petalinux-create --type project --template zynq --name $1
PROJECT=$1
## 导入硬件信息
cd $PROJECT
petalinux-config --get-hw-description $2
## 使PetaLinux不删除源码
echo 'RM_WORK_EXCLUDE += "linux-xlnx"'>> project-spec/meta-user/conf/petalinuxbsp.conf
echo 'RM_WORK_EXCLUDE += "u-boot-xlnx"'>> project-spec/meta-user/conf/petalinuxbsp.conf
echo ''>> project-spec/meta-user/conf/petalinuxbsp.conf
# 删除带有指定关键字的行
delete_line_with_special_word ()
{
if [[ $# -lt 2 ]]; then
return
fi
FILE=$1
WORD=$2
sed -i "/${WORD}/d" ${FILE}
}
# 文件内容追加
append_line_into_file ()
{
if [[ $# -lt 2 ]]; then
return
fi
FILE=$1
LINE=$2
echo $LINE >> $FILE
}
CONFIG=project-spec/configs/config
cp $CONFIG $CONFIG.old
## 网络设置
delete_line_with_special_word $CONFIG CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_USE_DHCP
append_line_into_file $CONFIG "# CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_USE_DHCP is not set"
append_line_into_file $CONFIG "CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_IP_ADDRESS=\"$IPADDR\""
append_line_into_file $CONFIG "CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_IP_NETMASK=\"255.255.255.0\""
append_line_into_file $CONFIG "CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_IP_GATEWAY=\"$NET.1\""
## 本地包
delete_line_with_special_word $CONFIG CONFIG_YOCTO_NETWORK_SSTATE_FEEDS
append_line_into_file $CONFIG "# CONFIG_YOCTO_NETWORK_SSTATE_FEEDS is not set"
delete_line_with_special_word $CONFIG CONFIG_YOCTO_BB_NO_NETWORK
append_line_into_file $CONFIG "CONFIG_YOCTO_BB_NO_NETWORK=y"
delete_line_with_special_word $CONFIG CONFIG_PRE_MIRROR_URL
append_line_into_file $CONFIG "CONFIG_PRE_MIRROR_URL=\"file://${SSTATE_LOCAL_PATH}/downloads\""
delete_line_with_special_word $CONFIG CONFIG_YOCTO_LOCAL_SSTATE_FEEDS_URL
append_line_into_file $CONFIG "CONFIG_YOCTO_LOCAL_SSTATE_FEEDS_URL=\"${SSTATE_LOCAL_PATH}/arm\"" #zynq
## | 目录 | 平台 |
## | --------- | ----------- |
## | aarch64 | ZynqMP |
## | arm | Zynq |
## | mb-full | MB AXI |
## | mb-lite | MB AXI lite |
## | downloads | 全平台 |
## 免输入密码登陆
delete_line_with_special_word $CONFIG CONFIG_YOCTO_ENABLE_DEBUG_TWEAKS
append_line_into_file $CONFIG "CONFIG_YOCTO_ENABLE_DEBUG_TWEAKS=y"
附录:PetaLinux注意事项
导入项目创建项目以后,工程项目会确定当前路径,所以需要注意,不要随便改动工程路径。
ERROR: OE-core's config sanity checker detected a potential misconfiguration.
Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
Following is the list of potential problems / advisories:
Error, TMPDIR has changed location. You need to either move it back to /home/huangshuchao/ax_1_design1hw0_retry/build/tmp or rebuild
不过可以通过拷贝petalinux工程的配置到另外的目录,再build出那些临时文件。
详情见:加速 PetaLinux 工程编译、复制 PetaLinux 工程
附录: 构建各部分
petalinux-build -c kernel
petalinux-build -c device-tree
petalinux-build -c fsbl
petalinux-build -c u-boot
petalinux-package --boot --fsbl --fpga --u-boot --force
这样在images目录下就会生成我们需要的uImage、system.dtb以及BOOT.BIN,为了确保设备树修改完好,我们这里先反编译一下设备树,生成system.dts,查看里面是否我们要修改的东西都已经修改好了(需要device-tree-compiler)。
在system.dtb文件的目录下运行
dtc -I dtb -O dts -o system.dts system.dtb
打开ststem.dts,我们可以看到已经修改完毕
若在页首无特别声明,本篇文章由 Schips 经过整理后发布。
博客地址:https://www.cnblogs.com/schips/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端