Skip to content

Commit c1c4d48

Browse files
committed
transport: allow transport name jtag/swd for hla and dapdirect
The transport used on adapter's wires is either 'jtag' or 'swd' but, depending on the adapter, in the command 'transport select' we have to use either 'jtag' or 'swd' or the similar 'hla_jtag', 'hla_swd', 'dapdirect_jtag' or 'dapdirect_swd'. This becomes cumbersome when we just want to change adapter and we get forced to modify the 'transport select' command too. There is no reason for an adapter driver to support two of the similar transports. In fact 'dapdirect' one is a superset of the 'hla', and the native 'jtag' or 'swd' is a superset of the 'dapdirect' one. While the adapter could support more than one similar transports, its adapter driver should only support the most complete of these similar transports. Modify the 'transport select' code to accept 'jtag' or 'swd' for the 'dapdirect' and the 'hla' adapters too. Issue a deprecated message for the old 'dapdirect' and 'hla' transport names. In command 'transport list', print only the transport names that can be selected through 'transport select' skipping information about 'dapdirect' and 'hla' versions and avoid duplicated entries. This improvement was listed in the TODO file. Update it! Change-Id: I626b50e7a94c141c042eab388cd1ffe77eb864c2 Signed-off-by: Antonio Borneo <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8677 Tested-by: jenkins
1 parent 98c09dc commit c1c4d48

File tree

4 files changed

+70
-41
lines changed

4 files changed

+70
-41
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ openocd -f interface/ftdi/jtagkey2.cfg -c "transport select jtag" \
4242
```
4343

4444
```
45-
openocd -f interface/stlink.cfg -c "transport select hla_swd" \
45+
openocd -f interface/stlink.cfg -c "transport select swd" \
4646
-f target/stm32l0.cfg
4747
```
4848

TODO

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ changes pending in gerrit.
6060
to replicate it in the drivers, apart in case the driver sets TRST
6161
independently
6262
- add .hla_ops to "adapter"
63-
- HLA is a API level (.hla_ops). Transport should simply be {jtag,swd},
64-
not {hla_jtag,hla_swd}.
6563

6664
@subsection thelistadapterjtagcore JTAG Core
6765

doc/openocd.texi

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3783,10 +3783,8 @@ JTAG supports both debugging and boundary scan testing.
37833783
Flash programming support is built on top of debug support.
37843784

37853785
JTAG transport is selected with the command @command{transport select
3786-
jtag}. Unless your adapter uses either @ref{hla_interface,the hla interface
3787-
driver} (in which case the command is @command{transport select hla_jtag})
3788-
or @ref{st_link_dap_interface,the st-link interface driver} (in which case
3789-
the command is @command{transport select dapdirect_jtag}).
3786+
jtag}. This command has to be used also for @ref{hla_interface,the hla interface
3787+
driver} and @ref{st_link_dap_interface,the st-link interface driver}.
37903788

37913789
@subsection SWD Transport
37923790
@cindex SWD
@@ -3799,10 +3797,8 @@ Flash programming support is built on top of debug support.
37993797
(Some processors support both JTAG and SWD.)
38003798

38013799
SWD transport is selected with the command @command{transport select
3802-
swd}. Unless your adapter uses either @ref{hla_interface,the hla interface
3803-
driver} (in which case the command is @command{transport select hla_swd})
3804-
or @ref{st_link_dap_interface,the st-link interface driver} (in which case
3805-
the command is @command{transport select dapdirect_swd}).
3800+
swd}. This command has to be used also for @ref{hla_interface,the hla interface
3801+
driver} and @ref{st_link_dap_interface,the st-link interface driver}.
38063802

38073803
@deffn {Config Command} {swd newdap} ...
38083804
Declares a single DAP which uses SWD transport.
@@ -10889,7 +10885,7 @@ baud with our custom divisor to get 12MHz)
1088910885
@item OpenOCD invocation line:
1089010886
@example
1089110887
openocd -f interface/stlink.cfg \
10892-
-c "transport select dapdirect_swd" \
10888+
-c "transport select swd" \
1089310889
-f target/stm32l1.cfg \
1089410890
-c "stm32l1.tpiu configure -protocol uart" \
1089510891
-c "stm32l1.tpiu configure -traceclk 24000000 -pin-freq 12000000" \

src/transport/transport.c

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ extern struct command_context *global_cmd_ctx;
4949
static const struct {
5050
unsigned int id;
5151
const char *name;
52+
const char *full_name;
53+
const char *deprecated_name;
5254
} transport_names[] = {
53-
{ TRANSPORT_JTAG, "jtag", },
54-
{ TRANSPORT_SWD, "swd", },
55-
{ TRANSPORT_HLA_JTAG, "hla_jtag", },
56-
{ TRANSPORT_HLA_SWD, "hla_swd", },
57-
{ TRANSPORT_DAPDIRECT_JTAG, "dapdirect_jtag", },
58-
{ TRANSPORT_DAPDIRECT_SWD, "dapdirect_swd", },
59-
{ TRANSPORT_SWIM, "swim", },
55+
{ TRANSPORT_JTAG, "jtag", "jtag", NULL, },
56+
{ TRANSPORT_SWD, "swd", "swd", NULL, },
57+
{ TRANSPORT_HLA_JTAG, "jtag", "jtag (hla)", "hla_jtag", },
58+
{ TRANSPORT_HLA_SWD, "swd", "swd (hla)", "hla_swd", },
59+
{ TRANSPORT_DAPDIRECT_JTAG, "jtag", "jtag (dapdirect)", "dapdirect_jtag", },
60+
{ TRANSPORT_DAPDIRECT_SWD, "swd", "swd (dapdirect)", "dapdirect_swd", },
61+
{ TRANSPORT_SWIM, "swim", "swim", NULL, },
6062
};
6163

6264
/** List of transports registered in OpenOCD, alphabetically sorted per name. */
@@ -90,18 +92,36 @@ const char *transport_name(unsigned int id)
9092
return NULL;
9193
}
9294

95+
static const char *transport_full_name(unsigned int id)
96+
{
97+
for (unsigned int i = 0; i < ARRAY_SIZE(transport_names); i++)
98+
if (id == transport_names[i].id)
99+
return transport_names[i].full_name;
100+
101+
return NULL;
102+
}
103+
104+
static const char *transport_deprecated_name(unsigned int id)
105+
{
106+
for (unsigned int i = 0; i < ARRAY_SIZE(transport_names); i++)
107+
if (id == transport_names[i].id)
108+
return transport_names[i].deprecated_name;
109+
110+
return NULL;
111+
}
112+
93113
static bool is_transport_id_valid(unsigned int id)
94114
{
95115
return (id != 0) && ((id & ~TRANSPORT_VALID_MASK) == 0) && IS_PWR_OF_2(id);
96116
}
97117

98-
static int transport_select(struct command_context *ctx, const char *name)
118+
static int transport_select(struct command_context *ctx, unsigned int transport_id)
99119
{
100120
/* name may only identify a known transport;
101121
* caller guarantees session's transport isn't yet set.*/
102122
struct transport *t;
103123
list_for_each_entry(t, &transport_list, lh) {
104-
if (!strcmp(transport_name(t->id), name)) {
124+
if (t->id == transport_id) {
105125
int retval = t->select(ctx);
106126
/* select() registers commands specific to this
107127
* transport, and may also reset the link, e.g.
@@ -110,12 +130,14 @@ static int transport_select(struct command_context *ctx, const char *name)
110130
if (retval == ERROR_OK)
111131
session = t;
112132
else
113-
LOG_ERROR("Error selecting '%s' as transport", name);
133+
LOG_ERROR("Error selecting '%s' as transport",
134+
transport_full_name(transport_id));
114135
return retval;
115136
}
116137
}
117138

118-
LOG_ERROR("No transport named '%s' is available.", name);
139+
LOG_ERROR("No transport named '%s' is available.",
140+
transport_full_name(transport_id));
119141
return ERROR_FAIL;
120142
}
121143

@@ -165,7 +187,7 @@ int allow_transports(struct command_context *ctx, unsigned int transport_ids,
165187
if (IS_PWR_OF_2(transport_ids)) {
166188
LOG_DEBUG("only one transport option; autoselecting '%s'", transport_name(transport_ids));
167189
transport_single_is_autoselected = true;
168-
return transport_select(ctx, transport_name(transport_ids));
190+
return transport_select(ctx, transport_ids);
169191
}
170192

171193
return ERROR_OK;
@@ -205,7 +227,7 @@ int transport_register(struct transport *new_transport)
205227

206228
if (!new_transport->select || !new_transport->init)
207229
LOG_ERROR("invalid transport %s",
208-
transport_name(new_transport->id));
230+
transport_full_name(new_transport->id));
209231

210232
/* splice this into the list, sorted in alphabetic order */
211233
list_for_each_entry(t, &transport_list, lh) {
@@ -216,7 +238,7 @@ int transport_register(struct transport *new_transport)
216238
list_add_tail(&new_transport->lh, &t->lh);
217239

218240
LOG_DEBUG("register '%s' (ID %d)",
219-
transport_name(new_transport->id), new_transport->id);
241+
transport_full_name(new_transport->id), new_transport->id);
220242

221243
return ERROR_OK;
222244
}
@@ -238,7 +260,7 @@ const char *get_current_transport_name(void)
238260
if (!session || !is_transport_id_valid(session->id))
239261
NULL;
240262

241-
return transport_name(session->id);
263+
return transport_full_name(session->id);
242264
}
243265

244266
/*-----------------------------------------------------------------------*/
@@ -257,15 +279,15 @@ COMMAND_HANDLER(handle_transport_init)
257279
LOG_ERROR("Transports available:");
258280
for (unsigned int i = BIT(0); i & TRANSPORT_VALID_MASK; i <<= 1) {
259281
if (i & allowed_transports)
260-
LOG_ERROR("%s", transport_name(i));
282+
LOG_ERROR("%s", transport_full_name(i));
261283
}
262284
return ERROR_FAIL;
263285
}
264286

265287
if (transport_single_is_autoselected)
266288
LOG_WARNING("DEPRECATED: auto-selecting transport \"%s\". "
267289
"Use 'transport select %s' to suppress this message.",
268-
transport_name(session->id), transport_name(session->id));
290+
transport_full_name(session->id), transport_name(session->id));
269291

270292
return session->init(CMD_CTX);
271293
}
@@ -278,8 +300,14 @@ COMMAND_HANDLER(handle_transport_list)
278300
command_print(CMD, "The following transports are available:");
279301

280302
struct transport *t;
281-
list_for_each_entry(t, &transport_list, lh)
282-
command_print(CMD, "\t%s", transport_name(t->id));
303+
const char *prev_name = NULL;
304+
/* list is sorted, don't print duplicated transport names */
305+
list_for_each_entry(t, &transport_list, lh) {
306+
const char *name = transport_name(t->id);
307+
if (!prev_name || strcmp(prev_name, name))
308+
command_print(CMD, "\t%s", name);
309+
prev_name = name;
310+
}
283311

284312
return ERROR_OK;
285313
}
@@ -304,19 +332,21 @@ COMMAND_HANDLER(handle_transport_select)
304332
}
305333
LOG_WARNING("DEPRECATED: auto-selecting transport \"%s\". "
306334
"Use 'transport select %s' to suppress this message.",
307-
transport_name(preferred_transport),
335+
transport_full_name(preferred_transport),
308336
transport_name(preferred_transport));
309-
int retval = transport_select(CMD_CTX, transport_name(preferred_transport));
337+
int retval = transport_select(CMD_CTX, preferred_transport);
310338
if (retval != ERROR_OK)
311339
return retval;
312340
}
313-
command_print(CMD, "%s", transport_name(session->id));
341+
command_print(CMD, "%s", transport_full_name(session->id));
314342
return ERROR_OK;
315343
}
316344

317345
/* assign transport */
318346
if (session) {
319-
if (!strcmp(transport_name(session->id), CMD_ARGV[0])) {
347+
if (!strcmp(transport_name(session->id), CMD_ARGV[0])
348+
|| (transport_deprecated_name(session->id)
349+
&& !strcmp(transport_deprecated_name(session->id), CMD_ARGV[0]))) {
320350
if (transport_single_is_autoselected) {
321351
/* Nothing to do, but also nothing to complain */
322352
transport_single_is_autoselected = false;
@@ -341,12 +371,17 @@ COMMAND_HANDLER(handle_transport_select)
341371
}
342372

343373
for (unsigned int i = BIT(0); i & TRANSPORT_VALID_MASK; i <<= 1) {
344-
if ((i & allowed_transports)
345-
&& !strcmp(transport_name(i), CMD_ARGV[0])) {
346-
int retval = transport_select(CMD_CTX, CMD_ARGV[0]);
347-
if (retval != ERROR_OK)
348-
return retval;
349-
return ERROR_OK;
374+
if (!(i & allowed_transports))
375+
continue;
376+
377+
if (!strcmp(transport_name(i), CMD_ARGV[0]))
378+
return transport_select(CMD_CTX, i);
379+
380+
if (transport_deprecated_name(i)
381+
&& !strcmp(transport_deprecated_name(i), CMD_ARGV[0])) {
382+
LOG_WARNING("DEPRECATED! use 'transport select %s', not 'transport select %s'",
383+
transport_name(i), transport_deprecated_name(i));
384+
return transport_select(CMD_CTX, i);
350385
}
351386
}
352387

0 commit comments

Comments
 (0)