ScriptBeagleBoard_OMAP3530.JLinkScript 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*********************************************************************
  2. * SEGGER Microcontroller GmbH *
  3. * Solutions for real time microcontroller applications *
  4. **********************************************************************
  5. * *
  6. * (c) 1995 - 2018 SEGGER Microcontroller GmbH *
  7. * *
  8. * www.segger.com Support: support@segger.com *
  9. * *
  10. **********************************************************************
  11. ----------------------------------------------------------------------
  12. Purpose : J-Link script file for BeagleBoard which has a
  13. TI OMAP3530 (Cortex-A8 core) on it.
  14. By default, only the TI ICEPick is in the JTAG chain
  15. which means that we have to add the Cortex-A8 by configuring the ICEPick.
  16. Moreover, the OMAP3530 also requires to set the DEBGEN signal in order to allow debugging.
  17. ---------------------------END-OF-HEADER------------------------------
  18. */
  19. /*********************************************************************
  20. *
  21. * _StoreSelDP
  22. */
  23. void _StoreSelDP(void) {
  24. JTAG_StoreIR(0xA); // DPACC command
  25. JTAG_StoreClocks(1);
  26. }
  27. /*********************************************************************
  28. *
  29. * _StoreSelAP
  30. */
  31. void _StoreSelAP(void) {
  32. JTAG_StoreIR(0xB); // APACC command
  33. JTAG_StoreClocks(1);
  34. }
  35. /*********************************************************************
  36. *
  37. * _StoreTriggerReadAPDPReg
  38. *
  39. * Function description
  40. * Triggers a read of an AP or DP register. Depends on the previous command (DPACC / APACC)
  41. */
  42. int _StoreTriggerReadAPDPReg(unsigned int RegIndex) {
  43. U32 v;
  44. int BitPos;
  45. //
  46. // Write 35 bits (32 bits data, 2 bits addr, 1 bit RnW)
  47. //
  48. v = 1; // 1 indicates read access
  49. v |= (RegIndex << 1);
  50. JLINK_JTAG_StartDR();
  51. BitPos = JLINK_JTAG_WriteDRCont(v, 3);
  52. v = 0;
  53. JLINK_JTAG_WriteDREnd(v, 32);
  54. JTAG_StoreClocks(8);
  55. return BitPos;
  56. }
  57. /*********************************************************************
  58. *
  59. * _StoreWriteAPDPReg
  60. *
  61. * Function description
  62. * Writes an AP or DP register. Depends on the previous command (DPACC / APACC)
  63. */
  64. int _StoreWriteAPDPReg(unsigned int RegIndex, U32 Data) {
  65. U32 v;
  66. int BitPos;
  67. //
  68. // Write 35 bits (32 bits data, 2 bits addr, 1 bit RnW)
  69. //
  70. v = 0; // 0 indicates write access
  71. v |= (RegIndex << 1);
  72. JLINK_JTAG_StartDR();
  73. BitPos = JLINK_JTAG_WriteDRCont(v, 3);
  74. v = Data;
  75. JLINK_JTAG_WriteDREnd(v, 32);
  76. JTAG_StoreClocks(8);
  77. return BitPos;
  78. }
  79. /*********************************************************************
  80. *
  81. * _InitIcePick
  82. *
  83. * Function description
  84. * Configures the ICEPick so that the CPU core also becomes
  85. * visible in the JTAG chain.
  86. */
  87. int _InitIcePick(void) {
  88. int BitPos;
  89. int v;
  90. int DPIdCode;
  91. int ICEPickIdCode;
  92. int i;
  93. int Speed;
  94. Report("J-Link script: Init ICEPick");
  95. JTAG_Reset(); // Perform TAP reset and J-Link JTAG auto-detection
  96. if (JTAG_TotalIRLen != 6) {
  97. MessageBox("Can not find Beagle eval board (IRLen mismatch)");
  98. }
  99. JTAG_DRPre = 0;
  100. JTAG_DRPost = 0;
  101. JTAG_IRPre = 0;
  102. JTAG_IRPost = 0;
  103. JTAG_IRLen = 6;
  104. Speed = JTAG_Speed;
  105. JTAG_Speed = 50;
  106. //
  107. // Check IDCODE of ICEPick (do not confuse with ICEPICKCODE or IDCODE of JTAG-DP)
  108. //
  109. JTAG_WriteIR(4); // IDCODE instruction for ICEPick device
  110. BitPos = JTAG_WriteDR(0x00000000, 32);
  111. v = JTAG_GetU32(BitPos);
  112. //
  113. // Seems the part number of the ICEPick has been changed
  114. // between BeagleBoard and BeagleBoard-xM, so we have
  115. // to check both part numbers.
  116. //
  117. if (((v & 0x0FFFFFFF) != 0x0B7AE02F) && // ICEPICK-IDCODE of ICEPICK on BeagleBoard
  118. ((v & 0x0FFFFFFF) != 0x0B89102F) // ICEPICK-IDCODE of ICEPICK on BeagleBoard XM
  119. ) {
  120. MessageBox1("Can not find ICE-Pick (IDCODE mismatch). Expected 0x0B7AE02F / 0x0B89102F, found: ", v);
  121. return 1;
  122. }
  123. ICEPickIdCode = v;
  124. //
  125. // Read ICEPICKCODE
  126. //
  127. JTAG_WriteIR(5);
  128. BitPos = JTAG_WriteDR(0x00000000, 32);
  129. v = JTAG_GetU32(BitPos);
  130. if ((v & 0x0000FFF0) != 0x00001CC0) {
  131. MessageBox("Connected module is not an ICEPick Module (ICEPICKCODE mismatch)");
  132. return 1;
  133. }
  134. //
  135. // Put ARM core in JTAG chain
  136. //
  137. JTAG_WriteIR(7); // CONNECT
  138. JTAG_WriteDR(0x89, 8); // The ICEPick documentation (SPRUE64, 2.6 CONNECT instruction: Accessing the debug connect register). Bit 7 set means: Write debug connect register. We write 0x9 to the debug connect register which is the debug connect key.
  139. JTAG_WriteIR(2); // ROUTER (Accessing the mapped registers)
  140. v = 0
  141. | (1 << 31) // Write mapped register
  142. | (0x23 << 24) // SDTAP3 register
  143. | (1 << 13) // Debug connect
  144. | (1 << 8) // TAP select
  145. | (1 << 3) // Force active
  146. ;
  147. JTAG_WriteDR(v, 32);
  148. JTAG_WriteIR(0x3F); // Bypass
  149. JTAG_WriteClocks(10);
  150. //
  151. // Configure JTAG chain, so J-Link knows to which devices it has to "talk" to.
  152. // CPU core is in scan chain now, so we have to re-configure the JTAG chain settings
  153. //
  154. JTAG_DRPre = 0;
  155. JTAG_DRPost = 1;
  156. JTAG_IRPre = 0;
  157. JTAG_IRPost = 6;
  158. JTAG_IRLen = 4;
  159. CPU=CORTEX_A8;
  160. JTAG_AllowTAPReset=0;
  161. //
  162. // Check JTAG-DP ID
  163. // On the Cortex-A OMAP devices it seems that the manufacturer field of the JTAG-DP ID
  164. // is not set to ARM JEDEC ID but to TI JEDEC ID which is not really CoreSight compliant.
  165. // So we check if one of these manufacturer codes match.
  166. //
  167. JTAG_StoreIR(0xE); // Read JTAG-DP IDCODE register
  168. v = 0;
  169. BitPos = JTAG_StoreDR(v, 32); // Get ID
  170. v = JTAG_GetU32(BitPos);
  171. if (((v & 0x00000FFF) != 0x0000002F) && // TI JEDEC ID
  172. ((v & 0x00000FFF) != 0x00000477) // ARM JEDEC ID
  173. ) {
  174. MessageBox("Can not find JTAG-DP (IDCODE mismatch)");
  175. }
  176. //
  177. // Set JTAG Ids for all devices in the JTAG chain
  178. //
  179. JTAG_SetDeviceId(0, v); // JTAG-DP
  180. JTAG_SetDeviceId(1, ICEPickIdCode); // ICEPick
  181. //
  182. // Set DBGEN signal in order to enable invasive debugging
  183. //
  184. _StoreSelDP();
  185. _StoreWriteAPDPReg(1, 0xF0000000); // Write JTAG-DP CTRL/STAT in order to power-up debug port
  186. v = 0
  187. | (1 << 24) // Select AP 1 which is the APB-AP
  188. | (0 << 4) // Select Bank 0
  189. ;
  190. _StoreWriteAPDPReg(2, v); // Write JTAG-DP SELECT register, in order to select the APB-AP. On the OMAP3550 AP[1] is the APB-AP
  191. _StoreSelAP();
  192. _StoreWriteAPDPReg(0, 0x80000012); // Write APB-AP CSW
  193. _StoreWriteAPDPReg(1, 0xD401D030); // Write APB-AP TAR
  194. v = (1 << 13); // Set DBGEN signal
  195. _StoreWriteAPDPReg(3, v); // Write APB-AP DRW
  196. _StoreSelDP();
  197. JTAG_WriteClocks(1); // Make sure all JTAG buffers are cleared
  198. JTAG_Speed = Speed;
  199. }
  200. /*********************************************************************
  201. *
  202. * _SetBP
  203. */
  204. void _SetBP(int DbgRegBaseAddr) {
  205. __int64 Ctrl;
  206. //
  207. // Select & setup APB-AP
  208. //
  209. _StoreSelDP();
  210. _StoreWriteAPDPReg(2, (1 << 24) | (0 << 4)); // Select AP[1], bank 0
  211. _StoreSelAP();
  212. Ctrl = 0
  213. | (2 << 0) // AP-access size. Fixed to 2: 32-bit
  214. | (1 << 4) // Auto increment TAR after read/write access. Increment is NOT performed on access to banked data registers 0-3.
  215. | (1 << 31) // Enable software access to the Debug APB bus.
  216. ;
  217. _StoreWriteAPDPReg(0, Ctrl);
  218. //
  219. // Step 1. Disable the breakpoint being set.
  220. //
  221. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x50 << 2));
  222. _StoreWriteAPDPReg(3, 0x00000000);
  223. //
  224. // Step 2. Write address to the BVR, leaving the bottom 2 bits zero.
  225. //
  226. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x40 << 2));
  227. _StoreWriteAPDPReg(3, 0x00014000);
  228. //
  229. // Step 3. Write the mask and control register to enable the breakpoint.
  230. //
  231. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x50 << 2));
  232. _StoreWriteAPDPReg(3, 7 | (0xF << 5) | (0 << 20));
  233. JTAG_WriteClocks(1); // Make sure that JTAG buffers are empty and breakpoint is set
  234. }
  235. /*********************************************************************
  236. *
  237. * ResetTarget
  238. */
  239. void ResetTarget(void) {
  240. int DbgRegBaseAddr;
  241. int Speed;
  242. int BitPos;
  243. int Ctrl;
  244. __int64 v;
  245. Report("J-Link script: Reset");
  246. Speed = JTAG_Speed;
  247. JTAG_Speed = 100;
  248. DbgRegBaseAddr = 0x54011000;
  249. //
  250. // Set breakpoint to halt target as fast as possible after reset
  251. //
  252. _SetBP(DbgRegBaseAddr);
  253. //
  254. // Setup JTAG config to "talk" to the ICEPick, so we can use the JTAG API functions
  255. //
  256. JTAG_DRPre = 1;
  257. JTAG_DRPost = 0;
  258. JTAG_IRPre = 4;
  259. JTAG_IRPost = 0;
  260. JTAG_IRLen = 6;
  261. //
  262. // Perform reset via ICEPick system control register, by setting the SysReset bit
  263. //
  264. JTAG_StoreIR(2); // Cmd: ROUTER
  265. v = 0x01000000; // Read SYS_CNTL
  266. JTAG_StoreDR(v, 32); // Send read register command
  267. BitPos = JTAG_StoreDR(v, 32); // Shift out register content
  268. v = JTAG_GetU32(BitPos);
  269. v &= 0x00FFFFFF;
  270. v |= 0x81000001; // Write SYS_CNTL and set SysReset bit
  271. JTAG_StoreDR(v, 32);
  272. JTAG_WriteClocks(10); // The reset needs some time to get active
  273. //
  274. // Setup JTAG config to "talk" to the CPU core again
  275. //
  276. JTAG_DRPre = 0;
  277. JTAG_DRPost = 1;
  278. JTAG_IRPre = 0;
  279. JTAG_IRPost = 6;
  280. JTAG_IRLen = 4;
  281. //
  282. // Check if CPU is halted. If not, halt it.
  283. // Select & setup APB-AP
  284. //
  285. _StoreSelDP();
  286. _StoreWriteAPDPReg(2, (1 << 24) | (0 << 4)); // Select AP[1], bank 0
  287. _StoreSelAP();
  288. Ctrl = 0
  289. | (2 << 0) // AP-access size. Fixed to 2: 32-bit
  290. | (1 << 4) // Auto increment TAR after read/write access. Increment is NOT performed on access to banked data registers 0-3.
  291. | (1 << 31) // Enable software access to the Debug APB bus.
  292. ;
  293. _StoreWriteAPDPReg(0, Ctrl);
  294. //
  295. // Read DSCR to check if CPU is halted
  296. //
  297. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x22 << 2));
  298. _StoreTriggerReadAPDPReg(3);
  299. _StoreSelDP();
  300. BitPos = _StoreTriggerReadAPDPReg(3);
  301. v = JTAG_GetU32(BitPos + 3);
  302. _StoreSelAP();
  303. if ((v & 1) == 0) {
  304. //
  305. // If CPU did not halt after reset, halt it
  306. //
  307. Report("J-Link script: Core did not halt after reset. Halting core...");
  308. v |= (1 << 14);
  309. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x22 << 2)); // Enable debug halt mode by writing the DSCR
  310. _StoreWriteAPDPReg(3, v);
  311. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x24 << 2)); // Write DRCR to halt CPU
  312. _StoreWriteAPDPReg(3, 1);
  313. JTAG_WriteClocks(1);
  314. }
  315. //
  316. // Remove breakpoint
  317. //
  318. _StoreWriteAPDPReg(1, DbgRegBaseAddr + (0x50 << 2));
  319. _StoreWriteAPDPReg(3, 0);
  320. _StoreSelDP();
  321. JTAG_WriteClocks(1);
  322. JTAG_Speed = Speed;
  323. }
  324. /*********************************************************************
  325. *
  326. * InitEMU
  327. */
  328. void InitEMU(void) {
  329. EMU_ETB_IsPresent = 0;
  330. }
  331. /*********************************************************************
  332. *
  333. * InitTarget
  334. */
  335. void InitTarget(void) {
  336. int v;
  337. Report("Beagle Board OMAP3530 (Cortex-A8 core) J-Link script");
  338. JTAG_TRSTPin = 0;
  339. SYS_Sleep(50);
  340. JTAG_TRSTPin = 1;
  341. SYS_Sleep(50);
  342. JTAG_Write(0x1F, 0, 6);
  343. _InitIcePick();
  344. }