华为光猫HG8245H救砖笔记④为HG8245H配置OpenOCD调试环境

准备工具:

Windows下使用OpenOCD+FT2232H进行片上调试需要以下工具:

HG8245H的硬件配置:

  • CPU: Hisilicon SD5115 (基于ARM Cortex-A9)
  • RAM:Hynix H5TQ1G63EFR-H9C (128 MBytes; 64Mbits x 16; DDR3-1333 9-9-9)
  • Nand Flash:Spansion S34ML01G1-00TFI000 (128 MBytes; 48 nm SLC; 100,000 P/E)
  • WLAN:Broadcom BCM43217 (802.11 b/g/n; 2×2 MIMO)

OpneOCD配置文件概述:

使用OpenOCD来实现片上调试的最主要一步,就是编写OpenOCD的配置脚本文件。OpenOCD新版本的每次发布,或多或少都会更新一些自带的配置脚本文件。配置文件不光是描述如何与目标设备通信,还可以配置使用的JTAG适配器参数,目标设备上的Flash设备等。所以为了灵活的配置硬件,OpenOCD的scripts目录分了很多子目录:interface、cpu、fpga、board等,根据名字,大概可以知道该目录下的配置脚本文件的用途。

HG8245H的配置脚本文件:

这次的调试配置脚本,关于适配器部分我采用附带的FT2232系列配置文件,加以修改。而目标CPU部分,只能参考别的配置文件,自己写一个。具体编写过程就忽略不写了,这里直接放上来我写好的FT2232H的JTAG适配器配置文件和SD5115的配置文件:
ft2232h.cfg:

#
# FT2232H
#

telnet_port 14444
tcl_port 16666

interface ftdi
# ftdi_device_desc "FT2232H Board"
ftdi_vid_pid 0x0403 0x6010

adapter_khz 30000
ftdi_tdo_sample_edge falling

ftdi_layout_init 0x0508 0x0f1b
# ftdi_layout_signal nTRST -data 0x0200 -noe 0x0100
# ftdi_layout_signal nSRST -data 0x0800 -noe 0x0400

hi_sd5115_jtag.cfg:

#
# Hisilicon SD5115
#

transport select jtag

if { [info exists CHIPNAME] } {
    set  _CHIPNAME $CHIPNAME
} else {
    set  _CHIPNAME sd5115
}

if { [info exists CPUTAPID] } {
    set _CPU_TAPID $CPUTAPID
} else {
    set _CPU_TAPID 0x4ba00477
}

if { [info exists ENDIAN] } {
    set _ENDIAN $ENDIAN
} else {
    # this defaults to a bigendian
    set _ENDIAN little
}

if { [info exists ETB_TAPID] } {
    set _ETB_TAPID $ETB_TAPID
} else {
    set _ETB_TAPID 0x410CF231
}

jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPU_TAPID

# jtag newtap $_CHIPNAME etb -irlen 4 -expected-id $_ETB_TAPID

set _TARGETNAME $_CHIPNAME.cpu

target create $_TARGETNAME cortex_a -endian $_ENDIAN -chain-position $_TARGETNAME

# etm_dummy config $_TARGETNAME
# etb config $_TARGETNAME $_CHIPNAME.etb

proc sd5115_dbginit {target} {
    cortex_a dbginit
}

$_TARGETNAME configure -event reset-assert-post "sd5115_dbginit $_TARGETNAME"

# init
# dap apsel 1

OpenOCD快速启动脚本:

为了方便启动OpenOCD,写了2个bat脚本来实现一键调试:

ft2232h_x64.bat:

@echo off
bin-x64\openocd.exe -s ..\scripts -f ..\ft2232h.cfg -f ..\hi_sd5115_jtag.cfg
pause

open_telnet.bat(telnet的端口号根据实际配置文件,自行更改):

@echo off
telnet 127.0.0.1 14444

OpenOCD调试测试:

  • 首先为FT2232H替换驱动,因为FT2232H是双通道系列,所以PC上应该有2个设备(在通用串行总线控制器下,应该有USB Serial Converter A和B,2个设备,如果想用A通道做JTAG适配器,就替换USB Serial Converter A),只需要替换一个通道的驱动即可,另一个保留FTDI的驱动,用作UART通信。
  • 连接好HG8245H的JTAG并上拉DBGSEL,然后让CPU进入调试状态(让StartCode找不到UBoot,或者将Flash的RE#引脚与GND短接)。
  • 给HG8245H上电,然后执行ft2232h_x64.bat。

如果JTAG正常的话,OpenOCD的控制台里会输出以下类似的内容:

Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 30000 kHz
ftdi samples TDO on falling edge of TCK
Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
Info : clock speed 30000 kHz
Info : JTAG tap: sd5115.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : DAP transaction stalled (WAIT) – slowing down
Info : DAP transaction stalled (WAIT) – slowing down
Info : DAP transaction stalled (WAIT) – slowing down
Info : sd5115.cpu: hardware has 6 breakpoints, 4 watchpoints

需要注意的是:Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED。

该错误其实不是问题,因为FT2232H是双通道的,2个通道的VID,PID都是一样的。并且只替换了通道A的驱动,所以这个错误,可能是打开通道B时出现的,只要OpenOCD的控制台没有一闪而退,就是正常的。

没有问题的话,可以执行open_telnet.bat打开telnet,执行OpenOCD的命令。

如果不知道哪些命令可用,可以在telnet里执行help查看命令帮助,也可以翻看OpenOCD的用户手册

《华为光猫HG8245H救砖笔记④为HG8245H配置OpenOCD调试环境》有12条评论

  1. 你好,我最近也在调试openocd和ftdi,版本和你这个一样,但是运行时总是提示Error:JTAG-DP STICKY ERROR,不能下载程序等,想请教你一下,谢谢!

    回复
          • 我用zadig替换过了,但是没明白你说的这句话“只需要替换一个通道的驱动即可,另一个保留FTDI的驱动,用作UART通信。”,能不能加个QQ(631862180)详细说一下呢?去年我就调试过openocd,当时就有问题,但是通过几个命令进入halt状态后还是可以利用writeimage进行程序下载的。

            回复
  2. 你好,我也是windows上OpenOCD+FT2232H进行片上调试,但是运行时一直报错,特此请教nanapeng0101@126.com:
    D:\productTools\openocd\build\bin>openocd -f interface\ftdi\opendous_ftdi.cfg -f target\k60.cfg
    Open On-Chip Debugger 0.10.0
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
    Info : auto-selecting first available session transport “jtag”. To override use
    ‘transport select ‘.
    Info : add flash_bank kinetis k60.flash
    adapter speed: 1000 kHz
    none separate
    cortex_m reset_config sysresetreq
    Info : clock speed 1000 kHz
    Info : JTAG tap: k60.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), pa
    rt: 0xba00, ver: 0x4)
    Error: JTAG-DP STICKY ERROR
    Error: Failed to read memory at 0xe000ed00
    Error: JTAG-DP STICKY ERROR
    Polling target k60.cpu failed, trying to reexamine
    Error: The ‘check_security’ command must be used after ‘init’.
    in procedure ‘init’
    in procedure ‘ocd_bouncer’
    in procedure ‘flash’
    in procedure ‘ocd_bouncer’

    Error: JTAG-DP STICKY ERROR
    Error: Failed to read memory at 0xe000ed00
    Examination failed, GDB will be halted. Polling again in 100ms
    Error: JTAG-DP STICKY ERROR
    Polling target k60.cpu failed, trying to reexamine
    Error: The ‘check_security’ command must be used after ‘init’.
    in procedure ‘init’
    in procedure ‘ocd_bouncer’
    in procedure ‘nand’
    in procedure ‘ocd_bouncer’

    Error: JTAG-DP STICKY ERROR
    Error: Failed to read memory at 0xe000ed00
    Examination failed, GDB will be halted. Polling again in 300ms
    Polling target k60.cpu failed, trying to reexamine
    Warn : **** Your Kinetis MCU is probably locked-up in RESET/WDOG loop. ****
    Warn : **** Common reason is a blank flash (at least a reset vector). ****
    Warn : **** Issue ‘kinetis mdm halt’ command or if SRST is connected ****
    Warn : **** and configured, use ‘reset halt’ ****
    Warn : **** If MCU cannot be halted, it is likely secured and running ****
    Warn : **** in RESET/WDOG loop. Issue ‘kinetis mdm mass_erase’ ****
    Error: JTAG-DP STICKY ERROR
    Error: Failed to read memory at 0xe000ed00
    Examination failed, GDB will be halted. Polling again in 300ms

    回复

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据