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

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)