直播Qt(使用VC2015工具链) + 操作 JLink(V8) 烧写 NUC972 固件。
背景: 公司的量产程序一直用JLink烧录, 尽管NUC972可以方便的用USB烧录,但是还是得用回蛋疼的JLink烧录方式。
第一步当然是准备 vs2015.pro_chs.iso, qt-opensource-windows-x86-msvc2015_64-5.6.0.exe
一步一步安装
离线
卧槽, 出师不利, LoadLibrary("JLinkArm.dll"); 总是返回空指针NULL,
不断变化各种路径,还是返回空指针,
最后加一个 GetLastError() 得到的错误Id是193,
放狗一搜,发现是amd64与x86兼容问题, 我估计是 JLinkArm.dll是32位的,
而我的编译系统是64位。
赶快下载 x86 版本的Qt SDK
等安装完之后继续分解...
离线
typedef const char * (CALLBACK* PJLINKARM_Open)();
typedef void (CALLBACK* PJLINKARM_Close)();
typedef long (CALLBACK* PJLINKARM_GetSN)();
typedef long (CALLBACK* PJLINKARM_GetDllVersion)();
typedef void (CALLBACK* PJLINKARM_GetFirmwareString)(LPSTR hw);
typedef long (CALLBACK* PJLINKARM_GetHardwareVersion)();
typedef long (CALLBACK* PJLINKARM_GetId)();
typedef void (CALLBACK* PJLINKARM_GetOEMString)(LPSTR os);
typedef void (CALLBACK* PJLINKARM_ReadMemU8)(long addr,long len,byte * data,BYTE * data1);
typedef void (CALLBACK* PJLINKARM_ReadMemU16)(long addr,long len,WORD * data,BYTE * data1);
typedef void (CALLBACK* PJLINKARM_ReadMemU32)(long addr,long len,long * data,BYTE * data1);
typedef void (CALLBACK* PJLINKARM_WriteU8)(long addr,byte data);
typedef void (CALLBACK* PJLINKARM_WriteU16)(long addr,WORD data);
typedef void (CALLBACK* PJLINKARM_WriteU32)(long addr,long data);
typedef void (CALLBACK* PJLINK_SetSpeed)(long speed);
typedef void (CALLBACK* PJLINKARM_Reset)();
typedef void (CALLBACK* PJLINKARM_Halt)();
卧槽,网上下载的这个逆向的 jlink 头文件没有 setpc, 这得好折腾了.
speed 1000K
loadbin f:\vmlinux.bin 8000
setpc 8000
g
我需要实现这四个命令。
除了setpc 这个找不到头文件,其他基本没问题了。
离线
/*********************************************************************
*
* ARM core registers
*/
typedef enum {
ARM_REG_R0,
ARM_REG_R1,
ARM_REG_R2,
ARM_REG_R3,
ARM_REG_R4,
ARM_REG_R5,
ARM_REG_R6,
ARM_REG_R7,
ARM_REG_CPSR,
ARM_REG_R15,
ARM_REG_R8_USR, ARM_REG_R9_USR, ARM_REG_R10_USR, ARM_REG_R11_USR,
ARM_REG_R12_USR, ARM_REG_R13_USR, ARM_REG_R14_USR,
ARM_REG_SPSR_FIQ, ARM_REG_R8_FIQ, ARM_REG_R9_FIQ, ARM_REG_R10_FIQ,
ARM_REG_R11_FIQ, ARM_REG_R12_FIQ, ARM_REG_R13_FIQ, ARM_REG_R14_FIQ,
ARM_REG_SPSR_SVC, ARM_REG_R13_SVC, ARM_REG_R14_SVC,
ARM_REG_SPSR_ABT, ARM_REG_R13_ABT, ARM_REG_R14_ABT,
ARM_REG_SPSR_IRQ, ARM_REG_R13_IRQ, ARM_REG_R14_IRQ,
ARM_REG_SPSR_UND, ARM_REG_R13_UND, ARM_REG_R14_UND,
ARM_REG_SPSR_SYS, ARM_REG_R13_SYS, ARM_REG_R14_SYS,
ARM_NUM_REGS
} ARM_REG;
发现一个pudn的寄存器头文件
R15寄存器是 9
离线
下班前终于搞定 setpc 和 go
JLINKARM_WriteReg(9, type);
JLINK_Go();
typedef void (CALLBACK* PJLINKARM_WriteReg)(long addr,long data);
typedef void (CALLBACK* PJLINK_Go)();
extern PJLINK_Go JLINK_Go;
extern PJLINKARM_WriteReg JLINKARM_WriteReg;
离线
只能接着到这堆 API 里面继续找啊找啊
导出, JLinkARM.dll
序列 地址 名字
00000001 1001B1C0 JLINKARM_AddMirrorArea
00000002 1001B7A0 JLINKARM_CP15_IsPresent
00000003 1001B5E0 JLINKARM_CP15_ReadEx
00000004 1001B580 JLINKARM_CP15_ReadReg
00000005 1001B6F0 JLINKARM_CP15_WriteEx
00000006 1001B690 JLINKARM_CP15_WriteReg
00000007 1001A510 JLINKARM_Clock
00000008 1001BA30 JLINKARM_Close
00000009 10018DD0 JLINKARM_ClrBP
0000000A 10018BE0 JLINKARM_ClrBPEx
0000000B 10018E30 JLINKARM_ClrError
0000000C 1001BB00 JLINKARM_ClrRESET
0000000D 1001A5E0 JLINKARM_ClrTDI
0000000E 1001A560 JLINKARM_ClrTMS
0000000F 1001BB80 JLINKARM_ClrTRST
00000010 10018D20 JLINKARM_ClrWP
00000011 1001B3D0 JLINKARM_ConfigJTAG
00000012 10010070 JLINKARM_DEVICE_GetInfo
00000013 10010070 JLINKARM_DEVICE_GetSelected
00000014 10010070 JLINKARM_DEVICE_Select
00000015 1001BFD0 JLINKARM_DownloadECode
00000016 1001B310 JLINKARM_EMU_GetDeviceInfo
00000017 1001B2D0 JLINKARM_EMU_GetNumDevices
00000018 1001B350 JLINKARM_EMU_SelectByIndex
00000019 1001B390 JLINKARM_EMU_SelectByUSBSN
0000001A 1001AC90 JLINKARM_ETB_IsPresent
0000001B 1001ACF0 JLINKARM_ETB_ReadReg
0000001C 1001AD50 JLINKARM_ETB_WriteReg
0000001D 1001ADC0 JLINKARM_ETM_IsPresent
0000001E 1001AE20 JLINKARM_ETM_ReadReg
0000001F 1001AEF0 JLINKARM_ETM_StartTrace
00000020 1001AE80 JLINKARM_ETM_WriteReg
00000021 1001B4A0 JLINKARM_EnableCheckModeAfterWrite
00000022 1001B0D0 JLINKARM_EnableFlashCache
00000023 1001BAC0 JLINKARM_EnableLog
00000024 1001C1E0 JLINKARM_EnableLogCom
00000025 1001BDF0 JLINKARM_EnablePerformanceCnt
00000026 1001B120 JLINKARM_EnableSoftBPs
00000027 10016640 JLINKARM_ExecCommand
00000028 1001C010 JLINKARM_ExecECode
00000029 10018B10 JLINKARM_FindBP
0000002A 1001BEA0 JLINKARM_GetBPInfo
0000002B 1001B030 JLINKARM_GetBPInfoEx
0000002C 10018E60 JLINKARM_GetCompileDateTime
0000002D 1001B420 JLINKARM_GetConfigData
0000002E 10018DA0 JLINKARM_GetDLLVersion
0000002F 1001BF90 JLINKARM_GetDeviceFamily
00000030 1001C360 JLINKARM_GetDeviceId
00000031 1001C350 JLINKARM_GetEmbeddedFWVersion
00000032 1001B920 JLINKARM_GetEmuCaps
00000033 1001C2C0 JLINKARM_GetFeatureString
00000034 10018E90 JLINKARM_GetFirmwareString
00000035 1001A7D0 JLINKARM_GetHWInfo
00000036 1001A730 JLINKARM_GetHWStatus
00000037 1001B820 JLINKARM_GetHardwareVersion
00000038 1001B460 JLINKARM_GetIRLen
00000039 10018F80 JLINKARM_GetId
0000003A 10018FD0 JLINKARM_GetIdData
0000003B 1001B4F0 JLINKARM_GetNumBPUnits
0000003C 1001AFC0 JLINKARM_GetNumBPs
0000003D 1001B000 JLINKARM_GetNumWPs
0000003E 1001C230 JLINKARM_GetOEMString
0000003F 1001BE20 JLINKARM_GetPerformanceCnt
00000040 1001BF60 JLINKARM_GetRegisterName
00000041 1001C200 JLINKARM_GetSN
00000042 1001A4C0 JLINKARM_GetScanLen
00000043 10019020 JLINKARM_GetSelDevice
00000044 10019070 JLINKARM_GetSpeed
00000045 10018F30 JLINKARM_GetSpeedInfo
00000046 1001C3A0 JLINKARM_GetU32
00000047 1001B080 JLINKARM_GetWPInfoEx
00000048 100190C0 JLINKARM_Go
00000049 10019130 JLINKARM_GoAllowSim
0000004A 1001BE40 JLINKARM_GoHalt
0000004B 100191A0 JLINKARM_GoIntDis
0000004C 10019210 JLINKARM_Halt
0000004D 1001C190 JLINKARM_HasError
0000004E 10019260 JLINKARM_IsConnected
0000004F 100192C0 JLINKARM_IsHalted
00000050 1001BDB0 JLINKARM_IsOpen
00000051 1001AB60 JLINKARM_JTAG_ConfigDevices
00000052 1001AB10 JLINKARM_JTAG_GetData
00000053 1001A820 JLINKARM_JTAG_GetDeviceId
00000054 1001ABF0 JLINKARM_JTAG_GetU16
00000055 1001AC40 JLINKARM_JTAG_GetU32
00000056 1001ABA0 JLINKARM_JTAG_GetU8
00000057 1001A8C0 JLINKARM_JTAG_StoreData
00000058 1001A960 JLINKARM_JTAG_StoreGetData
00000059 1001A9E0 JLINKARM_JTAG_StoreGetRaw
0000005A 1001A870 JLINKARM_JTAG_StoreInst
0000005B 1001AA30 JLINKARM_JTAG_StoreRaw
0000005C 1001AAD0 JLINKARM_JTAG_SyncBits
0000005D 1001AA90 JLINKARM_JTAG_SyncBytes
0000005E 1001A910 JLINKARM_JTAG_WriteData
0000005F 1001BEF0 JLINKARM_MeasureCPUSpeed
00000060 10018EE0 JLINKARM_MeasureRTCKReactTime
00000061 1001AF30 JLINKARM_MeasureSCLen
00000062 1001B970 JLINKARM_Open
00000063 1001B9D0 JLINKARM_OpenEx
00000064 10019860 JLINKARM_ReadCodeMem
00000065 100194B0 JLINKARM_ReadDCC
00000066 10019540 JLINKARM_ReadDCCFast
00000067 1001C0A0 JLINKARM_ReadEmu
00000068 1001B8C0 JLINKARM_ReadEmuConfigMem
00000069 100195C0 JLINKARM_ReadICEReg
0000006A 10019620 JLINKARM_ReadMem
0000006B 100198E0 JLINKARM_ReadMemHW
0000006C 100197E0 JLINKARM_ReadMemIndirect
0000006D 10019A70 JLINKARM_ReadMemU16
0000006E 10019970 JLINKARM_ReadMemU32
0000006F 10019B10 JLINKARM_ReadMemU8
00000070 10019BA0 JLINKARM_ReadReg
00000071 10019C80 JLINKARM_Reset
00000072 10019CF0 JLINKARM_ResetNoHalt
00000073 10019D90 JLINKARM_ResetPullsRESET
00000074 10019D40 JLINKARM_ResetPullsTRST
00000075 1001A660 JLINKARM_ResetTRST
00000076 10019DE0 JLINKARM_SelDevice
00000077 1001BCB0 JLINKARM_SelectDeviceFamily
00000078 1001B200 JLINKARM_SelectIP
00000079 1001B260 JLINKARM_SelectUSB
0000007A 10019E30 JLINKARM_SetBP
0000007B 10018B60 JLINKARM_SetBPEx
0000007C 10019EA0 JLINKARM_SetEndian
0000007D 1001BA60 JLINKARM_SetErrorOutHandler
0000007E 1001B170 JLINKARM_SetFlashArea
0000007F 1001A470 JLINKARM_SetInitRegsOnReset
00000080 1001C1C0 JLINKARM_SetLogFile
00000081 10019FC0 JLINKARM_SetMaxSpeed
00000082 1001BB40 JLINKARM_SetRESET
00000083 10019EF0 JLINKARM_SetResetDelay
00000084 1001A6F0 JLINKARM_SetResetPara
00000085 1001BC00 JLINKARM_SetResetType
00000086 10019F30 JLINKARM_SetSpeed
00000087 1001A620 JLINKARM_SetTDI
00000088 1001A5A0 JLINKARM_SetTMS
00000089 1001BBC0 JLINKARM_SetTRST
0000008A 10018C60 JLINKARM_SetWP
0000008B 1001BA90 JLINKARM_SetWarnOutHandler
0000008C 1001A080 JLINKARM_SimulateInstruction
0000008D 1001A000 JLINKARM_Step
0000008E 1001C3B0 JLINKARM_StepComposite
0000008F 1001A6A0 JLINKARM_StoreBits
00000090 1001C370 JLINKARM_StoreCmd
00000091 1001C380 JLINKARM_StoreData
00000092 1001BD70 JLINKARM_TIF_GetAvailable
00000093 1001BCF0 JLINKARM_TIF_Select
00000094 10018310 JLINKARM_TRACE_AddInst
00000095 100182D0 JLINKARM_TRACE_AddItems
00000096 100181A0 JLINKARM_TRACE_Control
00000097 10018130 JLINKARM_TRACE_Read
00000098 1001C3C0 JLINKARM_Test
00000099 1001A0F0 JLINKARM_UpdateFirmware
0000009A 1001A110 JLINKARM_UpdateFirmwareIfNewer
0000009B 1001C0F0 JLINKARM_WA_AddRange
0000009C 1001C150 JLINKARM_WA_Restore
0000009D 10019320 JLINKARM_WaitDCCRead
0000009E 100161C0 JLINKARM_WriteBits
0000009F 100193A0 JLINKARM_WriteDCC
000000A0 10019430 JLINKARM_WriteDCCFast
000000A1 1001C050 JLINKARM_WriteEmu
000000A2 1001B860 JLINKARM_WriteEmuConfigMem
000000A3 1001A150 JLINKARM_WriteICEReg
000000A4 1001A1D0 JLINKARM_WriteMem
000000A5 1001C3F0 JLINKARM_WriteMemDelayed
000000A6 1001A250 JLINKARM_WriteMemHW
000000A7 10019C10 JLINKARM_WriteReg
000000A8 1001A350 JLINKARM_WriteU16
000000A9 1001A2D0 JLINKARM_WriteU32
000000AA 1001A3E0 JLINKARM_WriteU8
000000AB 10016390 JLINK_CP15_ReadReg
000000AC 10015940 JLINK_Clock
000000AD 10015950 JLINK_Close
000000AE 10015960 JLINK_ClrBP
000000AF 10015970 JLINK_ClrBPEx
000000B0 10015980 JLINK_ClrError
000000B1 10016440 JLINK_ClrRESET
000000B2 10015990 JLINK_ClrTDI
000000B3 100159A0 JLINK_ClrTMS
000000B4 10016460 JLINK_ClrTRST
000000B5 10016040 JLINK_ClrWP
000000B6 100159B0 JLINK_ConfigJTAG
000000B7 100161D0 JLINK_ETM_IsPresent
000000B8 100161E0 JLINK_ETM_ReadReg
000000B9 10016210 JLINK_ETM_StartTrace
000000BA 100161F0 JLINK_ETM_WriteReg
000000BB 10016220 JLINK_EnableCheckModeAfterWrite
000000BC 10016230 JLINK_EnableFlashCache
000000BD 100159D0 JLINK_EnableLog
000000BE 10015A20 JLINK_EnableLogCom
000000BF 10016050 JLINK_EnableSoftBPs
000000C0 10016060 JLINK_ExecCommand
000000C1 10016080 JLINK_FindBP
000000C2 10015A90 JLINK_GetCompileDateTime
000000C3 10015A70 JLINK_GetConfigData
000000C4 10015AA0 JLINK_GetDLLVersion
000000C5 10015AB0 JLINK_GetEmuCaps
000000C6 10016090 JLINK_GetFeatureString
000000C7 10015AC0 JLINK_GetFirmwareString
000000C8 10015AE0 JLINK_GetHWStatus
000000C9 10015AF0 JLINK_GetHardwareVersion
000000CA 10015B20 JLINK_GetIRLen
000000CB 10015B00 JLINK_GetId
000000CC 10015B10 JLINK_GetIdData
000000CD 10015B30 JLINK_GetNumBPUnits
000000CE 100160A0 JLINK_GetNumBPs
000000CF 100160B0 JLINK_GetNumWPs
000000D0 100160C0 JLINK_GetOEMString
000000D1 100160D0 JLINK_GetSN
000000D2 10015B40 JLINK_GetScanLen
000000D3 10015B50 JLINK_GetSelDevice
000000D4 10015B60 JLINK_GetSpeed
000000D5 100160E0 JLINK_GetU32
000000D6 10015B70 JLINK_Go
000000D7 10015B80 JLINK_GoAllowSim
000000D8 10015B90 JLINK_GoIntDis
000000D9 10015BA0 JLINK_Halt
000000DA 10016240 JLINK_HasError
000000DB 10015BB0 JLINK_IsConnected
000000DC 10015BC0 JLINK_IsHalted
000000DD 10016490 JLINK_IsOpen
000000DE 100163F0 JLINK_JTAG_GetDeviceId
000000DF 10016190 JLINK_JTAG_StoreData
000000E1 10016400 JLINK_JTAG_StoreGetRaw
000000E3 100161C0 JLINK_JTAG_SyncBits
000000E4 100161B0 JLINK_JTAG_SyncBytes
000000E5 10015BD0 JLINK_MeasureSCLen
000000E6 10015BE0 JLINK_Open
000000E7 10015BF0 JLINK_OpenEx
000000E8 10016420 JLINK_ReadCodeMem
000000E9 10015C30 JLINK_ReadDCC
000000EA 10015C50 JLINK_ReadDCCFast
000000EB 100163D0 JLINK_ReadEmuConfigMem
000000EC 10015C70 JLINK_ReadICEReg
000000ED 10015C80 JLINK_ReadMem
000000EE 100160F0 JLINK_ReadMemHW
000000EF 10015CC0 JLINK_ReadMemU16
000000F0 10015CE0 JLINK_ReadMemU32
000000F1 10015CA0 JLINK_ReadMemU8
000000F2 10015D00 JLINK_ReadReg
000000F3 10015D10 JLINK_Reset
000000F4 10015D20 JLINK_ResetNoHalt
000000F5 10015D30 JLINK_ResetPullsRESET
000000F6 10015D40 JLINK_ResetPullsTRST
000000F7 10015D50 JLINK_ResetTRST
000000F8 10015D60 JLINK_SelDevice
000000F9 10015D70 JLINK_SelectIP
000000FA 10015D90 JLINK_SelectUSB
000000FB 10015DA0 JLINK_SetBP
000000FC 10015DC0 JLINK_SetBPEx
000000FD 10015DE0 JLINK_SetEndian
000000FE 10015DF0 JLINK_SetErrorOutHandler
000000FF 10016250 JLINK_SetFlashArea
00000100 10015E40 JLINK_SetInitRegsOnReset
00000101 10016380 JLINK_SetLogFile
00000102 10015E50 JLINK_SetMaxSpeed
00000103 10016450 JLINK_SetRESET
00000104 10015E60 JLINK_SetResetDelay
00000105 10015E70 JLINK_SetResetPara
00000106 10016480 JLINK_SetResetType
00000107 10015E80 JLINK_SetSpeed
00000108 10015E90 JLINK_SetTDI
00000109 10015EA0 JLINK_SetTMS
0000010A 10016470 JLINK_SetTRST
0000010B 10016130 JLINK_SetWP
0000010C 10016160 JLINK_SimulateInstruction
0000010D 1001C3B0 JLINK_Step
0000010E 10015EB0 JLINK_StepComposite
0000010F 10015EC0 JLINK_StoreBits
00000110 10015EE0 JLINK_Test
00000111 10015EF0 JLINK_UpdateFirmware
00000112 10015F00 JLINK_UpdateFirmwareIfNewer
00000113 10015F10 JLINK_WaitDCCRead
00000114 10015F20 JLINK_WriteDCC
00000115 10015F40 JLINK_WriteDCCFast
00000116 100163B0 JLINK_WriteEmuConfigMem
00000117 10015F60 JLINK_WriteICEReg
00000118 10015F80 JLINK_WriteMem
00000119 10015FA0 JLINK_WriteMemDelayed
0000011A 10015FC0 JLINK_WriteReg
0000011B 10016000 JLINK_WriteU16
0000011C 10016020 JLINK_WriteU32
0000011D 10015FE0 JLINK_WriteU8
000000E0 10016110 _JLINK_JTAG_StoreGetData@12
000000E2 10016170 _JLINK_JTAG_StoreInst@8
离线
发现 JLINKARM_WriteMem 有点像那么回事。
放狗一搜, 搜到这个:
http://forum.segger.com/index.php?page=Thread&threadID=1068
JLINKARM_WriteMem(FLASH_START_ADDR, FileSize, pBuffer); // Download file (into flash).
离线
离线
void Widget::on_pbBurn_clicked()
{
#define BUFF_SIZE 2048
#define BASE_ADDR 0x8000 //NUC970基址
unsigned char a[BUFF_SIZE];
long baseaddr = BASE_ADDR;
QFile file("f:\\vmlinux.bin");
if (!file.open(QIODevice::ReadOnly))
return;
ui->pbDownload->setRange(0, file.size());
while(file.read((char*)&a[0], BUFF_SIZE) > 0)
{
QCoreApplication::processEvents();
JLINKARM_WriteMem(baseaddr, BUFF_SIZE, a);
baseaddr += BUFF_SIZE;
ui->pbDownload->setValue(file.pos());
}
file.close();
JLINKARM_WriteReg(9, BASE_ADDR);
JLINK_Go();
}
终于差不多搞定
离线
楼主V5,太牛了!
不过也可以写个批处理脚本,调用jlink.exe实现。
离线
确实需要这样的小工具,在裸机模式下不必每次都把程序下载到nandflash上调试,只需要能下载到ddr里运行即可。
不知道官方是否提供keil的例程,是否都已经做好相关配置了。
离线
https://whycan.cn/files/members/3/QQ20170920170709.png
基本搞定
暂不处理一台电脑连接多个 JLink的情况.
Qt源码本站下载: NUC972_JLink_BurnLinux.7z
这操作着实有点骚!
离线
学习qt操作也不错
离线
https://whycan.cn/files/members/3/QQ20170920170709.png
基本搞定
暂不处理一台电脑连接多个 JLink的情况.
Qt源码本站下载: NUC972_JLink_BurnLinux.7z
厉害,方便第三方下载了
离线
牛逼了,看看以后能不能用到
离线
很有用哦,批量生产
离线
也在做类似的软件,马一下
离线
离线
有人用c#写过例程吗
离线