天天看點

linux編譯錯誤定位,開發者分享 | 如何在 Petalinux 下定位 decice-tree 錯誤

作者:張超,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): /[email protected]: Duplicate label 'gem0' on /[email protected] and /amba/[email protected]

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 /[email protected] and /amba/[email protected]“,說明 ‘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 的報錯資訊,就可以容易地定位到錯誤類型和位置。