e7dbea4fa7e432fbf3b4c724d1da644fe8894a48
[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
30 #if 0
31 #define _ARM_JTAG_SCAN_N_CHECK_
32 #endif
33
34 int arm_jtag_set_instr(struct arm_jtag *jtag_info, uint32_t new_instr, void *no_verify_capture)
35 {
36 struct jtag_tap *tap;
37 tap = jtag_info->tap;
38 if (tap == NULL)
39 return ERROR_FAIL;
40
41 if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr)
42 {
43 struct scan_field field;
44 uint8_t t[4];
45
46 field.tap = tap;
47 field.num_bits = tap->ir_length;
48 field.out_value = t;
49 buf_set_u32(field.out_value, 0, field.num_bits, new_instr);
50 field.in_value = NULL;
51
52
53
54 if (no_verify_capture == NULL)
55 {
56 jtag_add_ir_scan(1, &field, jtag_get_end_state());
57 } else
58 {
59 /* FIX!!!! this is a kludge!!! arm926ejs.c should reimplement this arm_jtag_set_instr to
60 * have special verification code.
61 */
62 jtag_add_ir_scan_noverify(1, &field, jtag_get_end_state());
63 }
64 }
65
66 return ERROR_OK;
67 }
68
69 int arm_jtag_scann(struct arm_jtag *jtag_info, uint32_t new_scan_chain)
70 {
71 int retval = ERROR_OK;
72 if (jtag_info->cur_scan_chain != new_scan_chain)
73 {
74 uint32_t values[1];
75 int num_bits[1];
76
77 values[0]=new_scan_chain;
78 num_bits[0]=jtag_info->scann_size;
79
80 if ((retval = arm_jtag_set_instr(jtag_info, jtag_info->scann_instr, NULL)) != ERROR_OK)
81 {
82 return retval;
83 }
84
85 jtag_add_dr_out(jtag_info->tap,
86 1,
87 num_bits,
88 values,
89 jtag_get_end_state());
90
91 jtag_info->cur_scan_chain = new_scan_chain;
92 }
93
94 return retval;
95 }
96
97 int arm_jtag_reset_callback(enum jtag_event event, void *priv)
98 {
99 struct arm_jtag *jtag_info = priv;
100
101 if (event == JTAG_TRST_ASSERTED)
102 {
103 jtag_info->cur_scan_chain = 0;
104 }
105
106 return ERROR_OK;
107 }
108
109 int arm_jtag_setup_connection(struct arm_jtag *jtag_info)
110 {
111 jtag_info->scann_instr = 0x2;
112 jtag_info->cur_scan_chain = 0;
113 jtag_info->intest_instr = 0xc;
114
115 return jtag_register_event_callback(arm_jtag_reset_callback, jtag_info);
116 }
117
118 /* read JTAG buffer into host-endian uint32_t, flipping bit-order */
119 int arm_jtag_buf_to_u32_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
120 {
121 uint32_t *dest = priv;
122 *dest = flip_u32(le_to_h_u32(in_buf), 32);
123 return ERROR_OK;
124 }
125
126 /* read JTAG buffer into little-endian uint32_t, flipping bit-order */
127 int arm_jtag_buf_to_le32_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
128 {
129 h_u32_to_le(((uint8_t*)priv), flip_u32(le_to_h_u32(in_buf), 32));
130 return ERROR_OK;
131 }
132
133 /* read JTAG buffer into little-endian uint16_t, flipping bit-order */
134 int arm_jtag_buf_to_le16_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
135 {
136 h_u16_to_le(((uint8_t*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
137 return ERROR_OK;
138 }
139
140 /* read JTAG buffer into big-endian uint32_t, flipping bit-order */
141 int arm_jtag_buf_to_be32_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
142 {
143 h_u32_to_be(((uint8_t*)priv), flip_u32(le_to_h_u32(in_buf), 32));
144 return ERROR_OK;
145 }
146
147 /* read JTAG buffer into big-endian uint16_t, flipping bit-order */
148 int arm_jtag_buf_to_be16_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
149 {
150 h_u16_to_be(((uint8_t*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
151 return ERROR_OK;
152 }
153
154 /* read JTAG buffer into uint8_t, flipping bit-order */
155 int arm_jtag_buf_to_8_flip(uint8_t *in_buf, void *priv, struct scan_field_s *field)
156 {
157 uint8_t *dest = priv;
158 *dest = flip_u32(le_to_h_u32(in_buf), 32) & 0xff;
159 return ERROR_OK;
160 }
161
162 /* not-flipping variants */
163 /* read JTAG buffer into host-endian uint32_t */
164 int arm_jtag_buf_to_u32(uint8_t *in_buf, void *priv, struct scan_field_s *field)
165 {
166 uint32_t *dest = priv;
167 *dest = le_to_h_u32(in_buf);
168 return ERROR_OK;
169 }
170
171 /* read JTAG buffer into little-endian uint32_t */
172 int arm_jtag_buf_to_le32(uint8_t *in_buf, void *priv, struct scan_field_s *field)
173 {
174 h_u32_to_le(((uint8_t*)priv), le_to_h_u32(in_buf));
175 return ERROR_OK;
176 }
177
178 /* read JTAG buffer into little-endian uint16_t */
179 int arm_jtag_buf_to_le16(uint8_t *in_buf, void *priv, struct scan_field_s *field)
180 {
181 h_u16_to_le(((uint8_t*)priv), le_to_h_u32(in_buf) & 0xffff);
182 return ERROR_OK;
183 }
184
185 /* read JTAG buffer into big-endian uint32_t */
186 int arm_jtag_buf_to_be32(uint8_t *in_buf, void *priv, struct scan_field_s *field)
187 {
188 h_u32_to_be(((uint8_t*)priv), le_to_h_u32(in_buf));
189 return ERROR_OK;
190 }
191
192 /* read JTAG buffer into big-endian uint16_t */
193 int arm_jtag_buf_to_be16(uint8_t *in_buf, void *priv, struct scan_field_s *field)
194 {
195 h_u16_to_be(((uint8_t*)priv), le_to_h_u32(in_buf) & 0xffff);
196 return ERROR_OK;
197 }
198
199 /* read JTAG buffer into uint8_t */
200 int arm_jtag_buf_to_8(uint8_t *in_buf, void *priv, struct scan_field_s *field)
201 {
202 uint8_t *dest = priv;
203 *dest = le_to_h_u32(in_buf) & 0xff;
204 return ERROR_OK;
205 }

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)