debug_freeloader
规则分析、/conf/evalsoc/openocd.cfg
文件分析、课题组内的双系统规则分析464.# Please make sure freeloader, linux and uboot are generated
465.debug_freeloader:
466. $(target_gdb) $(freeloader_elf) -ex "set remotetimeout 240" \
467. -ex "target remote $(GDBREMOTE)" \
468. -ex "set confirm off" -ex "add-symbol-file $(vmlinux)" \
469. -ex "add-symbol-file $(opensbi_jumpelf)" \
470. -ex "add-symbol-file $(uboot_elf)" -ex "set confirm on"
CURDIR
是Makefile的内嵌变量,自动设置为当前目录
MAKEFILE_LIST
包含由make解析的每个makefile的名称,按解析顺序排列。
lastword
函数:参数名称被视为由空格分隔的一系列名称。该值为系列中的最后一个名称。
realpath
函数: 对于names中的每个文件名,返回规范绝对名称。
dir
函数:提取文件名的目录部分。
详情参考GNU make
下面代码的行号对应仓库的Makefile文件
$(CURDIR)/work/demosoc/buildroot_initramfs/host/bin/riscv-nuvlei-linux-gnu-gdb
182.target_gdb := $(CROSS_COMPILE)gdb
71.target := riscv-nuclei-linux-gnu
72.CROSS_COMPILE := $(RISCV)/bin/$(target)-
59.RISCV ?= $(buildroot_initramfs_wrkdir)/host
57.buildroot_initramfs_wrkdir := $(wrkdir)/buildroot_initramfs
46.wrkdir := $(wrkdir_root)/$(SOC)
42.wrkdir_root := $(CURDIR)/work
4.SOC ?= demosoc
$(CURDIR)/work/demosoc/freeloader/freeloader.elf
104.freeloader_wrkdir := $(wrkdir)/freeloader
106.freeloader_elf := $(freeloader_wrkdir)/freeloader.elf
| openocd -c \”gdb_port pipe; log_output openocd.log\” -f $(srcdir)/conf/demosoc/openocd.cfg
172.## Makefile Variable GDBREMOTE
173.# You can change GDBREMOTE to other gdb remotes
174.## eg. if you have started openocd server with (bindto 0.0.0.0 defined in openocd.cfg)
175.## make sure your machine can connect to remote machine
176.## in remote machine(ipaddr 192.168.43.199) which connect the hardware board,
177.## then you can change the GDBREMOTE to 192.168.43.199:3333
178.## GDBREMOTE ?= 192.168.43.199:3333
179.GDBREMOTE ?= | $(openocd) -c \"gdb_port pipe; log_output openocd.log\" -f $(platform_openocd_cfg)
69.platform_openocd_cfg := $(confdir)/openocd.cfg
45.confdir := $(srcdir)/conf/$(SOC)
40.srcdir := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
41.srcdir := $(srcdir:/=)
166.# openocd is prebuilt and installed to PATH
167.openocd := openocd
$(CURDIR)/work/demosoc/vmlinux/linux
84.vmlinux := $(linux_wrkdir)/vmlinux
80.linux_wrkdir := $(wrkdir)/linux
$(CURDIR)/work/demosoc/opensbi/platform/nuuclei/demosoc/firmware/fw_jump.elf
94.opensbi_wrkdir := $(wrkdir)/opensbi
99.opensbi_jumpelf := $(opensbi_wrkdir)/platform/nuclei/$(SOC)/firmware/fw_jump.elf
$(CURDIR)/work/demosoc/u-boot/u-boot
109.uboot_wrkdir := $(wrkdir)/u-boot
112.uboot_elf := $(uboot_wrkdir)/u-boot
执行单个gdb命令。可以多次使用此选项来调用多个命令。
设置等待远程目标响应240秒的超时限制。默认为2秒。
在后台运行openocd命令并使用管道与其通信
禁用确认请求
从文件filename中读取附加的符号表信息。
启用确认请求
make debug_freeloader:
启动$(target_gdb)
调试$(freeloader.elf)
并执行gdb命令:设置远程目标响应时间240s;远程目标为openocd进程,输出log文件openocd.log;关闭确认;添加符号表文件$(vmlinux)
,$(opensbi_jumpelf)
,$(uboot_elf)
;启动确认。
gdb命令参考文档:gdb.pdf
参考文档:openocd.pdf
1.
2.# 适配器频率设置
3.adapter_khz 1000
4.
5.# 适配器类型设置(官方改成了adapter driver ‘name’命令,即:adapter driver ftdi)
6.interface ftdi
7.# 适配器的供应商ID和产品ID(最新命令:ftdi vid_pid 0x0403 0x6010)
8.ftdi_vid_pid 0x0403 0x6010
9.# 关闭适配器OSCAN1模式(最新命令:ftdi oscan1_mode off)
10.ftdi_oscan1_mode off
11.
12.## Bind ftdi device using ftdi_serial
13.## the serial number could be checked using FT_Prog or dmesg
14.# ftdi_serial "FT5Q5L33"
15.
16.## bindto 0.0.0.0 can be used to cover all available interfaces.
17.## Uncomment bindto line to enable remote machine debug
18.# 指定监听的IP地址,0.0.0.0表示覆盖所有可用接口
19.bindto 0.0.0.0
20.
21.## If ftdi_device_desc not specified, the device description is ignored during device selection.
22.## So if you want to specify a dedicated FTDI device, you can select following device description:
23.## "Dual RS232-HS" is for HummingBird Debugger V1
24.## "USB <-> JTAG-DEBUGGER" is for HummingBird Debugger V2
25.## Uncomment one which match your device description
26.# ftdi_device_desc "Dual RS232-HS"
27.# ftdi_device_desc "USB <-> JTAG-DEBUGGER"
28.
29.# 选择在此OpenOCD会话中使用jtag的传输。
30.transport select jtag
31.
32.# 指定FTDI GPIO数据和方向寄存器的初始值分别为0x0008 0x001b
33.ftdi_layout_init 0x0008 0x001b
34.# 创建nSRST信号,-oe指示output-enable输入到输出缓存的连接位置:0x0020,
35.# -data表示不转换的数据掩码(管脚位掩码用于连接输出缓存的数据输入):0x0020
36.ftdi_layout_signal nSRST -oe 0x0020 -data 0x0020
37.# 创建TCK信号,数据掩码:0x0001
38.ftdi_layout_signal TCK -data 0x0001
39.# 创建TDI信号,数据掩码:0x0002
40.ftdi_layout_signal TDI -data 0x0002
41.# 创建TDO信号,-input表示用fidi get_signal方法读取管脚位掩码0x0004
42.ftdi_layout_signal TDO -input 0x0004
43.# 创建TMS信号,数据掩码:0x0008
44.ftdi_layout_signal TMS -data 0x0008
45.# 创建JTAG_SEL信号,数据掩码:0x0100, 连接位置:0x0100
46.ftdi_layout_signal JTAG_SEL -data 0x0100 -oe 0x0100
47.
48.# 设置芯片名称:riscv
49.set _CHIPNAME riscv
50.# 添加riscv芯片主cpu的TAP到JTAG scan chain,指令寄存器的位长度为5
51.jtag newtap $_CHIPNAME cpu -irlen 5
52.
53.# 设置debug target名称riscv.cpu
54.set _TARGETNAME $_CHIPNAME.cpu
55.# 创建gdb调试目标riscv.cpu,类型riscv,TAP名称:riscv.cpu
56.target create $_TARGETNAME riscv -chain-position $_TARGETNAME
57.# 配置riscv.cpu:工作区基址:0x80000000,指定工作区大小10000字节,工作区备份:是
58.$_TARGETNAME configure -work-area-phys 0x80000000 -work-area-size 10000 -work-area-backup 1
59.
60.# 设置flash名称:riscv.flash
61.set _FLASHNAME $_CHIPNAME.flash
62.# Please use Nuclei OpenOCD >= 2022.01 release version
63.# 配置flash bank,名称:riscv.flash,设备名称:nuspi(芯来科技的SPI控制器),flash芯片的基址:0x20000000,
64.# 芯片大小:0(自动检测),flash芯片宽:0(忽略),数据总线宽:0(忽略),target名:riscv.cpu
65.flash bank $_FLASHNAME nuspi 0x20000000 0 0 0 $_TARGETNAME
66.# Set the ILM space also as flash, to make sure it can be add breakpoint with hardware trigger
67.#flash bank onboard_ilm nuspi 0x80000000 0 0 0 $_TARGETNAME
68.
69.# Expose Nuclei self-defined CSRS
70.# See https://github.com/riscv/riscv-gnu-toolchain/issues/319#issuecomment-358397306
71.# Then user can view the csr register value in gdb using: info reg csr775 for CSR MTVT(0x307)
72.# 配置除了标准CSR之外还要公开哪些CSR。
73.riscv expose_csrs 416-496,770-800,835-850,1227-1231,1483-1486,1984-2032,2064-2070,2370-2380,2490-2500,4032-4040
74.
75.# 该命令终止配置阶段并进入运行阶段。
76.init
77.
78.# 如果当前上下文存在pulse_srst变量,设置信号nSRST为drive low,然后到高阻抗
79.if {[ info exists pulse_srst]} {
80. ftdi_set_signal nSRST 0
81. ftdi_set_signal nSRST z
82.}
83.# 向target发送中断请求,等待中断
84.halt
85.# We must turn on this because otherwise the IDE version debug cannot download the program into flash
86.# 关闭flash板0的保护块0到保护块last的flash块保护
87.flash protect 0 0 last off
debugocd:
openocd -f /cxws/np/ncx-linux-sdk/conf/demosoc/openocd.cfg
启动openocd,带有-f参数(指定配置文件)
debuggdbfl_null:
$(target_gdb) $(freeloader_elf) -ex "set remotetimeout 240" \
-ex "target remote localhost:3333" \
-ex "set confirm off" \
-ex "add-symbol-file $(srcdir)/work/demosoc/opensbi/platform/nuclei/demosoc/firmware/fw_jump.elf" \
-ex "add-symbol-file $(srcdircx)/cxrt/Debug/cxrt.elf" \
-ex "add-symbol-file $(srcdircx)/cxcp/cxcp.elf" \
-ex "set disassemble-next-line on" \
-ex "b system_demosoc.c:168" \
-ex "b _cx_b_rt" \
-ex "b sbi_hart_switch_mode" \
-ex "b _cx_rt_debug1" \
-ex "b _cx_rt_entry" \
-ex "set confirm on"
target remote localhost:3333
:设置远程连接到本机地址3333端口
set disassemble-next-line on
:表示自动反汇编后面要执行的代码
b function_name or line
:设置断点
debuggdbfl_null:
$(target_gdb) $(freeloader_elf) -ex "set remotetimeout 240" \
-ex "target remote localhost:3333" \
-ex "monitor reset halt" \
-ex "monitor halt" \
-ex "monitor flash protect 0 0 last off" \
-ex "load" \
-ex "set confirm off" \
-ex "add-symbol-file $(srcdir)/work/demosoc/opensbi/platform/nuclei/demosoc/firmware/fw_jump.elf" \
-ex "add-symbol-file $(srcdircx)/cxrt/Debug/cxrt.elf" \
-ex "add-symbol-file $(srcdircx)/cxcp/cxcp.elf" \
-ex "set disassemble-next-line on" \
-ex "b system_demosoc.c:168" \
-ex "b _cx_b_rt" \
-ex "b sbi_hart_switch_mode" \
-ex "b _cx_rt_debug1" \
-ex "b _cx_rt_entry" \
-ex "set confirm on"
monitor reset halt
:向远程发送复位和暂停命令
monitor halt
: 向远程发送暂停命令
monitor flash protect 0 0 last off
:向远程发送命令:关闭flash bank 0的flash块保护,从保护块0到最后一个保护块
load
:使(可执行文件)可用于远程系统上的调试