[工程师分享]在PetaLinux工程中导出所有关键模块代码

作者:付汉杰 hankf@amd.com

PetaLinux工程会自动下载代码并编译。很多时候,工程师需要修改代码,加入调试信息。使用下列脚本,可以一次性导出所有关键模块的代码。
脚本中,为了保持兼容性,导出了MPSoC和Versal的模块。有些模块不存在,不会导致其它副作用,请忽略不存在的模块错误信息。

#!/bin/bash
# hankf@amd.com

date_time=`date +%0m%0d-%0k%0M` 
current_dir=`pwd`
log_file=$current_dir/petalinux-devtool-modify-$date_time-log.txt
echo "Date-Time is $date_time"    2>&1   | tee -a $log_file
echo "Current directory is $current_dir"    2>&1   | tee -a $log_file
echo "Log file is $log_file"    2>&1   | tee -a $log_file

# check petalinux tool
which petalinux-build
which petalinux-devtool

petalinux_devtool=`which petalinux-devtool` 
echo "petalinux devtool 1:  $petalinux_devtool"    2>&1   | tee -a $log_file

# PetaLinux 2020.1: no petalinux-devtool
if [ "$petalinux_devtool" = "" ]; then
	echo "Source yocto environment"    2>&1   | tee -a $log_file

	if [ -f ./components/yocto/environment-setup-aarch64-xilinx-linux ]; then 
		echo "Source yocto environment: aarch64"    2>&1   | tee -a $log_file
		source ./components/yocto/environment-setup-aarch64-xilinx-linux 		
	elif [ -f ./components/yocto/environment-setup-cortexa72-cortexa53-xilinx-linux ]; then
		echo "Source yocto environment: cortexa72"    2>&1   | tee -a $log_file
		source ./components/yocto/environment-setup-cortexa72-cortexa53-xilinx-linux 		
	fi 

	source components/yocto/layers/core/oe-init-build-env    
	if [ -d ../components/yocto/ ]; then 
		cd .. 
	fi 

	petalinux_devtool=`which devtool`
	echo "petalinux devtool 2:  $petalinux_devtool"    2>&1   | tee -a $log_file
	# devtool create-workspace ./components/yocto/workspace/    2>&1   | tee -a $log_file
fi

if [ "$petalinux_devtool" = "" ]; then
	echo "Error: petalinux devtool is invalid"    2>&1   | tee -a $log_file
	exit
fi

# 
# Get the source code from git url specifi ed  in meta-layers:
#     petalinux-devtool modify <recipe-name>
# 
# Creates a patch for the committed  changes in recipe sources directory.
#     petalinux-devtool finish <recipe-name> <destination layer path>

echo -e "\nTry to modify linux-xlnx"      2>&1   | tee -a $log_file
$petalinux_devtool modify linux-xlnx       2>&1   | tee -a $log_file

echo -e "\nTry to modify u-boot-xlnx"      2>&1   | tee -a $log_file
$petalinux_devtool modify u-boot-xlnx       2>&1   | tee -a $log_file

echo -e "\nTry to modify arm-trusted-firmware"      2>&1   | tee -a $log_file
$petalinux_devtool modify arm-trusted-firmware       2>&1   | tee -a $log_file

echo -e "\nTry to modify fsbl-firmware"      2>&1   | tee -a $log_file
$petalinux_devtool modify fsbl-firmware       2>&1   | tee -a $log_file

echo -e "\nTry to modify pmu-firmware"      2>&1   | tee -a $log_file
$petalinux_devtool modify pmu-firmware       2>&1   | tee -a $log_file

echo -e "\nTry to modify plm-firmware"      2>&1   | tee -a $log_file
$petalinux_devtool modify plm-firmware       2>&1   | tee -a $log_file

echo -e "\nTry to modify psm-firmware"      2>&1   | tee -a $log_file
$petalinux_devtool modify psm-firmware       2>&1   | tee -a $log_file

echo -e "\nShow current directory: "     2>&1   | tee -a $log_file
pwd                                      2>&1   | tee -a $log_file

echo -e "\nShow components that can be modified in ./components/yocto/workspace/sources/"     2>&1   | tee -a $log_file
if [ -d ./components/yocto/workspace/sources/ ]; then 
	ls -l ./components/yocto/workspace/sources/            2>&1   | tee -a $log_file
fi 

# petalinux-devtool finish <recipe-name> <destination layer path>
# petalinux-devtool reset <recipe-name> to remove the source directory for the recipe from workspace.


调试完成后,使用命令“petalinux-devtool reset ”, 可以使PetaLinux工程恢复自动下载代码和编译。

测试环境

工具
X86 Ubuntu 18.04
PetaLinux 2022.1
PetaLinux 2020.1

测试单板
KR260
zcu102
vck190

最新文章