首页 新闻 会员 周边 捐助

Openocd 无法连接 gdb

0
悬赏园豆:30 [待解决问题]

问题概要:

仿真蜂鸟 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 (2024-08-06-20:01)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
User : 3 1 options.c:52 configuration_output_handler(): debug_level: 3User : 4 1 options.c:52 configuration_output_handler(): 
Debug: 5 1 options.c:346 parse_cmdline_args(): ARGV[0] = "openocd"
Debug: 6 1 options.c:346 parse_cmdline_args(): ARGV[1] = "-f"
Debug: 7 1 options.c:346 parse_cmdline_args(): ARGV[2] = "openocd-e203.cfg"
Debug: 8 1 options.c:346 parse_cmdline_args(): ARGV[3] = "-d"
Debug: 9 1 options.c:233 add_default_dirs(): bindir=/home/futreamer/software/openocd_install/bin
Debug: 10 1 options.c:234 add_default_dirs(): pkgdatadir=/home/futreamer/software/openocd_install/share/openocd
Debug: 11 1 options.c:235 add_default_dirs(): exepath=/home/futreamer/software/openocd_install/bin
Debug: 12 1 options.c:236 add_default_dirs(): bin2data=../share/openocd
Debug: 13 1 configuration.c:33 add_script_search_dir(): adding /home/futreamer/.config/openocd
Debug: 14 1 configuration.c:33 add_script_search_dir(): adding /home/futreamer/.openocd
Debug: 15 1 configuration.c:33 add_script_search_dir(): adding /home/futreamer/software/openocd_install/bin/../share/openocd/site
Debug: 16 1 configuration.c:33 add_script_search_dir(): adding /home/futreamer/software/openocd_install/bin/../share/openocd/scripts
Debug: 17 1 command.c:153 script_debug(): command - ocd_find openocd-e203.cfg
Debug: 18 1 configuration.c:88 find_file(): found openocd-e203.cfg
Debug: 19 1 command.c:153 script_debug(): command - echo DEPRECATED! use 'adapter driver' not 'interface'
User : 20 1 command.c:678 handle_echo(): DEPRECATED! use 'adapter driver' not 'interface'
Debug: 21 1 command.c:153 script_debug(): command - adapter driver remote_bitbang
Debug: 22 1 command.c:153 script_debug(): command - echo DEPRECATED! use 'remote_bitbang port' not 'remote_bitbang_port'
User : 23 1 command.c:678 handle_echo(): DEPRECATED! use 'remote_bitbang port' not 'remote_bitbang_port'
Debug: 24 1 command.c:153 script_debug(): command - remote_bitbang port 44853
Debug: 25 1 command.c:153 script_debug(): command - echo DEPRECATED! use 'remote_bitbang host' not 'remote_bitbang_host'
User : 26 1 command.c:678 handle_echo(): DEPRECATED! use 'remote_bitbang host' not 'remote_bitbang_host'
Debug: 27 1 command.c:153 script_debug(): command - remote_bitbang host localhost
Debug: 28 1 command.c:153 script_debug(): command - transport select
Info : 29 1 transport.c:267 handle_transport_select(): auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Debug: 30 1 command.c:153 script_debug(): command - transport select
Debug: 31 1 command.c:153 script_debug(): command - jtag newtap riscv tap -irlen 5 -expected-id 0x1e200a6d
Debug: 32 1 tcl.c:401 handle_jtag_newtap_args(): Creating New Tap, Chip: riscv, Tap: tap, Dotted: riscv.tap, 4 params
Debug: 33 1 core.c:1474 jtag_tap_init(): Created Tap: riscv.tap @ abs position 0, irlen 5, capture: 0x1 mask: 0x3
Debug: 34 1 command.c:153 script_debug(): command - target create riscv.tap.0 riscv -chain-position riscv.tap
Debug: 35 1 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Debug: 36 1 riscv.c:445 riscv_create_target(): [riscv.tap.0] riscv_create_target()
Debug: 37 1 command.c:153 script_debug(): command - riscv.tap.0 configure -work-area-phys 0x9000e000 -work-area-size 1000 -work-area-backup 0
Debug: 38 1 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Debug: 39 1 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Debug: 40 1 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Debug: 41 1 command.c:153 script_debug(): command - riscv expose_csrs 3040-3071
Debug: 42 1 command.c:153 script_debug(): command - gdb_report_data_abort enable
Debug: 43 1 command.c:153 script_debug(): command - gdb_report_register_access_error enable
Debug: 44 1 command.c:153 script_debug(): command - riscv set_command_timeout_sec 1200
Info : 45 1 server.c:298 add_service(): Listening on port 6666 for tcl connections
Info : 46 1 server.c:298 add_service(): Listening on port 4444 for telnet connections
Debug: 47 1 command.c:153 script_debug(): command - init
Debug: 48 1 command.c:153 script_debug(): command - target init
Debug: 49 1 command.c:153 script_debug(): command - target names
Debug: 50 1 command.c:153 script_debug(): command - riscv.tap.0 cget -event gdb-flash-erase-start
Debug: 51 1 command.c:153 script_debug(): command - riscv.tap.0 configure -event gdb-flash-erase-start reset init
Debug: 52 1 command.c:153 script_debug(): command - riscv.tap.0 cget -event gdb-flash-write-end
Debug: 53 1 command.c:153 script_debug(): command - riscv.tap.0 configure -event gdb-flash-write-end reset halt
Debug: 54 1 command.c:153 script_debug(): command - riscv.tap.0 cget -event gdb-attach
Debug: 55 1 command.c:153 script_debug(): command - riscv.tap.0 configure -event gdb-attach halt 1000
Debug: 56 1 target.c:1594 handle_target_init_command(): Initializing targets...
Debug: 57 1 riscv.c:458 riscv_init_target(): [riscv.tap.0] riscv_init_target()
Debug: 58 1 semihosting_common.c:107 semihosting_common_init():  
Info : 59 2 remote_bitbang.c:378 remote_bitbang_init(): Initializing remote_bitbang driver
Info : 60 2 remote_bitbang.c:300 remote_bitbang_init_tcp(): Connecting to localhost:44853
Info : 61 2 remote_bitbang.c:389 remote_bitbang_init(): remote_bitbang driver initialized
Info : 62 2 adapter.c:155 adapter_init(): Note: The adapter "remote_bitbang" doesn't support configurable speed
Debug: 63 2 openocd.c:133 handle_init_command(): Debug Adapter init complete
Debug: 64 2 command.c:153 script_debug(): command - transport init
Debug: 65 2 transport.c:219 handle_transport_init(): handle_transport_init
Debug: 66 2 core.c:830 jtag_add_reset(): SRST line released
Debug: 67 2 core.c:855 jtag_add_reset(): TRST line released
Debug: 68 2 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 69 2 command.c:153 script_debug(): command - jtag arp_init
Debug: 70 2 core.c:1509 jtag_init_inner(): Init JTAG chain
Debug: 71 2 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 72 2 core.c:1234 jtag_examine_chain(): DR scan interrogation for IDCODE/BYPASS
Debug: 73 2 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset

可以看出,启动 openocd 后,其未监听 gdb(3333) 端口,但是监听了 telnet (4444) 和 tcl (6666) 端口。
此外,Openocd 在 TAP(Test Access Port) 处卡住了,TAP reset了很多次,我分析是 jtag 的设备检测阶段没有通过,导致卡住?

当终止 SoC 的仿真时,Openocd 竟然开始监听了 gdb 端口,以下是新增的终端输出:

Error: 74 12320 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_fill_buf': errno==104, message: Connection reset by peer.
Error: 75 12320 core.c:1554 jtag_init_inner(): Trying to use configured scan chain anyway...
Debug: 76 12320 core.c:1364 jtag_validate_ircapture(): IR capture validation scan
Debug: 77 12320 server.c:608 sig_handler(): Terminating on Signal 13
Error: 78 12320 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Debug: 79 12320 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 80 12320 server.c:610 sig_handler(): Ignored extra Signal 13
Error: 81 12320 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Warn : 82 12320 core.c:1577 jtag_init_inner(): Bypassing JTAG setup events due to errors
Debug: 83 12320 command.c:153 script_debug(): command - dap init
Debug: 84 12320 log.c:408 gdb_timeout_warning(): keep_alive() was not invoked in the 1000 ms timelimit (12320 ms). This may cause trouble with GDB connections.
Debug: 85 12320 arm_dap.c:96 dap_init_all(): Initializing all DAPs ...
Debug: 86 12320 openocd.c:150 handle_init_command(): Examining targets...
Debug: 87 12320 target.c:675 target_examine_one(): [riscv.tap.0] Examination started
Debug: 88 12320 target.c:1780 target_call_event_callbacks(): target event 19 (examine-start) for core riscv.tap.0
Debug: 89 12320 riscv.c:2161 riscv_examine(): [riscv.tap.0] Starting examination
Debug: 90 12320 server.c:610 sig_handler(): Ignored extra Signal 13
Error: 91 12320 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Error: 92 12320 riscv.c:409 dtmcontrol_scan(): [riscv.tap.0] dtmcontrol scan failed, error code = -4
Error: 93 12320 riscv.c:2172 riscv_examine(): [riscv.tap.0] Could not read dtmcontrol. Check JTAG connectivity/board power.
Error: 94 12320 target.c:681 target_examine_one(): [riscv.tap.0] Examination failed
Debug: 95 12320 target.c:682 target_examine_one(): [riscv.tap.0] examine() returned error code -4
Debug: 96 12320 target.c:1780 target_call_event_callbacks(): target event 20 (examine-fail) for core riscv.tap.0
Warn : 97 12320 target.c:739 target_examine(): target riscv.tap.0 examination failed
Debug: 98 12320 openocd.c:152 handle_init_command(): target examination failed
Debug: 99 12320 command.c:153 script_debug(): command - flash init
Debug: 100 12320 tcl.c:1365 handle_flash_init_command(): Initializing flash devices...
Debug: 101 12320 command.c:153 script_debug(): command - nand init
Debug: 102 12320 tcl.c:484 handle_nand_init_command(): Initializing NAND devices...
Debug: 103 12320 command.c:153 script_debug(): command - pld init
Debug: 104 12320 pld.c:337 handle_pld_init_command(): Initializing PLDs...
Debug: 105 12320 command.c:153 script_debug(): command - tpiu init
Info : 106 12320 gdb_server.c:3936 gdb_target_start(): [riscv.tap.0] starting gdb server on 3333
Info : 107 12320 server.c:298 add_service(): Listening on port 3333 for gdb connections
Debug: 108 12320 command.c:153 script_debug(): command - target names
Debug: 109 12320 command.c:153 script_debug(): command - target names
Debug: 110 12320 command.c:153 script_debug(): command - riscv.tap.0 cget -type
Debug: 111 12320 command.c:153 script_debug(): command - shutdown
User : 112 12320 server.c:760 handle_shutdown_command(): shutdown command invoked
Debug: 113 12320 breakpoints.c:319 breakpoint_remove_all_internal(): [riscv.tap.0] Delete all breakpoints
Debug: 114 12320 riscv.c:511 riscv_deinit_target(): [riscv.tap.0] riscv_deinit_target()
Error: 115 12320 riscv.c:437 get_target_type(): [riscv.tap.0] Unsupported DTM version: -1
Error: 116 12320 riscv.c:516 riscv_deinit_target(): [riscv.tap.0] Could not identify target type.
Debug: 117 12320 target.c:2136 target_free_all_working_areas_restore(): freeing all working areas
Error: 118 12321 log.c:500 log_socket_error(): Error on socket 'remote_bitbang_putc': errno==32, message: Broken pipe.
Error: 119 12321 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 无法正常监听 gdb 端口呢?
您的任何提示我都感激不尽!

futreamer的主页 futreamer | 初学一级 | 园豆:172
提问于:2024-08-06 22:23
< >
分享
所有回答(1)
0

可以先用命令行调试,不使用配置文件,一句一句命令往上加,错误一般会有提示,最后合并到配置文件
之前调试stm32是这么调的,要监听gdb的3333的话是需要手动指定的

道剑相忘 | 园豆:211 (菜鸟二级) | 2024-08-16 15:52

十分感谢您的回复!
我理解的您的提示是在Openocd运行时在相应命令行直接输入命令,我尝试输入了几个(如下图的jtag_init, target init, noinit),发现Openocd没有反应,可否请您具体讲一下如何操作呢?


想请教您上面的现象是不是卡在配置阶段,官网上讲的Openocd是有配置阶段和运行阶段,配置阶段的指令完全依赖配置文件,只有运行阶段才能输入指令。

另外就是,我试过在配置文件以及启动Openocd时手动指定gdb为3333,但是现象和之前相同。

您的回复帮到了我,也对我很重要,谢谢您!

支持(0) 反对(0) futreamer | 园豆:172 (初学一级) | 2024-08-20 17:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册