參考文檔: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,我們可以看到已經修改完畢