adi.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  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. /* https://github.com/stlink-org/stlink/blob/develop/doc/devices_boards.md */
  786. {0x20, 0x410, "STM32F10 (med)", "(ROM Table)"},
  787. {0x20, 0x411, "STM32F2", "(ROM Table)"},
  788. {0x20, 0x412, "STM32F10 (low)", "(ROM Table)"},
  789. {0x20, 0x413, "STM32F40/41", "(ROM Table)"},
  790. {0x20, 0x414, "STM32F10 (high)", "(ROM Table)"},
  791. {0x20, 0x415, "STM32L47/48", "(ROM Table)"},
  792. {0x20, 0x416, "STM32L1xxx6/8/B", "(ROM Table)"},
  793. {0x20, 0x417, "STM32L05/06", "(ROM Table)"},
  794. {0x20, 0x418, "STM32F105xx/107", "(ROM Table)"},
  795. {0x20, 0x419, "STM32F42/43", "(ROM Table)"},
  796. {0x20, 0x420, "STM32F10 (med)", "(ROM Table)"},
  797. {0x20, 0x421, "STM32F446xx", "(ROM Table)"},
  798. {0x20, 0x422, "STM32FF358/02/03", "(ROM Table)"},
  799. {0x20, 0x423, "STM32F401xB/C", "(ROM Table)"},
  800. {0x20, 0x425, "STM32L031/41", "(ROM Table)"},
  801. {0x20, 0x427, "STM32L1xxxC", "(ROM Table)"},
  802. {0x20, 0x428, "STM32F10 (high)", "(ROM Table)"},
  803. {0x20, 0x429, "STM32L1xxx6A/8A/BA", "(ROM Table)"},
  804. {0x20, 0x430, "STM32F10 (xl)", "(ROM Table)"},
  805. {0x20, 0x431, "STM32F411xx", "(ROM Table)"},
  806. {0x20, 0x432, "STM32F373/8", "(ROM Table)"},
  807. {0x20, 0x433, "STM32F401xD/E", "(ROM Table)"},
  808. {0x20, 0x434, "STM32F469/79", "(ROM Table)"},
  809. {0x20, 0x435, "STM32L43/44", "(ROM Table)"},
  810. {0x20, 0x436, "STM32L1xxxD", "(ROM Table)"},
  811. {0x20, 0x437, "STM32L1xxxE", "(ROM Table)"},
  812. {0x20, 0x438, "STM32F303/34/28", "(ROM Table)"},
  813. {0x20, 0x439, "STM32F301/02/18 ", "(ROM Table)"},
  814. {0x20, 0x440, "STM32F03/5", "(ROM Table)"},
  815. {0x20, 0x441, "STM32F412xx", "(ROM Table)"},
  816. {0x20, 0x442, "STM32F03/9", "(ROM Table)"},
  817. {0x20, 0x444, "STM32F03xx4", "(ROM Table)"},
  818. {0x20, 0x445, "STM32F04/7", "(ROM Table)"},
  819. {0x20, 0x446, "STM32F302/03/98", "(ROM Table)"},
  820. {0x20, 0x447, "STM32L07/08", "(ROM Table)"},
  821. {0x20, 0x448, "STM32F070/1/2", "(ROM Table)"},
  822. {0x20, 0x449, "STM32F74/5", "(ROM Table)"},
  823. {0x20, 0x450, "STM32H74/5", "(ROM Table)"},
  824. {0x20, 0x451, "STM32F76/7", "(ROM Table)"},
  825. {0x20, 0x452, "STM32F72/3", "(ROM Table)"},
  826. {0x20, 0x457, "STM32L01/2", "(ROM Table)"},
  827. {0x20, 0x458, "STM32F410xx", "(ROM Table)"},
  828. {0x20, 0x460, "STM32G07/8", "(ROM Table)"},
  829. {0x20, 0x461, "STM32L496/A6", "(ROM Table)"},
  830. {0x20, 0x462, "STM32L45/46", "(ROM Table)"},
  831. {0x20, 0x463, "STM32F413/23", "(ROM Table)"},
  832. {0x20, 0x464, "STM32L412/22", "(ROM Table)"},
  833. {0x20, 0x466, "STM32G03/04", "(ROM Table)"},
  834. {0x20, 0x468, "STM32G431/41", "(ROM Table)"},
  835. {0x20, 0x469, "STM32G47/48", "(ROM Table)"},
  836. {0x20, 0x470, "STM32L4R/S", "(ROM Table)"},
  837. {0x20, 0x471, "STM32L4P5/Q5", "(ROM Table)"},
  838. {0x20, 0x479, "STM32G491xx", "(ROM Table)"},
  839. {0x20, 0x480, "STM32H7A/B", "(ROM Table)"},
  840. {0x20, 0x495, "STM32WB50/55", "(ROM Table)"},
  841. {0x20, 0x497, "STM32WLE5xx", "(ROM Table)"}};
  842. const char* adi_devarch_desc(uint32_t devarch) {
  843. if(!(devarch & ARM_CS_C9_DEVARCH_PRESENT)) {
  844. return "not present";
  845. }
  846. for(unsigned int i = 0; i < ARRAY_SIZE(class0x9_devarch); i++) {
  847. if((devarch & DEVARCH_ID_MASK) == class0x9_devarch[i].arch_id) {
  848. return class0x9_devarch[i].description;
  849. }
  850. }
  851. return "unknown";
  852. }
  853. const struct dap_part_nums* adi_part_num(unsigned int des, unsigned int part) {
  854. static char buf[32];
  855. static struct dap_part_nums unknown = {
  856. .type = "Unrecognized",
  857. .full = "",
  858. };
  859. for(unsigned int i = 0; i < ARRAY_SIZE(dap_part_nums); i++) {
  860. if(dap_part_nums[i].designer_id == des && dap_part_nums[i].part_num == part) {
  861. return &dap_part_nums[i];
  862. }
  863. }
  864. snprintf(buf, sizeof(buf), "D:%x P:%x", des, part);
  865. unknown.full = buf;
  866. return &unknown;
  867. }
  868. bool adi_get_pidr(AppFSM* const ctx, uint32_t base, pidr_data_t* data) {
  869. uint32_t pidrs[7];
  870. uint32_t offsets[] = {0xFE0, 0xFE4, 0xFE8, 0xFEC, 0xFD0, 0xFD4, 0xFD8, 0xFDC};
  871. furi_mutex_acquire(ctx->swd_mutex, FuriWaitForever);
  872. for(size_t pos = 0; pos < COUNT(pidrs); pos++) {
  873. uint8_t ret = swd_read_memory(ctx, ctx->ap_pos, base + offsets[pos], &pidrs[pos]);
  874. if(ret != 1) {
  875. DBGS("Read failed");
  876. furi_mutex_release(ctx->swd_mutex);
  877. return false;
  878. }
  879. }
  880. furi_mutex_release(ctx->swd_mutex);
  881. data->designer = ((pidrs[4] & 0x0F) << 7) | ((pidrs[2] & 0x07) << 4) |
  882. ((pidrs[1] >> 4) & 0x0F);
  883. data->part = (pidrs[0] & 0xFF) | ((pidrs[1] & 0x0F) << 8);
  884. data->revand = ((pidrs[3] >> 4) & 0x0F);
  885. data->cmod = (pidrs[3] & 0x0F);
  886. data->revision = ((pidrs[2] >> 4) & 0x0F);
  887. data->size = ((pidrs[2] >> 4) & 0x0F);
  888. return true;
  889. }
  890. bool adi_get_class(AppFSM* const ctx, uint32_t base, uint8_t* class) {
  891. uint32_t cidrs[4];
  892. uint32_t offsets[] = {0xFF0, 0xFF4, 0xFF8, 0xFFC};
  893. furi_mutex_acquire(ctx->swd_mutex, FuriWaitForever);
  894. for(size_t pos = 0; pos < COUNT(cidrs); pos++) {
  895. uint8_t ret = swd_read_memory(ctx, ctx->ap_pos, base + offsets[pos], &cidrs[pos]);
  896. if(ret != 1) {
  897. DBGS("Read failed");
  898. furi_mutex_release(ctx->swd_mutex);
  899. return false;
  900. }
  901. }
  902. furi_mutex_release(ctx->swd_mutex);
  903. if((cidrs[0] & 0xFF) != 0x0D) {
  904. return false;
  905. }
  906. if((cidrs[1] & 0x0F) != 0x00) {
  907. return false;
  908. }
  909. if((cidrs[2] & 0xFF) != 0x05) {
  910. return false;
  911. }
  912. if((cidrs[3] & 0xFF) != 0xB1) {
  913. return false;
  914. }
  915. *class = ((cidrs[1] >> 4) & 0x0F);
  916. return true;
  917. }
  918. const char* adi_romtable_type(AppFSM* const ctx, uint32_t base) {
  919. pidr_data_t data;
  920. if(!adi_get_pidr(ctx, base, &data)) {
  921. return "fail";
  922. }
  923. const struct dap_part_nums* info = adi_part_num(data.designer, data.part);
  924. return info->type;
  925. }
  926. const char* adi_romtable_full(AppFSM* const ctx, uint32_t base) {
  927. pidr_data_t data;
  928. if(!adi_get_pidr(ctx, base, &data)) {
  929. return "fail";
  930. }
  931. const struct dap_part_nums* info = adi_part_num(data.designer, data.part);
  932. return info->full;
  933. }
  934. uint32_t adi_romtable_entry_count(AppFSM* const ctx, uint32_t base) {
  935. uint32_t count = 0;
  936. uint32_t entry = 0;
  937. furi_mutex_acquire(ctx->swd_mutex, FuriWaitForever);
  938. for(size_t pos = 0; pos < 960; pos++) {
  939. uint8_t ret = 0;
  940. for(int tries = 0; tries < 10 && ret != 1; tries++) {
  941. ret = swd_read_memory(ctx, ctx->ap_pos, base + pos * 4, &entry);
  942. }
  943. if(ret != 1) {
  944. DBGS("Read failed");
  945. break;
  946. }
  947. if(!(entry & 1)) {
  948. break;
  949. }
  950. if(entry & 0x00000FFC) {
  951. break;
  952. }
  953. count++;
  954. }
  955. furi_mutex_release(ctx->swd_mutex);
  956. return count;
  957. }
  958. uint32_t adi_romtable_get(AppFSM* const ctx, uint32_t base, uint32_t pos) {
  959. uint32_t entry = 0;
  960. furi_mutex_acquire(ctx->swd_mutex, FuriWaitForever);
  961. uint8_t ret = swd_read_memory(ctx, ctx->ap_pos, base + pos * 4, &entry);
  962. if(ret != 1) {
  963. DBGS("Read failed");
  964. furi_mutex_release(ctx->swd_mutex);
  965. return 0;
  966. }
  967. furi_mutex_release(ctx->swd_mutex);
  968. return base + (entry & 0xFFFFF000);
  969. }
  970. bool adi_is_romtable(AppFSM* const ctx, uint32_t base) {
  971. uint8_t class = 0;
  972. if(!adi_get_class(ctx, base, &class)) {
  973. return false;
  974. }
  975. if(class != CIDR_CLASS_ROMTABLE) {
  976. return false;
  977. }
  978. return true;
  979. }