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) 2011 Tomasz Boleslaw CEDRO *
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
76 #include "arm_adi_v5.h"
77 #include <helper/time_support.h>
78 #include <jtag/interface.h>
80 //We need to have access to information on other layers such as transport etc
81 //these are kept in global interface structure for now. Change ASAP.
82 extern struct jtag_interface
*jtag_interface
;
84 /* ARM ADI Specification requires at least 10 bits used for TAR autoincrement */
87 uint32_t tar_block_size(uint32_t address)
88 Return the largest block starting at address that does not cross a tar block size alignment boundary
90 static uint32_t max_tar_block_size(uint32_t tar_autoincr_block
, uint32_t address
)
92 return (tar_autoincr_block
- ((tar_autoincr_block
- 1) & address
)) >> 2;
95 /***************************************************************************
97 * DP and MEM-AP register access through APACC and DPACC *
99 ***************************************************************************/
102 * Select one of the APs connected to the specified DAP. The
103 * selection is implicitly used with future AP transactions.
104 * This is a NOP if the specified AP is already selected.
107 * @param apsel Number of the AP to (implicitly) use with further
108 * transactions. This normally identifies a MEM-AP.
110 void dap_ap_select(struct adiv5_dap
*dap
,uint8_t ap
)
112 uint32_t new_ap
= (ap
<< 24) & 0xFF000000;
114 if (new_ap
!= dap
->ap_current
)
116 dap
->ap_current
= new_ap
;
117 /* Switching AP invalidates cached values.
118 * Values MUST BE UPDATED BEFORE AP ACCESS.
120 dap
->ap_bank_value
= -1;
121 dap
->ap_csw_value
= -1;
122 dap
->ap_tar_value
= -1;
127 * Queue transactions setting up transfer parameters for the
128 * currently selected MEM-AP.
130 * Subsequent transfers using registers like AP_REG_DRW or 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 * @todo Rename to reflect it being specifically a MEM-AP function.
137 * @param dap The DAP connected to the MEM-AP.
138 * @param csw MEM-AP Control/Status Word (CSW) register to assign. If this
139 * matches the cached value, the register is not changed.
140 * @param tar MEM-AP Transfer Address Register (TAR) to assign. If this
141 * matches the cached address, the register is not changed.
143 * @return ERROR_OK if the transaction was properly queued, else a fault code.
145 int dap_setup_accessport(struct adiv5_dap
*dap
, uint32_t csw
, uint32_t tar
)
149 csw
= csw
| CSW_DBGSWENABLE
| CSW_MASTER_DEBUG
| CSW_HPROT
;
150 if (csw
!= dap
->ap_csw_value
)
152 /* LOG_DEBUG("DAP: Set CSW %x",csw); */
153 retval
= dap_queue_ap_write(dap
, AP_REG_CSW
, csw
);
154 if (retval
!= ERROR_OK
)
156 dap
->ap_csw_value
= csw
;
158 if (tar
!= dap
->ap_tar_value
)
160 /* LOG_DEBUG("DAP: Set TAR %x",tar); */
161 retval
= dap_queue_ap_write(dap
, AP_REG_TAR
, tar
);
162 if (retval
!= ERROR_OK
)
164 dap
->ap_tar_value
= tar
;
166 /* Disable TAR cache when autoincrementing */
167 if (csw
& CSW_ADDRINC_MASK
)
168 dap
->ap_tar_value
= -1;
173 * Asynchronous (queued) read of a word from memory or a system register.
175 * @param dap The DAP connected to the MEM-AP performing the read.
176 * @param address Address of the 32-bit word to read; it must be
177 * readable by the currently selected MEM-AP.
178 * @param value points to where the word will be stored when the
179 * transaction queue is flushed (assuming no errors).
181 * @return ERROR_OK for success. Otherwise a fault code.
183 int mem_ap_read_u32(struct adiv5_dap
*dap
, uint32_t address
,
188 /* Use banked addressing (REG_BDx) to avoid some link traffic
189 * (updating TAR) when reading several consecutive addresses.
191 retval
= dap_setup_accessport(dap
, CSW_32BIT
| CSW_ADDRINC_OFF
,
192 address
& 0xFFFFFFF0);
193 if (retval
!= ERROR_OK
)
196 return dap_queue_ap_read(dap
, AP_REG_BD0
| (address
& 0xC), value
);
200 * Synchronous read of a word from memory or a system register.
201 * As a side effect, this flushes any queued transactions.
203 * @param dap The DAP connected to the MEM-AP performing the read.
204 * @param address Address of the 32-bit word to read; it must be
205 * readable by the currently selected MEM-AP.
206 * @param value points to where the result will be stored.
208 * @return ERROR_OK for success; *value holds the result.
209 * Otherwise a fault code.
211 int mem_ap_read_atomic_u32(struct adiv5_dap
*dap
, uint32_t address
,
216 retval
= mem_ap_read_u32(dap
, address
, value
);
217 if (retval
!= ERROR_OK
)
224 * Asynchronous (queued) write of a word to memory or a system register.
226 * @param dap The DAP connected to the MEM-AP.
227 * @param address Address to be written; it must be writable by
228 * the currently selected MEM-AP.
229 * @param value Word that will be written to the address when transaction
230 * queue is flushed (assuming no errors).
232 * @return ERROR_OK for success. Otherwise a fault code.
234 int mem_ap_write_u32(struct adiv5_dap
*dap
, uint32_t address
,
239 /* Use banked addressing (REG_BDx) to avoid some link traffic
240 * (updating TAR) when writing several consecutive addresses.
242 retval
= dap_setup_accessport(dap
, CSW_32BIT
| CSW_ADDRINC_OFF
,
243 address
& 0xFFFFFFF0);
244 if (retval
!= ERROR_OK
)
247 return dap_queue_ap_write(dap
, AP_REG_BD0
| (address
& 0xC),
252 * Synchronous write of a word to memory or a system register.
253 * As a side effect, this flushes any queued transactions.
255 * @param dap The DAP connected to the MEM-AP.
256 * @param address Address to be written; it must be writable by
257 * the currently selected MEM-AP.
258 * @param value Word that will be written.
260 * @return ERROR_OK for success; the data was written. Otherwise a fault code.
262 int mem_ap_write_atomic_u32(struct adiv5_dap
*dap
, uint32_t address
,
265 int retval
= mem_ap_write_u32(dap
, address
, value
);
267 if (retval
!= ERROR_OK
)
273 /*****************************************************************************
275 * mem_ap_write_buf(struct adiv5_dap *dap, uint8_t *buffer, int count, uint32_t address) *
277 * Write a buffer in target order (little endian) *
279 *****************************************************************************/
280 int mem_ap_write_buf_u32(struct adiv5_dap
*dap
, const uint8_t *buffer
, int count
, uint32_t address
)
282 int wcount
, blocksize
, writecount
, errorcount
= 0, retval
= ERROR_OK
;
283 uint32_t adr
= address
;
284 const uint8_t* pBuffer
= buffer
;
289 /* if we have an unaligned access - reorder data */
292 for (writecount
= 0; writecount
< count
; writecount
++)
296 memcpy(&outvalue
, pBuffer
, sizeof(uint32_t));
298 for (i
= 0; i
< 4; i
++)
300 *((uint8_t*)pBuffer
+ (adr
& 0x3)) = outvalue
;
304 pBuffer
+= sizeof(uint32_t);
310 /* Adjust to write blocks within boundaries aligned to the TAR autoincremnent size*/
311 blocksize
= max_tar_block_size(dap
->tar_autoincr_block
, address
);
312 if (wcount
< blocksize
)
315 /* handle unaligned data at 4k boundary */
319 retval
= dap_setup_accessport(dap
, CSW_32BIT
| CSW_ADDRINC_SINGLE
, address
);
320 if (retval
!= ERROR_OK
)
323 for (writecount
= 0; writecount
< blocksize
; writecount
++)
325 retval
= dap_queue_ap_write(dap
, AP_REG_DRW
,
326 *(uint32_t *) ((void *) (buffer
+ 4 * writecount
)));
327 if (retval
!= ERROR_OK
)
331 if ((retval
= dap_run(dap
)) == ERROR_OK
)
333 wcount
= wcount
- blocksize
;
334 address
= address
+ 4 * blocksize
;
335 buffer
= buffer
+ 4 * blocksize
;
344 LOG_WARNING("Block write error address 0x%" PRIx32
", wcount 0x%x", address
, wcount
);
352 static int mem_ap_write_buf_packed_u16(struct adiv5_dap
*dap
,
353 const uint8_t *buffer
, int count
, uint32_t address
)
355 int retval
= ERROR_OK
;
356 int wcount
, blocksize
, writecount
, i
;
364 /* Adjust to write blocks within boundaries aligned to the TAR autoincremnent size*/
365 blocksize
= max_tar_block_size(dap
->tar_autoincr_block
, address
);
367 if (wcount
< blocksize
)
370 /* handle unaligned data at 4k boundary */
374 retval
= dap_setup_accessport(dap
, CSW_16BIT
| CSW_ADDRINC_PACKED
, address
);
375 if (retval
!= ERROR_OK
)
377 writecount
= blocksize
;
381 nbytes
= MIN((writecount
<< 1), 4);
385 retval
= mem_ap_write_buf_u16(dap
, buffer
,
387 if (retval
!= ERROR_OK
)
389 LOG_WARNING("Block write error address "
390 "0x%" PRIx32
", count 0x%x",
395 address
+= nbytes
>> 1;
400 memcpy(&outvalue
, buffer
, sizeof(uint32_t));
402 for (i
= 0; i
< nbytes
; i
++)
404 *((uint8_t*)buffer
+ (address
& 0x3)) = outvalue
;
409 memcpy(&outvalue
, buffer
, sizeof(uint32_t));
410 retval
= dap_queue_ap_write(dap
,
411 AP_REG_DRW
, outvalue
);
412 if (retval
!= ERROR_OK
)
415 if ((retval
= dap_run(dap
)) != ERROR_OK
)
417 LOG_WARNING("Block write error address "
418 "0x%" PRIx32
", count 0x%x",
424 buffer
+= nbytes
>> 1;
425 writecount
-= nbytes
>> 1;
427 } while (writecount
);
434 int mem_ap_write_buf_u16(struct adiv5_dap
*dap
, const uint8_t *buffer
, int count
, uint32_t address
)
436 int retval
= ERROR_OK
;
439 return mem_ap_write_buf_packed_u16(dap
, buffer
, count
, address
);
443 retval
= dap_setup_accessport(dap
, CSW_16BIT
| CSW_ADDRINC_SINGLE
, address
);
444 if (retval
!= ERROR_OK
)
447 memcpy(&svalue
, buffer
, sizeof(uint16_t));
448 uint32_t outvalue
= (uint32_t)svalue
<< 8 * (address
& 0x3);
449 retval
= dap_queue_ap_write(dap
, AP_REG_DRW
, outvalue
);
450 if (retval
!= ERROR_OK
)
453 retval
= dap_run(dap
);
454 if (retval
!= ERROR_OK
)
465 static int mem_ap_write_buf_packed_u8(struct adiv5_dap
*dap
,
466 const uint8_t *buffer
, int count
, uint32_t address
)
468 int retval
= ERROR_OK
;
469 int wcount
, blocksize
, writecount
, i
;
477 /* Adjust to write blocks within boundaries aligned to the TAR autoincremnent size*/
478 blocksize
= max_tar_block_size(dap
->tar_autoincr_block
, address
);
480 if (wcount
< blocksize
)
483 retval
= dap_setup_accessport(dap
, CSW_8BIT
| CSW_ADDRINC_PACKED
, address
);
484 if (retval
!= ERROR_OK
)
486 writecount
= blocksize
;
490 nbytes
= MIN(writecount
, 4);
494 retval
= mem_ap_write_buf_u8(dap
, buffer
, nbytes
, address
);
495 if (retval
!= ERROR_OK
)
497 LOG_WARNING("Block write error address "
498 "0x%" PRIx32
", count 0x%x",
508 memcpy(&outvalue
, buffer
, sizeof(uint32_t));
510 for (i
= 0; i
< nbytes
; i
++)
512 *((uint8_t*)buffer
+ (address
& 0x3)) = outvalue
;
517 memcpy(&outvalue
, buffer
, sizeof(uint32_t));
518 retval
= dap_queue_ap_write(dap
,
519 AP_REG_DRW
, outvalue
);
520 if (retval
!= ERROR_OK
)
523 if ((retval
= dap_run(dap
)) != ERROR_OK
)
525 LOG_WARNING("Block write error address "
526 "0x%" PRIx32
", count 0x%x",
533 writecount
-= nbytes
;
535 } while (writecount
);
542 int mem_ap_write_buf_u8(struct adiv5_dap
*dap
, const uint8_t *buffer
, int count
, uint32_t address
)
544 int retval
= ERROR_OK
;
547 return mem_ap_write_buf_packed_u8(dap
, buffer
, count
, address
);
551 retval
= dap_setup_accessport(dap
, CSW_8BIT
| CSW_ADDRINC_SINGLE
, address
);
552 if (retval
!= ERROR_OK
)
554 uint32_t outvalue
= (uint32_t)*buffer
<< 8 * (address
& 0x3);
555 retval
= dap_queue_ap_write(dap
, AP_REG_DRW
, outvalue
);
556 if (retval
!= ERROR_OK
)
559 retval
= dap_run(dap
);
560 if (retval
!= ERROR_OK
)
571 /* FIXME don't import ... this is a temporary workaround for the
572 * mem_ap_read_buf_u32() mess, until it's no longer JTAG-specific.
574 extern int adi_jtag_dp_scan(struct adiv5_dap
*dap
,
575 uint8_t instr
, uint8_t reg_addr
, uint8_t RnW
,
576 uint8_t *outvalue
, uint8_t *invalue
, uint8_t *ack
);
579 * Synchronously read a block of 32-bit words into a buffer
580 * @param dap The DAP connected to the MEM-AP.
581 * @param buffer where the words will be stored (in host byte order).
582 * @param count How many words to read.
583 * @param address Memory address from which to read words; all the
584 * words must be readable by the currently selected MEM-AP.
586 int mem_ap_read_buf_u32(struct adiv5_dap
*dap
, uint8_t *buffer
,
587 int count
, uint32_t address
)
589 int wcount
, blocksize
, readcount
, errorcount
= 0, retval
= ERROR_OK
;
590 uint32_t adr
= address
;
591 uint8_t* pBuffer
= buffer
;
598 /* Adjust to read blocks within boundaries aligned to the
599 * TAR autoincrement size (at least 2^10). Autoincrement
600 * mode avoids an extra per-word roundtrip to update TAR.
602 blocksize
= max_tar_block_size(dap
->tar_autoincr_block
,
604 if (wcount
< blocksize
)
607 /* handle unaligned data at 4k boundary */
611 retval
= dap_setup_accessport(dap
, CSW_32BIT
| CSW_ADDRINC_SINGLE
,
613 if (retval
!= ERROR_OK
)
616 /* FIXME remove these three calls to adi_jtag_dp_scan(),
617 * so this routine becomes transport-neutral. Be careful
618 * not to cause performance problems with JTAG; would it
619 * suffice to loop over dap_queue_ap_read(), or would that
620 * be slower when JTAG is the chosen transport?
623 /* Scan out first read */
624 retval
= adi_jtag_dp_scan(dap
, JTAG_DP_APACC
, AP_REG_DRW
,
625 DPAP_READ
, 0, NULL
, NULL
);
626 if (retval
!= ERROR_OK
)
628 for (readcount
= 0; readcount
< blocksize
- 1; readcount
++)
630 /* Scan out next read; scan in posted value for the
631 * previous one. Assumes read is acked "OK/FAULT",
632 * and CTRL_STAT says that meant "OK".
634 retval
= adi_jtag_dp_scan(dap
, JTAG_DP_APACC
, AP_REG_DRW
,
635 DPAP_READ
, 0, buffer
+ 4 * readcount
,
637 if (retval
!= ERROR_OK
)
641 /* Scan in last posted value; RDBUFF has no other effect,
642 * assuming ack is OK/FAULT and CTRL_STAT says "OK".
644 retval
= adi_jtag_dp_scan(dap
, JTAG_DP_DPACC
, DP_RDBUFF
,
645 DPAP_READ
, 0, buffer
+ 4 * readcount
,
647 if (retval
!= ERROR_OK
)
650 retval
= dap_run(dap
);
651 if (retval
!= ERROR_OK
)
659 LOG_WARNING("Block read error address 0x%" PRIx32
, address
);
662 wcount
= wcount
- blocksize
;
663 address
+= 4 * blocksize
;
664 buffer
+= 4 * blocksize
;
667 /* if we have an unaligned access - reorder data */
670 for (readcount
= 0; readcount
< count
; readcount
++)
674 memcpy(&data
, pBuffer
, sizeof(uint32_t));
676 for (i
= 0; i
< 4; i
++)
678 *((uint8_t*)pBuffer
) =
679 (data
>> 8 * (adr
& 0x3));
689 static int mem_ap_read_buf_packed_u16(struct adiv5_dap
*dap
,
690 uint8_t *buffer
, int count
, uint32_t address
)
693 int retval
= ERROR_OK
;
694 int wcount
, blocksize
, readcount
, i
;
702 /* Adjust to read blocks within boundaries aligned to the TAR autoincremnent size*/
703 blocksize
= max_tar_block_size(dap
->tar_autoincr_block
, address
);
704 if (wcount
< blocksize
)
707 retval
= dap_setup_accessport(dap
, CSW_16BIT
| CSW_ADDRINC_PACKED
, address
);
708 if (retval
!= ERROR_OK
)
711 /* handle unaligned data at 4k boundary */
714 readcount
= blocksize
;
718 retval
= dap_queue_ap_read(dap
, AP_REG_DRW
, &invalue
);
719 if (retval
!= ERROR_OK
)
721 if ((retval
= dap_run(dap
)) != ERROR_OK
)
723 LOG_WARNING("Block read error address 0x%" PRIx32
", count 0x%x", address
, count
);
727 nbytes
= MIN((readcount
<< 1), 4);
729 for (i
= 0; i
< nbytes
; i
++)
731 *((uint8_t*)buffer
) = (invalue
>> 8 * (address
& 0x3));
736 readcount
-= (nbytes
>> 1);
745 * Synchronously read a block of 16-bit halfwords into a buffer
746 * @param dap The DAP connected to the MEM-AP.
747 * @param buffer where the halfwords will be stored (in host byte order).
748 * @param count How many halfwords to read.
749 * @param address Memory address from which to read words; all the
750 * words must be readable by the currently selected MEM-AP.
752 int mem_ap_read_buf_u16(struct adiv5_dap
*dap
, uint8_t *buffer
,
753 int count
, uint32_t address
)
756 int retval
= ERROR_OK
;
759 return mem_ap_read_buf_packed_u16(dap
, buffer
, count
, address
);
763 retval
= dap_setup_accessport(dap
, CSW_16BIT
| CSW_ADDRINC_SINGLE
, address
);
764 if (retval
!= ERROR_OK
)
766 retval
= dap_queue_ap_read(dap
, AP_REG_DRW
, &invalue
);
767 if (retval
!= ERROR_OK
)
770 retval
= dap_run(dap
);
771 if (retval
!= ERROR_OK
)
776 for (i
= 0; i
< 2; i
++)
778 *((uint8_t*)buffer
) = (invalue
>> 8 * (address
& 0x3));
785 uint16_t svalue
= (invalue
>> 8 * (address
& 0x3));
786 memcpy(buffer
, &svalue
, sizeof(uint16_t));
796 /* FIX!!! is this a potential performance bottleneck w.r.t. requiring too many
797 * roundtrips when jtag_execute_queue() has a large overhead(e.g. for USB)s?
799 * The solution is to arrange for a large out/in scan in this loop and
800 * and convert data afterwards.
802 static int mem_ap_read_buf_packed_u8(struct adiv5_dap
*dap
,
803 uint8_t *buffer
, int count
, uint32_t address
)
806 int retval
= ERROR_OK
;
807 int wcount
, blocksize
, readcount
, i
;
815 /* Adjust to read blocks within boundaries aligned to the TAR autoincremnent size*/
816 blocksize
= max_tar_block_size(dap
->tar_autoincr_block
, address
);
818 if (wcount
< blocksize
)
821 retval
= dap_setup_accessport(dap
, CSW_8BIT
| CSW_ADDRINC_PACKED
, address
);
822 if (retval
!= ERROR_OK
)
824 readcount
= blocksize
;
828 retval
= dap_queue_ap_read(dap
, AP_REG_DRW
, &invalue
);
829 if (retval
!= ERROR_OK
)
831 if ((retval
= dap_run(dap
)) != ERROR_OK
)
833 LOG_WARNING("Block read error address 0x%" PRIx32
", count 0x%x", address
, count
);
837 nbytes
= MIN(readcount
, 4);
839 for (i
= 0; i
< nbytes
; i
++)
841 *((uint8_t*)buffer
) = (invalue
>> 8 * (address
& 0x3));
855 * Synchronously read a block of bytes into a buffer
856 * @param dap The DAP connected to the MEM-AP.
857 * @param buffer where the bytes will be stored.
858 * @param count How many bytes to read.
859 * @param address Memory address from which to read data; all the
860 * data must be readable by the currently selected MEM-AP.
862 int mem_ap_read_buf_u8(struct adiv5_dap
*dap
, uint8_t *buffer
,
863 int count
, uint32_t address
)
866 int retval
= ERROR_OK
;
869 return mem_ap_read_buf_packed_u8(dap
, buffer
, count
, address
);
873 retval
= dap_setup_accessport(dap
, CSW_8BIT
| CSW_ADDRINC_SINGLE
, address
);
874 if (retval
!= ERROR_OK
)
876 retval
= dap_queue_ap_read(dap
, AP_REG_DRW
, &invalue
);
877 if (retval
!= ERROR_OK
)
879 retval
= dap_run(dap
);
880 if (retval
!= ERROR_OK
)
883 *((uint8_t*)buffer
) = (invalue
>> 8 * (address
& 0x3));
892 /*--------------------------------------------------------------------*/
893 /* Wrapping function with selection of AP */
894 /*--------------------------------------------------------------------*/
895 int mem_ap_sel_read_u32(struct adiv5_dap
*swjdp
, uint8_t ap
,
896 uint32_t address
, uint32_t *value
)
898 dap_ap_select(swjdp
, ap
);
899 return mem_ap_read_u32(swjdp
, address
, value
);
902 int mem_ap_sel_write_u32(struct adiv5_dap
*swjdp
, uint8_t ap
,
903 uint32_t address
, uint32_t value
)
905 dap_ap_select(swjdp
, ap
);
906 return mem_ap_write_u32(swjdp
, address
, value
);
909 int mem_ap_sel_read_atomic_u32(struct adiv5_dap
*swjdp
, uint8_t ap
,
910 uint32_t address
, uint32_t *value
)
912 dap_ap_select(swjdp
, ap
);
913 return mem_ap_read_atomic_u32(swjdp
, address
, value
);
916 int mem_ap_sel_write_atomic_u32(struct adiv5_dap
*swjdp
, uint8_t ap
,
917 uint32_t address
, uint32_t value
)
919 dap_ap_select(swjdp
, ap
);
920 return mem_ap_write_atomic_u32(swjdp
, address
, value
);
923 int mem_ap_sel_read_buf_u8(struct adiv5_dap
*swjdp
, uint8_t ap
,
924 uint8_t *buffer
, int count
, uint32_t address
)
926 dap_ap_select(swjdp
, ap
);
927 return mem_ap_read_buf_u8(swjdp
, buffer
, count
, address
);
930 int mem_ap_sel_read_buf_u16(struct adiv5_dap
*swjdp
, uint8_t ap
,
931 uint8_t *buffer
, int count
, uint32_t address
)
933 dap_ap_select(swjdp
, ap
);
934 return mem_ap_read_buf_u16(swjdp
, buffer
, count
, address
);
937 int mem_ap_sel_read_buf_u32(struct adiv5_dap
*swjdp
, uint8_t ap
,
938 uint8_t *buffer
, int count
, uint32_t address
)
940 dap_ap_select(swjdp
, ap
);
941 return mem_ap_read_buf_u32(swjdp
, buffer
, count
, address
);
944 int mem_ap_sel_write_buf_u8(struct adiv5_dap
*swjdp
, uint8_t ap
,
945 const uint8_t *buffer
, int count
, uint32_t address
)
947 dap_ap_select(swjdp
, ap
);
948 return mem_ap_write_buf_u8(swjdp
, buffer
, count
, address
);
951 int mem_ap_sel_write_buf_u16(struct adiv5_dap
*swjdp
, uint8_t ap
,
952 const uint8_t *buffer
, int count
, uint32_t address
)
954 dap_ap_select(swjdp
, ap
);
955 return mem_ap_write_buf_u16(swjdp
, buffer
, count
, address
);
958 int mem_ap_sel_write_buf_u32(struct adiv5_dap
*swjdp
, uint8_t ap
,
959 const uint8_t *buffer
, int count
, uint32_t address
)
961 dap_ap_select(swjdp
, ap
);
962 return mem_ap_write_buf_u32(swjdp
, buffer
, count
, address
);
965 #define MDM_REG_STAT 0x00
966 #define MDM_REG_CTRL 0x04
967 #define MDM_REG_ID 0xfc
969 #define MDM_STAT_FMEACK (1<<0)
970 #define MDM_STAT_FREADY (1<<1)
971 #define MDM_STAT_SYSSEC (1<<2)
972 #define MDM_STAT_SYSRES (1<<3)
973 #define MDM_STAT_FMEEN (1<<5)
974 #define MDM_STAT_BACKDOOREN (1<<6)
975 #define MDM_STAT_LPEN (1<<7)
976 #define MDM_STAT_VLPEN (1<<8)
977 #define MDM_STAT_LLSMODEXIT (1<<9)
978 #define MDM_STAT_VLLSXMODEXIT (1<<10)
979 #define MDM_STAT_CORE_HALTED (1<<16)
980 #define MDM_STAT_CORE_SLEEPDEEP (1<<17)
981 #define MDM_STAT_CORESLEEPING (1<<18)
983 #define MEM_CTRL_FMEIP (1<<0)
984 #define MEM_CTRL_DBG_DIS (1<<1)
985 #define MEM_CTRL_DBG_REQ (1<<2)
986 #define MEM_CTRL_SYS_RES_REQ (1<<3)
987 #define MEM_CTRL_CORE_HOLD_RES (1<<4)
988 #define MEM_CTRL_VLLSX_DBG_REQ (1<<5)
989 #define MEM_CTRL_VLLSX_DBG_ACK (1<<6)
990 #define MEM_CTRL_VLLSX_STAT_ACK (1<<7)
995 int dap_syssec_kinetis_mdmap(struct adiv5_dap
*dap
)
999 enum reset_types jtag_reset_config
= jtag_get_reset_config();
1001 dap_ap_select(dap
, 1);
1003 /* first check mdm-ap id register */
1004 retval
= dap_queue_ap_read(dap
, MDM_REG_ID
, &val
);
1005 if (retval
!= ERROR_OK
)
1009 if ( val
!= 0x001C0000 )
1011 LOG_DEBUG("id doesn't match %08X != 0x001C0000",val
);
1012 dap_ap_select(dap
, 0);
1016 /* read and parse status register
1017 * it's important that the device is out of
1020 retval
= dap_queue_ap_read(dap
, MDM_REG_STAT
, &val
);
1021 if (retval
!= ERROR_OK
)
1025 LOG_DEBUG("MDM_REG_STAT %08X",val
);
1027 if ( (val
& (MDM_STAT_SYSSEC
|MDM_STAT_FREADY
)) != (MDM_STAT_FREADY
) )
1029 LOG_DEBUG("MDMAP: system is secured, masserase needed");
1031 if ( !(val
& MDM_STAT_FMEEN
) )
1033 LOG_DEBUG("MDMAP: masserase is disabled");
1037 /* we need to assert reset */
1038 if ( jtag_reset_config
& RESET_HAS_SRST
)
1040 /* default to asserting srst */
1041 if (jtag_reset_config
& RESET_SRST_PULLS_TRST
)
1043 jtag_add_reset(1, 1);
1047 jtag_add_reset(0, 1);
1052 LOG_DEBUG("SRST not configured");
1053 dap_ap_select(dap
, 0);
1059 retval
= dap_queue_ap_write(dap
, MDM_REG_CTRL
, MEM_CTRL_FMEIP
);
1060 if (retval
!= ERROR_OK
)
1063 /* read status register and wait for ready */
1064 retval
= dap_queue_ap_read(dap
, MDM_REG_STAT
, &val
);
1065 if (retval
!= ERROR_OK
)
1068 LOG_DEBUG("MDM_REG_STAT %08X",val
);
1076 retval
= dap_queue_ap_write(dap
, MDM_REG_CTRL
, 0);
1077 if (retval
!= ERROR_OK
)
1080 /* read status register */
1081 retval
= dap_queue_ap_read(dap
, MDM_REG_STAT
, &val
);
1082 if (retval
!= ERROR_OK
)
1085 LOG_DEBUG("MDM_REG_STAT %08X",val
);
1086 /* read control register and wait for ready */
1087 retval
= dap_queue_ap_read(dap
, MDM_REG_CTRL
, &val
);
1088 if (retval
!= ERROR_OK
)
1091 LOG_DEBUG("MDM_REG_CTRL %08X",val
);
1099 dap_ap_select(dap
, 0);
1105 struct dap_syssec_filter
{
1109 int (*dap_init
)(struct adiv5_dap
*dap
);
1113 static struct dap_syssec_filter dap_syssec_filter_data
[] = {
1114 { 0x4BA00477, dap_syssec_kinetis_mdmap
}
1121 int dap_syssec(struct adiv5_dap
*dap
)
1124 struct jtag_tap
*tap
;
1126 for(i
=0;i
<sizeof(dap_syssec_filter_data
);i
++)
1128 tap
= dap
->jtag_info
->tap
;
1132 if ( tap
->hasidcode
&& (dap_syssec_filter_data
[i
].idcode
== tap
->idcode
) )
1134 LOG_DEBUG("DAP: mdmap_init for idcode: %08x",tap
->idcode
);
1135 dap_syssec_filter_data
[i
].dap_init(dap
);
1137 tap
= tap
->next_tap
;
1144 /*--------------------------------------------------------------------------*/
1147 /* FIXME don't import ... just initialize as
1148 * part of DAP transport setup
1150 extern const struct dap_ops jtag_dp_ops
;
1152 extern const struct dap_ops swd_dap_ops
;
1154 /*--------------------------------------------------------------------------*/
1157 * Initialize a DAP. This sets up the power domains, prepares the DP
1158 * for further use, and arranges to use AP #0 for all AP operations
1159 * until dap_ap-select() changes that policy.
1161 * @param dap The DAP being initialized.
1163 * @todo Rename this. We also need an initialization scheme which account
1164 * for SWD transports not just JTAG; that will need to address differences
1165 * in layering. (JTAG is useful without any debug target; but not SWD.)
1166 * And this may not even use an AHB-AP ... e.g. DAP-Lite uses an APB-AP.
1168 int ahbap_debugport_init(struct adiv5_dap
*dap
)
1176 /* JTAG-DP or SWJ-DP, in JTAG mode
1177 * ... for SWD mode this is patched as part
1178 * of link switchover
1181 * dap->ops = &jtag_dp_ops;
1184 /** TC@20110601: Now we must select DAP function set based on transport type.
1185 * Transport selection is part of interface initialization.
1186 * Interface and target are initialized separately.
1187 * Transport fills global structure with functions to operate on target.
1188 * If transport SWD is not selected JTAG is set as default (old behavior).
1191 struct jtag_interface
*interface
=jtag_interface
; //OMFG!
1193 if ((strncmp(interface
->transport
->name
, "swd", 3)==0)) {
1194 LOG_INFO("Selecting SWD transport command set.");
1195 dap
->ops
= &swd_dap_ops
;
1197 LOG_INFO("Selecting JTAG transport command set.");
1198 dap
->ops
= &jtag_dp_ops
;
1206 /* Default MEM-AP setup.
1208 * REVISIT AP #0 may be an inappropriate default for this.
1209 * Should we probe, or take a hint from the caller?
1210 * Presumably we can ignore the possibility of multiple APs.
1212 dap
->ap_current
= !0;
1213 dap_ap_select(dap
, 0);
1215 /* DP initialization */
1217 retval
= dap_queue_dp_read(dap
, DP_CTRL_STAT
, NULL
);
1218 if (retval
!= ERROR_OK
)
1221 retval
= dap_queue_dp_write(dap
, DP_CTRL_STAT
, SSTICKYERR
);
1222 if (retval
!= ERROR_OK
)
1225 retval
= dap_queue_dp_read(dap
, DP_CTRL_STAT
, NULL
);
1226 if (retval
!= ERROR_OK
)
1229 dap
->dp_ctrl_stat
= CDBGPWRUPREQ
| CSYSPWRUPREQ
;
1230 retval
= dap_queue_dp_write(dap
, DP_CTRL_STAT
, dap
->dp_ctrl_stat
);
1231 if (retval
!= ERROR_OK
)
1234 retval
= dap_queue_dp_read(dap
, DP_CTRL_STAT
, &ctrlstat
);
1235 if (retval
!= ERROR_OK
)
1237 if ((retval
= dap_run(dap
)) != ERROR_OK
)
1240 /* Check that we have debug power domains activated */
1241 while (!(ctrlstat
& CDBGPWRUPACK
) && (cnt
++ < 10))
1243 LOG_DEBUG("DAP: wait CDBGPWRUPACK");
1244 retval
= dap_queue_dp_read(dap
, DP_CTRL_STAT
, &ctrlstat
);
1245 if (retval
!= ERROR_OK
)
1247 if ((retval
= dap_run(dap
)) != ERROR_OK
)
1252 while (!(ctrlstat
& CSYSPWRUPACK
) && (cnt
++ < 10))
1254 LOG_DEBUG("DAP: wait CSYSPWRUPACK");
1255 retval
= dap_queue_dp_read(dap
, DP_CTRL_STAT
, &ctrlstat
);
1256 if (retval
!= ERROR_OK
)
1258 if ((retval
= dap_run(dap
)) != ERROR_OK
)
1263 retval
= dap_queue_dp_read(dap
, DP_CTRL_STAT
, NULL
);
1264 if (retval
!= ERROR_OK
)
1266 /* With debug power on we can activate OVERRUN checking */
1267 dap
->dp_ctrl_stat
= CDBGPWRUPREQ
| CSYSPWRUPREQ
| CORUNDETECT
;
1268 retval
= dap_queue_dp_write(dap
, DP_CTRL_STAT
, dap
->dp_ctrl_stat
);
1269 if (retval
!= ERROR_OK
)
1271 retval
= dap_queue_dp_read(dap
, DP_CTRL_STAT
, NULL
);
1272 if (retval
!= ERROR_OK
)
1280 /* CID interpretation -- see ARM IHI 0029B section 3
1281 * and ARM IHI 0031A table 13-3.
1283 static const char *class_description
[16] ={
1284 "Reserved", "ROM table", "Reserved", "Reserved",
1285 "Reserved", "Reserved", "Reserved", "Reserved",
1286 "Reserved", "CoreSight component", "Reserved", "Peripheral Test Block",
1287 "Reserved", "OptimoDE DESS",
1288 "Generic IP component", "PrimeCell or System component"
1292 is_dap_cid_ok(uint32_t cid3
, uint32_t cid2
, uint32_t cid1
, uint32_t cid0
)
1294 return cid3
== 0xb1 && cid2
== 0x05
1295 && ((cid1
& 0x0f) == 0) && cid0
== 0x0d;
1298 int dap_get_debugbase(struct adiv5_dap
*dap
, int ap
,
1299 uint32_t *out_dbgbase
, uint32_t *out_apid
)
1303 uint32_t dbgbase
, apid
;
1305 /* AP address is in bits 31:24 of DP_SELECT */
1307 return ERROR_INVALID_ARGUMENTS
;
1309 ap_old
= dap
->ap_current
;
1310 dap_ap_select(dap
, ap
);
1312 retval
= dap_queue_ap_read(dap
, AP_REG_BASE
, &dbgbase
);
1313 if (retval
!= ERROR_OK
)
1315 retval
= dap_queue_ap_read(dap
, AP_REG_IDR
, &apid
);
1316 if (retval
!= ERROR_OK
)
1318 retval
= dap_run(dap
);
1319 if (retval
!= ERROR_OK
)
1322 /* Excavate the device ID code */
1323 struct jtag_tap
*tap
= dap
->jtag_info
->tap
;
1324 while (tap
!= NULL
) {
1327 tap
= tap
->next_tap
;
1329 if (tap
== NULL
|| !tap
->hasidcode
)
1332 dap_ap_select(dap
, ap_old
);
1334 /* The asignment happens only here to prevent modification of these
1335 * values before they are certain. */
1336 *out_dbgbase
= dbgbase
;
1342 int dap_lookup_cs_component(struct adiv5_dap
*dap
, int ap
,
1343 uint32_t dbgbase
, uint8_t type
, uint32_t *addr
)
1346 uint32_t romentry
, entry_offset
= 0, component_base
, devtype
;
1347 int retval
= ERROR_FAIL
;
1350 return ERROR_INVALID_ARGUMENTS
;
1352 ap_old
= dap
->ap_current
;
1353 dap_ap_select(dap
, ap
);
1357 retval
= mem_ap_read_atomic_u32(dap
, (dbgbase
&0xFFFFF000) |
1358 entry_offset
, &romentry
);
1359 if (retval
!= ERROR_OK
)
1362 component_base
= (dbgbase
& 0xFFFFF000)
1363 + (romentry
& 0xFFFFF000);
1365 if (romentry
& 0x1) {
1366 retval
= mem_ap_read_atomic_u32(dap
,
1367 (component_base
& 0xfffff000) | 0xfcc,
1369 if ((devtype
& 0xff) == type
) {
1370 *addr
= component_base
;
1376 } while (romentry
> 0);
1378 dap_ap_select(dap
, ap_old
);
1383 static int dap_info_command(struct command_context
*cmd_ctx
,
1384 struct adiv5_dap
*dap
, int ap
)
1387 uint32_t dbgbase
= 0, apid
= 0; /* Silence gcc by initializing */
1388 int romtable_present
= 0;
1392 retval
= dap_get_debugbase(dap
, ap
, &dbgbase
, &apid
);
1393 if (retval
!= ERROR_OK
)
1396 ap_old
= dap
->ap_current
;
1397 dap_ap_select(dap
, ap
);
1399 /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec */
1400 mem_ap
= ((apid
&0x10000) && ((apid
&0x0F) != 0));
1401 command_print(cmd_ctx
, "AP ID register 0x%8.8" PRIx32
, apid
);
1407 command_print(cmd_ctx
, "\tType is JTAG-AP");
1410 command_print(cmd_ctx
, "\tType is MEM-AP AHB");
1413 command_print(cmd_ctx
, "\tType is MEM-AP APB");
1416 command_print(cmd_ctx
, "\tUnknown AP type");
1420 /* NOTE: a MEM-AP may have a single CoreSight component that's
1421 * not a ROM table ... or have no such components at all.
1424 command_print(cmd_ctx
, "AP BASE 0x%8.8" PRIx32
,
1429 command_print(cmd_ctx
, "No AP found at this ap 0x%x", ap
);
1432 romtable_present
= ((mem_ap
) && (dbgbase
!= 0xFFFFFFFF));
1433 if (romtable_present
)
1435 uint32_t cid0
,cid1
,cid2
,cid3
,memtype
,romentry
;
1436 uint16_t entry_offset
;
1438 /* bit 16 of apid indicates a memory access port */
1440 command_print(cmd_ctx
, "\tValid ROM table present");
1442 command_print(cmd_ctx
, "\tROM table in legacy format");
1444 /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec */
1445 retval
= mem_ap_read_u32(dap
, (dbgbase
&0xFFFFF000) | 0xFF0, &cid0
);
1446 if (retval
!= ERROR_OK
)
1448 retval
= mem_ap_read_u32(dap
, (dbgbase
&0xFFFFF000) | 0xFF4, &cid1
);
1449 if (retval
!= ERROR_OK
)
1451 retval
= mem_ap_read_u32(dap
, (dbgbase
&0xFFFFF000) | 0xFF8, &cid2
);
1452 if (retval
!= ERROR_OK
)
1454 retval
= mem_ap_read_u32(dap
, (dbgbase
&0xFFFFF000) | 0xFFC, &cid3
);
1455 if (retval
!= ERROR_OK
)
1457 retval
= mem_ap_read_u32(dap
, (dbgbase
&0xFFFFF000) | 0xFCC, &memtype
);
1458 if (retval
!= ERROR_OK
)
1460 retval
= dap_run(dap
);
1461 if (retval
!= ERROR_OK
)
1464 if (!is_dap_cid_ok(cid3
, cid2
, cid1
, cid0
))
1465 command_print(cmd_ctx
, "\tCID3 0x%2.2x"
1469 (unsigned) cid3
, (unsigned)cid2
,
1470 (unsigned) cid1
, (unsigned) cid0
);
1472 command_print(cmd_ctx
, "\tMEMTYPE system memory present on bus");
1474 command_print(cmd_ctx
, "\tMEMTYPE System memory not present. "
1475 "Dedicated debug bus.");
1477 /* Now we read ROM table entries from dbgbase&0xFFFFF000) | 0x000 until we get 0x00000000 */
1481 retval
= mem_ap_read_atomic_u32(dap
, (dbgbase
&0xFFFFF000) | entry_offset
, &romentry
);
1482 if (retval
!= ERROR_OK
)
1484 command_print(cmd_ctx
, "\tROMTABLE[0x%x] = 0x%" PRIx32
"",entry_offset
,romentry
);
1487 uint32_t c_cid0
, c_cid1
, c_cid2
, c_cid3
;
1488 uint32_t c_pid0
, c_pid1
, c_pid2
, c_pid3
, c_pid4
;
1489 uint32_t component_base
;
1493 component_base
= (dbgbase
& 0xFFFFF000)
1494 + (romentry
& 0xFFFFF000);
1496 /* IDs are in last 4K section */
1499 retval
= mem_ap_read_atomic_u32(dap
,
1500 component_base
+ 0xFE0, &c_pid0
);
1501 if (retval
!= ERROR_OK
)
1504 retval
= mem_ap_read_atomic_u32(dap
,
1505 component_base
+ 0xFE4, &c_pid1
);
1506 if (retval
!= ERROR_OK
)
1509 retval
= mem_ap_read_atomic_u32(dap
,
1510 component_base
+ 0xFE8, &c_pid2
);
1511 if (retval
!= ERROR_OK
)
1514 retval
= mem_ap_read_atomic_u32(dap
,
1515 component_base
+ 0xFEC, &c_pid3
);
1516 if (retval
!= ERROR_OK
)
1519 retval
= mem_ap_read_atomic_u32(dap
,
1520 component_base
+ 0xFD0, &c_pid4
);
1521 if (retval
!= ERROR_OK
)
1525 retval
= mem_ap_read_atomic_u32(dap
,
1526 component_base
+ 0xFF0, &c_cid0
);
1527 if (retval
!= ERROR_OK
)
1530 retval
= mem_ap_read_atomic_u32(dap
,
1531 component_base
+ 0xFF4, &c_cid1
);
1532 if (retval
!= ERROR_OK
)
1535 retval
= mem_ap_read_atomic_u32(dap
,
1536 component_base
+ 0xFF8, &c_cid2
);
1537 if (retval
!= ERROR_OK
)
1540 retval
= mem_ap_read_atomic_u32(dap
,
1541 component_base
+ 0xFFC, &c_cid3
);
1542 if (retval
!= ERROR_OK
)
1547 command_print(cmd_ctx
,
1548 "\t\tComponent base address 0x%" PRIx32
1549 ", start address 0x%" PRIx32
,
1551 /* component may take multiple 4K pages */
1552 component_base
- 0x1000*(c_pid4
>> 4));
1553 command_print(cmd_ctx
, "\t\tComponent class is 0x%x, %s",
1554 (int) (c_cid1
>> 4) & 0xf,
1555 /* See ARM IHI 0029B Table 3-3 */
1556 class_description
[(c_cid1
>> 4) & 0xf]);
1558 /* CoreSight component? */
1559 if (((c_cid1
>> 4) & 0x0f) == 9) {
1562 char *major
= "Reserved", *subtype
= "Reserved";
1564 retval
= mem_ap_read_atomic_u32(dap
,
1565 (component_base
& 0xfffff000) | 0xfcc,
1567 if (retval
!= ERROR_OK
)
1569 minor
= (devtype
>> 4) & 0x0f;
1570 switch (devtype
& 0x0f) {
1572 major
= "Miscellaneous";
1578 subtype
= "Validation component";
1583 major
= "Trace Sink";
1597 major
= "Trace Link";
1603 subtype
= "Funnel, router";
1609 subtype
= "FIFO, buffer";
1614 major
= "Trace Source";
1620 subtype
= "Processor";
1626 subtype
= "Engine/Coprocessor";
1634 major
= "Debug Control";
1640 subtype
= "Trigger Matrix";
1643 subtype
= "Debug Auth";
1648 major
= "Debug Logic";
1654 subtype
= "Processor";
1660 subtype
= "Engine/Coprocessor";
1665 command_print(cmd_ctx
, "\t\tType is 0x%2.2x, %s, %s",
1666 (unsigned) (devtype
& 0xff),
1668 /* REVISIT also show 0xfc8 DevId */
1671 if (!is_dap_cid_ok(cid3
, cid2
, cid1
, cid0
))
1672 command_print(cmd_ctx
,
1681 command_print(cmd_ctx
,
1682 "\t\tPeripheral ID[4..0] = hex "
1683 "%2.2x %2.2x %2.2x %2.2x %2.2x",
1684 (int) c_pid4
, (int) c_pid3
, (int) c_pid2
,
1685 (int) c_pid1
, (int) c_pid0
);
1687 /* Part number interpretations are from Cortex
1688 * core specs, the CoreSight components TRM
1689 * (ARM DDI 0314H), CoreSight System Design
1690 * Guide (ARM DGI 0012D) and ETM specs; also
1691 * from chip observation (e.g. TI SDTI).
1693 part_num
= (c_pid0
& 0xff);
1694 part_num
|= (c_pid1
& 0x0f) << 8;
1697 type
= "Cortex-M3 NVIC";
1698 full
= "(Interrupt Controller)";
1701 type
= "Cortex-M3 ITM";
1702 full
= "(Instrumentation Trace Module)";
1705 type
= "Cortex-M3 DWT";
1706 full
= "(Data Watchpoint and Trace)";
1709 type
= "Cortex-M3 FBP";
1710 full
= "(Flash Patch and Breakpoint)";
1713 type
= "CoreSight ETM11";
1714 full
= "(Embedded Trace)";
1716 // case 0x113: what?
1717 case 0x120: /* from OMAP3 memmap */
1719 full
= "(System Debug Trace Interface)";
1721 case 0x343: /* from OMAP3 memmap */
1726 type
= "Coresight CTI";
1727 full
= "(Cross Trigger)";
1730 type
= "Coresight ETB";
1731 full
= "(Trace Buffer)";
1734 type
= "Coresight CSTF";
1735 full
= "(Trace Funnel)";
1738 type
= "CoreSight ETM9";
1739 full
= "(Embedded Trace)";
1742 type
= "Coresight TPIU";
1743 full
= "(Trace Port Interface Unit)";
1746 type
= "Cortex-A8 ETM";
1747 full
= "(Embedded Trace)";
1750 type
= "Cortex-A8 CTI";
1751 full
= "(Cross Trigger)";
1754 type
= "Cortex-M3 TPIU";
1755 full
= "(Trace Port Interface Unit)";
1758 type
= "Cortex-M3 ETM";
1759 full
= "(Embedded Trace)";
1762 type
= "Cortex-R4 ETM";
1763 full
= "(Embedded Trace)";
1766 type
= "Cortex-A8 Debug";
1767 full
= "(Debug Unit)";
1770 type
= "-*- unrecognized -*-";
1774 command_print(cmd_ctx
, "\t\tPart is %s %s",
1780 command_print(cmd_ctx
, "\t\tComponent not present");
1782 command_print(cmd_ctx
, "\t\tEnd of ROM table");
1785 } while (romentry
> 0);
1789 command_print(cmd_ctx
, "\tNo ROM table present");
1791 dap_ap_select(dap
, ap_old
);
1796 COMMAND_HANDLER(handle_dap_info_command
)
1798 struct target
*target
= get_current_target(CMD_CTX
);
1799 struct arm
*arm
= target_to_arm(target
);
1800 struct adiv5_dap
*dap
= arm
->dap
;
1808 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], apsel
);
1811 return ERROR_COMMAND_SYNTAX_ERROR
;
1814 return dap_info_command(CMD_CTX
, dap
, apsel
);
1817 COMMAND_HANDLER(dap_baseaddr_command
)
1819 struct target
*target
= get_current_target(CMD_CTX
);
1820 struct arm
*arm
= target_to_arm(target
);
1821 struct adiv5_dap
*dap
= arm
->dap
;
1823 uint32_t apsel
, baseaddr
;
1831 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], apsel
);
1832 /* AP address is in bits 31:24 of DP_SELECT */
1834 return ERROR_INVALID_ARGUMENTS
;
1837 return ERROR_COMMAND_SYNTAX_ERROR
;
1840 dap_ap_select(dap
, apsel
);
1842 /* NOTE: assumes we're talking to a MEM-AP, which
1843 * has a base address. There are other kinds of AP,
1844 * though they're not common for now. This should
1845 * use the ID register to verify it's a MEM-AP.
1847 retval
= dap_queue_ap_read(dap
, AP_REG_BASE
, &baseaddr
);
1848 if (retval
!= ERROR_OK
)
1850 retval
= dap_run(dap
);
1851 if (retval
!= ERROR_OK
)
1854 command_print(CMD_CTX
, "0x%8.8" PRIx32
, baseaddr
);
1859 COMMAND_HANDLER(dap_memaccess_command
)
1861 struct target
*target
= get_current_target(CMD_CTX
);
1862 struct arm
*arm
= target_to_arm(target
);
1863 struct adiv5_dap
*dap
= arm
->dap
;
1865 uint32_t memaccess_tck
;
1869 memaccess_tck
= dap
->memaccess_tck
;
1872 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], memaccess_tck
);
1875 return ERROR_COMMAND_SYNTAX_ERROR
;
1877 dap
->memaccess_tck
= memaccess_tck
;
1879 command_print(CMD_CTX
, "memory bus access delay set to %" PRIi32
" tck",
1880 dap
->memaccess_tck
);
1885 COMMAND_HANDLER(dap_apsel_command
)
1887 struct target
*target
= get_current_target(CMD_CTX
);
1888 struct arm
*arm
= target_to_arm(target
);
1889 struct adiv5_dap
*dap
= arm
->dap
;
1891 uint32_t apsel
, apid
;
1899 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], apsel
);
1900 /* AP address is in bits 31:24 of DP_SELECT */
1902 return ERROR_INVALID_ARGUMENTS
;
1905 return ERROR_COMMAND_SYNTAX_ERROR
;
1909 dap_ap_select(dap
, apsel
);
1911 retval
= dap_queue_ap_read(dap
, AP_REG_IDR
, &apid
);
1912 if (retval
!= ERROR_OK
)
1914 retval
= dap_run(dap
);
1915 if (retval
!= ERROR_OK
)
1918 command_print(CMD_CTX
, "ap %" PRIi32
" selected, identification register 0x%8.8" PRIx32
,
1924 COMMAND_HANDLER(dap_apid_command
)
1926 struct target
*target
= get_current_target(CMD_CTX
);
1927 struct arm
*arm
= target_to_arm(target
);
1928 struct adiv5_dap
*dap
= arm
->dap
;
1930 uint32_t apsel
, apid
;
1938 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], apsel
);
1939 /* AP address is in bits 31:24 of DP_SELECT */
1941 return ERROR_INVALID_ARGUMENTS
;
1944 return ERROR_COMMAND_SYNTAX_ERROR
;
1947 dap_ap_select(dap
, apsel
);
1949 retval
= dap_queue_ap_read(dap
, AP_REG_IDR
, &apid
);
1950 if (retval
!= ERROR_OK
)
1952 retval
= dap_run(dap
);
1953 if (retval
!= ERROR_OK
)
1956 command_print(CMD_CTX
, "0x%8.8" PRIx32
, apid
);
1961 static const struct command_registration dap_commands
[] = {
1964 .handler
= handle_dap_info_command
,
1965 .mode
= COMMAND_EXEC
,
1966 .help
= "display ROM table for MEM-AP "
1967 "(default currently selected AP)",
1968 .usage
= "[ap_num]",
1972 .handler
= dap_apsel_command
,
1973 .mode
= COMMAND_EXEC
,
1974 .help
= "Set the currently selected AP (default 0) "
1975 "and display the result",
1976 .usage
= "[ap_num]",
1980 .handler
= dap_apid_command
,
1981 .mode
= COMMAND_EXEC
,
1982 .help
= "return ID register from AP "
1983 "(default currently selected AP)",
1984 .usage
= "[ap_num]",
1988 .handler
= dap_baseaddr_command
,
1989 .mode
= COMMAND_EXEC
,
1990 .help
= "return debug base address from MEM-AP "
1991 "(default currently selected AP)",
1992 .usage
= "[ap_num]",
1995 .name
= "memaccess",
1996 .handler
= dap_memaccess_command
,
1997 .mode
= COMMAND_EXEC
,
1998 .help
= "set/get number of extra tck for MEM-AP memory "
1999 "bus access [0-255]",
2000 .usage
= "[cycles]",
2002 COMMAND_REGISTRATION_DONE
2005 const struct command_registration dap_command_handlers
[] = {
2008 .mode
= COMMAND_EXEC
,
2009 .help
= "DAP command group",
2010 .chain
= dap_commands
,
2012 COMMAND_REGISTRATION_DONE