jtag: rewrite commands 'jtag newtap' and 'swd newdap' as COMMAND_HANDLER
[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 .jim_handler = jim_jtag_tap_enabler,
93 },
94 {
95 .name = "tapenable",
96 .mode = COMMAND_EXEC,
97 .jim_handler = jim_jtag_tap_enabler,
98 },
99 {
100 .name = "tapdisable",
101 .mode = COMMAND_EXEC,
102 .handler = dapdirect_jtag_empty_command,
103 .usage = "",
104 },
105 {
106 .name = "configure",
107 .mode = COMMAND_ANY,
108 .handler = dapdirect_jtag_empty_command,
109 .usage = "",
110 },
111 {
112 .name = "cget",
113 .mode = COMMAND_EXEC,
114 .jim_handler = jim_jtag_configure,
115 },
116 {
117 .name = "names",
118 .mode = COMMAND_ANY,
119 .handler = dapdirect_jtag_empty_command,
120 .usage = "",
121 },
122 COMMAND_REGISTRATION_DONE
123 };
124
125 static const struct command_registration dapdirect_jtag_handlers[] = {
126 {
127 .name = "jtag",
128 .mode = COMMAND_ANY,
129 .chain = dapdirect_jtag_subcommand_handlers,
130 .usage = "",
131 },
132 {
133 .name = "jtag_ntrst_delay",
134 .mode = COMMAND_ANY,
135 .handler = dapdirect_jtag_empty_command,
136 .usage = "",
137 },
138 COMMAND_REGISTRATION_DONE
139 };
140
141 static const struct command_registration dapdirect_swd_subcommand_handlers[] = {
142 {
143 .name = "newdap",
144 .mode = COMMAND_CONFIG,
145 .handler = handle_jtag_newtap,
146 .help = "declare a new SWD DAP",
147 .usage = "basename dap_type ['-irlen' count] "
148 "['-enable'|'-disable'] "
149 "['-expected_id' number] "
150 "['-ignore-version'] "
151 "['-ignore-bypass'] "
152 "['-ircapture' number] "
153 "['-mask' number]",
154 },
155 COMMAND_REGISTRATION_DONE
156 };
157
158 static const struct command_registration dapdirect_swd_handlers[] = {
159 {
160 .name = "swd",
161 .mode = COMMAND_ANY,
162 .help = "SWD command group",
163 .usage = "",
164 .chain = dapdirect_swd_subcommand_handlers,
165 },
166 COMMAND_REGISTRATION_DONE
167 };
168
169 static int dapdirect_jtag_select(struct command_context *ctx)
170 {
171 LOG_DEBUG("dapdirect_jtag_select()");
172
173 return register_commands(ctx, NULL, dapdirect_jtag_handlers);
174 }
175
176 static int dapdirect_swd_select(struct command_context *ctx)
177 {
178 LOG_DEBUG("dapdirect_swd_select()");
179
180 return register_commands(ctx, NULL, dapdirect_swd_handlers);
181 }
182
183 static int dapdirect_init(struct command_context *ctx)
184 {
185 enum reset_types jtag_reset_config = jtag_get_reset_config();
186
187 LOG_DEBUG("dapdirect_init()");
188
189 if (jtag_reset_config & RESET_CNCT_UNDER_SRST) {
190 if (jtag_reset_config & RESET_SRST_NO_GATING)
191 adapter_assert_reset();
192 else
193 LOG_WARNING("\'srst_nogate\' reset_config option is required");
194 } else
195 adapter_deassert_reset();
196
197 return ERROR_OK;
198 }
199
200 static struct transport dapdirect_jtag_transport = {
201 .name = "dapdirect_jtag",
202 .select = dapdirect_jtag_select,
203 .init = dapdirect_init,
204 };
205
206 static struct transport dapdirect_swd_transport = {
207 .name = "dapdirect_swd",
208 .select = dapdirect_swd_select,
209 .init = dapdirect_init,
210 };
211
212 static void dapdirect_constructor(void) __attribute__((constructor));
213 static void dapdirect_constructor(void)
214 {
215 transport_register(&dapdirect_jtag_transport);
216 transport_register(&dapdirect_swd_transport);
217 }
218
219 /**
220 * Returns true if the current debug session
221 * is using JTAG as its transport.
222 */
223 bool transport_is_dapdirect_jtag(void)
224 {
225 return get_current_transport() == &dapdirect_jtag_transport;
226 }
227
228 /**
229 * Returns true if the current debug session
230 * is using SWD as its transport.
231 */
232 bool transport_is_dapdirect_swd(void)
233 {
234 return get_current_transport() == &dapdirect_swd_transport;
235 }

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)