target: use bool for backup_working_area
[openocd.git] / src / target / adi_v5_dapdirect.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /*
4 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
5 * Author(s): Antonio Borneo <borneo.antonio@gmail.com> for STMicroelectronics
6 */
7
8 /**
9 * @file
10 * Utilities to support in-circuit debuggers that provide APIs to access
11 * directly ARM DAP, hiding the access to the underlining transport used
12 * for the physical connection (either JTAG or SWD).
13 * E.g. STMicroelectronics ST-Link/V2 (from version V2J24) and STLINK-V3.
14 *
15 * Single-DAP support only.
16 *
17 * For details, see "ARM IHI 0031A"
18 * ARM Debug Interface v5 Architecture Specification
19 *
20 * FIXME: in JTAG mode, trst is not managed
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <jtag/interface.h>
28 #include <jtag/tcl.h>
29 #include <transport/transport.h>
30
31 COMMAND_HANDLER(dapdirect_jtag_empty_command)
32 {
33 LOG_DEBUG("dapdirect_jtag_empty_command(\"%s\")", CMD_NAME);
34
35 return ERROR_OK;
36 }
37
38 COMMAND_HANDLER(dapdirect_jtag_reset_command)
39 {
40 enum reset_types jtag_reset_config = jtag_get_reset_config();
41
42 /*
43 * in case the adapter has not already handled asserting srst
44 * we will attempt it again
45 */
46 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
47 if (jtag_reset_config & RESET_SRST_NO_GATING) {
48 adapter_assert_reset();
49 return ERROR_OK;
50 }
51 LOG_WARNING("\'srst_nogate\' reset_config option is required");
52 }
53 adapter_deassert_reset();
54 return ERROR_OK;
55 }
56
57 static const struct command_registration dapdirect_jtag_subcommand_handlers[] = {
58 {
59 .name = "newtap",
60 .mode = COMMAND_CONFIG,
61 .handler = handle_jtag_newtap,
62 .help = "declare a new TAP",
63 .usage = "basename tap_type '-irlen' count "
64 "['-enable'|'-disable'] "
65 "['-expected_id' number] "
66 "['-ignore-version'] "
67 "['-ignore-bypass'] "
68 "['-ircapture' number] "
69 "['-mask' number]",
70 },
71 {
72 .name = "init",
73 .mode = COMMAND_ANY,
74 .handler = dapdirect_jtag_empty_command,
75 .usage = ""
76 },
77 {
78 .name = "arp_init",
79 .mode = COMMAND_ANY,
80 .handler = dapdirect_jtag_empty_command,
81 .usage = ""
82 },
83 {
84 .name = "arp_init-reset",
85 .mode = COMMAND_ANY,
86 .handler = dapdirect_jtag_reset_command,
87 .usage = ""
88 },
89 {
90 .name = "tapisenabled",
91 .mode = COMMAND_EXEC,
92 .handler = handle_jtag_tap_enabler,
93 .help = "Returns a Tcl boolean (0/1) indicating whether "
94 "the TAP is enabled (1) or not (0).",
95 .usage = "tap_name",
96 },
97 {
98 .name = "tapenable",
99 .mode = COMMAND_EXEC,
100 .handler = handle_jtag_tap_enabler,
101 .help = "Try to enable the specified TAP using the "
102 "'tap-enable' TAP event.",
103 .usage = "tap_name",
104 },
105 {
106 .name = "tapdisable",
107 .mode = COMMAND_EXEC,
108 .handler = dapdirect_jtag_empty_command,
109 .usage = "",
110 },
111 {
112 .name = "configure",
113 .mode = COMMAND_ANY,
114 .handler = dapdirect_jtag_empty_command,
115 .usage = "",
116 },
117 {
118 .name = "cget",
119 .mode = COMMAND_EXEC,
120 .jim_handler = jim_jtag_configure,
121 },
122 {
123 .name = "names",
124 .mode = COMMAND_ANY,
125 .handler = dapdirect_jtag_empty_command,
126 .usage = "",
127 },
128 COMMAND_REGISTRATION_DONE
129 };
130
131 static const struct command_registration dapdirect_jtag_handlers[] = {
132 {
133 .name = "jtag",
134 .mode = COMMAND_ANY,
135 .chain = dapdirect_jtag_subcommand_handlers,
136 .usage = "",
137 },
138 {
139 .name = "jtag_ntrst_delay",
140 .mode = COMMAND_ANY,
141 .handler = dapdirect_jtag_empty_command,
142 .usage = "",
143 },
144 COMMAND_REGISTRATION_DONE
145 };
146
147 static const struct command_registration dapdirect_swd_subcommand_handlers[] = {
148 {
149 .name = "newdap",
150 .mode = COMMAND_CONFIG,
151 .handler = handle_jtag_newtap,
152 .help = "declare a new SWD DAP",
153 .usage = "basename dap_type ['-irlen' count] "
154 "['-enable'|'-disable'] "
155 "['-expected_id' number] "
156 "['-ignore-version'] "
157 "['-ignore-bypass'] "
158 "['-ircapture' number] "
159 "['-mask' number]",
160 },
161 COMMAND_REGISTRATION_DONE
162 };
163
164 static const struct command_registration dapdirect_swd_handlers[] = {
165 {
166 .name = "swd",
167 .mode = COMMAND_ANY,
168 .help = "SWD command group",
169 .usage = "",
170 .chain = dapdirect_swd_subcommand_handlers,
171 },
172 COMMAND_REGISTRATION_DONE
173 };
174
175 static int dapdirect_jtag_select(struct command_context *ctx)
176 {
177 LOG_DEBUG("dapdirect_jtag_select()");
178
179 return register_commands(ctx, NULL, dapdirect_jtag_handlers);
180 }
181
182 static int dapdirect_swd_select(struct command_context *ctx)
183 {
184 LOG_DEBUG("dapdirect_swd_select()");
185
186 return register_commands(ctx, NULL, dapdirect_swd_handlers);
187 }
188
189 static int dapdirect_init(struct command_context *ctx)
190 {
191 enum reset_types jtag_reset_config = jtag_get_reset_config();
192
193 LOG_DEBUG("dapdirect_init()");
194
195 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
196 if (jtag_reset_config & RESET_SRST_NO_GATING)
197 adapter_assert_reset();
198 else
199 LOG_WARNING("\'srst_nogate\' reset_config option is required");
200 } else
201 adapter_deassert_reset();
202
203 return ERROR_OK;
204 }
205
206 static struct transport dapdirect_jtag_transport = {
207 .name = "dapdirect_jtag",
208 .select = dapdirect_jtag_select,
209 .init = dapdirect_init,
210 };
211
212 static struct transport dapdirect_swd_transport = {
213 .name = "dapdirect_swd",
214 .select = dapdirect_swd_select,
215 .init = dapdirect_init,
216 };
217
218 static void dapdirect_constructor(void) __attribute__((constructor));
219 static void dapdirect_constructor(void)
220 {
221 transport_register(&dapdirect_jtag_transport);
222 transport_register(&dapdirect_swd_transport);
223 }
224
225 /**
226 * Returns true if the current debug session
227 * is using JTAG as its transport.
228 */
229 bool transport_is_dapdirect_jtag(void)
230 {
231 return get_current_transport() == &dapdirect_jtag_transport;
232 }
233
234 /**
235 * Returns true if the current debug session
236 * is using SWD as its transport.
237 */
238 bool transport_is_dapdirect_swd(void)
239 {
240 return get_current_transport() == &dapdirect_swd_transport;
241 }

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)