我的其他博客有關於buildroot怎么用的介紹。
比如 buildroot-2020.11.1/configs/qemu_arm_vexpress_defconfig 這個配置。
make qemu_arm_vexpress_defconfig make
就能得到:
./start-qemu.sh 是運行qemu的shell腳本,同時加載kernel(zImage),dtb,rootfs。
用vscode調試:
buildroot:
buildroot默認不下載編譯gdb,需要 make menuconfig勾選: Toolchain ---> [*] Build cross gdb for the host buildroot里面的linux,默認配置一般也是關閉了debug,直接 make linux-menuconfig 去勾選: Kernel hacking ---> [*] Kernel debugging Compile-time checks and compiler options ---> [*] Compile the kernel with debug info
可以用這條命令,驗證kernel的編譯輸出里,有沒有debug info:
readelf -e /home/mmm/buildroot-2020.11.1/output/build/linux-rel_imx_5.4.24_2.1.0/vmlinux
有這樣的段就對了:
[32] .debug_line PROGBITS 00000000 d1fe36 f1d5ed 00 0 0 1
[33] .debug_info PROGBITS 00000000 1c3d423 7b50e92 00 0 0 1
[34] .debug_abbrev PROGBITS 00000000 978e2b5 46824b 00 0 0 1
[35] .debug_aranges PROGBITS 00000000 9bf6500 015e70 00 0 0 8
[36] .debug_str PROGBITS 00000000 9c0c370 2727f8 01 MS 0 0 1
[37] .debug_ranges PROGBITS 00000000 9e7eb68 4c78e0 00 0 0 8
[38] .debug_frame PROGBITS 00000000 a346448 16279c 00 0 0 4
[39] .debug_loc PROGBITS 00000000 a4a8be4 5b328b 00 0 0 1
qemu:
export PATH="/home/mmm/buildroot-2020.11.1/output/host/bin:${PATH}" # dtc -I dtb -O dts vexpress-v2p-ca9.dtb -o vexpress-v2p-ca9-all.dts qemu-system-arm \ -M vexpress-a9 \ -smp 1 \ -m 256 \ -kernel ${IMAGE_DIR}/zImage \ -dtb ${IMAGE_DIR}/vexpress-v2p-ca9.dtb \ -drive file=${IMAGE_DIR}/rootfs.ext2,if=sd,format=raw \ -append "console=ttyAMA0,115200 rootwait root=/dev/mmcblk0" \ -nographic \ -gdb tcp::12451 \ -S \
-gdb tcp::12451 //從qemu里引出gdb server到宿主機的 tcp::12451端口
-S //在第一條指令處暫停,等待gdb連接
-smp 1 //我在調試單核CPU,調試多核的linux(SMP)要改這個地方
vscode:自帶gdb插件,操作方法自己搜,關鍵是這個文件
buildroot-2020.11.1/output/build/linux-5.4.58/.vscode/launch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "/home/mmm/buildroot-2020.11.1/output/build/linux-5.4.58/vmlinux", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerServerAddress": "localhost:12451", "miDebuggerPath": "/home/mmm/buildroot-2020.11.1/output/host/bin/arm-buildroot-linux-uclibcgnueabihf-gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
另外:configs下的其他配置也可以用qemu跑,只是外設等可能沒有。
比如 imx6-sabresd_defconfig:
#!/bin/sh IMAGE_DIR="${0%/*}/" # if [ "${1}" = "serial-only" ]; then # EXTRA_ARGS='-nographic' # else # EXTRA_ARGS='-serial stdio' # fi export PATH="/home/mmm/buildroot-2020.11.1/output/host/bin:${PATH}" # dtc -I dtb -O dts imx6dl-sabresd.dtb -o dec.dts # qemu-img resize -f raw --shrink ${IMAGE_DIR}/rootfs.ext2 32M qemu-system-arm \ -M sabrelite \ -smp 1 \ -m 1G \ -nographic \ -kernel ${IMAGE_DIR}/zImage \ -dtb ${IMAGE_DIR}/imx6dl-sabresd.dtb \ -drive file=${IMAGE_DIR}/rootfs.ext2,format=raw,id=mysdcard \ -device sd-card,drive=mysdcard \ -append "console=ttymxc0 rootfstype=ext2 rootwait root=/dev/mmcblk3" \ -gdb tcp::12451 \ -S \
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "/home/mmm/buildroot-2020.11.1/output/build/linux-rel_imx_5.4.24_2.1.0/vmlinux", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerServerAddress": "localhost:12451", "miDebuggerPath": "/home/mmm/buildroot-2020.11.1/output/host/bin/arm-buildroot-linux-uclibcgnueabihf-gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
樹莓派也可以這么做,qemu對樹莓派的支持很好。
查看qemu對外設的支持可以在編譯完成后。看這個文件夾:buildroot-2020.11.1/output/build/host-qemu-5.1.0/hw/arm/vexpress.c