1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
5 * Author(s): Antonio Borneo <borneo.antonio@gmail.com> for STMicroelectronics
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.
15 * Single-DAP support only.
17 * For details, see "ARM IHI 0031A"
18 * ARM Debug Interface v5 Architecture Specification
20 * FIXME: in JTAG mode, trst is not managed
27 #include <jtag/interface.h>
29 #include <transport/transport.h>
31 COMMAND_HANDLER(dapdirect_jtag_empty_command
)
33 LOG_DEBUG("dapdirect_jtag_empty_command(\"%s\")", CMD_NAME
);
38 COMMAND_HANDLER(dapdirect_jtag_reset_command
)
40 enum reset_types jtag_reset_config
= jtag_get_reset_config();
43 * in case the adapter has not already handled asserting srst
44 * we will attempt it again
46 if (jtag_reset_config
& RESET_CNCT_UNDER_SRST
) {
47 if (jtag_reset_config
& RESET_SRST_NO_GATING
) {
48 adapter_assert_reset();
51 LOG_WARNING("\'srst_nogate\' reset_config option is required");
53 adapter_deassert_reset();
57 static const struct command_registration dapdirect_jtag_subcommand_handlers
[] = {
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'] "
68 "['-ircapture' number] "
69 "['-ir-bypass' number] "
75 .handler
= dapdirect_jtag_empty_command
,
81 .handler
= dapdirect_jtag_empty_command
,
85 .name
= "arp_init-reset",
87 .handler
= dapdirect_jtag_reset_command
,
91 .name
= "tapisenabled",
93 .handler
= handle_jtag_tap_enabler
,
94 .help
= "Returns a Tcl boolean (0/1) indicating whether "
95 "the TAP is enabled (1) or not (0).",
100 .mode
= COMMAND_EXEC
,
101 .handler
= handle_jtag_tap_enabler
,
102 .help
= "Try to enable the specified TAP using the "
103 "'tap-enable' TAP event.",
107 .name
= "tapdisable",
108 .mode
= COMMAND_EXEC
,
109 .handler
= dapdirect_jtag_empty_command
,
115 .handler
= dapdirect_jtag_empty_command
,
120 .mode
= COMMAND_EXEC
,
121 .handler
= handle_jtag_configure
,
127 .handler
= dapdirect_jtag_empty_command
,
130 COMMAND_REGISTRATION_DONE
133 static const struct command_registration dapdirect_jtag_handlers
[] = {
137 .chain
= dapdirect_jtag_subcommand_handlers
,
141 .name
= "jtag_ntrst_delay",
143 .handler
= dapdirect_jtag_empty_command
,
146 COMMAND_REGISTRATION_DONE
149 static const struct command_registration dapdirect_swd_subcommand_handlers
[] = {
152 .mode
= COMMAND_CONFIG
,
153 .handler
= handle_jtag_newtap
,
154 .help
= "declare a new SWD DAP",
155 .usage
= "basename dap_type ['-irlen' count] "
156 "['-enable'|'-disable'] "
157 "['-expected_id' number] "
158 "['-ignore-version'] "
159 "['-ignore-bypass'] "
160 "['-ircapture' number] "
161 "['-ir-bypass' number] "
164 COMMAND_REGISTRATION_DONE
167 static const struct command_registration dapdirect_swd_handlers
[] = {
171 .help
= "SWD command group",
173 .chain
= dapdirect_swd_subcommand_handlers
,
175 COMMAND_REGISTRATION_DONE
178 static int dapdirect_jtag_select(struct command_context
*ctx
)
180 LOG_DEBUG("dapdirect_jtag_select()");
182 return register_commands(ctx
, NULL
, dapdirect_jtag_handlers
);
185 static int dapdirect_swd_select(struct command_context
*ctx
)
187 LOG_DEBUG("dapdirect_swd_select()");
189 return register_commands(ctx
, NULL
, dapdirect_swd_handlers
);
192 static int dapdirect_init(struct command_context
*ctx
)
194 enum reset_types jtag_reset_config
= jtag_get_reset_config();
196 LOG_DEBUG("dapdirect_init()");
198 if (jtag_reset_config
& RESET_CNCT_UNDER_SRST
) {
199 if (jtag_reset_config
& RESET_SRST_NO_GATING
)
200 adapter_assert_reset();
202 LOG_WARNING("\'srst_nogate\' reset_config option is required");
204 adapter_deassert_reset();
209 static struct transport dapdirect_jtag_transport
= {
210 .name
= "dapdirect_jtag",
211 .select
= dapdirect_jtag_select
,
212 .init
= dapdirect_init
,
215 static struct transport dapdirect_swd_transport
= {
216 .name
= "dapdirect_swd",
217 .select
= dapdirect_swd_select
,
218 .init
= dapdirect_init
,
221 static void dapdirect_constructor(void) __attribute__((constructor
));
222 static void dapdirect_constructor(void)
224 transport_register(&dapdirect_jtag_transport
);
225 transport_register(&dapdirect_swd_transport
);
229 * Returns true if the current debug session
230 * is using JTAG as its transport.
232 bool transport_is_dapdirect_jtag(void)
234 return get_current_transport() == &dapdirect_jtag_transport
;
238 * Returns true if the current debug session
239 * is using SWD as its transport.
241 bool transport_is_dapdirect_swd(void)
243 return get_current_transport() == &dapdirect_swd_transport
;