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
;
95 LOG_DEBUG("Initializing all DAPs ...");
97 list_for_each_entry(obj
, &all_dap
, lh
) {
98 struct adiv5_dap
*dap
= &obj
->dap
;
100 /* with hla, dap is just a dummy */
101 if (transport_is_hla())
104 /* skip taps that are disabled */
105 if (!dap
->tap
->enabled
)
108 if (transport_is_swd()) {
109 dap
->ops
= &swd_dap_ops
;
110 obj
->swd
= adapter_driver
->swd_ops
;
111 } else if (transport_is_dapdirect_swd()) {
112 dap
->ops
= adapter_driver
->dap_swd_ops
;
113 } else if (transport_is_dapdirect_jtag()) {
114 dap
->ops
= adapter_driver
->dap_jtag_ops
;
116 dap
->ops
= &jtag_dp_ops
;
118 if (dap
->adi_version
== 0) {
119 LOG_DEBUG("DAP %s configured by default to use ADIv5 protocol", jtag_tap_name(dap
->tap
));
120 dap
->adi_version
= 5;
122 LOG_DEBUG("DAP %s configured to use %s protocol by user cfg file", jtag_tap_name(dap
->tap
),
123 is_adiv6(dap
) ? "ADIv6" : "ADIv5");
126 retval
= dap
->ops
->connect(dap
);
127 if (retval
!= ERROR_OK
)
130 /* see if address size of ROM Table is greater than 32-bits */
134 retval
= dap
->ops
->queue_dp_read(dap
, DP_DPIDR1
, &dpidr1
);
135 if (retval
!= ERROR_OK
) {
136 LOG_ERROR("DAP read of DPIDR1 failed...");
139 retval
= dap_run(dap
);
140 if (retval
!= ERROR_OK
) {
141 LOG_ERROR("DAP read of DPIDR1 failed...");
144 dap
->asize
= dpidr1
& DP_DPIDR1_ASIZE_MASK
;
151 int dap_cleanup_all(void)
153 struct arm_dap_object
*obj
, *tmp
;
154 struct adiv5_dap
*dap
;
156 list_for_each_entry_safe(obj
, tmp
, &all_dap
, lh
) {
158 for (unsigned int i
= 0; i
<= DP_APSEL_MAX
; i
++) {
159 if (dap
->ap
[i
].refcount
!= 0)
160 LOG_ERROR("BUG: refcount AP#%u still %u at exit", i
, dap
->ap
[i
].refcount
);
162 if (dap
->ops
&& dap
->ops
->quit
)
174 CFG_IGNORE_SYSPWRUPACK
,
181 static const struct jim_nvp nvp_config_opts
[] = {
182 { .name
= "-chain-position", .value
= CFG_CHAIN_POSITION
},
183 { .name
= "-ignore-syspwrupack", .value
= CFG_IGNORE_SYSPWRUPACK
},
184 { .name
= "-dp-id", .value
= CFG_DP_ID
},
185 { .name
= "-instance-id", .value
= CFG_INSTANCE_ID
},
186 { .name
= "-adiv6", .value
= CFG_ADIV6
},
187 { .name
= "-adiv5", .value
= CFG_ADIV5
},
188 { .name
= NULL
, .value
= -1 }
191 static int dap_configure(struct jim_getopt_info
*goi
, struct arm_dap_object
*dap
)
196 /* parse config ... */
197 while (goi
->argc
> 0) {
198 Jim_SetEmptyResult(goi
->interp
);
200 e
= jim_getopt_nvp(goi
, nvp_config_opts
, &n
);
202 jim_getopt_nvp_unknown(goi
, nvp_config_opts
, 0);
206 case CFG_CHAIN_POSITION
: {
208 e
= jim_getopt_obj(goi
, &o_t
);
212 struct jtag_tap
*tap
;
213 tap
= jtag_tap_by_jim_obj(goi
->interp
, o_t
);
215 Jim_SetResultString(goi
->interp
, "-chain-position is invalid", -1);
222 case CFG_IGNORE_SYSPWRUPACK
:
223 dap
->dap
.ignore_syspwrupack
= true;
227 e
= jim_getopt_wide(goi
, &w
);
229 Jim_SetResultFormatted(goi
->interp
,
230 "create %s: bad parameter %s",
234 if (w
< 0 || w
> DP_TARGETSEL_DPID_MASK
) {
235 Jim_SetResultFormatted(goi
->interp
,
236 "create %s: %s out of range",
240 dap
->dap
.multidrop_targetsel
=
241 (dap
->dap
.multidrop_targetsel
& DP_TARGETSEL_INSTANCEID_MASK
)
242 | (w
& DP_TARGETSEL_DPID_MASK
);
243 dap
->dap
.multidrop_dp_id_valid
= true;
246 case CFG_INSTANCE_ID
: {
248 e
= jim_getopt_wide(goi
, &w
);
250 Jim_SetResultFormatted(goi
->interp
,
251 "create %s: bad parameter %s",
255 if (w
< 0 || w
> 15) {
256 Jim_SetResultFormatted(goi
->interp
,
257 "create %s: %s out of range",
261 dap
->dap
.multidrop_targetsel
=
262 (dap
->dap
.multidrop_targetsel
& DP_TARGETSEL_DPID_MASK
)
263 | ((w
<< DP_TARGETSEL_INSTANCEID_SHIFT
) & DP_TARGETSEL_INSTANCEID_MASK
);
264 dap
->dap
.multidrop_instance_id_valid
= true;
268 dap
->dap
.adi_version
= 6;
271 dap
->dap
.adi_version
= 5;
281 static int dap_check_config(struct adiv5_dap
*dap
)
283 if (transport_is_jtag() || transport_is_dapdirect_jtag() || transport_is_hla())
286 struct arm_dap_object
*obj
;
287 bool new_multidrop
= dap_is_multidrop(dap
);
288 bool had_multidrop
= new_multidrop
;
289 uint32_t targetsel
= dap
->multidrop_targetsel
;
290 unsigned int non_multidrop_count
= had_multidrop
? 0 : 1;
292 list_for_each_entry(obj
, &all_dap
, lh
) {
293 struct adiv5_dap
*dap_it
= &obj
->dap
;
295 if (transport_is_swd()) {
296 if (dap_is_multidrop(dap_it
)) {
297 had_multidrop
= true;
298 if (new_multidrop
&& dap_it
->multidrop_targetsel
== targetsel
) {
299 uint32_t dp_id
= targetsel
& DP_TARGETSEL_DPID_MASK
;
300 uint32_t instance_id
= targetsel
>> DP_TARGETSEL_INSTANCEID_SHIFT
;
301 LOG_ERROR("%s and %s have the same multidrop selectors -dp-id 0x%08"
302 PRIx32
" and -instance-id 0x%" PRIx32
,
303 obj
->name
, adiv5_dap_name(dap
),
308 non_multidrop_count
++;
310 } else if (transport_is_dapdirect_swd()) {
311 non_multidrop_count
++;
315 if (non_multidrop_count
> 1) {
316 LOG_ERROR("Two or more SWD non multidrop DAPs are not supported");
319 if (had_multidrop
&& non_multidrop_count
) {
320 LOG_ERROR("Mixing of SWD multidrop DAPs and non multidrop DAPs is not supported");
327 static int dap_create(struct jim_getopt_info
*goi
)
329 struct command_context
*cmd_ctx
;
330 static struct arm_dap_object
*dap
;
336 cmd_ctx
= current_command_context(goi
->interp
);
340 Jim_WrongNumArgs(goi
->interp
, 1, goi
->argv
, "?name? ..options...");
344 jim_getopt_obj(goi
, &new_cmd
);
345 /* does this command exist? */
346 cmd
= Jim_GetCommand(goi
->interp
, new_cmd
, JIM_NONE
);
348 cp
= Jim_GetString(new_cmd
, NULL
);
349 Jim_SetResultFormatted(goi
->interp
, "Command: %s Exists", cp
);
354 dap
= calloc(1, sizeof(struct arm_dap_object
));
358 dap_instance_init(&dap
->dap
);
360 cp
= Jim_GetString(new_cmd
, NULL
);
361 dap
->name
= strdup(cp
);
363 e
= dap_configure(goi
, dap
);
368 Jim_SetResultString(goi
->interp
, "-chain-position required when creating DAP", -1);
373 e
= dap_check_config(&dap
->dap
);
379 struct command_registration dap_create_commands
[] = {
383 .help
= "dap instance command group",
385 .chain
= dap_instance_commands
,
387 COMMAND_REGISTRATION_DONE
390 /* don't expose the instance commands when using hla */
391 if (transport_is_hla())
392 dap_create_commands
[0].chain
= NULL
;
394 e
= register_commands_with_data(cmd_ctx
, NULL
, dap_create_commands
, dap
);
400 list_add_tail(&dap
->lh
, &all_dap
);
410 static int jim_dap_create(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
412 struct jim_getopt_info goi
;
413 jim_getopt_setup(&goi
, interp
, argc
- 1, argv
+ 1);
415 Jim_WrongNumArgs(goi
.interp
, goi
.argc
, goi
.argv
,
416 "<name> [<dap_options> ...]");
419 return dap_create(&goi
);
422 COMMAND_HANDLER(handle_dap_names
)
425 return ERROR_COMMAND_SYNTAX_ERROR
;
427 struct arm_dap_object
*obj
;
428 list_for_each_entry(obj
, &all_dap
, lh
)
429 command_print(CMD
, "%s", obj
->name
);
434 COMMAND_HANDLER(handle_dap_init
)
436 return dap_init_all();
439 COMMAND_HANDLER(handle_dap_info_command
)
441 struct target
*target
= get_current_target(CMD_CTX
);
442 struct arm
*arm
= target_to_arm(target
);
443 struct adiv5_dap
*dap
= arm
->dap
;
447 LOG_ERROR("DAP instance not available. Probably a HLA target...");
448 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
456 if (!strcmp(CMD_ARGV
[0], "root")) {
457 if (!is_adiv6(dap
)) {
458 command_print(CMD
, "Option \"root\" not allowed with ADIv5 DAP");
459 return ERROR_COMMAND_ARGUMENT_INVALID
;
461 int retval
= adiv6_dap_read_baseptr(CMD
, dap
, &apsel
);
462 if (retval
!= ERROR_OK
) {
463 command_print(CMD
, "Failed reading DAP baseptr");
468 COMMAND_PARSE_NUMBER(u64
, CMD_ARGV
[0], apsel
);
469 if (!is_ap_num_valid(dap
, apsel
))
470 return ERROR_COMMAND_SYNTAX_ERROR
;
473 return ERROR_COMMAND_SYNTAX_ERROR
;
476 struct adiv5_ap
*ap
= dap_get_ap(dap
, apsel
);
478 command_print(CMD
, "Cannot get AP");
481 int retval
= dap_info_command(CMD
, ap
);
486 static const struct command_registration dap_subcommand_handlers
[] = {
490 .jim_handler
= jim_dap_create
,
491 .usage
= "name '-chain-position' name",
492 .help
= "Creates a new DAP instance",
497 .handler
= handle_dap_names
,
499 .help
= "Lists all registered DAP instances by name",
504 .handler
= handle_dap_init
,
506 .help
= "Initialize all registered DAP instances"
510 .handler
= handle_dap_info_command
,
511 .mode
= COMMAND_EXEC
,
512 .help
= "display ROM table for specified MEM-AP (default MEM-AP of current target) "
513 "or the ADIv6 root ROM table of current target's DAP",
514 .usage
= "[ap_num | 'root']",
516 COMMAND_REGISTRATION_DONE
519 static const struct command_registration dap_commands
[] = {
522 .mode
= COMMAND_CONFIG
,
523 .help
= "DAP commands",
524 .chain
= dap_subcommand_handlers
,
527 COMMAND_REGISTRATION_DONE
530 int dap_register_commands(struct command_context
*cmd_ctx
)
532 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)