2020年11月16日月曜日

yocto+petalinux2020.1でカーネルデバッグしてみようとした話

yoctoでカーネルデバッグをしてみようとした話。

エミュレータでは正常起動しているのに、実機だとブートの途中でハングするという問題を調査した際の手順をまとめた。 ビルドし始めてすぐにaxi_intcのdevicetreeが間違っていそうだなと気がついたけど、せっかくなので最後までやってみた。

結果、kgdbwaitはpetalinuxだと期待通りの動きをしないことがわかった。ドライバの修正方法について記載あったりするので、折を見てkgdbが起動時に使えるようにしておきたいところ。

環境

petalinux 2020.1
Ubuntu 18.04
https://github.com/akira-nishiyama/petalinux-ros2-manifests.git

エラー時のメッセージ

...(略)...
[    0.000000] GIC: Adjusting CPU interface base to 0x00000000f902f000
[    0.000000] GIC: Using split EOI/Deactivate mode
[    0.000000] irq-xilinx: /amba_pl@0/interrupt-controller@a0090000: num_irq=32, sw_irq=0, edge=0x0
実機の場合にここで止まる。

準備

cd ~/work
source setupsdk
MACHINE=ultra96v2 bitbake linux-xlnx -c do_menuconfig

以下の通り設定する。

Kernel hacking -> KGDB: Kernel debugger (Check it and Enter):
Check: KGDB: use kgdb over the serial console
Check: KGDB_KDB: include kdb frontend for kgdb        
Enable: Kernel debugging and Magic SysRq key
Enable: Compile the kernel with debug info

local.confに以下を設定する。 DEBUG_BUILD以降は必要かどうかはよくわからなかった。 RM_WORK_EXCLUDE += "linux-xlnx-dev"だけでも良いかも。

########################
# For debug
########################
EXTRA_IMAGE_FEATURES += "\
      tools-debug \    
      debug-tweaks \   
      "        

# Specifies to build packages with debugging information
DEBUG_BUILD = "1"

# Do not remove debug symbols
INHIBIT_PACKAGE_STRIP = "1"

# OPTIONAL: Do not split debug symbols in a separate file
INHIBIT_PACKAGE_DEBUG_SPLIT= "1"

ビルド

MACHINE=ultra96v2-zynqmp bitbake petalinux-image-minimal
MACHINE=ultra96v2-zynqmp bitbake petalinux-image-minimal -c do_populate_sdk

実行

u-bootのautobootを途中で止めてブートオプションを設定する。

setenv bootargs "kgdboc=ttyPS0,115200 kgdbwait"
boot

通常通り起動してしまった。 ここに情報があり、どうもpetalinux(というかxilinx_uartps.c?)の問題のよう。 とりあえずはLinuxが立ち上がった後は使用可能な模様。

root@ultra96v2-zynqmp:~# echo ttyPS0 > /sys/module/kgdboc/parameters/kgdboc
[   48.462920] KGDB: Registered I/O driver kgdboc
[   48.491488] KGDB: Waiting for connection from remote gdb...

Entering kdb (current=0xffffff805b8c1140, pid 390) on processor 2 due to Keyboard Entry
[2]kdb>

devicetreeを修正したら最初に調べようと思っていた問題は解決した。むしろ今まで何故動いていたのかが謎。

参考ページ

https://developer.ridgerun.com/wiki/index.php?title=Preparing_Yocto_Development_Environment_for_Debugging https://sites.google.com/site/kandamotohiro/linux/kgdb https://docs.windriver.com/bundle/Wind_River_Linux_Tutorial_Kernel_Debugging_with_GDB_and_KGDB_LTS_18_1/page/mmo1403548696698.html https://forums.xilinx.com/t5/Embedded-Linux/quot-KGDBWait-quot-parameter-is-not-waiting-while-booting-the/td-p/550816

0 件のコメント:

コメントを投稿