增加所有文件

This commit is contained in:
2025-11-07 09:57:14 +08:00
parent b598c1d479
commit 97bc808489
9392 changed files with 3483224 additions and 21 deletions

View File

@@ -0,0 +1,94 @@
## 简介
介绍通过j-link使用secure debug功能
该功能支持JTAG模式不支持SWD模式
芯片匹配debug key成功后开启debug接口
##硬件连接
- e3_gateway参考板
- Jlink debugger
##注意事项
- 确认板子JTAG功能正常对于e3 gateway参考板需要去掉TDO/TDI上的两个电阻。
- 需要通过fuse工具烧UID,debug key和使能secure debug。
- 确认sf.JLinkScript中SetupSecureDebug的操作被打开默认是关闭的。
- IAR工程下 接口如果是SWD,修改为JTAG。
- IAR工程下 如果 options->Debugger->Extra Options下没有指定sf.JLinkScript
增加command--jlink_script_file=$PROJ_DIR$\..\..\..\..\..\..\devices\script\JLINK\e3\sf.JLinkScript
- SES工程下 接口如果是SWD,修改为JTAG。
- SES工程下 如果 options->Debug->J-Link->Script File下没有选择sf.JLinkScript
则手动指定路径ssdk\devices\script\JLINK\e3\sf.JLinkScript
##测试方法
当板子以以下方式烧UID,debug key和使能secure debug.
Debug Key:
+-----------------------+------------+------------------+
| name | fuse addr | fuse value |
+-----------------------+------------+------------------+
| UID[0, 31] | 0x1010 | 0x12345678 |
| UID[32, 63] | 0x1014 | 0xABCDEF88 |
| SEC_DBG_CFG[31, 0] | 0x1280 | 0x74657374(key0) |
| SEC_DBG_CFG[63, 32] | 0x1284 | 0x6b657930(key1) |
| MSIC_CFG3/SDBG_MODE | 0x12b0 | 0x00800000 |
+-----------------------+------------+------------------+
IAR下执行attach通过脚本同时会返回UID
SES下可以通过执行connect确认
提供错误的debug key则无法执行通过。
##expected log
--------------SetupSecureDebug-----------------
UID: 0x12345678
UID: 0xABCDEF88
ID: 0x4BA00477
##流程说明
- 该流程涉及JTAG状态机的转化instruction和data的传入。
- key0, key1对应传入的debug key。v保存读出来的id。
- Note: key0 --> SEC_DBG_CFG[31, 0], key1 --> SEC_DBG_CFG[63, 32]!!
void SetupSecureDebug(void) {
int v;
int key0;
int key1;
int cmd;
cmd = 0xf;
key0 = 0x74657374;
key1 = 0x6b657930;
JLINK_SYS_Report("--------------SetupSecureDebug-----------------");
JLINK_SelectTIF(JLINK_TIF_JTAG);
CPU = CORTEX_R5;
//prototype:int JLINK_JTAG_Write(U32 tms, U32 tdi, U32 NumBits);
JLINK_JTAG_Write(0x1f, 0, 5); // goto Test-Logic Reset state
JLINK_JTAG_Write(0x6, 0, 5); //goto shift-ir state
JLINK_JTAG_Write(0x8, 0xf, 4); // shift in UID instruction, goto exit1-ir
JLINK_JTAG_Write(0x3, cmd, 4); //goto shift-dr state
JLINK_JTAG_Write(0x00000000, 0x0, 32); //shift in 64bit dummy code. shift out our uid
v = JLINK_JTAG_GetU32(0);
JLINK_SYS_Report1("UID: ", v);
JLINK_JTAG_Write(0x80000000, 0x0, 32); //shift in 64bit dummy code. shift out our uid, goto exit1-dr
v = JLINK_JTAG_GetU32(0);
JLINK_SYS_Report1("UID: ", v);
JLINK_JTAG_Write(0x1f, 0, 5); // goto Test-Logic Reset state
JLINK_JTAG_Write(0x2, 0x0, 4); // goto shift-dr state
JLINK_JTAG_Write(0x00000000, key0, 32); //shift in the corresponding key
JLINK_JTAG_Write(0x80000000, key1, 32); //shift in the corresponding key
JLINK_JTAG_Write(0x1f, 0, 5); // goto Test-Logic Reset state
JLINK_JTAG_Write(0x2, 0x0, 4); // goto shift-dr state
JLINK_JTAG_Write(0x80000000, 0x0, 32); // shift our IDCODE
v = JLINK_JTAG_GetU32(0);
JLINK_SYS_Report1("ID: ", v);
JLINK_JTAG_Write(0x1, 0, 2); // goto idle state
}