在PetaLinux工程中调试关键模块代码

在PetaLinux工程中,与单板相关的UBoot、Linux等模块,经常需要编辑、调试。

在旧版本中,可以为UBoot、Linux选择“ext-local-src”, 指定UBoot、Linux的代码,从而使PetaLinux使用工程师修改后带调试信息的代码。现在已经不建议这种模式。

对于新的的PetaLinux,建议使用命令“petalinux-devtool modify ”,导出相关模块代码,然后编辑编译,就能看到调试信息。导出的代码,在目录“components/yocto/workspace/sources/”中。

对于2020等旧版本,没有命令“petalinux-devtool”。建议先导入yocto的环境,从而得到工具“devtool”,使用“devtool”替代“petalinux-devtool”。可以参考下列命令。

source /opt/pkg/petalinux/settings.sh
source <plnx-proj-root>/components/yocto/environment-setup-aarch64-xilinx-linux
source <plnx-proj-root>/components/yocto/layers/core/oe-init-build-env

在PetaLinux工程中导出所有关键模块代码 提供了统一的脚本,可以在PetaLinux 2020、2022中,导出代码。

比如最近在u-boot-xlnx/common/usb.c的开始处,定义宏DEBUG,使能uboot的usb调试信息。其它usb相关文件也可以增加“#define DEBUG”。再编译PetaLinux工程,运行新的boot.bin,执行命令“usb stop && usb start && fatls usb 0 && usb stop”,就会有usb调试信息。

/*
 * How it works:
 *
 * Since this is a bootloader, the devices will not be automatic
 * (re)configured on hotplug, but after a restart of the USB the
 * device should work.
 *
 * For each transfer (except "Interrupt") we wait for completion.
 */

// Hank, debug_usb
#define DEBUG

#include <common.h>
#include <command.h>
#include <dm.h>

调试完成后,执行命令下列命令,还可以给原来的recipe,创建patch。

git add <filename>
git commit -s
petalinux-devtool finish <recipe-name> <destination layer path>

调试完成后,执行命令下列命令,删除对应的recipe。

petalinux-devtool reset <recipe-name> to remove the source directory for the recipe from workspace.

测试环境

X86 Ubuntu 18.04
PetaLinux 2022.1
PetaLinux 2021.1
PetaLinux 2020.1

posted @ 2022-11-10 09:49  HankFu  阅读(163)  评论(0编辑  收藏  举报