1 /***************************************************************************
2 * Copyright (C) 2006 by Magnus Lundin *
5 * Copyright (C) 2008 by Spencer Oliver *
6 * spen@spen-soft.co.uk *
8 * Copyright (C) 2009-2010 by Oyvind Harboe *
9 * oyvind.harboe@zylin.com *
11 * Copyright (C) 2009-2010 by David Brownell *
13 * Copyright (C) 2013 by Andreas Fritiofson *
14 * andreas.fritiofson@gmail.com *
16 * This program is free software; you can redistribute it and/or modify *
17 * it under the terms of the GNU General Public License as published by *
18 * the Free Software Foundation; either version 2 of the License, or *
19 * (at your option) any later version. *
21 * This program is distributed in the hope that it will be useful, *
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
24 * GNU General Public License for more details. *
26 * You should have received a copy of the GNU General Public License *
27 * along with this program; if not, write to the *
28 * Free Software Foundation, Inc., *
29 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
30 ***************************************************************************/
34 * This file implements support for the ARM Debug Interface version 5 (ADIv5)
35 * debugging architecture. Compared with previous versions, this includes
36 * a low pin-count Serial Wire Debug (SWD) alternative to JTAG for message
37 * transport, and focusses on memory mapped resources as defined by the
38 * CoreSight architecture.
40 * A key concept in ADIv5 is the Debug Access Port, or DAP. A DAP has two
41 * basic components: a Debug Port (DP) transporting messages to and from a
42 * debugger, and an Access Port (AP) accessing resources. Three types of DP
43 * are defined. One uses only JTAG for communication, and is called JTAG-DP.
44 * One uses only SWD for communication, and is called SW-DP. The third can
45 * use either SWD or JTAG, and is called SWJ-DP. The most common type of AP
46 * is used to access memory mapped resources and is called a MEM-AP. Also a
47 * JTAG-AP is also defined, bridging to JTAG resources; those are uncommon.
49 * This programming interface allows DAP pipelined operations through a
50 * transaction queue. This primarily affects AP operations (such as using
51 * a MEM-AP to access memory or registers). If the current transaction has
52 * not finished by the time the next one must begin, and the ORUNDETECT bit
53 * is set in the DP_CTRL_STAT register, the SSTICKYORUN status is set and
54 * further AP operations will fail. There are two basic methods to avoid
55 * such overrun errors. One involves polling for status instead of using
56 * transaction piplining. The other involves adding delays to ensure the
57 * AP has enough time to complete one operation before starting the next
58 * one. (For JTAG these delays are controlled by memaccess_tck.)
62 * Relevant specifications from ARM include:
64 * ARM(tm) Debug Interface v5 Architecture Specification ARM IHI 0031A
65 * CoreSight(tm) v1.0 Architecture Specification ARM IHI 0029B
67 * CoreSight(tm) DAP-Lite TRM, ARM DDI 0316D
68 * Cortex-M3(tm) TRM, ARM DDI 0337G
75 #include "jtag/interface.h"
77 #include "arm_adi_v5.h"
78 #include <helper/time_support.h>
79 #include <helper/list.h>
81 /* ARM ADI Specification requires at least 10 bits used for TAR autoincrement */
84 uint32_t tar_block_size(uint32_t address)
85 Return the largest block starting at address that does not cross a tar block size alignment boundary
87 static uint32_t max_tar_block_size(uint32_t tar_autoincr_block, uint32_t address)
89 return tar_autoincr_block - ((tar_autoincr_block - 1) & address);
92 /***************************************************************************
94 * DP and MEM-AP register access through APACC and DPACC *
96 ***************************************************************************/
98 static int mem_ap_setup_csw(struct adiv5_ap *ap, uint32_t csw)
100 csw = csw | CSW_DBGSWENABLE | CSW_MASTER_DEBUG | CSW_HPROT |
103 if (csw != ap->csw_value) {
104 /* LOG_DEBUG("DAP: Set CSW %x",csw); */
105 int retval = dap_queue_ap_write(ap, MEM_AP_REG_CSW, csw);
106 if (retval != ERROR_OK)
113 static int mem_ap_setup_tar(struct adiv5_ap *ap, uint32_t tar)
115 if (tar != ap->tar_value ||
116 (ap->csw_value & CSW_ADDRINC_MASK)) {
117 /* LOG_DEBUG("DAP: Set TAR %x",tar); */
118 int retval = dap_queue_ap_write(ap, MEM_AP_REG_TAR, tar);
119 if (retval != ERROR_OK)
127 * Queue transactions setting up transfer parameters for the
128 * currently selected MEM-AP.
130 * Subsequent transfers using registers like MEM_AP_REG_DRW or MEM_AP_REG_BD2
131 * initiate data reads or writes using memory or peripheral addresses.
132 * If the CSW is configured for it, the TAR may be automatically
133 * incremented after each transfer.
135 * @param ap The MEM-AP.
136 * @param csw MEM-AP Control/Status Word (CSW) register to assign. If this
137 * matches the cached value, the register is not changed.
138 * @param tar MEM-AP Transfer Address Register (TAR) to assign. If this
139 * matches the cached address, the register is not changed.
141 * @return ERROR_OK if the transaction was properly queued, else a fault code.
143 static int mem_ap_setup_transfer(struct adiv5_ap *ap, uint32_t csw, uint32_t tar)
146 retval = mem_ap_setup_csw(ap, csw);
147 if (retval != ERROR_OK)
149 retval = mem_ap_setup_tar(ap, tar);
150 if (retval != ERROR_OK)
156 * Asynchronous (queued) read of a word from memory or a system register.
158 * @param ap The MEM-AP to access.
159 * @param address Address of the 32-bit word to read; it must be
160 * readable by the currently selected MEM-AP.
161 * @param value points to where the word will be stored when the
162 * transaction queue is flushed (assuming no errors).
164 * @return ERROR_OK for success. Otherwise a fault code.
166 int mem_ap_read_u32(struct adiv5_ap *ap, uint32_t address,
171 /* Use banked addressing (REG_BDx) to avoid some link traffic
172 * (updating TAR) when reading several consecutive addresses.
174 retval = mem_ap_setup_transfer(ap, CSW_32BIT | CSW_ADDRINC_OFF,
175 address & 0xFFFFFFF0);
176 if (retval != ERROR_OK)
179 return dap_queue_ap_read(ap, MEM_AP_REG_BD0 | (address & 0xC), value);
183 * Synchronous read of a word from memory or a system register.
184 * As a side effect, this flushes any queued transactions.
186 * @param ap The MEM-AP to access.
187 * @param address Address of the 32-bit word to read; it must be
188 * readable by the currently selected MEM-AP.
189 * @param value points to where the result will be stored.
191 * @return ERROR_OK for success; *value holds the result.
192 * Otherwise a fault code.
194 int mem_ap_read_atomic_u32(struct adiv5_ap *ap, uint32_t address,
199 retval = mem_ap_read_u32(ap, address, value);
200 if (retval != ERROR_OK)
203 return dap_run(ap->dap);
207 * Asynchronous (queued) write of a word to memory or a system register.
209 * @param ap The MEM-AP to access.
210 * @param address Address to be written; it must be writable by
211 * the currently selected MEM-AP.
212 * @param value Word that will be written to the address when transaction
213 * queue is flushed (assuming no errors).
215 * @return ERROR_OK for success. Otherwise a fault code.
217 int mem_ap_write_u32(struct adiv5_ap *ap, uint32_t address,
222 /* Use banked addressing (REG_BDx) to avoid some link traffic
223 * (updating TAR) when writing several consecutive addresses.
225 retval = mem_ap_setup_transfer(ap, CSW_32BIT | CSW_ADDRINC_OFF,
226 address & 0xFFFFFFF0);
227 if (retval != ERROR_OK)
230 return dap_queue_ap_write(ap, MEM_AP_REG_BD0 | (address & 0xC),
235 * Synchronous write of a word to memory or a system register.
236 * As a side effect, this flushes any queued transactions.
238 * @param ap The MEM-AP to access.
239 * @param address Address to be written; it must be writable by
240 * the currently selected MEM-AP.
241 * @param value Word that will be written.
243 * @return ERROR_OK for success; the data was written. Otherwise a fault code.
245 int mem_ap_write_atomic_u32(struct adiv5_ap *ap, uint32_t address,
248 int retval = mem_ap_write_u32(ap, address, value);
250 if (retval != ERROR_OK)
253 return dap_run(ap->dap);
257 * Synchronous write of a block of memory, using a specific access size.
259 * @param ap The MEM-AP to access.
260 * @param buffer The data buffer to write. No particular alignment is assumed.
261 * @param size Which access size to use, in bytes. 1, 2 or 4.
262 * @param count The number of writes to do (in size units, not bytes).
263 * @param address Address to be written; it must be writable by the currently selected MEM-AP.
264 * @param addrinc Whether the target address should be increased for each write or not. This
265 * should normally be true, except when writing to e.g. a FIFO.
266 * @return ERROR_OK on success, otherwise an error code.
268 static int mem_ap_write(struct adiv5_ap *ap, const uint8_t *buffer, uint32_t size, uint32_t count,
269 uint32_t address, bool addrinc)
271 struct adiv5_dap *dap = ap->dap;
272 size_t nbytes = size * count;
273 const uint32_t csw_addrincr = addrinc ? CSW_ADDRINC_SINGLE : CSW_ADDRINC_OFF;
278 /* TI BE-32 Quirks mode:
279 * Writes on big-endian TMS570 behave very strangely. Observed behavior:
280 * size write address bytes written in order
281 * 4 TAR ^ 0 (val >> 24), (val >> 16), (val >> 8), (val)
282 * 2 TAR ^ 2 (val >> 8), (val)
284 * For example, if you attempt to write a single byte to address 0, the processor
285 * will actually write a byte to address 3.
287 * To make writes of size < 4 work as expected, we xor a value with the address before
288 * setting the TAP, and we set the TAP after every transfer rather then relying on
289 * address increment. */
292 csw_size = CSW_32BIT;
294 } else if (size == 2) {
295 csw_size = CSW_16BIT;
296 addr_xor = dap->ti_be_32_quirks ? 2 : 0;
297 } else if (size == 1) {
299 addr_xor = dap->ti_be_32_quirks ? 3 : 0;
301 return ERROR_TARGET_UNALIGNED_ACCESS;
304 if (ap->unaligned_access_bad && (address % size != 0))
305 return ERROR_TARGET_UNALIGNED_ACCESS;
307 retval = mem_ap_setup_tar(ap, address ^ addr_xor);
308 if (retval != ERROR_OK)
312 uint32_t this_size = size;
314 /* Select packed transfer if possible */
315 if (addrinc && ap->packed_transfers && nbytes >= 4
316 && max_tar_block_size(ap->tar_autoincr_block, address) >= 4) {
318 retval = mem_ap_setup_csw(ap, csw_size | CSW_ADDRINC_PACKED);
320 retval = mem_ap_setup_csw(ap, csw_size | csw_addrincr);
323 if (retval != ERROR_OK)
326 /* How many source bytes each transfer will consume, and their location in the DRW,
327 * depends on the type of transfer and alignment. See ARM document IHI0031C. */
328 uint32_t outvalue = 0;
329 if (dap->ti_be_32_quirks) {
332 outvalue |= (uint32_t)*buffer++ << 8 * (3 ^ (address++ & 3) ^ addr_xor);
333 outvalue |= (uint32_t)*buffer++ << 8 * (3 ^ (address++ & 3) ^ addr_xor);
334 outvalue |= (uint32_t)*buffer++ << 8 * (3 ^ (address++ & 3) ^ addr_xor);
335 outvalue |= (uint32_t)*buffer++ << 8 * (3 ^ (address++ & 3) ^ addr_xor);
338 outvalue |= (uint32_t)*buffer++ << 8 * (1 ^ (address++ & 3) ^ addr_xor);
339 outvalue |= (uint32_t)*buffer++ << 8 * (1 ^ (address++ & 3) ^ addr_xor);
342 outvalue |= (uint32_t)*buffer++ << 8 * (0 ^ (address++ & 3) ^ addr_xor);
348 outvalue |= (uint32_t)*buffer++ << 8 * (address++ & 3);
349 outvalue |= (uint32_t)*buffer++ << 8 * (address++ & 3);
351 outvalue |= (uint32_t)*buffer++ << 8 * (address++ & 3);
353 outvalue |= (uint32_t)*buffer++ << 8 * (address++ & 3);
359 retval = dap_queue_ap_write(ap, MEM_AP_REG_DRW, outvalue);
360 if (retval != ERROR_OK)
363 /* Rewrite TAR if it wrapped or we're xoring addresses */
364 if (addrinc && (addr_xor || (address % ap->tar_autoincr_block < size && nbytes > 0))) {
365 retval = mem_ap_setup_tar(ap, address ^ addr_xor);
366 if (retval != ERROR_OK)
371 /* REVISIT: Might want to have a queued version of this function that does not run. */
372 if (retval == ERROR_OK)
373 retval = dap_run(dap);
375 if (retval != ERROR_OK) {
377 if (dap_queue_ap_read(ap, MEM_AP_REG_TAR, &tar) == ERROR_OK
378 && dap_run(dap) == ERROR_OK)
379 LOG_ERROR("Failed to write memory at 0x%08"PRIx32, tar);
381 LOG_ERROR("Failed to write memory and, additionally, failed to find out where");
388 * Synchronous read of a block of memory, using a specific access size.
390 * @param ap The MEM-AP to access.
391 * @param buffer The data buffer to receive the data. No particular alignment is assumed.
392 * @param size Which access size to use, in bytes. 1, 2 or 4.
393 * @param count The number of reads to do (in size units, not bytes).
394 * @param address Address to be read; it must be readable by the currently selected MEM-AP.
395 * @param addrinc Whether the target address should be increased after each read or not. This
396 * should normally be true, except when reading from e.g. a FIFO.
397 * @return ERROR_OK on success, otherwise an error code.
399 static int mem_ap_read(struct adiv5_ap *ap, uint8_t *buffer, uint32_t size, uint32_t count,
400 uint32_t adr, bool addrinc)
402 struct adiv5_dap *dap = ap->dap;
403 size_t nbytes = size * count;
404 const uint32_t csw_addrincr = addrinc ? CSW_ADDRINC_SINGLE : CSW_ADDRINC_OFF;
406 uint32_t address = adr;
409 /* TI BE-32 Quirks mode:
410 * Reads on big-endian TMS570 behave strangely differently than writes.
411 * They read from the physical address requested, but with DRW byte-reversed.
412 * For example, a byte read from address 0 will place the result in the high bytes of DRW.
413 * Also, packed 8-bit and 16-bit transfers seem to sometimes return garbage in some bytes,
417 csw_size = CSW_32BIT;
419 csw_size = CSW_16BIT;
423 return ERROR_TARGET_UNALIGNED_ACCESS;
425 if (ap->unaligned_access_bad && (adr % size != 0))
426 return ERROR_TARGET_UNALIGNED_ACCESS;
428 /* Allocate buffer to hold the sequence of DRW reads that will be made. This is a significant
429 * over-allocation if packed transfers are going to be used, but determining the real need at
430 * this point would be messy. */
431 uint32_t *read_buf = malloc(count * sizeof(uint32_t));
432 uint32_t *read_ptr = read_buf;
433 if (read_buf == NULL) {
434 LOG_ERROR("Failed to allocate read buffer");
438 retval = mem_ap_setup_tar(ap, address);
439 if (retval != ERROR_OK) {
444 /* Queue up all reads. Each read will store the entire DRW word in the read buffer. How many
445 * useful bytes it contains, and their location in the word, depends on the type of transfer
448 uint32_t this_size = size;
450 /* Select packed transfer if possible */
451 if (addrinc && ap->packed_transfers && nbytes >= 4
452 && max_tar_block_size(ap->tar_autoincr_block, address) >= 4) {
454 retval = mem_ap_setup_csw(ap, csw_size | CSW_ADDRINC_PACKED);
456 retval = mem_ap_setup_csw(ap, csw_size | csw_addrincr);
458 if (retval != ERROR_OK)
461 retval = dap_queue_ap_read(ap, MEM_AP_REG_DRW, read_ptr++);
462 if (retval != ERROR_OK)
466 address += this_size;
468 /* Rewrite TAR if it wrapped */
469 if (addrinc && address % ap->tar_autoincr_block < size && nbytes > 0) {
470 retval = mem_ap_setup_tar(ap, address);
471 if (retval != ERROR_OK)
476 if (retval == ERROR_OK)
477 retval = dap_run(dap);
481 nbytes = size * count;
484 /* If something failed, read TAR to find out how much data was successfully read, so we can
485 * at least give the caller what we have. */
486 if (retval != ERROR_OK) {
488 if (dap_queue_ap_read(ap, MEM_AP_REG_TAR, &tar) == ERROR_OK
489 && dap_run(dap) == ERROR_OK) {
490 LOG_ERROR("Failed to read memory at 0x%08"PRIx32, tar);
491 if (nbytes > tar - address)
492 nbytes = tar - address;
494 LOG_ERROR("Failed to read memory and, additionally, failed to find out where");
499 /* Replay loop to populate caller's buffer from the correct word and byte lane */
501 uint32_t this_size = size;
503 if (addrinc && ap->packed_transfers && nbytes >= 4
504 && max_tar_block_size(ap->tar_autoincr_block, address) >= 4) {
508 if (dap->ti_be_32_quirks) {
511 *buffer++ = *read_ptr >> 8 * (3 - (address++ & 3));
512 *buffer++ = *read_ptr >> 8 * (3 - (address++ & 3));
514 *buffer++ = *read_ptr >> 8 * (3 - (address++ & 3));
516 *buffer++ = *read_ptr >> 8 * (3 - (address++ & 3));
521 *buffer++ = *read_ptr >> 8 * (address++ & 3);
522 *buffer++ = *read_ptr >> 8 * (address++ & 3);
524 *buffer++ = *read_ptr >> 8 * (address++ & 3);
526 *buffer++ = *read_ptr >> 8 * (address++ & 3);
538 int mem_ap_read_buf(struct adiv5_ap *ap,
539 uint8_t *buffer, uint32_t size, uint32_t count, uint32_t address)
541 return mem_ap_read(ap, buffer, size, count, address, true);
544 int mem_ap_write_buf(struct adiv5_ap *ap,
545 const uint8_t *buffer, uint32_t size, uint32_t count, uint32_t address)
547 return mem_ap_write(ap, buffer, size, count, address, true);
550 int mem_ap_read_buf_noincr(struct adiv5_ap *ap,
551 uint8_t *buffer, uint32_t size, uint32_t count, uint32_t address)
553 return mem_ap_read(ap, buffer, size, count, address, false);
556 int mem_ap_write_buf_noincr(struct adiv5_ap *ap,
557 const uint8_t *buffer, uint32_t size, uint32_t count, uint32_t address)
559 return mem_ap_write(ap, buffer, size, count, address, false);
562 /*--------------------------------------------------------------------------*/
565 #define DAP_POWER_DOMAIN_TIMEOUT (10)
567 /* FIXME don't import ... just initialize as
568 * part of DAP transport setup
570 extern const struct dap_ops jtag_dp_ops;
572 /*--------------------------------------------------------------------------*/
577 struct adiv5_dap *dap_init(void)
579 struct adiv5_dap *dap = calloc(1, sizeof(struct adiv5_dap));
581 /* Set up with safe defaults */
582 for (i = 0; i <= 255; i++) {
583 dap->ap[i].dap = dap;
584 dap->ap[i].ap_num = i;
585 /* memaccess_tck max is 255 */
586 dap->ap[i].memaccess_tck = 255;
587 /* Number of bits for tar autoincrement, impl. dep. at least 10 */
588 dap->ap[i].tar_autoincr_block = (1<<10);
590 INIT_LIST_HEAD(&dap->cmd_journal);
595 * Initialize a DAP. This sets up the power domains, prepares the DP
596 * for further use and activates overrun checking.
598 * @param dap The DAP being initialized.
600 int dap_dp_init(struct adiv5_dap *dap)
605 /* JTAG-DP or SWJ-DP, in JTAG mode
606 * ... for SWD mode this is patched as part
608 * FIXME: This should already be setup by the respective transport specific DAP creation.
611 dap->ops = &jtag_dp_ops;
613 dap->select = DP_SELECT_INVALID;
614 dap->last_read = NULL;
616 for (size_t i = 0; i < 10; i++) {
617 /* DP initialization */
619 retval = dap_queue_dp_read(dap, DP_CTRL_STAT, NULL);
620 if (retval != ERROR_OK)
623 retval = dap_queue_dp_write(dap, DP_CTRL_STAT, SSTICKYERR);
624 if (retval != ERROR_OK)
627 retval = dap_queue_dp_read(dap, DP_CTRL_STAT, NULL);
628 if (retval != ERROR_OK)
631 dap->dp_ctrl_stat = CDBGPWRUPREQ | CSYSPWRUPREQ;
632 retval = dap_queue_dp_write(dap, DP_CTRL_STAT, dap->dp_ctrl_stat);
633 if (retval != ERROR_OK)
636 /* Check that we have debug power domains activated */
637 LOG_DEBUG("DAP: wait CDBGPWRUPACK");
638 retval = dap_dp_poll_register(dap, DP_CTRL_STAT,
639 CDBGPWRUPACK, CDBGPWRUPACK,
640 DAP_POWER_DOMAIN_TIMEOUT);
641 if (retval != ERROR_OK)
644 LOG_DEBUG("DAP: wait CSYSPWRUPACK");
645 retval = dap_dp_poll_register(dap, DP_CTRL_STAT,
646 CSYSPWRUPACK, CSYSPWRUPACK,
647 DAP_POWER_DOMAIN_TIMEOUT);
648 if (retval != ERROR_OK)
651 retval = dap_queue_dp_read(dap, DP_CTRL_STAT, NULL);
652 if (retval != ERROR_OK)
655 /* With debug power on we can activate OVERRUN checking */
656 dap->dp_ctrl_stat = CDBGPWRUPREQ | CSYSPWRUPREQ | CORUNDETECT;
657 retval = dap_queue_dp_write(dap, DP_CTRL_STAT, dap->dp_ctrl_stat);
658 if (retval != ERROR_OK)
660 retval = dap_queue_dp_read(dap, DP_CTRL_STAT, NULL);
661 if (retval != ERROR_OK)
664 retval = dap_run(dap);
665 if (retval != ERROR_OK)
675 * Initialize a DAP. This sets up the power domains, prepares the DP
676 * for further use, and arranges to use AP #0 for all AP operations
677 * until dap_ap-select() changes that policy.
679 * @param ap The MEM-AP being initialized.
681 int mem_ap_init(struct adiv5_ap *ap)
683 /* check that we support packed transfers */
686 struct adiv5_dap *dap = ap->dap;
688 retval = mem_ap_setup_transfer(ap, CSW_8BIT | CSW_ADDRINC_PACKED, 0);
689 if (retval != ERROR_OK)
692 retval = dap_queue_ap_read(ap, MEM_AP_REG_CSW, &csw);
693 if (retval != ERROR_OK)
696 retval = dap_queue_ap_read(ap, MEM_AP_REG_CFG, &cfg);
697 if (retval != ERROR_OK)
700 retval = dap_run(dap);
701 if (retval != ERROR_OK)
704 if (csw & CSW_ADDRINC_PACKED)
705 ap->packed_transfers = true;
707 ap->packed_transfers = false;
709 /* Packed transfers on TI BE-32 processors do not work correctly in
711 if (dap->ti_be_32_quirks)
712 ap->packed_transfers = false;
714 LOG_DEBUG("MEM_AP Packed Transfers: %s",
715 ap->packed_transfers ? "enabled" : "disabled");
717 /* The ARM ADI spec leaves implementation-defined whether unaligned
718 * memory accesses work, only work partially, or cause a sticky error.
719 * On TI BE-32 processors, reads seem to return garbage in some bytes
720 * and unaligned writes seem to cause a sticky error.
721 * TODO: it would be nice to have a way to detect whether unaligned
722 * operations are supported on other processors. */
723 ap->unaligned_access_bad = dap->ti_be_32_quirks;
725 LOG_DEBUG("MEM_AP CFG: large data %d, long address %d, big-endian %d",
726 !!(cfg & 0x04), !!(cfg & 0x02), !!(cfg & 0x01));
731 /* CID interpretation -- see ARM IHI 0029B section 3
732 * and ARM IHI 0031A table 13-3.
734 static const char *class_description[16] = {
735 "Reserved", "ROM table", "Reserved", "Reserved",
736 "Reserved", "Reserved", "Reserved", "Reserved",
737 "Reserved", "CoreSight component", "Reserved", "Peripheral Test Block",
738 "Reserved", "OptimoDE DESS",
739 "Generic IP component", "PrimeCell or System component"
742 static bool is_dap_cid_ok(uint32_t cid3, uint32_t cid2, uint32_t cid1, uint32_t cid0)
744 return cid3 == 0xb1 && cid2 == 0x05
745 && ((cid1 & 0x0f) == 0) && cid0 == 0x0d;
749 * This function checks the ID for each access port to find the requested Access Port type
751 int dap_find_ap(struct adiv5_dap *dap, enum ap_type type_to_find, struct adiv5_ap **ap_out)
755 /* Maximum AP number is 255 since the SELECT register is 8 bits */
756 for (ap_num = 0; ap_num <= 255; ap_num++) {
758 /* read the IDR register of the Access Port */
761 int retval = dap_queue_ap_read(dap_ap(dap, ap_num), AP_REG_IDR, &id_val);
762 if (retval != ERROR_OK)
765 retval = dap_run(dap);
769 * 27-24 : JEDEC bank (0x4 for ARM)
770 * 23-17 : JEDEC code (0x3B for ARM)
771 * 16-13 : Class (0b1000=Mem-AP)
773 * 7-4 : AP Variant (non-zero for JTAG-AP)
774 * 3-0 : AP Type (0=JTAG-AP 1=AHB-AP 2=APB-AP 4=AXI-AP)
777 /* Reading register for a non-existant AP should not cause an error,
778 * but just to be sure, try to continue searching if an error does happen.
780 if ((retval == ERROR_OK) && /* Register read success */
781 ((id_val & IDR_JEP106) == IDR_JEP106_ARM) && /* Jedec codes match */
782 ((id_val & IDR_TYPE) == type_to_find)) { /* type matches*/
784 LOG_DEBUG("Found %s at AP index: %d (IDR=0x%08" PRIX32 ")",
785 (type_to_find == AP_TYPE_AHB_AP) ? "AHB-AP" :
786 (type_to_find == AP_TYPE_APB_AP) ? "APB-AP" :
787 (type_to_find == AP_TYPE_AXI_AP) ? "AXI-AP" :
788 (type_to_find == AP_TYPE_JTAG_AP) ? "JTAG-AP" : "Unknown",
791 *ap_out = &dap->ap[ap_num];
796 LOG_DEBUG("No %s found",
797 (type_to_find == AP_TYPE_AHB_AP) ? "AHB-AP" :
798 (type_to_find == AP_TYPE_APB_AP) ? "APB-AP" :
799 (type_to_find == AP_TYPE_AXI_AP) ? "AXI-AP" :
800 (type_to_find == AP_TYPE_JTAG_AP) ? "JTAG-AP" : "Unknown");
804 int dap_get_debugbase(struct adiv5_ap *ap,
805 uint32_t *dbgbase, uint32_t *apid)
807 struct adiv5_dap *dap = ap->dap;
810 retval = dap_queue_ap_read(ap, MEM_AP_REG_BASE, dbgbase);
811 if (retval != ERROR_OK)
813 retval = dap_queue_ap_read(ap, AP_REG_IDR, apid);
814 if (retval != ERROR_OK)
816 retval = dap_run(dap);
817 if (retval != ERROR_OK)
823 int dap_lookup_cs_component(struct adiv5_ap *ap,
824 uint32_t dbgbase, uint8_t type, uint32_t *addr, int32_t *idx)
826 uint32_t romentry, entry_offset = 0, component_base, devtype;
832 retval = mem_ap_read_atomic_u32(ap, (dbgbase&0xFFFFF000) |
833 entry_offset, &romentry);
834 if (retval != ERROR_OK)
837 component_base = (dbgbase & 0xFFFFF000)
838 + (romentry & 0xFFFFF000);
840 if (romentry & 0x1) {
842 retval = mem_ap_read_atomic_u32(ap, component_base | 0xff4, &c_cid1);
843 if (retval != ERROR_OK) {
844 LOG_ERROR("Can't read component with base address 0x%" PRIx32
845 ", the corresponding core might be turned off", component_base);
848 if (((c_cid1 >> 4) & 0x0f) == 1) {
849 retval = dap_lookup_cs_component(ap, component_base,
851 if (retval == ERROR_OK)
853 if (retval != ERROR_TARGET_RESOURCE_NOT_AVAILABLE)
857 retval = mem_ap_read_atomic_u32(ap,
858 (component_base & 0xfffff000) | 0xfcc,
860 if (retval != ERROR_OK)
862 if ((devtype & 0xff) == type) {
864 *addr = component_base;
871 } while (romentry > 0);
874 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
879 /* The designer identity code is encoded as:
880 * bits 11:8 : JEP106 Bank (number of continuation codes), only valid when bit 7 is 1.
881 * bit 7 : Set when bits 6:0 represent a JEP106 ID and cleared when bits 6:0 represent
882 * a legacy ASCII Identity Code.
883 * bits 6:0 : JEP106 Identity Code (without parity) or legacy ASCII code according to bit 7.
884 * JEP106 is a standard available from jedec.org
887 /* Part number interpretations are from Cortex
888 * core specs, the CoreSight components TRM
889 * (ARM DDI 0314H), CoreSight System Design
890 * Guide (ARM DGI 0012D) and ETM specs; also
891 * from chip observation (e.g. TI SDTI).
894 /* The legacy code only used the part number field to identify CoreSight peripherals.
895 * This meant that the same part number from two different manufacturers looked the same.
896 * It is desirable for all future additions to identify with both part number and JEP106.
897 * "ANY_ID" is a wildcard (any JEP106) only to preserve legacy behavior for legacy entries.
900 #define ANY_ID 0x1000
904 static const struct {
905 uint16_t designer_id;
910 { ARM_ID, 0x000, "Cortex-M3 SCS", "(System Control Space)", },
911 { ARM_ID, 0x001, "Cortex-M3 ITM", "(Instrumentation Trace Module)", },
912 { ARM_ID, 0x002, "Cortex-M3 DWT", "(Data Watchpoint and Trace)", },
913 { ARM_ID, 0x003, "Cortex-M3 FBP", "(Flash Patch and Breakpoint)", },
914 { ARM_ID, 0x008, "Cortex-M0 SCS", "(System Control Space)", },
915 { ARM_ID, 0x00a, "Cortex-M0 DWT", "(Data Watchpoint and Trace)", },
916 { ARM_ID, 0x00b, "Cortex-M0 BPU", "(Breakpoint Unit)", },
917 { ARM_ID, 0x00c, "Cortex-M4 SCS", "(System Control Space)", },
918 { ARM_ID, 0x00d, "CoreSight ETM11", "(Embedded Trace)", },
919 { ARM_ID, 0x490, "Cortex-A15 GIC", "(Generic Interrupt Controller)", },
920 { ARM_ID, 0x4c7, "Cortex-M7 PPB", "(Private Peripheral Bus ROM Table)", },
921 { ARM_ID, 0x906, "CoreSight CTI", "(Cross Trigger)", },
922 { ARM_ID, 0x907, "CoreSight ETB", "(Trace Buffer)", },
923 { ARM_ID, 0x908, "CoreSight CSTF", "(Trace Funnel)", },
924 { ARM_ID, 0x910, "CoreSight ETM9", "(Embedded Trace)", },
925 { ARM_ID, 0x912, "CoreSight TPIU", "(Trace Port Interface Unit)", },
926 { ARM_ID, 0x913, "CoreSight ITM", "(Instrumentation Trace Macrocell)", },
927 { ARM_ID, 0x914, "CoreSight SWO", "(Single Wire Output)", },
928 { ARM_ID, 0x917, "CoreSight HTM", "(AHB Trace Macrocell)", },
929 { ARM_ID, 0x920, "CoreSight ETM11", "(Embedded Trace)", },
930 { ARM_ID, 0x921, "Cortex-A8 ETM", "(Embedded Trace)", },
931 { ARM_ID, 0x922, "Cortex-A8 CTI", "(Cross Trigger)", },
932 { ARM_ID, 0x923, "Cortex-M3 TPIU", "(Trace Port Interface Unit)", },
933 { ARM_ID, 0x924, "Cortex-M3 ETM", "(Embedded Trace)", },
934 { ARM_ID, 0x925, "Cortex-M4 ETM", "(Embedded Trace)", },
935 { ARM_ID, 0x930, "Cortex-R4 ETM", "(Embedded Trace)", },
936 { ARM_ID, 0x931, "Cortex-R5 ETM", "(Embedded Trace)", },
937 { ARM_ID, 0x941, "CoreSight TPIU-Lite", "(Trace Port Interface Unit)", },
938 { ARM_ID, 0x950, "Cortex-A9 PTM", "(Program Trace Macrocell)", },
939 { ARM_ID, 0x955, "Cortex-A5 ETM", "(Embedded Trace)", },
940 { ARM_ID, 0x95a, "Cortex-A72 ETM", "(Embedded Trace)", },
941 { ARM_ID, 0x95b, "Cortex-A17 PTM", "(Program Trace Macrocell)", },
942 { ARM_ID, 0x95d, "Cortex-A53 ETM", "(Embedded Trace)", },
943 { ARM_ID, 0x95e, "Cortex-A57 ETM", "(Embedded Trace)", },
944 { ARM_ID, 0x95f, "Cortex-A15 PTM", "(Program Trace Macrocell)", },
945 { ARM_ID, 0x961, "CoreSight TMC", "(Trace Memory Controller)", },
946 { ARM_ID, 0x962, "CoreSight STM", "(System Trace Macrocell)", },
947 { ARM_ID, 0x9a0, "CoreSight PMU", "(Performance Monitoring Unit)", },
948 { ARM_ID, 0x9a1, "Cortex-M4 TPIU", "(Trace Port Interface Unit)", },
949 { ARM_ID, 0x9a5, "Cortex-A5 PMU", "(Performance Monitor Unit)", },
950 { ARM_ID, 0x9a7, "Cortex-A7 PMU", "(Performance Monitor Unit)", },
951 { ARM_ID, 0x9a8, "Cortex-A53 CTI", "(Cross Trigger)", },
952 { ARM_ID, 0x9ae, "Cortex-A17 PMU", "(Performance Monitor Unit)", },
953 { ARM_ID, 0x9af, "Cortex-A15 PMU", "(Performance Monitor Unit)", },
954 { ARM_ID, 0x9b7, "Cortex-R7 PMU", "(Performance Monitoring Unit)", },
955 { ARM_ID, 0x9d3, "Cortex-A53 PMU", "(Performance Monitor Unit)", },
956 { ARM_ID, 0x9d7, "Cortex-A57 PMU", "(Performance Monitor Unit)", },
957 { ARM_ID, 0x9d8, "Cortex-A72 PMU", "(Performance Monitor Unit)", },
958 { ARM_ID, 0xc05, "Cortex-A5 Debug", "(Debug Unit)", },
959 { ARM_ID, 0xc07, "Cortex-A7 Debug", "(Debug Unit)", },
960 { ARM_ID, 0xc08, "Cortex-A8 Debug", "(Debug Unit)", },
961 { ARM_ID, 0xc09, "Cortex-A9 Debug", "(Debug Unit)", },
962 { ARM_ID, 0xc0e, "Cortex-A17 Debug", "(Debug Unit)", },
963 { ARM_ID, 0xc0f, "Cortex-A15 Debug", "(Debug Unit)", },
964 { ARM_ID, 0xc14, "Cortex-R4 Debug", "(Debug Unit)", },
965 { ARM_ID, 0xc15, "Cortex-R5 Debug", "(Debug Unit)", },
966 { ARM_ID, 0xc17, "Cortex-R7 Debug", "(Debug Unit)", },
967 { ARM_ID, 0xd03, "Cortex-A53 Debug", "(Debug Unit)", },
968 { ARM_ID, 0xd07, "Cortex-A57 Debug", "(Debug Unit)", },
969 { ARM_ID, 0xd08, "Cortex-A72 Debug", "(Debug Unit)", },
970 { 0x0E5, 0x000, "SHARC+/Blackfin+", "", },
971 /* legacy comment: 0x113: what? */
972 { ANY_ID, 0x120, "TI SDTI", "(System Debug Trace Interface)", }, /* from OMAP3 memmap */
973 { ANY_ID, 0x343, "TI DAPCTL", "", }, /* from OMAP3 memmap */
976 static int dap_rom_display(struct command_context *cmd_ctx,
977 struct adiv5_ap *ap, uint32_t dbgbase, int depth)
979 struct adiv5_dap *dap = ap->dap;
981 uint32_t cid0, cid1, cid2, cid3, memtype, romentry;
982 uint16_t entry_offset;
986 command_print(cmd_ctx, "\tTables too deep");
991 snprintf(tabs, sizeof(tabs), "[L%02d] ", depth);
993 /* bit 16 of apid indicates a memory access port */
995 command_print(cmd_ctx, "\t%sValid ROM table present", tabs);
997 command_print(cmd_ctx, "\t%sROM table in legacy format", tabs);
999 /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec */
1000 retval = mem_ap_read_u32(ap, (dbgbase&0xFFFFF000) | 0xFF0, &cid0);
1001 if (retval != ERROR_OK)
1003 retval = mem_ap_read_u32(ap, (dbgbase&0xFFFFF000) | 0xFF4, &cid1);
1004 if (retval != ERROR_OK)
1006 retval = mem_ap_read_u32(ap, (dbgbase&0xFFFFF000) | 0xFF8, &cid2);
1007 if (retval != ERROR_OK)
1009 retval = mem_ap_read_u32(ap, (dbgbase&0xFFFFF000) | 0xFFC, &cid3);
1010 if (retval != ERROR_OK)
1012 retval = mem_ap_read_u32(ap, (dbgbase&0xFFFFF000) | 0xFCC, &memtype);
1013 if (retval != ERROR_OK)
1015 retval = dap_run(dap);
1016 if (retval != ERROR_OK)
1019 if (!is_dap_cid_ok(cid3, cid2, cid1, cid0))
1020 command_print(cmd_ctx, "\t%sCID3 0x%02x"
1025 (unsigned)cid3, (unsigned)cid2,
1026 (unsigned)cid1, (unsigned)cid0);
1028 command_print(cmd_ctx, "\t%sMEMTYPE system memory present on bus", tabs);
1030 command_print(cmd_ctx, "\t%sMEMTYPE system memory not present: dedicated debug bus", tabs);
1032 /* Now we read ROM table entries from dbgbase&0xFFFFF000) | 0x000 until we get 0x00000000 */
1033 for (entry_offset = 0; ; entry_offset += 4) {
1034 retval = mem_ap_read_atomic_u32(ap, (dbgbase&0xFFFFF000) | entry_offset, &romentry);
1035 if (retval != ERROR_OK)
1037 command_print(cmd_ctx, "\t%sROMTABLE[0x%x] = 0x%" PRIx32 "",
1038 tabs, entry_offset, romentry);
1039 if (romentry & 0x01) {
1040 uint32_t c_cid0, c_cid1, c_cid2, c_cid3;
1041 uint32_t c_pid0, c_pid1, c_pid2, c_pid3, c_pid4;
1042 uint32_t component_base;
1043 uint16_t part_num, designer_id;
1044 const char *type, *full;
1046 component_base = (dbgbase & 0xFFFFF000) + (romentry & 0xFFFFF000);
1048 /* IDs are in last 4K section */
1049 retval = mem_ap_read_atomic_u32(ap, component_base + 0xFE0, &c_pid0);
1050 if (retval != ERROR_OK) {
1051 command_print(cmd_ctx, "\t%s\tCan't read component with base address 0x%" PRIx32
1052 ", the corresponding core might be turned off", tabs, component_base);
1056 retval = mem_ap_read_atomic_u32(ap, component_base + 0xFE4, &c_pid1);
1057 if (retval != ERROR_OK)
1060 retval = mem_ap_read_atomic_u32(ap, component_base + 0xFE8, &c_pid2);
1061 if (retval != ERROR_OK)
1064 retval = mem_ap_read_atomic_u32(ap, component_base + 0xFEC, &c_pid3);
1065 if (retval != ERROR_OK)
1068 retval = mem_ap_read_atomic_u32(ap, component_base + 0xFD0, &c_pid4);
1069 if (retval != ERROR_OK)
1073 retval = mem_ap_read_atomic_u32(ap, component_base + 0xFF0, &c_cid0);
1074 if (retval != ERROR_OK)
1077 retval = mem_ap_read_atomic_u32(ap, component_base + 0xFF4, &c_cid1);
1078 if (retval != ERROR_OK)
1081 retval = mem_ap_read_atomic_u32(ap, component_base + 0xFF8, &c_cid2);
1082 if (retval != ERROR_OK)
1085 retval = mem_ap_read_atomic_u32(ap, component_base + 0xFFC, &c_cid3);
1086 if (retval != ERROR_OK)
1090 command_print(cmd_ctx, "\t\tComponent base address 0x%" PRIx32 ", "
1091 "start address 0x%" PRIx32, component_base,
1092 /* component may take multiple 4K pages */
1093 (uint32_t)(component_base - 0x1000*(c_pid4 >> 4)));
1094 command_print(cmd_ctx, "\t\tComponent class is 0x%" PRIx8 ", %s",
1095 (uint8_t)((c_cid1 >> 4) & 0xf),
1096 /* See ARM IHI 0029B Table 3-3 */
1097 class_description[(c_cid1 >> 4) & 0xf]);
1099 /* CoreSight component? */
1100 if (((c_cid1 >> 4) & 0x0f) == 9) {
1103 const char *major = "Reserved", *subtype = "Reserved";
1105 retval = mem_ap_read_atomic_u32(ap,
1106 (component_base & 0xfffff000) | 0xfcc,
1108 if (retval != ERROR_OK)
1110 minor = (devtype >> 4) & 0x0f;
1111 switch (devtype & 0x0f) {
1113 major = "Miscellaneous";
1119 subtype = "Validation component";
1124 major = "Trace Sink";
1141 major = "Trace Link";
1147 subtype = "Funnel, router";
1153 subtype = "FIFO, buffer";
1158 major = "Trace Source";
1164 subtype = "Processor";
1170 subtype = "Engine/Coprocessor";
1176 subtype = "Software";
1181 major = "Debug Control";
1187 subtype = "Trigger Matrix";
1190 subtype = "Debug Auth";
1193 subtype = "Power Requestor";
1198 major = "Debug Logic";
1204 subtype = "Processor";
1210 subtype = "Engine/Coprocessor";
1221 major = "Perfomance Monitor";
1227 subtype = "Processor";
1233 subtype = "Engine/Coprocessor";
1244 command_print(cmd_ctx, "\t\tType is 0x%02" PRIx8 ", %s, %s",
1245 (uint8_t)(devtype & 0xff),
1247 /* REVISIT also show 0xfc8 DevId */
1250 if (!is_dap_cid_ok(cid3, cid2, cid1, cid0))
1251 command_print(cmd_ctx,
1260 command_print(cmd_ctx,
1261 "\t\tPeripheral ID[4..0] = hex "
1262 "%02x %02x %02x %02x %02x",
1263 (int)c_pid4, (int)c_pid3, (int)c_pid2,
1264 (int)c_pid1, (int)c_pid0);
1266 part_num = (c_pid0 & 0xff);
1267 part_num |= (c_pid1 & 0x0f) << 8;
1268 designer_id = (c_pid1 & 0xf0) >> 4;
1269 designer_id |= (c_pid2 & 0x0f) << 4;
1270 designer_id |= (c_pid4 & 0x0f) << 8;
1271 if ((designer_id & 0x80) == 0) {
1272 /* Legacy ASCII ID, clear invalid bits */
1273 designer_id &= 0x7f;
1276 /* default values to be overwritten upon finding a match */
1280 /* search dap_partnums[] array for a match */
1282 for (entry = 0; entry < ARRAY_SIZE(dap_partnums); entry++) {
1284 if ((dap_partnums[entry].designer_id != designer_id) && (dap_partnums[entry].designer_id != ANY_ID))
1287 if (dap_partnums[entry].part_num != part_num)
1290 type = dap_partnums[entry].type;
1291 full = dap_partnums[entry].full;
1296 command_print(cmd_ctx, "\t\tPart is %s %s",
1299 command_print(cmd_ctx, "\t\tUnrecognized (Part 0x%" PRIx16 ", designer 0x%" PRIx16 ")",
1300 part_num, designer_id);
1304 if (((c_cid1 >> 4) & 0x0f) == 1) {
1305 retval = dap_rom_display(cmd_ctx, ap, component_base, depth + 1);
1306 if (retval != ERROR_OK)
1311 command_print(cmd_ctx, "\t\tComponent not present");
1316 command_print(cmd_ctx, "\t%s\tEnd of ROM table", tabs);
1320 static int dap_info_command(struct command_context *cmd_ctx,
1321 struct adiv5_ap *ap)
1324 uint32_t dbgbase, apid;
1325 int romtable_present = 0;
1328 /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec */
1329 retval = dap_get_debugbase(ap, &dbgbase, &apid);
1330 if (retval != ERROR_OK)
1333 command_print(cmd_ctx, "AP ID register 0x%8.8" PRIx32, apid);
1335 command_print(cmd_ctx, "No AP found at this ap 0x%x", ap->ap_num);
1339 switch (apid & (IDR_JEP106 | IDR_TYPE)) {
1340 case IDR_JEP106_ARM | AP_TYPE_JTAG_AP:
1341 command_print(cmd_ctx, "\tType is JTAG-AP");
1343 case IDR_JEP106_ARM | AP_TYPE_AHB_AP:
1344 command_print(cmd_ctx, "\tType is MEM-AP AHB");
1346 case IDR_JEP106_ARM | AP_TYPE_APB_AP:
1347 command_print(cmd_ctx, "\tType is MEM-AP APB");
1349 case IDR_JEP106_ARM | AP_TYPE_AXI_AP:
1350 command_print(cmd_ctx, "\tType is MEM-AP AXI");
1353 command_print(cmd_ctx, "\tUnknown AP type");
1357 /* NOTE: a MEM-AP may have a single CoreSight component that's
1358 * not a ROM table ... or have no such components at all.
1360 mem_ap = (apid & IDR_CLASS) == AP_CLASS_MEM_AP;
1362 command_print(cmd_ctx, "MEM-AP BASE 0x%8.8" PRIx32, dbgbase);
1364 romtable_present = dbgbase != 0xFFFFFFFF;
1365 if (romtable_present)
1366 dap_rom_display(cmd_ctx, ap, dbgbase, 0);
1368 command_print(cmd_ctx, "\tNo ROM table present");
1374 COMMAND_HANDLER(handle_dap_info_command)
1376 struct target *target = get_current_target(CMD_CTX);
1377 struct arm *arm = target_to_arm(target);
1378 struct adiv5_dap *dap = arm->dap;
1386 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
1388 return ERROR_COMMAND_SYNTAX_ERROR;
1391 return ERROR_COMMAND_SYNTAX_ERROR;
1394 return dap_info_command(CMD_CTX, &dap->ap[apsel]);
1397 COMMAND_HANDLER(dap_baseaddr_command)
1399 struct target *target = get_current_target(CMD_CTX);
1400 struct arm *arm = target_to_arm(target);
1401 struct adiv5_dap *dap = arm->dap;
1403 uint32_t apsel, baseaddr;
1411 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
1412 /* AP address is in bits 31:24 of DP_SELECT */
1414 return ERROR_COMMAND_SYNTAX_ERROR;
1417 return ERROR_COMMAND_SYNTAX_ERROR;
1420 /* NOTE: assumes we're talking to a MEM-AP, which
1421 * has a base address. There are other kinds of AP,
1422 * though they're not common for now. This should
1423 * use the ID register to verify it's a MEM-AP.
1425 retval = dap_queue_ap_read(dap_ap(dap, apsel), MEM_AP_REG_BASE, &baseaddr);
1426 if (retval != ERROR_OK)
1428 retval = dap_run(dap);
1429 if (retval != ERROR_OK)
1432 command_print(CMD_CTX, "0x%8.8" PRIx32, baseaddr);
1437 COMMAND_HANDLER(dap_memaccess_command)
1439 struct target *target = get_current_target(CMD_CTX);
1440 struct arm *arm = target_to_arm(target);
1441 struct adiv5_dap *dap = arm->dap;
1443 uint32_t memaccess_tck;
1447 memaccess_tck = dap->ap[dap->apsel].memaccess_tck;
1450 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], memaccess_tck);
1453 return ERROR_COMMAND_SYNTAX_ERROR;
1455 dap->ap[dap->apsel].memaccess_tck = memaccess_tck;
1457 command_print(CMD_CTX, "memory bus access delay set to %" PRIi32 " tck",
1458 dap->ap[dap->apsel].memaccess_tck);
1463 COMMAND_HANDLER(dap_apsel_command)
1465 struct target *target = get_current_target(CMD_CTX);
1466 struct arm *arm = target_to_arm(target);
1467 struct adiv5_dap *dap = arm->dap;
1469 uint32_t apsel, apid;
1477 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
1478 /* AP address is in bits 31:24 of DP_SELECT */
1480 return ERROR_COMMAND_SYNTAX_ERROR;
1483 return ERROR_COMMAND_SYNTAX_ERROR;
1488 retval = dap_queue_ap_read(dap_ap(dap, apsel), AP_REG_IDR, &apid);
1489 if (retval != ERROR_OK)
1491 retval = dap_run(dap);
1492 if (retval != ERROR_OK)
1495 command_print(CMD_CTX, "ap %" PRIi32 " selected, identification register 0x%8.8" PRIx32,
1501 COMMAND_HANDLER(dap_apcsw_command)
1503 struct target *target = get_current_target(CMD_CTX);
1504 struct arm *arm = target_to_arm(target);
1505 struct adiv5_dap *dap = arm->dap;
1507 uint32_t apcsw = dap->ap[dap->apsel].csw_default, sprot = 0;
1511 command_print(CMD_CTX, "apsel %" PRIi32 " selected, csw 0x%8.8" PRIx32,
1512 (dap->apsel), apcsw);
1515 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], sprot);
1516 /* AP address is in bits 31:24 of DP_SELECT */
1518 return ERROR_COMMAND_SYNTAX_ERROR;
1522 apcsw &= ~CSW_SPROT;
1525 return ERROR_COMMAND_SYNTAX_ERROR;
1527 dap->ap[dap->apsel].csw_default = apcsw;
1534 COMMAND_HANDLER(dap_apid_command)
1536 struct target *target = get_current_target(CMD_CTX);
1537 struct arm *arm = target_to_arm(target);
1538 struct adiv5_dap *dap = arm->dap;
1540 uint32_t apsel, apid;
1548 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel);
1549 /* AP address is in bits 31:24 of DP_SELECT */
1551 return ERROR_COMMAND_SYNTAX_ERROR;
1554 return ERROR_COMMAND_SYNTAX_ERROR;
1557 retval = dap_queue_ap_read(dap_ap(dap, apsel), AP_REG_IDR, &apid);
1558 if (retval != ERROR_OK)
1560 retval = dap_run(dap);
1561 if (retval != ERROR_OK)
1564 command_print(CMD_CTX, "0x%8.8" PRIx32, apid);
1569 COMMAND_HANDLER(dap_ti_be_32_quirks_command)
1571 struct target *target = get_current_target(CMD_CTX);
1572 struct arm *arm = target_to_arm(target);
1573 struct adiv5_dap *dap = arm->dap;
1575 uint32_t enable = dap->ti_be_32_quirks;
1581 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], enable);
1583 return ERROR_COMMAND_SYNTAX_ERROR;
1586 return ERROR_COMMAND_SYNTAX_ERROR;
1588 dap->ti_be_32_quirks = enable;
1589 command_print(CMD_CTX, "TI BE-32 quirks mode %s",
1590 enable ? "enabled" : "disabled");
1595 static const struct command_registration dap_commands[] = {
1598 .handler = handle_dap_info_command,
1599 .mode = COMMAND_EXEC,
1600 .help = "display ROM table for MEM-AP "
1601 "(default currently selected AP)",
1602 .usage = "[ap_num]",
1606 .handler = dap_apsel_command,
1607 .mode = COMMAND_EXEC,
1608 .help = "Set the currently selected AP (default 0) "
1609 "and display the result",
1610 .usage = "[ap_num]",
1614 .handler = dap_apcsw_command,
1615 .mode = COMMAND_EXEC,
1616 .help = "Set csw access bit ",
1622 .handler = dap_apid_command,
1623 .mode = COMMAND_EXEC,
1624 .help = "return ID register from AP "
1625 "(default currently selected AP)",
1626 .usage = "[ap_num]",
1630 .handler = dap_baseaddr_command,
1631 .mode = COMMAND_EXEC,
1632 .help = "return debug base address from MEM-AP "
1633 "(default currently selected AP)",
1634 .usage = "[ap_num]",
1637 .name = "memaccess",
1638 .handler = dap_memaccess_command,
1639 .mode = COMMAND_EXEC,
1640 .help = "set/get number of extra tck for MEM-AP memory "
1641 "bus access [0-255]",
1642 .usage = "[cycles]",
1645 .name = "ti_be_32_quirks",
1646 .handler = dap_ti_be_32_quirks_command,
1647 .mode = COMMAND_CONFIG,
1648 .help = "set/get quirks mode for TI TMS450/TMS570 processors",
1649 .usage = "[enable]",
1651 COMMAND_REGISTRATION_DONE
1654 const struct command_registration dap_command_handlers[] = {
1657 .mode = COMMAND_EXEC,
1658 .help = "DAP command group",
1660 .chain = dap_commands,
1662 COMMAND_REGISTRATION_DONE