This is an automated email from Gerrit. "Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8677
-- gerrit commit a512086784a18e060a09333468c00aea6beb0e2d Author: Antonio Borneo <borneo.anto...@gmail.com> Date: Mon Dec 23 17:44:47 2024 +0100 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 diver should only support the most complete transport. 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', add a side information to inform user about 'dapdirect' and 'hla' versions. This improvement was listed in the TODO file. Update it! Change-Id: I626b50e7a94c141c042eab388cd1ffe77eb864c2 Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com> diff --git a/README b/README index 950c71f707..9c32ef82e2 100644 --- a/README +++ b/README @@ -42,7 +42,7 @@ openocd -f interface/ftdi/jtagkey2.cfg -c "transport select jtag" \ ``` ``` -openocd -f interface/stlink.cfg -c "transport select hla_swd" \ +openocd -f interface/stlink.cfg -c "transport select swd" \ -f target/stm32l0.cfg ``` diff --git a/TODO b/TODO index e4dded0ce6..239b358f57 100644 --- a/TODO +++ b/TODO @@ -60,8 +60,6 @@ changes pending in gerrit. to replicate it in the drivers, apart in case the driver sets TRST independently - add .hla_ops to "adapter" -- HLA is a API level (.hla_ops). Transport should simply be {jtag,swd}, - not {hla_jtag,hla_swd}. @subsection thelistadapterjtagcore JTAG Core diff --git a/doc/openocd.texi b/doc/openocd.texi index b3f8403fb7..8a41d325cb 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -3706,10 +3706,8 @@ JTAG supports both debugging and boundary scan testing. Flash programming support is built on top of debug support. JTAG transport is selected with the command @command{transport select -jtag}. Unless your adapter uses either @ref{hla_interface,the hla interface -driver} (in which case the command is @command{transport select hla_jtag}) -or @ref{st_link_dap_interface,the st-link interface driver} (in which case -the command is @command{transport select dapdirect_jtag}). +jtag}. This command has to be used also for @ref{hla_interface,the hla interface +driver} and @ref{st_link_dap_interface,the st-link interface driver}. @subsection SWD Transport @cindex SWD @@ -3722,10 +3720,8 @@ Flash programming support is built on top of debug support. (Some processors support both JTAG and SWD.) SWD transport is selected with the command @command{transport select -swd}. Unless your adapter uses either @ref{hla_interface,the hla interface -driver} (in which case the command is @command{transport select hla_swd}) -or @ref{st_link_dap_interface,the st-link interface driver} (in which case -the command is @command{transport select dapdirect_swd}). +swd}. This command has to be used also for @ref{hla_interface,the hla interface +driver} and @ref{st_link_dap_interface,the st-link interface driver}. @deffn {Config Command} {swd newdap} ... Declares a single DAP which uses SWD transport. @@ -10659,7 +10655,7 @@ baud with our custom divisor to get 12MHz) @item OpenOCD invocation line: @example openocd -f interface/stlink.cfg \ --c "transport select dapdirect_swd" \ +-c "transport select swd" \ -f target/stm32l1.cfg \ -c "stm32l1.tpiu configure -protocol uart" \ -c "stm32l1.tpiu configure -traceclk 24000000 -pin-freq 12000000" \ diff --git a/src/transport/transport.c b/src/transport/transport.c index 76eb11cd7f..c1a3dba01e 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -44,14 +44,18 @@ extern struct command_context *global_cmd_ctx; */ /** List of transports known to OpenOCD. */ -static const char * const transport_name[] = { - [TRANSPORT_JTAG] = "jtag", - [TRANSPORT_SWD] = "swd", - [TRANSPORT_HLA_JTAG] = "hla_jtag", - [TRANSPORT_HLA_SWD] = "hla_swd", - [TRANSPORT_DAPDIRECT_JTAG] = "dapdirect_jtag", - [TRANSPORT_DAPDIRECT_SWD] = "dapdirect_swd", - [TRANSPORT_SWIM] = "swim", +static const struct { + const char *name; + const char *full_name; + const char *deprecated_name; +} transport_name[] = { + [TRANSPORT_JTAG] = { "jtag", "jtag", NULL, }, + [TRANSPORT_SWD] = { "swd", "swd", NULL, }, + [TRANSPORT_HLA_JTAG] = { "jtag", "jtag (hla)", "hla_jtag", }, + [TRANSPORT_HLA_SWD] = { "swd", "swd (hla)", "hla_swd", }, + [TRANSPORT_DAPDIRECT_JTAG] = { "jtag", "jtag (dapdirect)", "dapdirect_jtag", }, + [TRANSPORT_DAPDIRECT_SWD] = { "swd", "swd (dapdirect)", "dapdirect_swd", }, + [TRANSPORT_SWIM] = { "swim", "swim", NULL, }, }; /** List of transports registered in OpenOCD. */ @@ -72,12 +76,12 @@ static bool is_transport_id_valid(int id) return (id > TRANSPORT_UNKNOWN) && (id < TRANSPORT_INVALID); } -static int transport_select(struct command_context *ctx, const char *name) +static int transport_select(struct command_context *ctx, unsigned char transport_id) { /* name may only identify a known transport; * caller guarantees session's transport isn't yet set.*/ for (struct transport *t = transport_list; t; t = t->next) { - if (!strcmp(transport_name[t->id], name)) { + if (t->id == transport_id) { int retval = t->select(ctx); /* select() registers commands specific to this * transport, and may also reset the link, e.g. @@ -86,12 +90,14 @@ static int transport_select(struct command_context *ctx, const char *name) if (retval == ERROR_OK) session = t; else - LOG_ERROR("Error selecting '%s' as transport", name); + LOG_ERROR("Error selecting '%s' as transport", + transport_name[transport_id].full_name); return retval; } } - LOG_ERROR("No transport named '%s' is available.", name); + LOG_ERROR("No transport named '%s' is available.", + transport_name[transport_id].full_name); return ERROR_FAIL; } @@ -133,8 +139,9 @@ int allow_transports(struct command_context *ctx, const unsigned char *vector) /* autoselect if there's no choice ... */ if (!vector[1]) { - LOG_INFO("only one transport option; autoselecting '%s'", transport_name[vector[0]]); - return transport_select(ctx, transport_name[vector[0]]); + LOG_INFO("only one transport option; autoselecting '%s'", + transport_name[vector[0]].full_name); + return transport_select(ctx, vector[0]); } return ERROR_OK; @@ -167,20 +174,20 @@ int transport_register(struct transport *new_transport) for (t = transport_list; t; t = t->next) { if (t->id == new_transport->id) { LOG_ERROR("transport '%s' already registered", - transport_name[t->id]); + transport_name[t->id].full_name); return ERROR_FAIL; } } if (!new_transport->select || !new_transport->init) LOG_ERROR("invalid transport %s", - transport_name[new_transport->id]); + transport_name[new_transport->id].full_name); /* splice this into the list */ new_transport->next = transport_list; transport_list = new_transport; LOG_DEBUG("register '%s' (ID %d)", - transport_name[new_transport->id], new_transport->id); + transport_name[new_transport->id].full_name, new_transport->id); return ERROR_OK; } @@ -202,7 +209,7 @@ const char *get_current_transport_name(void) if (!session || !is_transport_id_valid(session->id)) NULL; - return transport_name[session->id]; + return transport_name[session->id].full_name; } /*-----------------------------------------------------------------------*/ @@ -221,7 +228,7 @@ COMMAND_HANDLER(handle_transport_init) LOG_ERROR("Transports available:"); const unsigned char *vector = allowed_transports; while (*vector) { - LOG_ERROR("%s", transport_name[*vector]); + LOG_ERROR("%s", transport_name[*vector].full_name); vector++; } return ERROR_FAIL; @@ -238,7 +245,7 @@ COMMAND_HANDLER(handle_transport_list) command_print(CMD, "The following transports are available:"); for (struct transport *t = transport_list; t; t = t->next) - command_print(CMD, "\t%s", transport_name[t->id]); + command_print(CMD, "\t%s", transport_name[t->id].full_name); return ERROR_OK; } @@ -263,18 +270,20 @@ COMMAND_HANDLER(handle_transport_select) } LOG_INFO("auto-selecting first available session transport \"%s\". " "To override use 'transport select <transport>'.", - transport_name[allowed_transports[0]]); - int retval = transport_select(CMD_CTX, transport_name[allowed_transports[0]]); + transport_name[allowed_transports[0]].full_name); + int retval = transport_select(CMD_CTX, allowed_transports[0]); if (retval != ERROR_OK) return retval; } - command_print(CMD, "%s", transport_name[session->id]); + command_print(CMD, "%s", transport_name[session->id].full_name); return ERROR_OK; } /* assign transport */ if (session) { - if (!strcmp(transport_name[session->id], CMD_ARGV[0])) { + if (!strcmp(transport_name[session->id].name, CMD_ARGV[0]) + || (transport_name[session->id].deprecated_name + && !strcmp(transport_name[session->id].deprecated_name, CMD_ARGV[0]))) { LOG_WARNING("Transport \"%s\" was already selected", CMD_ARGV[0]); return ERROR_OK; } @@ -294,11 +303,14 @@ COMMAND_HANDLER(handle_transport_select) } for (unsigned int i = 0; allowed_transports[i]; i++) { - if (!strcmp(transport_name[allowed_transports[i]], CMD_ARGV[0])) { - int retval = transport_select(CMD_CTX, CMD_ARGV[0]); - if (retval != ERROR_OK) - return retval; - return ERROR_OK; + if (!strcmp(transport_name[allowed_transports[i]].name, CMD_ARGV[0])) + return transport_select(CMD_CTX, allowed_transports[i]); + + if (transport_name[allowed_transports[i]].deprecated_name + && !strcmp(transport_name[allowed_transports[i]].deprecated_name, CMD_ARGV[0])) { + LOG_WARNING("DEPRECATED! use 'transport select %s', not 'transport select %s'", + transport_name[allowed_transports[i]].name, transport_name[allowed_transports[i]].deprecated_name); + return transport_select(CMD_CTX, allowed_transports[i]); } } --