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 by Oyvind Harboe *
9 * oyvind.harboe@zylin.com *
11 * Copyright (C) 2009-2010 by David Brownell *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
18 * This program is distributed in the hope that it will be useful, *
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21 * GNU General Public License for more details. *
23 * You should have received a copy of the GNU General Public License *
24 * along with this program; if not, write to the *
25 * Free Software Foundation, Inc., *
26 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
27 ***************************************************************************/
31 * This file implements support for the ARM Debug Interface version 5 (ADIv5)
32 * debugging architecture. Compared with previous versions, this includes
33 * a low pin-count Serial Wire Debug (SWD) alternative to JTAG for message
34 * transport, and focusses on memory mapped resources as defined by the
35 * CoreSight architecture.
37 * A key concept in ADIv5 is the Debug Access Port, or DAP. A DAP has two
38 * basic components: a Debug Port (DP) transporting messages to and from a
39 * debugger, and an Access Port (AP) accessing resources. Three types of DP
40 * are defined. One uses only JTAG for communication, and is called JTAG-DP.
41 * One uses only SWD for communication, and is called SW-DP. The third can
42 * use either SWD or JTAG, and is called SWJ-DP. The most common type of AP
43 * is used to access memory mapped resources and is called a MEM-AP. Also a
44 * JTAG-AP is also defined, bridging to JTAG resources; those are uncommon.
48 * Relevant specifications from ARM include:
50 * ARM(tm) Debug Interface v5 Architecture Specification ARM IHI 0031A
51 * CoreSight(tm) v1.0 Architecture Specification ARM IHI 0029B
53 * CoreSight(tm) DAP-Lite TRM, ARM DDI 0316D
54 * Cortex-M3(tm) TRM, ARM DDI 0337G
61 #include "arm_adi_v5.h"
62 #include <helper/time_support.h>
66 * swjdp->trans_mode = TRANS_MODE_COMPOSITE;
67 * Uses Overrun checking mode and does not do actual JTAG send/receive or transaction
68 * result checking until swjdp_end_transaction()
69 * This must be done before using or deallocating any return variables.
70 * swjdp->trans_mode == TRANS_MODE_ATOMIC
71 * All reads and writes to the AHB bus are checked for valid completion, and return values
72 * are immediatley available.
76 /* ARM ADI Specification requires at least 10 bits used for TAR autoincrement */
79 uint32_t tar_block_size(uint32_t address)
80 Return the largest block starting at address that does not cross a tar block size alignment boundary
82 static uint32_t max_tar_block_size(uint32_t tar_autoincr_block
, uint32_t address
)
84 return (tar_autoincr_block
- ((tar_autoincr_block
- 1) & address
)) >> 2;
87 /***************************************************************************
89 * DPACC and APACC scanchain access through JTAG-DP *
91 ***************************************************************************/
94 * Scan DPACC or APACC using target ordered uint8_t buffers. No endianness
95 * conversions are performed. See section 4.4.3 of the ADIv5 spec, which
96 * discusses operations which access these registers.
98 * Note that only one scan is performed. If RnW is set, a separate scan
99 * will be needed to collect the data which was read; the "invalue" collects
100 * the posted result of a preceding operation, not the current one.
102 * @param swjdp the DAP
103 * @param instr JTAG_DP_APACC (AP access) or JTAG_DP_DPACC (DP access)
104 * @param reg_addr two significant bits; A[3:2]; for APACC access, the
105 * SELECT register has more addressing bits.
106 * @param RnW false iff outvalue will be written to the DP or AP
107 * @param outvalue points to a 32-bit (little-endian) integer
108 * @param invalue NULL, or points to a 32-bit (little-endian) integer
109 * @param ack points to where the three bit JTAG_ACK_* code will be stored
111 static int adi_jtag_dp_scan(struct swjdp_common
*swjdp
,
112 uint8_t instr
, uint8_t reg_addr
, uint8_t RnW
,
113 uint8_t *outvalue
, uint8_t *invalue
, uint8_t *ack
)
115 struct arm_jtag
*jtag_info
= swjdp
->jtag_info
;
116 struct scan_field fields
[2];
117 uint8_t out_addr_buf
;
119 jtag_set_end_state(TAP_IDLE
);
120 arm_jtag_set_instr(jtag_info
, instr
, NULL
);
122 /* Add specified number of tck clocks before accessing memory bus */
124 /* REVISIT these TCK cycles should be *AFTER* updating APACC, since
125 * they provide more time for the (MEM) AP to complete the read ...
126 * See "Minimum Response Time" for JTAG-DP, in the ADIv5 spec.
128 if ((instr
== JTAG_DP_APACC
)
129 && ((reg_addr
== AP_REG_DRW
)
130 || ((reg_addr
& 0xF0) == AP_REG_BD0
))
131 && (swjdp
->memaccess_tck
!= 0))
132 jtag_add_runtest(swjdp
->memaccess_tck
, jtag_set_end_state(TAP_IDLE
));
134 /* Scan out a read or write operation using some DP or AP register.
135 * For APACC access with any sticky error flag set, this is discarded.
137 fields
[0].tap
= jtag_info
->tap
;
138 fields
[0].num_bits
= 3;
139 buf_set_u32(&out_addr_buf
, 0, 3, ((reg_addr
>> 1) & 0x6) | (RnW
& 0x1));
140 fields
[0].out_value
= &out_addr_buf
;
141 fields
[0].in_value
= ack
;
143 /* NOTE: if we receive JTAG_ACK_WAIT, the previous operation did not
144 * complete; data we write is discarded, data we read is unpredictable.
145 * When overrun detect is active, STICKYORUN is set.
148 fields
[1].tap
= jtag_info
->tap
;
149 fields
[1].num_bits
= 32;
150 fields
[1].out_value
= outvalue
;
151 fields
[1].in_value
= invalue
;
153 jtag_add_dr_scan(2, fields
, jtag_get_end_state());
158 /* Scan out and in from host ordered uint32_t variables */
159 static int adi_jtag_dp_scan_u32(struct swjdp_common
*swjdp
,
160 uint8_t instr
, uint8_t reg_addr
, uint8_t RnW
,
161 uint32_t outvalue
, uint32_t *invalue
, uint8_t *ack
)
163 struct arm_jtag
*jtag_info
= swjdp
->jtag_info
;
164 struct scan_field fields
[2];
165 uint8_t out_value_buf
[4];
166 uint8_t out_addr_buf
;
168 jtag_set_end_state(TAP_IDLE
);
169 arm_jtag_set_instr(jtag_info
, instr
, NULL
);
171 /* Add specified number of tck clocks before accessing memory bus */
173 /* REVISIT these TCK cycles should be *AFTER* updating APACC, since
174 * they provide more time for the (MEM) AP to complete the read ...
176 if ((instr
== JTAG_DP_APACC
)
177 && ((reg_addr
== AP_REG_DRW
)
178 || ((reg_addr
& 0xF0) == AP_REG_BD0
))
179 && (swjdp
->memaccess_tck
!= 0))
180 jtag_add_runtest(swjdp
->memaccess_tck
, jtag_set_end_state(TAP_IDLE
));
182 fields
[0].tap
= jtag_info
->tap
;
183 fields
[0].num_bits
= 3;
184 buf_set_u32(&out_addr_buf
, 0, 3, ((reg_addr
>> 1) & 0x6) | (RnW
& 0x1));
185 fields
[0].out_value
= &out_addr_buf
;
186 fields
[0].in_value
= ack
;
188 fields
[1].tap
= jtag_info
->tap
;
189 fields
[1].num_bits
= 32;
190 buf_set_u32(out_value_buf
, 0, 32, outvalue
);
191 fields
[1].out_value
= out_value_buf
;
192 fields
[1].in_value
= NULL
;
196 fields
[1].in_value
= (uint8_t *)invalue
;
197 jtag_add_dr_scan(2, fields
, jtag_get_end_state());
199 jtag_add_callback(arm_le_to_h_u32
, (jtag_callback_data_t
) invalue
);
203 jtag_add_dr_scan(2, fields
, jtag_get_end_state());
209 /* scan_inout_check adds one extra inscan for DPAP_READ commands to read variables */
210 static int scan_inout_check(struct swjdp_common
*swjdp
,
211 uint8_t instr
, uint8_t reg_addr
, uint8_t RnW
,
212 uint8_t *outvalue
, uint8_t *invalue
)
214 adi_jtag_dp_scan(swjdp
, instr
, reg_addr
, RnW
, outvalue
, NULL
, NULL
);
216 if ((RnW
== DPAP_READ
) && (invalue
!= NULL
))
217 adi_jtag_dp_scan(swjdp
, JTAG_DP_DPACC
,
218 DP_RDBUFF
, DPAP_READ
, 0, invalue
, &swjdp
->ack
);
220 /* In TRANS_MODE_ATOMIC all JTAG_DP_APACC transactions wait for
221 * ack = OK/FAULT and the check CTRL_STAT
223 if ((instr
== JTAG_DP_APACC
)
224 && (swjdp
->trans_mode
== TRANS_MODE_ATOMIC
))
225 return jtagdp_transaction_endcheck(swjdp
);
230 static int scan_inout_check_u32(struct swjdp_common
*swjdp
,
231 uint8_t instr
, uint8_t reg_addr
, uint8_t RnW
,
232 uint32_t outvalue
, uint32_t *invalue
)
234 /* Issue the read or write */
235 adi_jtag_dp_scan_u32(swjdp
, instr
, reg_addr
, RnW
, outvalue
, NULL
, NULL
);
237 /* For reads, collect posted value; RDBUFF has no other effect.
238 * Assumes read gets acked with OK/FAULT, and CTRL_STAT says "OK".
240 if ((RnW
== DPAP_READ
) && (invalue
!= NULL
))
241 adi_jtag_dp_scan_u32(swjdp
, JTAG_DP_DPACC
,
242 DP_RDBUFF
, DPAP_READ
, 0, invalue
, &swjdp
->ack
);
244 /* In TRANS_MODE_ATOMIC all JTAG_DP_APACC transactions wait for
245 * ack = OK/FAULT and then check CTRL_STAT
247 if ((instr
== JTAG_DP_APACC
)
248 && (swjdp
->trans_mode
== TRANS_MODE_ATOMIC
))
249 return jtagdp_transaction_endcheck(swjdp
);
254 int jtagdp_transaction_endcheck(struct swjdp_common
*swjdp
)
259 /* too expensive to call keep_alive() here */
262 /* Danger!!!! BROKEN!!!! */
263 scan_inout_check_u32(swjdp
, JTAG_DP_DPACC
,
264 DP_CTRL_STAT
, DPAP_READ
, 0, &ctrlstat
);
265 /* Danger!!!! BROKEN!!!! Why will jtag_execute_queue() fail here????
266 R956 introduced the check on return value here and now Michael Schwingen reports
267 that this code no longer works....
269 https://lists.berlios.de/pipermail/openocd-development/2008-September/003107.html
271 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
273 LOG_ERROR("BUG: Why does this fail the first time????");
275 /* Why??? second time it works??? */
278 /* Post CTRL/STAT read; discard any previous posted read value
279 * but collect its ACK status.
281 scan_inout_check_u32(swjdp
, JTAG_DP_DPACC
,
282 DP_CTRL_STAT
, DPAP_READ
, 0, &ctrlstat
);
283 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
286 swjdp
->ack
= swjdp
->ack
& 0x7;
288 /* common code path avoids calling timeval_ms() */
289 if (swjdp
->ack
!= JTAG_ACK_OK_FAULT
)
291 long long then
= timeval_ms();
293 while (swjdp
->ack
!= JTAG_ACK_OK_FAULT
)
295 if (swjdp
->ack
== JTAG_ACK_WAIT
)
297 if ((timeval_ms()-then
) > 1000)
299 /* NOTE: this would be a good spot
300 * to use JTAG_DP_ABORT.
302 LOG_WARNING("Timeout (1000ms) waiting "
304 "in JTAG-DP transaction");
305 return ERROR_JTAG_DEVICE_ERROR
;
310 LOG_WARNING("Invalid ACK %#x "
311 "in JTAG-DP transaction",
313 return ERROR_JTAG_DEVICE_ERROR
;
316 scan_inout_check_u32(swjdp
, JTAG_DP_DPACC
,
317 DP_CTRL_STAT
, DPAP_READ
, 0, &ctrlstat
);
318 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
320 swjdp
->ack
= swjdp
->ack
& 0x7;
324 /* REVISIT also STICKYCMP, for pushed comparisons (nyet used) */
326 /* Check for STICKYERR and STICKYORUN */
327 if (ctrlstat
& (SSTICKYORUN
| SSTICKYERR
))
329 LOG_DEBUG("jtag-dp: CTRL/STAT error, 0x%" PRIx32
, ctrlstat
);
330 /* Check power to debug regions */
331 if ((ctrlstat
& 0xf0000000) != 0xf0000000)
332 ahbap_debugport_init(swjdp
);
335 uint32_t mem_ap_csw
, mem_ap_tar
;
337 /* Maybe print information about last MEM-AP access */
338 if (swjdp
->ap_tar_value
!= (uint32_t) -1)
339 LOG_DEBUG("MEM-AP Cached values: "
341 ", ap_csw 0x%" PRIx32
342 ", ap_tar 0x%" PRIx32
,
343 swjdp
->dp_select_value
,
345 swjdp
->ap_tar_value
);
347 LOG_ERROR("Invalid MEM-AP TAR cache!");
349 if (ctrlstat
& SSTICKYORUN
)
350 LOG_ERROR("JTAG-DP OVERRUN - check clock, "
351 "memaccess, or reduce jtag speed");
353 if (ctrlstat
& SSTICKYERR
)
354 LOG_ERROR("JTAG-DP STICKY ERROR");
356 /* Clear Sticky Error Bits */
357 scan_inout_check_u32(swjdp
, JTAG_DP_DPACC
,
358 DP_CTRL_STAT
, DPAP_WRITE
,
359 swjdp
->dp_ctrl_stat
| SSTICKYORUN
361 scan_inout_check_u32(swjdp
, JTAG_DP_DPACC
,
362 DP_CTRL_STAT
, DPAP_READ
, 0, &ctrlstat
);
363 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
366 LOG_DEBUG("jtag-dp: CTRL/STAT 0x%" PRIx32
, ctrlstat
);
368 dap_ap_read_reg_u32(swjdp
, AP_REG_CSW
, &mem_ap_csw
);
369 dap_ap_read_reg_u32(swjdp
, AP_REG_TAR
, &mem_ap_tar
);
370 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
372 LOG_ERROR("MEM_AP_CSW 0x%" PRIx32
", MEM_AP_TAR 0x%"
373 PRIx32
, mem_ap_csw
, mem_ap_tar
);
376 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
378 return ERROR_JTAG_DEVICE_ERROR
;
384 /***************************************************************************
386 * DP and MEM-AP register access through APACC and DPACC *
388 ***************************************************************************/
390 static int dap_dp_write_reg(struct swjdp_common
*swjdp
,
391 uint32_t value
, uint8_t reg_addr
)
393 return scan_inout_check_u32(swjdp
, JTAG_DP_DPACC
,
394 reg_addr
, DPAP_WRITE
, value
, NULL
);
397 static int dap_dp_read_reg(struct swjdp_common
*swjdp
,
398 uint32_t *value
, uint8_t reg_addr
)
400 return scan_inout_check_u32(swjdp
, JTAG_DP_DPACC
,
401 reg_addr
, DPAP_READ
, 0, value
);
404 int dap_ap_select(struct swjdp_common
*swjdp
,uint8_t apsel
)
407 select
= (apsel
<< 24) & 0xFF000000;
409 if (select
!= swjdp
->apsel
)
411 swjdp
->apsel
= select
;
412 /* Switching AP invalidates cached values */
413 swjdp
->dp_select_value
= -1;
414 swjdp
->ap_csw_value
= -1;
415 swjdp
->ap_tar_value
= -1;
421 static int dap_dp_bankselect(struct swjdp_common
*swjdp
, uint32_t ap_reg
)
424 select
= (ap_reg
& 0x000000F0);
426 if (select
!= swjdp
->dp_select_value
)
428 dap_dp_write_reg(swjdp
, select
| swjdp
->apsel
, DP_SELECT
);
429 swjdp
->dp_select_value
= select
;
435 static int dap_ap_write_reg(struct swjdp_common
*swjdp
,
436 uint32_t reg_addr
, uint8_t *out_value_buf
)
438 dap_dp_bankselect(swjdp
, reg_addr
);
439 scan_inout_check(swjdp
, JTAG_DP_APACC
, reg_addr
,
440 DPAP_WRITE
, out_value_buf
, NULL
);
445 int dap_ap_write_reg_u32(struct swjdp_common
*swjdp
, uint32_t reg_addr
, uint32_t value
)
447 uint8_t out_value_buf
[4];
449 buf_set_u32(out_value_buf
, 0, 32, value
);
450 dap_dp_bankselect(swjdp
, reg_addr
);
451 scan_inout_check(swjdp
, JTAG_DP_APACC
, reg_addr
,
452 DPAP_WRITE
, out_value_buf
, NULL
);
457 int dap_ap_read_reg_u32(struct swjdp_common
*swjdp
, uint32_t reg_addr
, uint32_t *value
)
459 dap_dp_bankselect(swjdp
, reg_addr
);
460 scan_inout_check_u32(swjdp
, JTAG_DP_APACC
, reg_addr
,
461 DPAP_READ
, 0, value
);
466 /***************************************************************************
468 * AHB-AP access to memory and system registers on AHB bus *
470 ***************************************************************************/
472 int dap_setup_accessport(struct swjdp_common
*swjdp
, uint32_t csw
, uint32_t tar
)
474 csw
= csw
| CSW_DBGSWENABLE
| CSW_MASTER_DEBUG
| CSW_HPROT
;
475 if (csw
!= swjdp
->ap_csw_value
)
477 /* LOG_DEBUG("DAP: Set CSW %x",csw); */
478 dap_ap_write_reg_u32(swjdp
, AP_REG_CSW
, csw
);
479 swjdp
->ap_csw_value
= csw
;
481 if (tar
!= swjdp
->ap_tar_value
)
483 /* LOG_DEBUG("DAP: Set TAR %x",tar); */
484 dap_ap_write_reg_u32(swjdp
, AP_REG_TAR
, tar
);
485 swjdp
->ap_tar_value
= tar
;
487 if (csw
& CSW_ADDRINC_MASK
)
489 /* Do not cache TAR value when autoincrementing */
490 swjdp
->ap_tar_value
= -1;
495 /*****************************************************************************
497 * mem_ap_read_u32(struct swjdp_common *swjdp, uint32_t address, uint32_t *value) *
499 * Read a uint32_t value from memory or system register *
500 * Functionally equivalent to target_read_u32(target, address, uint32_t *value), *
501 * but with less overhead *
502 *****************************************************************************/
503 int mem_ap_read_u32(struct swjdp_common
*swjdp
, uint32_t address
, uint32_t *value
)
505 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
507 dap_setup_accessport(swjdp
, CSW_32BIT
| CSW_ADDRINC_OFF
, address
& 0xFFFFFFF0);
508 dap_ap_read_reg_u32(swjdp
, AP_REG_BD0
| (address
& 0xC), value
);
513 int mem_ap_read_atomic_u32(struct swjdp_common
*swjdp
, uint32_t address
, uint32_t *value
)
515 mem_ap_read_u32(swjdp
, address
, value
);
517 return jtagdp_transaction_endcheck(swjdp
);
520 /*****************************************************************************
522 * mem_ap_write_u32(struct swjdp_common *swjdp, uint32_t address, uint32_t value) *
524 * Write a uint32_t value to memory or memory mapped register *
526 *****************************************************************************/
527 int mem_ap_write_u32(struct swjdp_common
*swjdp
, uint32_t address
, uint32_t value
)
529 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
531 dap_setup_accessport(swjdp
, CSW_32BIT
| CSW_ADDRINC_OFF
, address
& 0xFFFFFFF0);
532 dap_ap_write_reg_u32(swjdp
, AP_REG_BD0
| (address
& 0xC), value
);
537 int mem_ap_write_atomic_u32(struct swjdp_common
*swjdp
, uint32_t address
, uint32_t value
)
539 mem_ap_write_u32(swjdp
, address
, value
);
541 return jtagdp_transaction_endcheck(swjdp
);
544 /*****************************************************************************
546 * mem_ap_write_buf(struct swjdp_common *swjdp, uint8_t *buffer, int count, uint32_t address) *
548 * Write a buffer in target order (little endian) *
550 *****************************************************************************/
551 int mem_ap_write_buf_u32(struct swjdp_common
*swjdp
, uint8_t *buffer
, int count
, uint32_t address
)
553 int wcount
, blocksize
, writecount
, errorcount
= 0, retval
= ERROR_OK
;
554 uint32_t adr
= address
;
555 uint8_t* pBuffer
= buffer
;
557 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
562 /* if we have an unaligned access - reorder data */
565 for (writecount
= 0; writecount
< count
; writecount
++)
569 memcpy(&outvalue
, pBuffer
, sizeof(uint32_t));
571 for (i
= 0; i
< 4; i
++)
573 *((uint8_t*)pBuffer
+ (adr
& 0x3)) = outvalue
;
577 pBuffer
+= sizeof(uint32_t);
583 /* Adjust to write blocks within boundaries aligned to the TAR autoincremnent size*/
584 blocksize
= max_tar_block_size(swjdp
->tar_autoincr_block
, address
);
585 if (wcount
< blocksize
)
588 /* handle unaligned data at 4k boundary */
592 dap_setup_accessport(swjdp
, CSW_32BIT
| CSW_ADDRINC_SINGLE
, address
);
594 for (writecount
= 0; writecount
< blocksize
; writecount
++)
596 dap_ap_write_reg(swjdp
, AP_REG_DRW
, buffer
+ 4 * writecount
);
599 if (jtagdp_transaction_endcheck(swjdp
) == ERROR_OK
)
601 wcount
= wcount
- blocksize
;
602 address
= address
+ 4 * blocksize
;
603 buffer
= buffer
+ 4 * blocksize
;
612 LOG_WARNING("Block write error address 0x%" PRIx32
", wcount 0x%x", address
, wcount
);
613 return ERROR_JTAG_DEVICE_ERROR
;
620 static int mem_ap_write_buf_packed_u16(struct swjdp_common
*swjdp
,
621 uint8_t *buffer
, int count
, uint32_t address
)
623 int retval
= ERROR_OK
;
624 int wcount
, blocksize
, writecount
, i
;
626 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
634 /* Adjust to write blocks within boundaries aligned to the TAR autoincremnent size*/
635 blocksize
= max_tar_block_size(swjdp
->tar_autoincr_block
, address
);
637 if (wcount
< blocksize
)
640 /* handle unaligned data at 4k boundary */
644 dap_setup_accessport(swjdp
, CSW_16BIT
| CSW_ADDRINC_PACKED
, address
);
645 writecount
= blocksize
;
649 nbytes
= MIN((writecount
<< 1), 4);
653 if (mem_ap_write_buf_u16(swjdp
, buffer
,
654 nbytes
, address
) != ERROR_OK
)
656 LOG_WARNING("Block write error address "
657 "0x%" PRIx32
", count 0x%x",
659 return ERROR_JTAG_DEVICE_ERROR
;
662 address
+= nbytes
>> 1;
667 memcpy(&outvalue
, buffer
, sizeof(uint32_t));
669 for (i
= 0; i
< nbytes
; i
++)
671 *((uint8_t*)buffer
+ (address
& 0x3)) = outvalue
;
676 memcpy(&outvalue
, buffer
, sizeof(uint32_t));
677 dap_ap_write_reg_u32(swjdp
, AP_REG_DRW
, outvalue
);
678 if (jtagdp_transaction_endcheck(swjdp
) != ERROR_OK
)
680 LOG_WARNING("Block write error address "
681 "0x%" PRIx32
", count 0x%x",
683 return ERROR_JTAG_DEVICE_ERROR
;
687 buffer
+= nbytes
>> 1;
688 writecount
-= nbytes
>> 1;
690 } while (writecount
);
697 int mem_ap_write_buf_u16(struct swjdp_common
*swjdp
, uint8_t *buffer
, int count
, uint32_t address
)
699 int retval
= ERROR_OK
;
702 return mem_ap_write_buf_packed_u16(swjdp
, buffer
, count
, address
);
704 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
708 dap_setup_accessport(swjdp
, CSW_16BIT
| CSW_ADDRINC_SINGLE
, address
);
710 memcpy(&svalue
, buffer
, sizeof(uint16_t));
711 uint32_t outvalue
= (uint32_t)svalue
<< 8 * (address
& 0x3);
712 dap_ap_write_reg_u32(swjdp
, AP_REG_DRW
, outvalue
);
713 retval
= jtagdp_transaction_endcheck(swjdp
);
722 static int mem_ap_write_buf_packed_u8(struct swjdp_common
*swjdp
,
723 uint8_t *buffer
, int count
, uint32_t address
)
725 int retval
= ERROR_OK
;
726 int wcount
, blocksize
, writecount
, i
;
728 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
736 /* Adjust to write blocks within boundaries aligned to the TAR autoincremnent size*/
737 blocksize
= max_tar_block_size(swjdp
->tar_autoincr_block
, address
);
739 if (wcount
< blocksize
)
742 dap_setup_accessport(swjdp
, CSW_8BIT
| CSW_ADDRINC_PACKED
, address
);
743 writecount
= blocksize
;
747 nbytes
= MIN(writecount
, 4);
751 if (mem_ap_write_buf_u8(swjdp
, buffer
, nbytes
, address
) != ERROR_OK
)
753 LOG_WARNING("Block write error address "
754 "0x%" PRIx32
", count 0x%x",
756 return ERROR_JTAG_DEVICE_ERROR
;
764 memcpy(&outvalue
, buffer
, sizeof(uint32_t));
766 for (i
= 0; i
< nbytes
; i
++)
768 *((uint8_t*)buffer
+ (address
& 0x3)) = outvalue
;
773 memcpy(&outvalue
, buffer
, sizeof(uint32_t));
774 dap_ap_write_reg_u32(swjdp
, AP_REG_DRW
, outvalue
);
775 if (jtagdp_transaction_endcheck(swjdp
) != ERROR_OK
)
777 LOG_WARNING("Block write error address "
778 "0x%" PRIx32
", count 0x%x",
780 return ERROR_JTAG_DEVICE_ERROR
;
785 writecount
-= nbytes
;
787 } while (writecount
);
794 int mem_ap_write_buf_u8(struct swjdp_common
*swjdp
, uint8_t *buffer
, int count
, uint32_t address
)
796 int retval
= ERROR_OK
;
799 return mem_ap_write_buf_packed_u8(swjdp
, buffer
, count
, address
);
801 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
805 dap_setup_accessport(swjdp
, CSW_8BIT
| CSW_ADDRINC_SINGLE
, address
);
806 uint32_t outvalue
= (uint32_t)*buffer
<< 8 * (address
& 0x3);
807 dap_ap_write_reg_u32(swjdp
, AP_REG_DRW
, outvalue
);
808 retval
= jtagdp_transaction_endcheck(swjdp
);
817 /*********************************************************************************
819 * mem_ap_read_buf_u32(struct swjdp_common *swjdp, uint8_t *buffer, int count, uint32_t address) *
821 * Read block fast in target order (little endian) into a buffer *
823 **********************************************************************************/
824 int mem_ap_read_buf_u32(struct swjdp_common
*swjdp
, uint8_t *buffer
, int count
, uint32_t address
)
826 int wcount
, blocksize
, readcount
, errorcount
= 0, retval
= ERROR_OK
;
827 uint32_t adr
= address
;
828 uint8_t* pBuffer
= buffer
;
830 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
837 /* Adjust to read blocks within boundaries aligned to the TAR autoincremnent size*/
838 blocksize
= max_tar_block_size(swjdp
->tar_autoincr_block
, address
);
839 if (wcount
< blocksize
)
842 /* handle unaligned data at 4k boundary */
846 dap_setup_accessport(swjdp
, CSW_32BIT
| CSW_ADDRINC_SINGLE
, address
);
848 /* Scan out first read */
849 adi_jtag_dp_scan(swjdp
, JTAG_DP_APACC
, AP_REG_DRW
,
850 DPAP_READ
, 0, NULL
, NULL
);
851 for (readcount
= 0; readcount
< blocksize
- 1; readcount
++)
853 /* Scan out next read; scan in posted value for the
854 * previous one. Assumes read is acked "OK/FAULT",
855 * and CTRL_STAT says that meant "OK".
857 adi_jtag_dp_scan(swjdp
, JTAG_DP_APACC
, AP_REG_DRW
,
858 DPAP_READ
, 0, buffer
+ 4 * readcount
,
862 /* Scan in last posted value; RDBUFF has no other effect,
863 * assuming ack is OK/FAULT and CTRL_STAT says "OK".
865 adi_jtag_dp_scan(swjdp
, JTAG_DP_DPACC
, DP_RDBUFF
,
866 DPAP_READ
, 0, buffer
+ 4 * readcount
,
868 if (jtagdp_transaction_endcheck(swjdp
) == ERROR_OK
)
870 wcount
= wcount
- blocksize
;
871 address
+= 4 * blocksize
;
872 buffer
+= 4 * blocksize
;
881 LOG_WARNING("Block read error address 0x%" PRIx32
", count 0x%x", address
, count
);
882 return ERROR_JTAG_DEVICE_ERROR
;
886 /* if we have an unaligned access - reorder data */
889 for (readcount
= 0; readcount
< count
; readcount
++)
893 memcpy(&data
, pBuffer
, sizeof(uint32_t));
895 for (i
= 0; i
< 4; i
++)
897 *((uint8_t*)pBuffer
) = (data
>> 8 * (adr
& 0x3));
907 static int mem_ap_read_buf_packed_u16(struct swjdp_common
*swjdp
,
908 uint8_t *buffer
, int count
, uint32_t address
)
911 int retval
= ERROR_OK
;
912 int wcount
, blocksize
, readcount
, i
;
914 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
922 /* Adjust to read blocks within boundaries aligned to the TAR autoincremnent size*/
923 blocksize
= max_tar_block_size(swjdp
->tar_autoincr_block
, address
);
924 if (wcount
< blocksize
)
927 dap_setup_accessport(swjdp
, CSW_16BIT
| CSW_ADDRINC_PACKED
, address
);
929 /* handle unaligned data at 4k boundary */
932 readcount
= blocksize
;
936 dap_ap_read_reg_u32(swjdp
, AP_REG_DRW
, &invalue
);
937 if (jtagdp_transaction_endcheck(swjdp
) != ERROR_OK
)
939 LOG_WARNING("Block read error address 0x%" PRIx32
", count 0x%x", address
, count
);
940 return ERROR_JTAG_DEVICE_ERROR
;
943 nbytes
= MIN((readcount
<< 1), 4);
945 for (i
= 0; i
< nbytes
; i
++)
947 *((uint8_t*)buffer
) = (invalue
>> 8 * (address
& 0x3));
952 readcount
-= (nbytes
>> 1);
960 int mem_ap_read_buf_u16(struct swjdp_common
*swjdp
, uint8_t *buffer
, int count
, uint32_t address
)
963 int retval
= ERROR_OK
;
966 return mem_ap_read_buf_packed_u16(swjdp
, buffer
, count
, address
);
968 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
972 dap_setup_accessport(swjdp
, CSW_16BIT
| CSW_ADDRINC_SINGLE
, address
);
973 dap_ap_read_reg_u32(swjdp
, AP_REG_DRW
, &invalue
);
974 retval
= jtagdp_transaction_endcheck(swjdp
);
977 for (i
= 0; i
< 2; i
++)
979 *((uint8_t*)buffer
) = (invalue
>> 8 * (address
& 0x3));
986 uint16_t svalue
= (invalue
>> 8 * (address
& 0x3));
987 memcpy(buffer
, &svalue
, sizeof(uint16_t));
997 /* FIX!!! is this a potential performance bottleneck w.r.t. requiring too many
998 * roundtrips when jtag_execute_queue() has a large overhead(e.g. for USB)s?
1000 * The solution is to arrange for a large out/in scan in this loop and
1001 * and convert data afterwards.
1003 static int mem_ap_read_buf_packed_u8(struct swjdp_common
*swjdp
,
1004 uint8_t *buffer
, int count
, uint32_t address
)
1007 int retval
= ERROR_OK
;
1008 int wcount
, blocksize
, readcount
, i
;
1010 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
1018 /* Adjust to read blocks within boundaries aligned to the TAR autoincremnent size*/
1019 blocksize
= max_tar_block_size(swjdp
->tar_autoincr_block
, address
);
1021 if (wcount
< blocksize
)
1024 dap_setup_accessport(swjdp
, CSW_8BIT
| CSW_ADDRINC_PACKED
, address
);
1025 readcount
= blocksize
;
1029 dap_ap_read_reg_u32(swjdp
, AP_REG_DRW
, &invalue
);
1030 if (jtagdp_transaction_endcheck(swjdp
) != ERROR_OK
)
1032 LOG_WARNING("Block read error address 0x%" PRIx32
", count 0x%x", address
, count
);
1033 return ERROR_JTAG_DEVICE_ERROR
;
1036 nbytes
= MIN(readcount
, 4);
1038 for (i
= 0; i
< nbytes
; i
++)
1040 *((uint8_t*)buffer
) = (invalue
>> 8 * (address
& 0x3));
1045 readcount
-= nbytes
;
1046 } while (readcount
);
1047 wcount
-= blocksize
;
1053 int mem_ap_read_buf_u8(struct swjdp_common
*swjdp
, uint8_t *buffer
, int count
, uint32_t address
)
1056 int retval
= ERROR_OK
;
1059 return mem_ap_read_buf_packed_u8(swjdp
, buffer
, count
, address
);
1061 swjdp
->trans_mode
= TRANS_MODE_COMPOSITE
;
1065 dap_setup_accessport(swjdp
, CSW_8BIT
| CSW_ADDRINC_SINGLE
, address
);
1066 dap_ap_read_reg_u32(swjdp
, AP_REG_DRW
, &invalue
);
1067 retval
= jtagdp_transaction_endcheck(swjdp
);
1068 *((uint8_t*)buffer
) = (invalue
>> 8 * (address
& 0x3));
1080 * @todo Rename this. We also need an initialization scheme which account
1081 * for SWD transports not just JTAG; that will need to address differences
1082 * in layering. (JTAG is useful without any debug target; but not SWD.)
1083 * And this may not even use an AHB-AP ... e.g. DAP-Lite uses an APB-AP.
1085 int ahbap_debugport_init(struct swjdp_common
*swjdp
)
1087 uint32_t idreg
, romaddr
, dummy
;
1094 /* Default MEM-AP setup.
1096 * REVISIT AP #0 may be an inappropriate default for this.
1097 * Should we probe, or receve a hint from the caller?
1098 * Presumably we can ignore the possibility of multiple APs.
1101 swjdp
->ap_csw_value
= -1;
1102 swjdp
->ap_tar_value
= -1;
1104 /* DP initialization */
1105 swjdp
->trans_mode
= TRANS_MODE_ATOMIC
;
1106 dap_dp_read_reg(swjdp
, &dummy
, DP_CTRL_STAT
);
1107 dap_dp_write_reg(swjdp
, SSTICKYERR
, DP_CTRL_STAT
);
1108 dap_dp_read_reg(swjdp
, &dummy
, DP_CTRL_STAT
);
1110 swjdp
->dp_ctrl_stat
= CDBGPWRUPREQ
| CSYSPWRUPREQ
;
1112 dap_dp_write_reg(swjdp
, swjdp
->dp_ctrl_stat
, DP_CTRL_STAT
);
1113 dap_dp_read_reg(swjdp
, &ctrlstat
, DP_CTRL_STAT
);
1114 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
1117 /* Check that we have debug power domains activated */
1118 while (!(ctrlstat
& CDBGPWRUPACK
) && (cnt
++ < 10))
1120 LOG_DEBUG("DAP: wait CDBGPWRUPACK");
1121 dap_dp_read_reg(swjdp
, &ctrlstat
, DP_CTRL_STAT
);
1122 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
1127 while (!(ctrlstat
& CSYSPWRUPACK
) && (cnt
++ < 10))
1129 LOG_DEBUG("DAP: wait CSYSPWRUPACK");
1130 dap_dp_read_reg(swjdp
, &ctrlstat
, DP_CTRL_STAT
);
1131 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
1136 dap_dp_read_reg(swjdp
, &dummy
, DP_CTRL_STAT
);
1137 /* With debug power on we can activate OVERRUN checking */
1138 swjdp
->dp_ctrl_stat
= CDBGPWRUPREQ
| CSYSPWRUPREQ
| CORUNDETECT
;
1139 dap_dp_write_reg(swjdp
, swjdp
->dp_ctrl_stat
, DP_CTRL_STAT
);
1140 dap_dp_read_reg(swjdp
, &dummy
, DP_CTRL_STAT
);
1143 * REVISIT this isn't actually *initializing* anything in an AP,
1144 * and doesn't care if it's a MEM-AP at all (much less AHB-AP).
1145 * Should it? If the ROM address is valid, is this the right
1146 * place to scan the table and do any topology detection?
1148 dap_ap_read_reg_u32(swjdp
, AP_REG_IDR
, &idreg
);
1149 dap_ap_read_reg_u32(swjdp
, AP_REG_BASE
, &romaddr
);
1151 LOG_DEBUG("MEM-AP #%d ID Register 0x%" PRIx32
1152 ", Debug ROM Address 0x%" PRIx32
,
1153 swjdp
->apsel
, idreg
, romaddr
);
1158 /* CID interpretation -- see ARM IHI 0029B section 3
1159 * and ARM IHI 0031A table 13-3.
1161 static const char *class_description
[16] ={
1162 "Reserved", "ROM table", "Reserved", "Reserved",
1163 "Reserved", "Reserved", "Reserved", "Reserved",
1164 "Reserved", "CoreSight component", "Reserved", "Peripheral Test Block",
1165 "Reserved", "OptimoDE DESS",
1166 "Generic IP component", "PrimeCell or System component"
1170 is_dap_cid_ok(uint32_t cid3
, uint32_t cid2
, uint32_t cid1
, uint32_t cid0
)
1172 return cid3
== 0xb1 && cid2
== 0x05
1173 && ((cid1
& 0x0f) == 0) && cid0
== 0x0d;
1176 int dap_info_command(struct command_context
*cmd_ctx
,
1177 struct swjdp_common
*swjdp
, int apsel
)
1180 uint32_t dbgbase
, apid
;
1181 int romtable_present
= 0;
1185 /* AP address is in bits 31:24 of DP_SELECT */
1187 return ERROR_INVALID_ARGUMENTS
;
1189 apselold
= swjdp
->apsel
;
1190 dap_ap_select(swjdp
, apsel
);
1191 dap_ap_read_reg_u32(swjdp
, AP_REG_BASE
, &dbgbase
);
1192 dap_ap_read_reg_u32(swjdp
, AP_REG_IDR
, &apid
);
1193 jtagdp_transaction_endcheck(swjdp
);
1194 /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec */
1195 mem_ap
= ((apid
&0x10000) && ((apid
&0x0F) != 0));
1196 command_print(cmd_ctx
, "AP ID register 0x%8.8" PRIx32
, apid
);
1202 command_print(cmd_ctx
, "\tType is JTAG-AP");
1205 command_print(cmd_ctx
, "\tType is MEM-AP AHB");
1208 command_print(cmd_ctx
, "\tType is MEM-AP APB");
1211 command_print(cmd_ctx
, "\tUnknown AP type");
1215 /* NOTE: a MEM-AP may have a single CoreSight component that's
1216 * not a ROM table ... or have no such components at all.
1219 command_print(cmd_ctx
, "AP BASE 0x%8.8" PRIx32
,
1224 command_print(cmd_ctx
, "No AP found at this apsel 0x%x", apsel
);
1227 romtable_present
= ((mem_ap
) && (dbgbase
!= 0xFFFFFFFF));
1228 if (romtable_present
)
1230 uint32_t cid0
,cid1
,cid2
,cid3
,memtype
,romentry
;
1231 uint16_t entry_offset
;
1233 /* bit 16 of apid indicates a memory access port */
1235 command_print(cmd_ctx
, "\tValid ROM table present");
1237 command_print(cmd_ctx
, "\tROM table in legacy format");
1239 /* Now we read ROM table ID registers, ref. ARM IHI 0029B sec */
1240 mem_ap_read_u32(swjdp
, (dbgbase
&0xFFFFF000) | 0xFF0, &cid0
);
1241 mem_ap_read_u32(swjdp
, (dbgbase
&0xFFFFF000) | 0xFF4, &cid1
);
1242 mem_ap_read_u32(swjdp
, (dbgbase
&0xFFFFF000) | 0xFF8, &cid2
);
1243 mem_ap_read_u32(swjdp
, (dbgbase
&0xFFFFF000) | 0xFFC, &cid3
);
1244 mem_ap_read_u32(swjdp
, (dbgbase
&0xFFFFF000) | 0xFCC, &memtype
);
1245 jtagdp_transaction_endcheck(swjdp
);
1246 if (!is_dap_cid_ok(cid3
, cid2
, cid1
, cid0
))
1247 command_print(cmd_ctx
, "\tCID3 0x%2.2" PRIx32
1248 ", CID2 0x%2.2" PRIx32
1249 ", CID1 0x%2.2" PRIx32
1250 ", CID0 0x%2.2" PRIx32
,
1251 cid3
, cid2
, cid1
, cid0
);
1253 command_print(cmd_ctx
, "\tMEMTYPE system memory present on bus");
1255 command_print(cmd_ctx
, "\tMEMTYPE System memory not present. "
1256 "Dedicated debug bus.");
1258 /* Now we read ROM table entries from dbgbase&0xFFFFF000) | 0x000 until we get 0x00000000 */
1262 mem_ap_read_atomic_u32(swjdp
, (dbgbase
&0xFFFFF000) | entry_offset
, &romentry
);
1263 command_print(cmd_ctx
, "\tROMTABLE[0x%x] = 0x%" PRIx32
"",entry_offset
,romentry
);
1266 uint32_t c_cid0
, c_cid1
, c_cid2
, c_cid3
;
1267 uint32_t c_pid0
, c_pid1
, c_pid2
, c_pid3
, c_pid4
;
1268 uint32_t component_start
, component_base
;
1272 component_base
= (uint32_t)((dbgbase
& 0xFFFFF000)
1273 + (int)(romentry
& 0xFFFFF000));
1274 mem_ap_read_atomic_u32(swjdp
,
1275 (component_base
& 0xFFFFF000) | 0xFE0, &c_pid0
);
1276 mem_ap_read_atomic_u32(swjdp
,
1277 (component_base
& 0xFFFFF000) | 0xFE4, &c_pid1
);
1278 mem_ap_read_atomic_u32(swjdp
,
1279 (component_base
& 0xFFFFF000) | 0xFE8, &c_pid2
);
1280 mem_ap_read_atomic_u32(swjdp
,
1281 (component_base
& 0xFFFFF000) | 0xFEC, &c_pid3
);
1282 mem_ap_read_atomic_u32(swjdp
,
1283 (component_base
& 0xFFFFF000) | 0xFD0, &c_pid4
);
1284 mem_ap_read_atomic_u32(swjdp
,
1285 (component_base
& 0xFFFFF000) | 0xFF0, &c_cid0
);
1286 mem_ap_read_atomic_u32(swjdp
,
1287 (component_base
& 0xFFFFF000) | 0xFF4, &c_cid1
);
1288 mem_ap_read_atomic_u32(swjdp
,
1289 (component_base
& 0xFFFFF000) | 0xFF8, &c_cid2
);
1290 mem_ap_read_atomic_u32(swjdp
,
1291 (component_base
& 0xFFFFF000) | 0xFFC, &c_cid3
);
1292 component_start
= component_base
- 0x1000*(c_pid4
>> 4);
1294 command_print(cmd_ctx
, "\t\tComponent base address 0x%" PRIx32
1295 ", start address 0x%" PRIx32
,
1296 component_base
, component_start
);
1297 command_print(cmd_ctx
, "\t\tComponent class is 0x%x, %s",
1298 (int) (c_cid1
>> 4) & 0xf,
1299 /* See ARM IHI 0029B Table 3-3 */
1300 class_description
[(c_cid1
>> 4) & 0xf]);
1302 /* CoreSight component? */
1303 if (((c_cid1
>> 4) & 0x0f) == 9) {
1306 char *major
= "Reserved", *subtype
= "Reserved";
1308 mem_ap_read_atomic_u32(swjdp
,
1309 (component_base
& 0xfffff000) | 0xfcc,
1311 minor
= (devtype
>> 4) & 0x0f;
1312 switch (devtype
& 0x0f) {
1314 major
= "Miscellaneous";
1320 subtype
= "Validation component";
1325 major
= "Trace Sink";
1339 major
= "Trace Link";
1345 subtype
= "Funnel, router";
1351 subtype
= "FIFO, buffer";
1356 major
= "Trace Source";
1362 subtype
= "Processor";
1368 subtype
= "Engine/Coprocessor";
1376 major
= "Debug Control";
1382 subtype
= "Trigger Matrix";
1385 subtype
= "Debug Auth";
1390 major
= "Debug Logic";
1396 subtype
= "Processor";
1402 subtype
= "Engine/Coprocessor";
1407 command_print(cmd_ctx
, "\t\tType is 0x%2.2x, %s, %s",
1408 (unsigned) (devtype
& 0xff),
1410 /* REVISIT also show 0xfc8 DevId */
1413 if (!is_dap_cid_ok(cid3
, cid2
, cid1
, cid0
))
1414 command_print(cmd_ctx
, "\t\tCID3 0x%2.2" PRIx32
1415 ", CID2 0x%2.2" PRIx32
1416 ", CID1 0x%2.2" PRIx32
1417 ", CID0 0x%2.2" PRIx32
,
1418 c_cid3
, c_cid2
, c_cid1
, c_cid0
);
1419 command_print(cmd_ctx
, "\t\tPeripheral ID[4..0] = hex "
1420 "%2.2x %2.2x %2.2x %2.2x %2.2x",
1422 (int) c_pid3
, (int) c_pid2
,
1423 (int) c_pid1
, (int) c_pid0
);
1425 /* Part number interpretations are from Cortex
1426 * core specs, the CoreSight components TRM
1427 * (ARM DDI 0314H), and ETM specs; also from
1428 * chip observation (e.g. TI SDTI).
1430 part_num
= c_pid0
& 0xff;
1431 part_num
|= (c_pid1
& 0x0f) << 8;
1434 type
= "Cortex-M3 NVIC";
1435 full
= "(Interrupt Controller)";
1438 type
= "Cortex-M3 ITM";
1439 full
= "(Instrumentation Trace Module)";
1442 type
= "Cortex-M3 DWT";
1443 full
= "(Data Watchpoint and Trace)";
1446 type
= "Cortex-M3 FBP";
1447 full
= "(Flash Patch and Breakpoint)";
1450 type
= "CoreSight ETM11";
1451 full
= "(Embedded Trace)";
1453 // case 0x113: what?
1454 case 0x120: /* from OMAP3 memmap */
1456 full
= "(System Debug Trace Interface)";
1458 case 0x343: /* from OMAP3 memmap */
1463 type
= "Cortex-M3 ETM";
1464 full
= "(Embedded Trace)";
1467 type
= "Coresight CTI";
1468 full
= "(Cross Trigger)";
1471 type
= "Coresight ETB";
1472 full
= "(Trace Buffer)";
1475 type
= "Coresight CSTF";
1476 full
= "(Trace Funnel)";
1479 type
= "CoreSight ETM9";
1480 full
= "(Embedded Trace)";
1483 type
= "Coresight TPIU";
1484 full
= "(Trace Port Interface Unit)";
1487 type
= "Cortex-A8 ETM";
1488 full
= "(Embedded Trace)";
1491 type
= "Cortex-A8 CTI";
1492 full
= "(Cross Trigger)";
1495 type
= "Cortex-M3 TPIU";
1496 full
= "(Trace Port Interface Unit)";
1499 type
= "Cortex-A8 Debug";
1500 full
= "(Debug Unit)";
1503 type
= "-*- unrecognized -*-";
1507 command_print(cmd_ctx
, "\t\tPart is %s %s",
1513 command_print(cmd_ctx
, "\t\tComponent not present");
1515 command_print(cmd_ctx
, "\t\tEnd of ROM table");
1518 } while (romentry
> 0);
1522 command_print(cmd_ctx
, "\tNo ROM table present");
1524 dap_ap_select(swjdp
, apselold
);
1529 DAP_COMMAND_HANDLER(dap_baseaddr_command
)
1531 uint32_t apsel
, apselsave
, baseaddr
;
1534 apselsave
= swjdp
->apsel
;
1537 apsel
= swjdp
->apsel
;
1540 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], apsel
);
1541 /* AP address is in bits 31:24 of DP_SELECT */
1543 return ERROR_INVALID_ARGUMENTS
;
1546 return ERROR_COMMAND_SYNTAX_ERROR
;
1549 if (apselsave
!= apsel
)
1550 dap_ap_select(swjdp
, apsel
);
1552 /* NOTE: assumes we're talking to a MEM-AP, which
1553 * has a base address. There are other kinds of AP,
1554 * though they're not common for now. This should
1555 * use the ID register to verify it's a MEM-AP.
1557 dap_ap_read_reg_u32(swjdp
, AP_REG_BASE
, &baseaddr
);
1558 retval
= jtagdp_transaction_endcheck(swjdp
);
1559 command_print(CMD_CTX
, "0x%8.8" PRIx32
, baseaddr
);
1561 if (apselsave
!= apsel
)
1562 dap_ap_select(swjdp
, apselsave
);
1567 DAP_COMMAND_HANDLER(dap_memaccess_command
)
1569 uint32_t memaccess_tck
;
1573 memaccess_tck
= swjdp
->memaccess_tck
;
1576 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], memaccess_tck
);
1579 return ERROR_COMMAND_SYNTAX_ERROR
;
1581 swjdp
->memaccess_tck
= memaccess_tck
;
1583 command_print(CMD_CTX
, "memory bus access delay set to %" PRIi32
" tck",
1584 swjdp
->memaccess_tck
);
1589 DAP_COMMAND_HANDLER(dap_apsel_command
)
1591 uint32_t apsel
, apid
;
1599 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], apsel
);
1600 /* AP address is in bits 31:24 of DP_SELECT */
1602 return ERROR_INVALID_ARGUMENTS
;
1605 return ERROR_COMMAND_SYNTAX_ERROR
;
1608 dap_ap_select(swjdp
, apsel
);
1609 dap_ap_read_reg_u32(swjdp
, AP_REG_IDR
, &apid
);
1610 retval
= jtagdp_transaction_endcheck(swjdp
);
1611 command_print(CMD_CTX
, "ap %" PRIi32
" selected, identification register 0x%8.8" PRIx32
,
1617 DAP_COMMAND_HANDLER(dap_apid_command
)
1619 uint32_t apsel
, apselsave
, apid
;
1622 apselsave
= swjdp
->apsel
;
1625 apsel
= swjdp
->apsel
;
1628 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], apsel
);
1629 /* AP address is in bits 31:24 of DP_SELECT */
1631 return ERROR_INVALID_ARGUMENTS
;
1634 return ERROR_COMMAND_SYNTAX_ERROR
;
1637 if (apselsave
!= apsel
)
1638 dap_ap_select(swjdp
, apsel
);
1640 dap_ap_read_reg_u32(swjdp
, AP_REG_IDR
, &apid
);
1641 retval
= jtagdp_transaction_endcheck(swjdp
);
1642 command_print(CMD_CTX
, "0x%8.8" PRIx32
, apid
);
1643 if (apselsave
!= apsel
)
1644 dap_ap_select(swjdp
, apselsave
);