ad57cef940198a5e9fd8c28cf8ff4037054ec4c2
[openocd.git] / src / target / arm_jtag.c
1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "arm_jtag.h"
28
29 #include "binarybuffer.h"
30 #include "log.h"
31 #include "jtag.h"
32
33 #include <stdlib.h>
34
35 #if 0
36 #define _ARM_JTAG_SCAN_N_CHECK_
37 #endif
38
39 int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, void *no_verify_capture)
40 {
41 jtag_tap_t *tap;
42 tap = jtag_info->tap;
43 if (tap==NULL)
44 return ERROR_FAIL;
45
46 if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr)
47 {
48 scan_field_t field;
49 u8 t[4];
50
51 field.tap = tap;
52 field.num_bits = tap->ir_length;
53 field.out_value = t;
54 buf_set_u32(field.out_value, 0, field.num_bits, new_instr);
55 field.in_value = NULL;
56
57
58
59 if (no_verify_capture==NULL)
60 {
61 jtag_add_ir_scan(1, &field, TAP_INVALID);
62 } else
63 {
64 /* FIX!!!! this is a kludge!!! arm926ejs.c should reimplement this arm_jtag_set_instr to
65 * have special verification code.
66 */
67 jtag_add_ir_scan_noverify(1, &field, TAP_INVALID);
68 }
69 }
70
71 return ERROR_OK;
72 }
73
74 int arm_jtag_scann(arm_jtag_t *jtag_info, u32 new_scan_chain)
75 {
76 int retval = ERROR_OK;
77 if(jtag_info->cur_scan_chain != new_scan_chain)
78 {
79 u32 values[1];
80 int num_bits[1];
81
82 values[0]=new_scan_chain;
83 num_bits[0]=jtag_info->scann_size;
84
85 if((retval = arm_jtag_set_instr(jtag_info, jtag_info->scann_instr, NULL)) != ERROR_OK)
86 {
87 return retval;
88 }
89
90 jtag_add_dr_out(jtag_info->tap,
91 1,
92 num_bits,
93 values,
94 TAP_INVALID);
95
96 jtag_info->cur_scan_chain = new_scan_chain;
97 }
98
99 return retval;
100 }
101
102 int arm_jtag_reset_callback(enum jtag_event event, void *priv)
103 {
104 arm_jtag_t *jtag_info = priv;
105
106 if (event == JTAG_TRST_ASSERTED)
107 {
108 jtag_info->cur_scan_chain = 0;
109 }
110
111 return ERROR_OK;
112 }
113
114 int arm_jtag_setup_connection(arm_jtag_t *jtag_info)
115 {
116 jtag_info->scann_instr = 0x2;
117 jtag_info->cur_scan_chain = 0;
118 jtag_info->intest_instr = 0xc;
119
120 return jtag_register_event_callback(arm_jtag_reset_callback, jtag_info);
121 }
122
123 /* read JTAG buffer into host-endian u32, flipping bit-order */
124 int arm_jtag_buf_to_u32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
125 {
126 u32 *dest = priv;
127 *dest = flip_u32(le_to_h_u32(in_buf), 32);
128 return ERROR_OK;
129 }
130
131 /* read JTAG buffer into little-endian u32, flipping bit-order */
132 int arm_jtag_buf_to_le32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
133 {
134 h_u32_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
135 return ERROR_OK;
136 }
137
138 /* read JTAG buffer into little-endian u16, flipping bit-order */
139 int arm_jtag_buf_to_le16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
140 {
141 h_u16_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
142 return ERROR_OK;
143 }
144
145 /* read JTAG buffer into big-endian u32, flipping bit-order */
146 int arm_jtag_buf_to_be32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
147 {
148 h_u32_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
149 return ERROR_OK;
150 }
151
152 /* read JTAG buffer into big-endian u16, flipping bit-order */
153 int arm_jtag_buf_to_be16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
154 {
155 h_u16_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
156 return ERROR_OK;
157 }
158
159 /* read JTAG buffer into u8, flipping bit-order */
160 int arm_jtag_buf_to_8_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
161 {
162 u8 *dest = priv;
163 *dest = flip_u32(le_to_h_u32(in_buf), 32) & 0xff;
164 return ERROR_OK;
165 }
166
167 /* not-flipping variants */
168 /* read JTAG buffer into host-endian u32 */
169 int arm_jtag_buf_to_u32(u8 *in_buf, void *priv, struct scan_field_s *field)
170 {
171 u32 *dest = priv;
172 *dest = le_to_h_u32(in_buf);
173 return ERROR_OK;
174 }
175
176 /* read JTAG buffer into little-endian u32 */
177 int arm_jtag_buf_to_le32(u8 *in_buf, void *priv, struct scan_field_s *field)
178 {
179 h_u32_to_le(((u8*)priv), le_to_h_u32(in_buf));
180 return ERROR_OK;
181 }
182
183 /* read JTAG buffer into little-endian u16 */
184 int arm_jtag_buf_to_le16(u8 *in_buf, void *priv, struct scan_field_s *field)
185 {
186 h_u16_to_le(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
187 return ERROR_OK;
188 }
189
190 /* read JTAG buffer into big-endian u32 */
191 int arm_jtag_buf_to_be32(u8 *in_buf, void *priv, struct scan_field_s *field)
192 {
193 h_u32_to_be(((u8*)priv), le_to_h_u32(in_buf));
194 return ERROR_OK;
195 }
196
197 /* read JTAG buffer into big-endian u16 */
198 int arm_jtag_buf_to_be16(u8 *in_buf, void *priv, struct scan_field_s *field)
199 {
200 h_u16_to_be(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
201 return ERROR_OK;
202 }
203
204 /* read JTAG buffer into u8 */
205 int arm_jtag_buf_to_8(u8 *in_buf, void *priv, struct scan_field_s *field)
206 {
207 u8 *dest = priv;
208 *dest = le_to_h_u32(in_buf) & 0xff;
209 return ERROR_OK;
210 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)