开发者分享 | 如何在 Petalinux 下定位 decice-tree 错误

作者:张超,XILINX 产品应用工程师;来源: XILINX开发者社区微信公众号

今天邀请到赛灵思专家和大家分享下如何在 Petalinux 下定位 decice-tree 错误的一些技巧。

首先我们来了解下 Petalinux 工程中 device-tree 的文件位置:

工具自动生成的device-tree文件位于

components/plnx_workspace/device-tree/device-tree,

该文件夹下的文件请勿自行修改,供用户编辑的 device-tree 文件位于

project-spec/meta-user/recipes-bsp/device-tree/files

对于大部分错误,通过 petalinux 工具的 error log 已经足够定位错误类型和位置。比如下面,

ERROR: device-tree-xilinx-v2020.1+gitAUTOINC+f725aaecff-r0 do_compile: Error executing a python function in exec_python_func() autogenerated:

The stack trace of python calls that resulted in this exception/failure was

……

Subprocess output:

/tmp/xilinx-zcu102-2020.2-2021.02.08-01.47.20-87H/work/zynqmp_generic-xilinx-linux/device-tree/xilinx-v2020.1+gitAUTOINC+f725aaecff-r0/system-user.dtsi:3.31-15.9: ERROR (duplicate_label): /ethernet@ff0b0000: Duplicate label 'gem0' on /ethernet@ff0b0000 and /amba/ethernet@ff0b0000

ERROR: Input tree has errors, aborting (use -f to force output)

ERROR: Logfile of failure stored in: /tmp/xilinx-zcu102-2020.2-2021.02.08-01.47.20-87H/work/zynqmp_generic-xilinx-linux/device-tree/xilinx-v2020.1+gitAUTOINC+f725aaecff-r0/temp/log.do_compile.62492

ERROR: Task (/group/bcapps/chaoz/plnx_zcu102_bsp_2020p2/xilinx-zcu102-2020.2/components/yocto/layers/meta-xilinx/meta-xilinx-bsp/recipes-bsp/device-tree/device-tree.bb:do_compile) failed with exit code '1'

NOTE: Tasks Summary: Attempted 3410 tasks of which 3402 didn't need to be rerun and 1 failed.

……

ERROR: Failed to build project

实际的 log 会非常冗长,我们在其中仔细找 dtc 的报错,其中提示 “Duplicate label 'gem0' on /ethernet@ff0b0000 and /amba/ethernet@ff0b0000“,说明 ‘gem0’ 的 label 在多个地方重复定义了。而且报错也提示了错误的位置为“…/system-user.dtsi:3.31-15.9”,我们根据错误提示去删除重复的 gem0 定义即可。

  有时候通过 petalinux 的 log 无法定位到具体错误位置,这时候我们可以通过在 Petalinux 之外手动编译 device tree文件的方式来获得更具体的错误信息。手动编译需要用到dtc (Devicetree Compiler), 如果你的机器上还没有 dtc 的话可以从 linux-xlnx/scripts/dtc 位置找到源码并执行 make 来编译生成 dtc 工具。

如前所述 Petalinux 下的 device tree 分布在两个位置,我们先把所有 dts/dtsi 文件都拷贝到单独工作目录中方便后续手动编译。

设备树的顶层为 system-top.dts, 并引用了很多其它 dtsi 文件,类似 C 语言中的 include 机制。可以先利用 gcc 来进行预处理,将分立的 dts/dtsi 文件汇总到一个文件中,

gcc -I -E -nostdinc -undef -D__DTS__ -x assembler-with-cpp -o .dts .dts

再用 dtc 来编译设备树文件。

dtc -I dts -O dtb -o out.dtb .dts

接下来根据 dtc 的报错信息,就可以容易地定位到错误类型和位置。

最新文章

最新文章