【jtag】Jtag debug guide for Duo

1. DIY CKLink

参考 & 固件来源(Reference):【平头哥Sipeed LicheeRV 86 Panel测评】自制CKLink-lite调试器,调试D1裸机编程 http://bbs.eeworld.com.cn/thread-1200313-1-1.html

如果你已经有了平头哥官方的 CKLink 工具,可以直接跳到 软件安装
If you already have a CKLink tool from T-Head, you can jump to Software Prepare.

首先我们需要准备一个 stm32f103 开发板,然后下载 CKLink 固件,并烧录到 stm32f103 中:
A stm32f103 board is needed. Download the CKLink firmware and flash it into the board:

wget https://github.com/Judehahh/duo-buildroot-sdk/releases/download/Duo-debug/cklink_lite_mod.hex

# 使用你喜欢的方式来烧录
# Burn the firmware with the way you like
openocd -f interface/cmsis-dap.cfg -f target/stm32f1x.cfg -c init -c halt -c "flash write_image erase cklink_lite_mod.hex"

然后连接 stm32f103 和 Duo:
Then connect stm32f103 and Duo:


2. 软件安装 / Software Prepare

Download the T-Head-DebugServer:

wget https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1698310757460/T-Head-DebugServer-linux-x86_64-V5.18.0-20230926.sh.tar.gz
tar xf T-Head-DebugServer-linux-x86_64-V5.18.0-20230926.sh.tar.gz
sudo ./T-Head-DebugServer-linux-x86_64-V5.18.0-20230926.sh -i

3. 替换 fip.bin / Replace fip.bin

替换前记得备份自己的 fip.bin 文件
Remember to backup your fip.bin before you replace it.

需要替换 sd 卡中的 fip.bin 文件,以开启 debug 的相关配置,修改后的 fip.bin 我发布在了 github 上: Duo-debug-release,具体的修改内容可参考以下链接:
Replace the fip.bin file in the sd card to enable debug function, the modified fip.bin has been posted on github: Duo-debug-release, the specific changes can be referred to the following link:

在替换了 fip.bin之后,使用杜邦线将 Duo 上的 GP15 端口与 3V3(OUT) 连接,在 bl2 中会通过判断该端口是否拉高来决定是否开始 Debug 模式。
After replacing the fip.bin, connect the GP15 port to 3V3(OUT), cause it is decided whether to start debug mode by judging whether the GP15 port is pulled up or not in bl2.

You can see this information after power on the Duo:

断开 GP15 与 3V3(OUT) 的连接之后就可以正常启动了。
To boot normally, just disconnect the GP15 port and 3V3(OUT).

4. Time To Debug

在做好准备工作之后就可以愉快地 Debug 了 :
Your can start to debug your Duo now::sunglasses:

% DebugServerConsole
+---                                                    ---+
|  T-Head Debugger Server (Build: Sep 26 2023, Linux)      |
   User   Layer Version : 5.18.00 
   Target Layer version : 2.0
|  Copyright (C) 2023 T-HEAD Semiconductor Co.,Ltd.        |
+---                                                    ---+
New firmware of CKLINK is detected, please enter 'y' to update or 'n' to ignore:

如果你使用 stm32,请按 n
Enter n if you use stm32.

The connection is successful if you see this:

And you can open a new terminal to debug now:

# Connect to the main core
riscv64-linux-gnu-gdb -ex "target remote :1025"

# Connect to the small core
riscv64-linux-gnu-gdb -ex "target remote :1026"

直接用 uart4 好像不太行,需要另外设置一下 uart4 吗

1 Like

我这里只是开启了 uart4 的引脚复用,还没有对 uart4 设备进行初始化的,需要自己初始化一下串口设备才行

have you managed to get JTAG working for the Duo256?

Have you tried applying the required source changes to cv181x duo256 platform ?
It currently only applies to cv180x duo

Yep, applied and updated with the correct Pin/function calls to setup the pinmux. (JTAG_CPU_TMS/TCLK and IICO_SDA/SCL pins)
The T-HeadDebugServer doesn’t detect anything though.

Reading through the TRM it talks about the debug firewall, so not sure if that’s something that needs to be disabled somehow.

Ok, yes, @Judehahh can you comment ?

@Fishwaldo @mark.birss

Sorry, I’ve been a little busy lately and didn’t start playing with my Duo256 until tonight.

It seems that Duo256’s pinmux is set to jtag by default, and you just need to stop before the last step of bl2:

Also note the difference between the pinout of Duo and Duo256, you should change the connection of JTAG_TMS and JTAG_TCK for Duo256:

1 Like



while(1) 之后在 gdb 里直接用 load 命令将二进制加载到内存里就可以了,这样可以直接调试 M mode 的程序。如果想调试 Uboot 引导的 S mode 程序,我猜可能需要在 Uboot 的最后停下来再加载后续程序。

把uboot删掉之后把S mode的程序打包进fip用Opensbi引导就OK了。