1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Copyright (C) 2016 by Matthias Welwarsky *
6 ***************************************************************************/
14 #include "target/arm_adi_v5.h"
15 #include "target/arm.h"
16 #include "helper/list.h"
17 #include "helper/command.h"
18 #include "transport/transport.h"
19 #include "jtag/interface.h"
21 static LIST_HEAD(all_dap
);
23 extern struct adapter_driver
*adapter_driver
;
25 /* DAP command support */
26 struct arm_dap_object
{
30 const struct swd_driver
*swd
;
33 static void dap_instance_init(struct adiv5_dap
*dap
)
36 /* Set up with safe defaults */
37 for (i
= 0; i
<= DP_APSEL_MAX
; i
++) {
39 dap
->ap
[i
].ap_num
= DP_APSEL_INVALID
;
40 /* memaccess_tck max is 255 */
41 dap
->ap
[i
].memaccess_tck
= 255;
42 /* Number of bits for tar autoincrement, impl. dep. at least 10 */
43 dap
->ap
[i
].tar_autoincr_block
= (1<<10);
44 /* default CSW value */
45 dap
->ap
[i
].csw_default
= CSW_AHB_DEFAULT
;
46 dap
->ap
[i
].cfg_reg
= MEM_AP_REG_CFG_INVALID
; /* mem_ap configuration reg (large physical addr, etc.) */
47 dap
->ap
[i
].refcount
= 0;
48 dap
->ap
[i
].config_ap_never_release
= false;
50 INIT_LIST_HEAD(&dap
->cmd_journal
);
51 INIT_LIST_HEAD(&dap
->cmd_pool
);
54 const char *adiv5_dap_name(struct adiv5_dap
*self
)
56 struct arm_dap_object
*obj
= container_of(self
, struct arm_dap_object
, dap
);
60 const struct swd_driver
*adiv5_dap_swd_driver(struct adiv5_dap
*self
)
62 struct arm_dap_object
*obj
= container_of(self
, struct arm_dap_object
, dap
);
66 struct adiv5_dap
*adiv5_get_dap(struct arm_dap_object
*obj
)
70 struct adiv5_dap
*dap_instance_by_jim_obj(Jim_Interp
*interp
, Jim_Obj
*o
)
72 struct arm_dap_object
*obj
= NULL
;
76 name
= Jim_GetString(o
, NULL
);
78 list_for_each_entry(obj
, &all_dap
, lh
) {
79 if (!strcmp(name
, obj
->name
)) {
90 static int dap_init_all(void)
92 struct arm_dap_object
*obj
;
94 bool pre_connect
= true;
96 LOG_DEBUG("Initializing all DAPs ...");
98 list_for_each_entry(obj
, &all_dap
, lh
) {
99 struct adiv5_dap
*dap
= &obj
->dap
;
101 /* with hla, dap is just a dummy */
102 if (transport_is_hla())
105 /* skip taps that are disabled */
106 if (!dap
->tap
->enabled
)
109 if (transport_is_swd()) {
110 dap
->ops
= &swd_dap_ops
;
111 obj
->swd
= adapter_driver
->swd_ops
;
112 } else if (transport_is_dapdirect_swd()) {
113 dap
->ops
= adapter_driver
->dap_swd_ops
;
114 } else if (transport_is_dapdirect_jtag()) {
115 dap
->ops
= adapter_driver
->dap_jtag_ops
;
117 dap
->ops
= &jtag_dp_ops
;
119 if (dap
->adi_version
== 0) {
120 LOG_DEBUG("DAP %s configured by default to use ADIv5 protocol", jtag_tap_name(dap
->tap
));
121 dap
->adi_version
= 5;
123 LOG_DEBUG("DAP %s configured to use %s protocol by user cfg file", jtag_tap_name(dap
->tap
),
124 is_adiv6(dap
) ? "ADIv6" : "ADIv5");
127 if (pre_connect
&& dap
->ops
->pre_connect_init
) {
128 retval
= dap
->ops
->pre_connect_init(dap
);
129 if (retval
!= ERROR_OK
)
135 retval
= dap
->ops
->connect(dap
);
136 if (retval
!= ERROR_OK
)
139 /* see if address size of ROM Table is greater than 32-bits */
143 retval
= dap
->ops
->queue_dp_read(dap
, DP_DPIDR1
, &dpidr1
);
144 if (retval
!= ERROR_OK
) {
145 LOG_ERROR("DAP read of DPIDR1 failed...");
148 retval
= dap_run(dap
);
149 if (retval
!= ERROR_OK
) {
150 LOG_ERROR("DAP read of DPIDR1 failed...");
153 dap
->asize
= dpidr1
& DP_DPIDR1_ASIZE_MASK
;
160 int dap_cleanup_all(void)
162 struct arm_dap_object
*obj
, *tmp
;
163 struct adiv5_dap
*dap
;
165 list_for_each_entry_safe(obj
, tmp
, &all_dap
, lh
) {
167 for (unsigned int i
= 0; i
<= DP_APSEL_MAX
; i
++) {
168 if (dap
->ap
[i
].refcount
!= 0)
169 LOG_ERROR("BUG: refcount AP#%u still %u at exit", i
, dap
->ap
[i
].refcount
);
171 if (dap
->ops
&& dap
->ops
->quit
)
183 CFG_IGNORE_SYSPWRUPACK
,
190 static const struct jim_nvp nvp_config_opts
[] = {
191 { .name
= "-chain-position", .value
= CFG_CHAIN_POSITION
},
192 { .name
= "-ignore-syspwrupack", .value
= CFG_IGNORE_SYSPWRUPACK
},
193 { .name
= "-dp-id", .value
= CFG_DP_ID
},
194 { .name
= "-instance-id", .value
= CFG_INSTANCE_ID
},
195 { .name
= "-adiv6", .value
= CFG_ADIV6
},
196 { .name
= "-adiv5", .value
= CFG_ADIV5
},
197 { .name
= NULL
, .value
= -1 }
200 static int dap_configure(struct jim_getopt_info
*goi
, struct arm_dap_object
*dap
)
205 /* parse config ... */
206 while (goi
->argc
> 0) {
207 Jim_SetEmptyResult(goi
->interp
);
209 e
= jim_getopt_nvp(goi
, nvp_config_opts
, &n
);
211 jim_getopt_nvp_unknown(goi
, nvp_config_opts
, 0);
215 case CFG_CHAIN_POSITION
: {
217 e
= jim_getopt_obj(goi
, &o_t
);
221 struct jtag_tap
*tap
;
222 tap
= jtag_tap_by_jim_obj(goi
->interp
, o_t
);
224 Jim_SetResultString(goi
->interp
, "-chain-position is invalid", -1);
231 case CFG_IGNORE_SYSPWRUPACK
:
232 dap
->dap
.ignore_syspwrupack
= true;
236 e
= jim_getopt_wide(goi
, &w
);
238 Jim_SetResultFormatted(goi
->interp
,
239 "create %s: bad parameter %s",
243 if (w
< 0 || w
> DP_TARGETSEL_DPID_MASK
) {
244 Jim_SetResultFormatted(goi
->interp
,
245 "create %s: %s out of range",
249 dap
->dap
.multidrop_targetsel
=
250 (dap
->dap
.multidrop_targetsel
& DP_TARGETSEL_INSTANCEID_MASK
)
251 | (w
& DP_TARGETSEL_DPID_MASK
);
252 dap
->dap
.multidrop_dp_id_valid
= true;
255 case CFG_INSTANCE_ID
: {
257 e
= jim_getopt_wide(goi
, &w
);
259 Jim_SetResultFormatted(goi
->interp
,
260 "create %s: bad parameter %s",
264 if (w
< 0 || w
> 15) {
265 Jim_SetResultFormatted(goi
->interp
,
266 "create %s: %s out of range",
270 dap
->dap
.multidrop_targetsel
=
271 (dap
->dap
.multidrop_targetsel
& DP_TARGETSEL_DPID_MASK
)
272 | ((w
<< DP_TARGETSEL_INSTANCEID_SHIFT
) & DP_TARGETSEL_INSTANCEID_MASK
);
273 dap
->dap
.multidrop_instance_id_valid
= true;
277 dap
->dap
.adi_version
= 6;
280 dap
->dap
.adi_version
= 5;
290 static int dap_check_config(struct adiv5_dap
*dap
)
292 if (transport_is_jtag() || transport_is_dapdirect_jtag() || transport_is_hla())
295 struct arm_dap_object
*obj
;
296 bool new_multidrop
= dap_is_multidrop(dap
);
297 bool had_multidrop
= new_multidrop
;
298 uint32_t targetsel
= dap
->multidrop_targetsel
;
299 unsigned int non_multidrop_count
= had_multidrop
? 0 : 1;
301 list_for_each_entry(obj
, &all_dap
, lh
) {
302 struct adiv5_dap
*dap_it
= &obj
->dap
;
304 if (transport_is_swd()) {
305 if (dap_is_multidrop(dap_it
)) {
306 had_multidrop
= true;
307 if (new_multidrop
&& dap_it
->multidrop_targetsel
== targetsel
) {
308 uint32_t dp_id
= targetsel
& DP_TARGETSEL_DPID_MASK
;
309 uint32_t instance_id
= targetsel
>> DP_TARGETSEL_INSTANCEID_SHIFT
;
310 LOG_ERROR("%s and %s have the same multidrop selectors -dp-id 0x%08"
311 PRIx32
" and -instance-id 0x%" PRIx32
,
312 obj
->name
, adiv5_dap_name(dap
),
317 non_multidrop_count
++;
319 } else if (transport_is_dapdirect_swd()) {
320 non_multidrop_count
++;
324 if (non_multidrop_count
> 1) {
325 LOG_ERROR("Two or more SWD non multidrop DAPs are not supported");
328 if (had_multidrop
&& non_multidrop_count
) {
329 LOG_ERROR("Mixing of SWD multidrop DAPs and non multidrop DAPs is not supported");
336 static int dap_create(struct jim_getopt_info
*goi
)
338 struct command_context
*cmd_ctx
;
339 static struct arm_dap_object
*dap
;
345 cmd_ctx
= current_command_context(goi
->interp
);
349 Jim_WrongNumArgs(goi
->interp
, 1, goi
->argv
, "?name? ..options...");
353 jim_getopt_obj(goi
, &new_cmd
);
354 /* does this command exist? */
355 cmd
= Jim_GetCommand(goi
->interp
, new_cmd
, JIM_NONE
);
357 cp
= Jim_GetString(new_cmd
, NULL
);
358 Jim_SetResultFormatted(goi
->interp
, "Command: %s Exists", cp
);
363 dap
= calloc(1, sizeof(struct arm_dap_object
));
367 dap_instance_init(&dap
->dap
);
369 cp
= Jim_GetString(new_cmd
, NULL
);
370 dap
->name
= strdup(cp
);
372 e
= dap_configure(goi
, dap
);
377 Jim_SetResultString(goi
->interp
, "-chain-position required when creating DAP", -1);
382 e
= dap_check_config(&dap
->dap
);
388 struct command_registration dap_create_commands
[] = {
392 .help
= "dap instance command group",
394 .chain
= dap_instance_commands
,
396 COMMAND_REGISTRATION_DONE
399 /* don't expose the instance commands when using hla */
400 if (transport_is_hla())
401 dap_create_commands
[0].chain
= NULL
;
403 e
= register_commands_with_data(cmd_ctx
, NULL
, dap_create_commands
, dap
);
409 list_add_tail(&dap
->lh
, &all_dap
);
419 static int jim_dap_create(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
421 struct jim_getopt_info goi
;
422 jim_getopt_setup(&goi
, interp
, argc
- 1, argv
+ 1);
424 Jim_WrongNumArgs(goi
.interp
, goi
.argc
, goi
.argv
,
425 "<name> [<dap_options> ...]");
428 return dap_create(&goi
);
431 COMMAND_HANDLER(handle_dap_names
)
434 return ERROR_COMMAND_SYNTAX_ERROR
;
436 struct arm_dap_object
*obj
;
437 list_for_each_entry(obj
, &all_dap
, lh
)
438 command_print(CMD
, "%s", obj
->name
);
443 COMMAND_HANDLER(handle_dap_init
)
445 return dap_init_all();
448 COMMAND_HANDLER(handle_dap_info_command
)
450 struct target
*target
= get_current_target(CMD_CTX
);
451 struct arm
*arm
= target_to_arm(target
);
452 struct adiv5_dap
*dap
= arm
->dap
;
456 LOG_ERROR("DAP instance not available. Probably a HLA target...");
457 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
465 if (!strcmp(CMD_ARGV
[0], "root")) {
466 if (!is_adiv6(dap
)) {
467 command_print(CMD
, "Option \"root\" not allowed with ADIv5 DAP");
468 return ERROR_COMMAND_ARGUMENT_INVALID
;
470 int retval
= adiv6_dap_read_baseptr(CMD
, dap
, &apsel
);
471 if (retval
!= ERROR_OK
) {
472 command_print(CMD
, "Failed reading DAP baseptr");
477 COMMAND_PARSE_NUMBER(u64
, CMD_ARGV
[0], apsel
);
478 if (!is_ap_num_valid(dap
, apsel
))
479 return ERROR_COMMAND_SYNTAX_ERROR
;
482 return ERROR_COMMAND_SYNTAX_ERROR
;
485 struct adiv5_ap
*ap
= dap_get_ap(dap
, apsel
);
487 command_print(CMD
, "Cannot get AP");
490 int retval
= dap_info_command(CMD
, ap
);
495 static const struct command_registration dap_subcommand_handlers
[] = {
499 .jim_handler
= jim_dap_create
,
500 .usage
= "name '-chain-position' name",
501 .help
= "Creates a new DAP instance",
506 .handler
= handle_dap_names
,
508 .help
= "Lists all registered DAP instances by name",
513 .handler
= handle_dap_init
,
515 .help
= "Initialize all registered DAP instances"
519 .handler
= handle_dap_info_command
,
520 .mode
= COMMAND_EXEC
,
521 .help
= "display ROM table for specified MEM-AP (default MEM-AP of current target) "
522 "or the ADIv6 root ROM table of current target's DAP",
523 .usage
= "[ap_num | 'root']",
525 COMMAND_REGISTRATION_DONE
528 static const struct command_registration dap_commands
[] = {
531 .mode
= COMMAND_CONFIG
,
532 .help
= "DAP commands",
533 .chain
= dap_subcommand_handlers
,
536 COMMAND_REGISTRATION_DONE
539 int dap_register_commands(struct command_context
*cmd_ctx
)
541 return register_commands(cmd_ctx
, NULL
, dap_commands
);
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)