adi.c 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. #include <furi.h>
  2. #include <stdlib.h>
  3. #include "adi.h"
  4. #include "swd_probe_app.h"
  5. /* https://github.com/openocd-org/openocd/blob/master/src/target/arm_adi_v5.c */
  6. /*
  7. static const char* class_description[16] = {
  8. [0x0] = "Generic verification component",
  9. [0x1] = "(ROM Table)",
  10. [0x2] = "Reserved",
  11. [0x3] = "Reserved",
  12. [0x4] = "Reserved",
  13. [0x5] = "Reserved",
  14. [0x6] = "Reserved",
  15. [0x7] = "Reserved",
  16. [0x8] = "Reserved",
  17. [0x9] = "CoreSight component",
  18. [0xA] = "Reserved",
  19. [0xB] = "Peripheral Test Block",
  20. [0xC] = "Reserved",
  21. [0xD] = "OptimoDE DESS",
  22. [0xE] = "Generic IP component",
  23. [0xF] = "CoreLink, PrimeCell or System component",
  24. };
  25. */
  26. static const struct {
  27. uint32_t arch_id;
  28. const char* description;
  29. } class0x9_devarch[] = {
  30. /* keep same unsorted order as in ARM IHI0029E */
  31. {ARCH_ID(ARM_ID, 0x0A00), "RAS architecture"},
  32. {ARCH_ID(ARM_ID, 0x1A01), "Instrumentation Trace Macrocell (ITM) architecture"},
  33. {ARCH_ID(ARM_ID, 0x1A02), "DWT architecture"},
  34. {ARCH_ID(ARM_ID, 0x1A03), "Flash Patch and Breakpoint unit (FPB) architecture"},
  35. {ARCH_ID(ARM_ID, 0x2A04), "Processor debug architecture (ARMv8-M)"},
  36. {ARCH_ID(ARM_ID, 0x6A05), "Processor debug architecture (ARMv8-R)"},
  37. {ARCH_ID(ARM_ID, 0x0A10), "PC sample-based profiling"},
  38. {ARCH_ID(ARM_ID, 0x4A13), "Embedded Trace Macrocell (ETM) architecture"},
  39. {ARCH_ID(ARM_ID, 0x1A14), "Cross Trigger Interface (CTI) architecture"},
  40. {ARCH_ID(ARM_ID, 0x6A15), "Processor debug architecture (v8.0-A)"},
  41. {ARCH_ID(ARM_ID, 0x7A15), "Processor debug architecture (v8.1-A)"},
  42. {ARCH_ID(ARM_ID, 0x8A15), "Processor debug architecture (v8.2-A)"},
  43. {ARCH_ID(ARM_ID, 0x2A16), "Processor Performance Monitor (PMU) architecture"},
  44. {ARCH_ID(ARM_ID, 0x0A17), "Memory Access Port v2 architecture"},
  45. {ARCH_ID(ARM_ID, 0x0A27), "JTAG Access Port v2 architecture"},
  46. {ARCH_ID(ARM_ID, 0x0A31), "Basic trace router"},
  47. {ARCH_ID(ARM_ID, 0x0A37), "Power requestor"},
  48. {ARCH_ID(ARM_ID, 0x0A47), "Unknown Access Port v2 architecture"},
  49. {ARCH_ID(ARM_ID, 0x0A50), "HSSTP architecture"},
  50. {ARCH_ID(ARM_ID, 0x0A63), "System Trace Macrocell (STM) architecture"},
  51. {ARCH_ID(ARM_ID, 0x0A75), "CoreSight ELA architecture"},
  52. {ARCH_ID(ARM_ID, 0x0AF7), "CoreSight ROM architecture"},
  53. };
  54. /* Part number interpretations are from Cortex
  55. * core specs, the CoreSight components TRM
  56. * (ARM DDI 0314H), CoreSight System Design
  57. * Guide (ARM DGI 0012D) and ETM specs; also
  58. * from chip observation (e.g. TI SDTI).
  59. */
  60. static const struct dap_part_nums {
  61. uint16_t designer_id;
  62. uint16_t part_num;
  63. const char* type;
  64. const char* full;
  65. } dap_part_nums[] = {
  66. {
  67. ARM_ID,
  68. 0x000,
  69. "Cortex-M3 SCS",
  70. "(System Control Space)",
  71. },
  72. {
  73. ARM_ID,
  74. 0x001,
  75. "Cortex-M3 ITM",
  76. "(Instrumentation Trace Module)",
  77. },
  78. {
  79. ARM_ID,
  80. 0x002,
  81. "Cortex-M3 DWT",
  82. "(Data Watchpoint and Trace)",
  83. },
  84. {
  85. ARM_ID,
  86. 0x003,
  87. "Cortex-M3 FPB",
  88. "(Flash Patch and Breakpoint)",
  89. },
  90. {
  91. ARM_ID,
  92. 0x008,
  93. "Cortex-M0 SCS",
  94. "(System Control Space)",
  95. },
  96. {
  97. ARM_ID,
  98. 0x00a,
  99. "Cortex-M0 DWT",
  100. "(Data Watchpoint and Trace)",
  101. },
  102. {
  103. ARM_ID,
  104. 0x00b,
  105. "Cortex-M0 BPU",
  106. "(Breakpoint Unit)",
  107. },
  108. {
  109. ARM_ID,
  110. 0x00c,
  111. "Cortex-M4 SCS",
  112. "(System Control Space)",
  113. },
  114. {
  115. ARM_ID,
  116. 0x00d,
  117. "CoreSight ETM11",
  118. "(Embedded Trace)",
  119. },
  120. {
  121. ARM_ID,
  122. 0x00e,
  123. "Cortex-M7 FPB",
  124. "(Flash Patch and Breakpoint)",
  125. },
  126. {
  127. ARM_ID,
  128. 0x193,
  129. "SoC-600 TSGEN",
  130. "(Timestamp Generator)",
  131. },
  132. {
  133. ARM_ID,
  134. 0x470,
  135. "Cortex-M1 ROM",
  136. "(ROM Table)",
  137. },
  138. {
  139. ARM_ID,
  140. 0x471,
  141. "Cortex-M0 ROM",
  142. "(ROM Table)",
  143. },
  144. {
  145. ARM_ID,
  146. 0x490,
  147. "Cortex-A15 GIC",
  148. "(Generic Interrupt Controller)",
  149. },
  150. {
  151. ARM_ID,
  152. 0x492,
  153. "Cortex-R52 GICD",
  154. "(Distributor)",
  155. },
  156. {
  157. ARM_ID,
  158. 0x493,
  159. "Cortex-R52 GICR",
  160. "(Redistributor)",
  161. },
  162. {
  163. ARM_ID,
  164. 0x4a1,
  165. "Cortex-A53 ROM",
  166. "(v8 Memory Map ROM Table)",
  167. },
  168. {
  169. ARM_ID,
  170. 0x4a2,
  171. "Cortex-A57 ROM",
  172. "(ROM Table)",
  173. },
  174. {
  175. ARM_ID,
  176. 0x4a3,
  177. "Cortex-A53 ROM",
  178. "(v7 Memory Map ROM Table)",
  179. },
  180. {
  181. ARM_ID,
  182. 0x4a4,
  183. "Cortex-A72 ROM",
  184. "(ROM Table)",
  185. },
  186. {
  187. ARM_ID,
  188. 0x4a9,
  189. "Cortex-A9 ROM",
  190. "(ROM Table)",
  191. },
  192. {
  193. ARM_ID,
  194. 0x4aa,
  195. "Cortex-A35 ROM",
  196. "(v8 Memory Map ROM Table)",
  197. },
  198. {
  199. ARM_ID,
  200. 0x4af,
  201. "Cortex-A15 ROM",
  202. "(ROM Table)",
  203. },
  204. {
  205. ARM_ID,
  206. 0x4b5,
  207. "Cortex-R5 ROM",
  208. "(ROM Table)",
  209. },
  210. {
  211. ARM_ID,
  212. 0x4b8,
  213. "Cortex-R52 ROM",
  214. "(ROM Table)",
  215. },
  216. {
  217. ARM_ID,
  218. 0x4c0,
  219. "Cortex-M0+ ROM",
  220. "(ROM Table)",
  221. },
  222. {
  223. ARM_ID,
  224. 0x4c3,
  225. "Cortex-M3 ROM",
  226. "(ROM Table)",
  227. },
  228. {
  229. ARM_ID,
  230. 0x4c4,
  231. "Cortex-M4 ROM",
  232. "(ROM Table)",
  233. },
  234. {
  235. ARM_ID,
  236. 0x4c7,
  237. "Cortex-M7 PPB ROM",
  238. "(Private Peripheral Bus ROM Table)",
  239. },
  240. {
  241. ARM_ID,
  242. 0x4c8,
  243. "Cortex-M7 ROM",
  244. "(ROM Table)",
  245. },
  246. {
  247. ARM_ID,
  248. 0x4e0,
  249. "Cortex-A35 ROM",
  250. "(v7 Memory Map ROM Table)",
  251. },
  252. {
  253. ARM_ID,
  254. 0x4e4,
  255. "Cortex-A76 ROM",
  256. "(ROM Table)",
  257. },
  258. {
  259. ARM_ID,
  260. 0x906,
  261. "CoreSight CTI",
  262. "(Cross Trigger)",
  263. },
  264. {
  265. ARM_ID,
  266. 0x907,
  267. "CoreSight ETB",
  268. "(Trace Buffer)",
  269. },
  270. {
  271. ARM_ID,
  272. 0x908,
  273. "CoreSight CSTF",
  274. "(Trace Funnel)",
  275. },
  276. {
  277. ARM_ID,
  278. 0x909,
  279. "CoreSight ATBR",
  280. "(Advanced Trace Bus Replicator)",
  281. },
  282. {
  283. ARM_ID,
  284. 0x910,
  285. "CoreSight ETM9",
  286. "(Embedded Trace)",
  287. },
  288. {
  289. ARM_ID,
  290. 0x912,
  291. "CoreSight TPIU",
  292. "(Trace Port Interface Unit)",
  293. },
  294. {
  295. ARM_ID,
  296. 0x913,
  297. "CoreSight ITM",
  298. "(Instrumentation Trace Macrocell)",
  299. },
  300. {
  301. ARM_ID,
  302. 0x914,
  303. "CoreSight SWO",
  304. "(Single Wire Output)",
  305. },
  306. {
  307. ARM_ID,
  308. 0x917,
  309. "CoreSight HTM",
  310. "(AHB Trace Macrocell)",
  311. },
  312. {
  313. ARM_ID,
  314. 0x920,
  315. "CoreSight ETM11",
  316. "(Embedded Trace)",
  317. },
  318. {
  319. ARM_ID,
  320. 0x921,
  321. "Cortex-A8 ETM",
  322. "(Embedded Trace)",
  323. },
  324. {
  325. ARM_ID,
  326. 0x922,
  327. "Cortex-A8 CTI",
  328. "(Cross Trigger)",
  329. },
  330. {
  331. ARM_ID,
  332. 0x923,
  333. "Cortex-M3 TPIU",
  334. "(Trace Port Interface Unit)",
  335. },
  336. {
  337. ARM_ID,
  338. 0x924,
  339. "Cortex-M3 ETM",
  340. "(Embedded Trace)",
  341. },
  342. {
  343. ARM_ID,
  344. 0x925,
  345. "Cortex-M4 ETM",
  346. "(Embedded Trace)",
  347. },
  348. {
  349. ARM_ID,
  350. 0x930,
  351. "Cortex-R4 ETM",
  352. "(Embedded Trace)",
  353. },
  354. {
  355. ARM_ID,
  356. 0x931,
  357. "Cortex-R5 ETM",
  358. "(Embedded Trace)",
  359. },
  360. {
  361. ARM_ID,
  362. 0x932,
  363. "CoreSight MTB-M0+",
  364. "(Micro Trace Buffer)",
  365. },
  366. {
  367. ARM_ID,
  368. 0x941,
  369. "CoreSight TPIU-Lite",
  370. "(Trace Port Interface Unit)",
  371. },
  372. {
  373. ARM_ID,
  374. 0x950,
  375. "Cortex-A9 PTM",
  376. "(Program Trace Macrocell)",
  377. },
  378. {
  379. ARM_ID,
  380. 0x955,
  381. "Cortex-A5 ETM",
  382. "(Embedded Trace)",
  383. },
  384. {
  385. ARM_ID,
  386. 0x95a,
  387. "Cortex-A72 ETM",
  388. "(Embedded Trace)",
  389. },
  390. {
  391. ARM_ID,
  392. 0x95b,
  393. "Cortex-A17 PTM",
  394. "(Program Trace Macrocell)",
  395. },
  396. {
  397. ARM_ID,
  398. 0x95d,
  399. "Cortex-A53 ETM",
  400. "(Embedded Trace)",
  401. },
  402. {
  403. ARM_ID,
  404. 0x95e,
  405. "Cortex-A57 ETM",
  406. "(Embedded Trace)",
  407. },
  408. {
  409. ARM_ID,
  410. 0x95f,
  411. "Cortex-A15 PTM",
  412. "(Program Trace Macrocell)",
  413. },
  414. {
  415. ARM_ID,
  416. 0x961,
  417. "CoreSight TMC",
  418. "(Trace Memory Controller)",
  419. },
  420. {
  421. ARM_ID,
  422. 0x962,
  423. "CoreSight STM",
  424. "(System Trace Macrocell)",
  425. },
  426. {
  427. ARM_ID,
  428. 0x975,
  429. "Cortex-M7 ETM",
  430. "(Embedded Trace)",
  431. },
  432. {
  433. ARM_ID,
  434. 0x9a0,
  435. "CoreSight PMU",
  436. "(Performance Monitoring Unit)",
  437. },
  438. {
  439. ARM_ID,
  440. 0x9a1,
  441. "Cortex-M4 TPIU",
  442. "(Trace Port Interface Unit)",
  443. },
  444. {
  445. ARM_ID,
  446. 0x9a4,
  447. "CoreSight GPR",
  448. "(Granular Power Requester)",
  449. },
  450. {
  451. ARM_ID,
  452. 0x9a5,
  453. "Cortex-A5 PMU",
  454. "(Performance Monitor Unit)",
  455. },
  456. {
  457. ARM_ID,
  458. 0x9a7,
  459. "Cortex-A7 PMU",
  460. "(Performance Monitor Unit)",
  461. },
  462. {
  463. ARM_ID,
  464. 0x9a8,
  465. "Cortex-A53 CTI",
  466. "(Cross Trigger)",
  467. },
  468. {
  469. ARM_ID,
  470. 0x9a9,
  471. "Cortex-M7 TPIU",
  472. "(Trace Port Interface Unit)",
  473. },
  474. {
  475. ARM_ID,
  476. 0x9ae,
  477. "Cortex-A17 PMU",
  478. "(Performance Monitor Unit)",
  479. },
  480. {
  481. ARM_ID,
  482. 0x9af,
  483. "Cortex-A15 PMU",
  484. "(Performance Monitor Unit)",
  485. },
  486. {
  487. ARM_ID,
  488. 0x9b6,
  489. "Cortex-R52 PMU/CTI/ETM",
  490. "(Performance Monitor Unit/Cross Trigger/ETM)",
  491. },
  492. {
  493. ARM_ID,
  494. 0x9b7,
  495. "Cortex-R7 PMU",
  496. "(Performance Monitor Unit)",
  497. },
  498. {
  499. ARM_ID,
  500. 0x9d3,
  501. "Cortex-A53 PMU",
  502. "(Performance Monitor Unit)",
  503. },
  504. {
  505. ARM_ID,
  506. 0x9d7,
  507. "Cortex-A57 PMU",
  508. "(Performance Monitor Unit)",
  509. },
  510. {
  511. ARM_ID,
  512. 0x9d8,
  513. "Cortex-A72 PMU",
  514. "(Performance Monitor Unit)",
  515. },
  516. {
  517. ARM_ID,
  518. 0x9da,
  519. "Cortex-A35 PMU/CTI/ETM",
  520. "(Performance Monitor Unit/Cross Trigger/ETM)",
  521. },
  522. {
  523. ARM_ID,
  524. 0x9e2,
  525. "SoC-600 APB-AP",
  526. "(APB4 Memory Access Port)",
  527. },
  528. {
  529. ARM_ID,
  530. 0x9e3,
  531. "SoC-600 AHB-AP",
  532. "(AHB5 Memory Access Port)",
  533. },
  534. {
  535. ARM_ID,
  536. 0x9e4,
  537. "SoC-600 AXI-AP",
  538. "(AXI Memory Access Port)",
  539. },
  540. {
  541. ARM_ID,
  542. 0x9e5,
  543. "SoC-600 APv1 Adapter",
  544. "(Access Port v1 Adapter)",
  545. },
  546. {
  547. ARM_ID,
  548. 0x9e6,
  549. "SoC-600 JTAG-AP",
  550. "(JTAG Access Port)",
  551. },
  552. {
  553. ARM_ID,
  554. 0x9e7,
  555. "SoC-600 TPIU",
  556. "(Trace Port Interface Unit)",
  557. },
  558. {
  559. ARM_ID,
  560. 0x9e8,
  561. "SoC-600 TMC ETR/ETS",
  562. "(Embedded Trace Router/Streamer)",
  563. },
  564. {
  565. ARM_ID,
  566. 0x9e9,
  567. "SoC-600 TMC ETB",
  568. "(Embedded Trace Buffer)",
  569. },
  570. {
  571. ARM_ID,
  572. 0x9ea,
  573. "SoC-600 TMC ETF",
  574. "(Embedded Trace FIFO)",
  575. },
  576. {
  577. ARM_ID,
  578. 0x9eb,
  579. "SoC-600 ATB Funnel",
  580. "(Trace Funnel)",
  581. },
  582. {
  583. ARM_ID,
  584. 0x9ec,
  585. "SoC-600 ATB Replicator",
  586. "(Trace Replicator)",
  587. },
  588. {
  589. ARM_ID,
  590. 0x9ed,
  591. "SoC-600 CTI",
  592. "(Cross Trigger)",
  593. },
  594. {
  595. ARM_ID,
  596. 0x9ee,
  597. "SoC-600 CATU",
  598. "(Address Translation Unit)",
  599. },
  600. {
  601. ARM_ID,
  602. 0xc05,
  603. "Cortex-A5 Debug",
  604. "(Debug Unit)",
  605. },
  606. {
  607. ARM_ID,
  608. 0xc07,
  609. "Cortex-A7 Debug",
  610. "(Debug Unit)",
  611. },
  612. {
  613. ARM_ID,
  614. 0xc08,
  615. "Cortex-A8 Debug",
  616. "(Debug Unit)",
  617. },
  618. {
  619. ARM_ID,
  620. 0xc09,
  621. "Cortex-A9 Debug",
  622. "(Debug Unit)",
  623. },
  624. {
  625. ARM_ID,
  626. 0xc0e,
  627. "Cortex-A17 Debug",
  628. "(Debug Unit)",
  629. },
  630. {
  631. ARM_ID,
  632. 0xc0f,
  633. "Cortex-A15 Debug",
  634. "(Debug Unit)",
  635. },
  636. {
  637. ARM_ID,
  638. 0xc14,
  639. "Cortex-R4 Debug",
  640. "(Debug Unit)",
  641. },
  642. {
  643. ARM_ID,
  644. 0xc15,
  645. "Cortex-R5 Debug",
  646. "(Debug Unit)",
  647. },
  648. {
  649. ARM_ID,
  650. 0xc17,
  651. "Cortex-R7 Debug",
  652. "(Debug Unit)",
  653. },
  654. {
  655. ARM_ID,
  656. 0xd03,
  657. "Cortex-A53 Debug",
  658. "(Debug Unit)",
  659. },
  660. {
  661. ARM_ID,
  662. 0xd04,
  663. "Cortex-A35 Debug",
  664. "(Debug Unit)",
  665. },
  666. {
  667. ARM_ID,
  668. 0xd07,
  669. "Cortex-A57 Debug",
  670. "(Debug Unit)",
  671. },
  672. {
  673. ARM_ID,
  674. 0xd08,
  675. "Cortex-A72 Debug",
  676. "(Debug Unit)",
  677. },
  678. {
  679. ARM_ID,
  680. 0xd0b,
  681. "Cortex-A76 Debug",
  682. "(Debug Unit)",
  683. },
  684. {
  685. ARM_ID,
  686. 0xd0c,
  687. "Neoverse N1",
  688. "(Debug Unit)",
  689. },
  690. {
  691. ARM_ID,
  692. 0xd13,
  693. "Cortex-R52 Debug",
  694. "(Debug Unit)",
  695. },
  696. {
  697. ARM_ID,
  698. 0xd49,
  699. "Neoverse N2",
  700. "(Debug Unit)",
  701. },
  702. {
  703. 0x017,
  704. 0x120,
  705. "TI SDTI",
  706. "(System Debug Trace Interface)",
  707. }, /* from OMAP3 memmap */
  708. {
  709. 0x017,
  710. 0x343,
  711. "TI DAPCTL",
  712. "",
  713. }, /* from OMAP3 memmap */
  714. {0x017, 0x9af, "MSP432 ROM", "(ROM Table)"},
  715. {0x01f, 0xcd0, "Atmel CPU with DSU", "(CPU)"},
  716. {0x041, 0x1db, "XMC4500 ROM", "(ROM Table)"},
  717. {0x041, 0x1df, "XMC4700/4800 ROM", "(ROM Table)"},
  718. {0x041, 0x1ed, "XMC1000 ROM", "(ROM Table)"},
  719. {
  720. 0x065,
  721. 0x000,
  722. "SHARC+/Blackfin+",
  723. "",
  724. },
  725. {
  726. 0x070,
  727. 0x440,
  728. "Qualcomm QDSS Component v1",
  729. "(Qualcomm Designed CoreSight Component v1)",
  730. },
  731. {
  732. 0x0bf,
  733. 0x100,
  734. "Brahma-B53 Debug",
  735. "(Debug Unit)",
  736. },
  737. {
  738. 0x0bf,
  739. 0x9d3,
  740. "Brahma-B53 PMU",
  741. "(Performance Monitor Unit)",
  742. },
  743. {
  744. 0x0bf,
  745. 0x4a1,
  746. "Brahma-B53 ROM",
  747. "(ROM Table)",
  748. },
  749. {
  750. 0x0bf,
  751. 0x721,
  752. "Brahma-B53 ROM",
  753. "(ROM Table)",
  754. },
  755. {
  756. 0x1eb,
  757. 0x181,
  758. "Tegra 186 ROM",
  759. "(ROM Table)",
  760. },
  761. {
  762. 0x1eb,
  763. 0x202,
  764. "Denver ETM",
  765. "(Denver Embedded Trace)",
  766. },
  767. {
  768. 0x1eb,
  769. 0x211,
  770. "Tegra 210 ROM",
  771. "(ROM Table)",
  772. },
  773. {
  774. 0x1eb,
  775. 0x302,
  776. "Denver Debug",
  777. "(Debug Unit)",
  778. },
  779. {
  780. 0x1eb,
  781. 0x402,
  782. "Denver PMU",
  783. "(Performance Monitor Unit)",
  784. },
  785. {0x20, 0x410, "STM32F10 (med)", "(ROM Table)"},
  786. {0x20, 0x411, "STM32F2", "(ROM Table)"},
  787. {0x20, 0x412, "STM32F10 (low)", "(ROM Table)"},
  788. {0x20, 0x413, "STM32F40/41", "(ROM Table)"},
  789. {0x20, 0x414, "STM32F10 (high)", "(ROM Table)"},
  790. {0x20, 0x415, "STM32L47/48", "(ROM Table)"},
  791. {0x20, 0x416, "STM32L1xxx6/8/B", "(ROM Table)"},
  792. {0x20, 0x417, "STM32L05/06", "(ROM Table)"},
  793. {0x20, 0x418, "STM32F105xx/107", "(ROM Table)"},
  794. {0x20, 0x419, "STM32F42/43", "(ROM Table)"},
  795. {0x20, 0x420, "STM32F10 (med)", "(ROM Table)"},
  796. {0x20, 0x421, "STM32F446xx", "(ROM Table)"},
  797. {0x20, 0x422, "STM32FF358/02/03", "(ROM Table)"},
  798. {0x20, 0x423, "STM32F401xB/C", "(ROM Table)"},
  799. {0x20, 0x425, "STM32L031/41", "(ROM Table)"},
  800. {0x20, 0x427, "STM32L1xxxC", "(ROM Table)"},
  801. {0x20, 0x428, "STM32F10 (high)", "(ROM Table)"},
  802. {0x20, 0x429, "STM32L1xxx6A/8A/BA", "(ROM Table)"},
  803. {0x20, 0x430, "STM32F10 (xl)", "(ROM Table)"},
  804. {0x20, 0x431, "STM32F411xx", "(ROM Table)"},
  805. {0x20, 0x432, "STM32F373/8", "(ROM Table)"},
  806. {0x20, 0x433, "STM32F401xD/E", "(ROM Table)"},
  807. {0x20, 0x434, "STM32F469/79", "(ROM Table)"},
  808. {0x20, 0x435, "STM32L43/44", "(ROM Table)"},
  809. {0x20, 0x436, "STM32L1xxxD", "(ROM Table)"},
  810. {0x20, 0x437, "STM32L1xxxE", "(ROM Table)"},
  811. {0x20, 0x438, "STM32F303/34/28", "(ROM Table)"},
  812. {0x20, 0x439, "STM32F301/02/18 ", "(ROM Table)"},
  813. {0x20, 0x440, "STM32F03/5", "(ROM Table)"},
  814. {0x20, 0x441, "STM32F412xx", "(ROM Table)"},
  815. {0x20, 0x442, "STM32F03/9", "(ROM Table)"},
  816. {0x20, 0x444, "STM32F03xx4", "(ROM Table)"},
  817. {0x20, 0x445, "STM32F04/7", "(ROM Table)"},
  818. {0x20, 0x446, "STM32F302/03/98", "(ROM Table)"},
  819. {0x20, 0x447, "STM32L07/08", "(ROM Table)"},
  820. {0x20, 0x448, "STM32F070/1/2", "(ROM Table)"},
  821. {0x20, 0x449, "STM32F74/5", "(ROM Table)"},
  822. {0x20, 0x450, "STM32H74/5", "(ROM Table)"},
  823. {0x20, 0x451, "STM32F76/7", "(ROM Table)"},
  824. {0x20, 0x452, "STM32F72/3", "(ROM Table)"},
  825. {0x20, 0x457, "STM32L01/2", "(ROM Table)"},
  826. {0x20, 0x458, "STM32F410xx", "(ROM Table)"},
  827. {0x20, 0x460, "STM32G07/8", "(ROM Table)"},
  828. {0x20, 0x461, "STM32L496/A6", "(ROM Table)"},
  829. {0x20, 0x462, "STM32L45/46", "(ROM Table)"},
  830. {0x20, 0x463, "STM32F413/23", "(ROM Table)"},
  831. {0x20, 0x464, "STM32L412/22", "(ROM Table)"},
  832. {0x20, 0x466, "STM32G03/04", "(ROM Table)"},
  833. {0x20, 0x468, "STM32G431/41", "(ROM Table)"},
  834. {0x20, 0x469, "STM32G47/48", "(ROM Table)"},
  835. {0x20, 0x470, "STM32L4R/S", "(ROM Table)"},
  836. {0x20, 0x471, "STM32L4P5/Q5", "(ROM Table)"},
  837. {0x20, 0x479, "STM32G491xx", "(ROM Table)"},
  838. {0x20, 0x480, "STM32H7A/B", "(ROM Table)"},
  839. {0x20, 0x495, "STM32WB50/55", "(ROM Table)"},
  840. {0x20, 0x497, "STM32WLE5xx", "(ROM Table)"}};
  841. const char* adi_devarch_desc(uint32_t devarch) {
  842. if(!(devarch & ARM_CS_C9_DEVARCH_PRESENT)) {
  843. return "not present";
  844. }
  845. for(unsigned int i = 0; i < ARRAY_SIZE(class0x9_devarch); i++) {
  846. if((devarch & DEVARCH_ID_MASK) == class0x9_devarch[i].arch_id) {
  847. return class0x9_devarch[i].description;
  848. }
  849. }
  850. return "unknown";
  851. }
  852. const struct dap_part_nums* adi_part_num(unsigned int des, unsigned int part) {
  853. static char buf[32];
  854. static struct dap_part_nums unknown = {
  855. .type = "Unrecognized",
  856. .full = "",
  857. };
  858. for(unsigned int i = 0; i < ARRAY_SIZE(dap_part_nums); i++) {
  859. if(dap_part_nums[i].designer_id == des && dap_part_nums[i].part_num == part) {
  860. return &dap_part_nums[i];
  861. }
  862. }
  863. snprintf(buf, sizeof(buf), "D:%x P:%x", des, part);
  864. unknown.full = buf;
  865. return &unknown;
  866. }
  867. bool adi_get_pidr(AppFSM* const ctx, uint32_t base, pidr_data_t* data) {
  868. uint32_t pidrs[7];
  869. uint32_t offsets[] = {0xFE0, 0xFE4, 0xFE8, 0xFEC, 0xFD0, 0xFD4, 0xFD8, 0xFDC};
  870. furi_mutex_acquire(ctx->swd_mutex, FuriWaitForever);
  871. for(size_t pos = 0; pos < COUNT(pidrs); pos++) {
  872. uint8_t ret = swd_read_memory(ctx, ctx->ap_pos, base + offsets[pos], &pidrs[pos]);
  873. if(ret != 1) {
  874. DBGS("Read failed");
  875. furi_mutex_release(ctx->swd_mutex);
  876. return false;
  877. }
  878. }
  879. furi_mutex_release(ctx->swd_mutex);
  880. data->designer = ((pidrs[4] & 0x0F) << 7) | ((pidrs[2] & 0x07) << 4) |
  881. ((pidrs[1] >> 4) & 0x0F);
  882. data->part = (pidrs[0] & 0xFF) | ((pidrs[1] & 0x0F) << 8);
  883. data->revand = ((pidrs[3] >> 4) & 0x0F);
  884. data->cmod = (pidrs[3] & 0x0F);
  885. data->revision = ((pidrs[2] >> 4) & 0x0F);
  886. data->size = ((pidrs[2] >> 4) & 0x0F);
  887. return true;
  888. }
  889. bool adi_get_class(AppFSM* const ctx, uint32_t base, uint8_t* class) {
  890. uint32_t cidrs[4];
  891. uint32_t offsets[] = {0xFF0, 0xFF4, 0xFF8, 0xFFC};
  892. furi_mutex_acquire(ctx->swd_mutex, FuriWaitForever);
  893. for(size_t pos = 0; pos < COUNT(cidrs); pos++) {
  894. uint8_t ret = swd_read_memory(ctx, ctx->ap_pos, base + offsets[pos], &cidrs[pos]);
  895. if(ret != 1) {
  896. DBGS("Read failed");
  897. furi_mutex_release(ctx->swd_mutex);
  898. return false;
  899. }
  900. }
  901. furi_mutex_release(ctx->swd_mutex);
  902. if((cidrs[0] & 0xFF) != 0x0D) {
  903. return false;
  904. }
  905. if((cidrs[1] & 0x0F) != 0x00) {
  906. return false;
  907. }
  908. if((cidrs[2] & 0xFF) != 0x05) {
  909. return false;
  910. }
  911. if((cidrs[3] & 0xFF) != 0xB1) {
  912. return false;
  913. }
  914. *class = ((cidrs[1] >> 4) & 0x0F);
  915. return true;
  916. }
  917. const char* adi_romtable_type(AppFSM* const ctx, uint32_t base) {
  918. pidr_data_t data;
  919. if(!adi_get_pidr(ctx, base, &data)) {
  920. return "fail";
  921. }
  922. const struct dap_part_nums* info = adi_part_num(data.designer, data.part);
  923. return info->type;
  924. }
  925. const char* adi_romtable_full(AppFSM* const ctx, uint32_t base) {
  926. pidr_data_t data;
  927. if(!adi_get_pidr(ctx, base, &data)) {
  928. return "fail";
  929. }
  930. const struct dap_part_nums* info = adi_part_num(data.designer, data.part);
  931. return info->full;
  932. }
  933. uint32_t adi_romtable_entry_count(AppFSM* const ctx, uint32_t base) {
  934. uint32_t count = 0;
  935. uint32_t entry = 0;
  936. furi_mutex_acquire(ctx->swd_mutex, FuriWaitForever);
  937. for(size_t pos = 0; pos < 960; pos++) {
  938. uint8_t ret = 0;
  939. for(int tries = 0; tries < 10 && ret != 1; tries++) {
  940. ret = swd_read_memory(ctx, ctx->ap_pos, base + pos * 4, &entry);
  941. }
  942. if(ret != 1) {
  943. DBGS("Read failed");
  944. break;
  945. }
  946. if(!(entry & 1)) {
  947. break;
  948. }
  949. if(entry & 0x00000FFC) {
  950. break;
  951. }
  952. count++;
  953. }
  954. furi_mutex_release(ctx->swd_mutex);
  955. return count;
  956. }
  957. uint32_t adi_romtable_get(AppFSM* const ctx, uint32_t base, uint32_t pos) {
  958. uint32_t entry = 0;
  959. furi_mutex_acquire(ctx->swd_mutex, FuriWaitForever);
  960. uint8_t ret = swd_read_memory(ctx, ctx->ap_pos, base + pos * 4, &entry);
  961. if(ret != 1) {
  962. DBGS("Read failed");
  963. furi_mutex_release(ctx->swd_mutex);
  964. return 0;
  965. }
  966. furi_mutex_release(ctx->swd_mutex);
  967. return base + (entry & 0xFFFFF000);
  968. }
  969. bool adi_is_romtable(AppFSM* const ctx, uint32_t base) {
  970. uint8_t class = 0;
  971. if(!adi_get_class(ctx, base, &class)) {
  972. return false;
  973. }
  974. if(class != CIDR_CLASS_ROMTABLE) {
  975. return false;
  976. }
  977. return true;
  978. }