本文记录了NVDLA的QBOX(QEMU+SystemC)的源代码debug方法。主要步骤如下:
- 重编译hw的cmod代码
- 重编译vp
- 开始debug
注意!使用Docker的时候,一定要在run或者exec的时候使用priviledged模式!
docker exec --privileged -it f163e40905c1 /bin/bash
重编译hw的cmod代码
首先在cmod文件夹下Makefile的C++代码编译控制行中添加argument “-g”
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP -g -fPIC -Wall -Werror -DSC_INCLUDE_DYNAMIC_PROCESSES -Wp,-w -std=c++11
然后重新编译hw的cmod代码
./tools/bin/tmake -build cmod_top
重编译vp
我的hw文件夹放在vp文件夹里面,所以设置如下
cmake -DCMAKE_INSTALL_PREFIX=build -DSYSTEMC_PREFIX=/usr/local/systemc-2.3.0/ -DNVDLA_HW_PREFIX=/vp/hw/ -DNVDLA_HW_PROJECT=nv_full -DCMAKE_BUILD_TYPE=Debug
make
make install
开始debug
更新configure文件,设置对应的image和文件系统.ext4所在位置(此处的Linux镜像编译方法可参考之前的文档)。更改之后的config文件名为aarch64_nvdla_my.lua。我的CPU的设置如下:
CPU = {
library = "libqbox-nvdla.so",
extra_arguments = "-machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 1024 -kernel /vp/sw/buildroot-2017.11-rc1/output/images/Image --append \"root=/dev/vda\" -drive file=/vp/sw/buildroot-2017.11-rc1/output/images/rootfs.ext4,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -fsdev local,id=r,path=.,security_model=none -device virtio-9p-device,fsdev=r,mount_tag=r -netdev user,id=user0,hostfwd=tcp::6666-:6666,hostfwd=tcp::6667-:22 -device virtio-net-device,netdev=user0"
}
运行编译完成的arrch64_toplevel
./build/bin/arrch64_toplevel -c conf/aarch64_nvdla_my.lua
打开另一个terminal,使用如下命令,其中为aarch64_toplevel对应的PID。
ps -ef | grep "aarch64_toplevel"
gdb attach <PID>
然后即可设置断点
并且在Virtual Simulator中运行程序
mount -t 9p -o trans=virtio r /mnt # mount pwd
cd /mnt
insmod drm.ko # install drm driver
insmod opendla_1.ko # install nvdla driver
./nvdla_runtime --loadable fast-math.nvdla --image 8_inv.pgm --rawdump
即可在GDB终端里看到断点信息
参考资料
Debugging virtual platform with gdb #11
How to use cmod code for simulation #157
does sw use SystemC model?or how to use my own SystemC model? #86
CMOD: assertion for certain SDP throughput settings. #223