问题概要:
仿真蜂鸟 e203 SoC 并使用 gdb + Openocd 调试,但是 Openocd 不监听 gdb 端口,导致无法连接 gdb。
问题描述:
e203 使用 jtagdpi 作为 jtag 适配器,在 tb.v 中连接 jtagdpi 和 e203_soc_top 两个模块;Openocd 作为 gdb server。
在终端1运行 vcs 仿真 e203 ,同时在终端 2 运行 Openocd,以下是 Openocd 的配置文件(参考了开源代码):
# "JTAG adapter" for simulation, exposed to OpenOCD through a TCP socket
# speaking the remote_bitbang protocol. The adapter is implemented as
# SystemVerilog DPI module.
interface remote_bitbang
remote_bitbang_port 44853
remote_bitbang_host localhost
# Target configuration for the hummingbird E203 chip
if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME riscv
}
if { [info exists CPUTAPID ] } {
set _CPUTAPID $CPUTAPID
} else {
set _CPUTAPID 0x1e200a6d
}
jtag newtap $_CHIPNAME tap -irlen 5 -expected-id $_CPUTAPID
set _TARGETNAME $_CHIPNAME.tap
target create $_TARGETNAME.0 riscv -chain-position $_TARGETNAME
# Configure work area in on-chip SRAM
$_TARGETNAME.0 configure -work-area-phys 0x9000e000 -work-area-size 1000 -work-area-backup 0
riscv expose_csrs 3040-3071
# Be verbose about GDB errors
gdb_report_data_abort enable
gdb_report_register_access_error enable
# Increase timeouts in simulation
riscv set_command_timeout_sec 1200
配置文件设置 remote_bitbang_port 为 44853的原因是jtagdpi的监听端口是44853。
以下是终端 2 的输出信息(个别用*标注的是我的调试信息,可忽略):
openocd -f openocd-e203.cfg -d
Open On-Chip Debugger 0.12.0+dev-03884-g5afed58fc-dirty (2024-08-01-22:02)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
User : 3 2 options.c:52 configuration_output_handler(): debug_level: 3User : 4 2 options.c:52 configuration_output_handler():
Debug: 5 2 options.c:346 parse_cmdline_args(): ARGV[0] = "openocd"
Debug: 6 2 options.c:346 parse_cmdline_args(): ARGV[1] = "-f"
Debug: 7 2 options.c:346 parse_cmdline_args(): ARGV[2] = "openocd-e203.cfg"
Debug: 8 2 options.c:346 parse_cmdline_args(): ARGV[3] = "-d"
Debug: 9 3 options.c:233 add_default_dirs(): bindir=/home/futreamer/software/openocd_install/bin
Debug: 10 3 options.c:234 add_default_dirs(): pkgdatadir=/home/futreamer/software/openocd_install/share/openocd
Debug: 11 3 options.c:235 add_default_dirs(): exepath=/home/futreamer/software/openocd_install/bin
Debug: 12 3 options.c:236 add_default_dirs(): bin2data=../share/openocd
Debug: 13 3 configuration.c:33 add_script_search_dir(): adding /home/futreamer/.config/openocd
Debug: 14 3 configuration.c:33 add_script_search_dir(): adding /home/futreamer/.openocd
Debug: 15 3 configuration.c:33 add_script_search_dir(): adding /home/futreamer/software/openocd_install/bin/../share/openocd/site
Debug: 16 3 configuration.c:33 add_script_search_dir(): adding /home/futreamer/software/openocd_install/bin/../share/openocd/scripts
Debug: 17 3 command.c:153 script_debug(): command - ocd_find openocd-e203.cfg
Debug: 18 3 configuration.c:88 find_file(): found openocd-e203.cfg
Debug: 19 3 command.c:153 script_debug(): command - echo DEPRECATED! use 'adapter driver' not 'interface'
User : 20 3 command.c:678 handle_echo(): DEPRECATED! use 'adapter driver' not 'interface'
Debug: 21 3 command.c:153 script_debug(): command - adapter driver remote_bitbang
Debug: 22 3 command.c:153 script_debug(): command - echo DEPRECATED! use 'remote_bitbang port' not 'remote_bitbang_port'
User : 23 3 command.c:678 handle_echo(): DEPRECATED! use 'remote_bitbang port' not 'remote_bitbang_port'
Debug: 24 3 command.c:153 script_debug(): command - remote_bitbang port 44853
Debug: 25 3 command.c:153 script_debug(): command - echo DEPRECATED! use 'remote_bitbang host' not 'remote_bitbang_host'
User : 26 3 command.c:678 handle_echo(): DEPRECATED! use 'remote_bitbang host' not 'remote_bitbang_host'
Debug: 27 3 command.c:153 script_debug(): command - remote_bitbang host localhost
Debug: 28 3 command.c:153 script_debug(): command - transport select
Info : 29 3 transport.c:267 handle_transport_select(): auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Debug: 30 3 command.c:153 script_debug(): command - transport select
Debug: 31 3 command.c:153 script_debug(): command - jtag newtap riscv tap -irlen 5 -expected-id 0x1e200a6d
Debug: 32 3 tcl.c:401 handle_jtag_newtap_args(): Creating New Tap, Chip: riscv, Tap: tap, Dotted: riscv.tap, 4 params
Debug: 33 3 core.c:1481 jtag_tap_init(): Created Tap: riscv.tap @ abs position 0, irlen 5, capture: 0x1 mask: 0x3
Debug: 34 3 command.c:153 script_debug(): command - target create riscv.tap.0 riscv -chain-position riscv.tap
Debug: 35 3 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Debug: 36 3 riscv.c:445 riscv_create_target(): [riscv.tap.0] riscv_create_target()
Debug: 37 3 command.c:153 script_debug(): command - riscv.tap.0 configure -work-area-phys 0x9000e000 -work-area-size 1000 -work-area-backup 0
Debug: 38 3 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Debug: 39 3 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Debug: 40 3 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Debug: 41 3 command.c:153 script_debug(): command - riscv expose_csrs 3040-3071
Debug: 42 3 command.c:153 script_debug(): command - gdb_report_data_abort enable
Debug: 43 3 command.c:153 script_debug(): command - gdb_report_register_access_error enable
Debug: 44 3 command.c:153 script_debug(): command - riscv set_command_timeout_sec 1200
Info : 45 3 server.c:298 add_service(): Listening on port 6666 for tcl connections
Info : 46 3 server.c:298 add_service(): Listening on port 4444 for telnet connections
Debug: 47 3 command.c:153 script_debug(): command - init
***********************************COMMAND_HANDLER(handle_init_command)****************************************
Debug: 48 3 command.c:153 script_debug(): command - target init
Debug: 49 3 command.c:153 script_debug(): command - target names
Debug: 50 3 command.c:153 script_debug(): command - riscv.tap.0 cget -event gdb-flash-erase-start
Debug: 51 3 command.c:153 script_debug(): command - riscv.tap.0 configure -event gdb-flash-erase-start reset init
Debug: 52 3 command.c:153 script_debug(): command - riscv.tap.0 cget -event gdb-flash-write-end
Debug: 53 3 command.c:153 script_debug(): command - riscv.tap.0 configure -event gdb-flash-write-end reset halt
Debug: 54 3 command.c:153 script_debug(): command - riscv.tap.0 cget -event gdb-attach
Debug: 55 3 command.c:153 script_debug(): command - riscv.tap.0 configure -event gdb-attach halt 1000
Debug: 56 3 target.c:1594 handle_target_init_command(): Initializing targets...
Debug: 57 3 riscv.c:458 riscv_init_target(): [riscv.tap.0] riscv_init_target()
Debug: 58 3 semihosting_common.c:107 semihosting_common_init():
Info : 59 3 remote_bitbang.c:378 remote_bitbang_init(): Initializing remote_bitbang driver
Info : 60 3 remote_bitbang.c:300 remote_bitbang_init_tcp(): Connecting to localhost:44853
Info : 61 4 remote_bitbang.c:389 remote_bitbang_init(): remote_bitbang driver initialized
Info : 62 4 adapter.c:155 adapter_init(): Note: The adapter "remote_bitbang" doesn't support configurable speed
Debug: 63 4 openocd.c:133 handle_init_command(): Debug Adapter init complete
Debug: 64 4 command.c:153 script_debug(): command - transport init
Debug: 65 4 transport.c:219 handle_transport_init(): handle_transport_init
Debug: 66 4 core.c:834 jtag_add_reset(): SRST line released
Debug: 67 4 core.c:859 jtag_add_reset(): TRST line released
***********************************jtag_add_reset JTAG_TRST_ASSERTED****************************************
Debug: 68 4 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 69 4 command.c:153 script_debug(): command - jtag arp_init
Debug: 70 4 core.c:1516 jtag_init_inner(): Init JTAG chain
***********************************jtag_add_tlr JTAG_TRST_ASSERTED****************************************
Debug: 71 4 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 72 4 core.c:1240 jtag_examine_chain(): DR scan interrogation for IDCODE/BYPASS
***********************************jtag_examine_chain_execute is executed****************************************
***********************************jtag_add_tlr JTAG_TRST_ASSERTED****************************************
Debug: 73 4 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
启动 openocd 后,发现其未监听 gdb(3333) 端口,但是监听了 telnet (4444) 和 tcl (6666) 端口。
从信息可以看出,在 TAP(Test Access Port) 卡住了,TAP reset了很多次,我分析是 jtag 的设备检测阶段没有通过,导致卡住?
当终止 SoC 的仿真时,Openocd 竟然开始监听了 gdb 端口,以下是新增的终端输出:
Error: 74 12846 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_fill_buf': errno==104, message: Connection reset by peer.
Error: 75 12846 core.c:1561 jtag_init_inner(): Trying to use configured scan chain anyway...
Debug: 76 12846 core.c:1370 jtag_validate_ircapture(): IR capture validation scan
Debug: 77 12846 server.c:608 sig_handler(): Terminating on Signal 13
Error: 78 12846 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
***********************************jtag_validate_ircapture is executed****************************************
***********************************jtag_add_tlr JTAG_TRST_ASSERTED****************************************
Debug: 79 12846 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 80 12846 server.c:610 sig_handler(): Ignored extra Signal 13
Error: 81 12846 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Warn : 82 12846 core.c:1584 jtag_init_inner(): Bypassing JTAG setup events due to errors
Debug: 83 12846 command.c:153 script_debug(): command - dap init
Debug: 84 12846 log.c:408 gdb_timeout_warning(): keep_alive() was not invoked in the 1000 ms timelimit (12846 ms). This may cause trouble with GDB connections.
Debug: 85 12846 arm_dap.c:96 dap_init_all(): Initializing all DAPs ...
Debug: 86 12846 openocd.c:150 handle_init_command(): Examining targets...
Debug: 87 12846 target.c:675 target_examine_one(): [riscv.tap.0] Examination started
Debug: 88 12846 target.c:1780 target_call_event_callbacks(): target event 19 (examine-start) for core riscv.tap.0
Debug: 89 12846 riscv.c:2161 riscv_examine(): [riscv.tap.0] Starting examination
Debug: 90 12846 server.c:610 sig_handler(): Ignored extra Signal 13
Error: 91 12846 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Error: 92 12846 riscv.c:409 dtmcontrol_scan(): [riscv.tap.0] dtmcontrol scan failed, error code = -4
Error: 93 12846 riscv.c:2172 riscv_examine(): [riscv.tap.0] Could not read dtmcontrol. Check JTAG connectivity/board power.
Error: 94 12846 target.c:681 target_examine_one(): [riscv.tap.0] Examination failed
Debug: 95 12846 target.c:682 target_examine_one(): [riscv.tap.0] examine() returned error code -4
Debug: 96 12846 target.c:1780 target_call_event_callbacks(): target event 20 (examine-fail) for core riscv.tap.0
Warn : 97 12846 target.c:739 target_examine(): target riscv.tap.0 examination failed
Debug: 98 12846 openocd.c:152 handle_init_command(): target examination failed
Debug: 99 12846 command.c:153 script_debug(): command - flash init
Debug: 100 12846 tcl.c:1365 handle_flash_init_command(): Initializing flash devices...
Debug: 101 12846 command.c:153 script_debug(): command - nand init
Debug: 102 12846 tcl.c:484 handle_nand_init_command(): Initializing NAND devices...
Debug: 103 12846 command.c:153 script_debug(): command - pld init
Debug: 104 12846 pld.c:337 handle_pld_init_command(): Initializing PLDs...
Debug: 105 12846 command.c:153 script_debug(): command - tpiu init
***********************************gdb target add all****************************************
***********************************gdb target add all****************************************
***********************************gdb target start next****************************************
Info : 106 12846 gdb_server.c:3936 gdb_target_start(): [riscv.tap.0] starting gdb server on 3333
***********************************add service gdb****************************************
Info : 107 12846 server.c:298 add_service(): Listening on port 3333 for gdb connections
Debug: 108 12846 command.c:153 script_debug(): command - target names
Debug: 109 12846 command.c:153 script_debug(): command - target names
Debug: 110 12846 command.c:153 script_debug(): command - riscv.tap.0 cget -type
Debug: 111 12846 command.c:153 script_debug(): command - shutdown
User : 112 12846 server.c:760 handle_shutdown_command(): shutdown command invoked
Debug: 113 12846 breakpoints.c:319 breakpoint_remove_all_internal(): [riscv.tap.0] Delete all breakpoints
Debug: 114 12846 riscv.c:511 riscv_deinit_target(): [riscv.tap.0] riscv_deinit_target()
Error: 115 12846 riscv.c:437 get_target_type(): [riscv.tap.0] Unsupported DTM version: -1
Error: 116 12846 riscv.c:516 riscv_deinit_target(): [riscv.tap.0] Could not identify target type.
Debug: 117 12846 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Error: 118 12846 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Error: 119 12846 adapter.c:191 adapter_quit(): failed: -4
make: *** [Makefile:70: run_open] Broken pipe
可以看到出现了“Listening on port 3333 for gdb connections”,但仿真已终止,Openocd 也被强行终断运行了。
此外,提取 e203 内的 TAP 状态机波形,发现 TMS 和 TRST 都为低电平后,状态机卡在了 SHIFT_DR 状态。
究竟是什么原因导致 Openocd 无法正常监听 gbd 端口呢?
您的任何提示我都感激不尽!