Skip to content

Commit 9a5de74

Browse files
committed
transport: deprecate auto-selection of transport
Historically, if the user does not specify a transport, OpenOCD select automatically the first transport listed in the adapter driver. This auto-selection can behave differently by changing adapter, so the transport should be enforced in the configuration file. Deprecate the auto-selection and print a warning message when a transport gets auto-selected. There are two cases: - adapter offers one transport only. The code early auto-selects the transport but does not print anything. If later the user selects the transport then no deprecation will be printed during 'transport init'; - user runs 'transport select', e.g. in 'swj-dp' script, and this triggers the auto-selection and the deprecated message. Change-Id: I2e55b9dcc6da77ca937978fbfb36bc365b803f0d Signed-off-by: Antonio Borneo <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8692 Reviewed-by: Jan Matyas <[email protected]> Reviewed-by: zapb <[email protected]> Tested-by: jenkins
1 parent da50873 commit 9a5de74

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/transport/transport.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ static struct transport *transport_list;
5252
*/
5353
static const char * const *allowed_transports;
5454

55+
/**
56+
* Adapter supports a single transport; it has been auto-selected
57+
*/
58+
static bool transport_single_is_autoselected;
59+
5560
/** * The transport being used for the current OpenOCD session. */
5661
static struct transport *session;
5762

@@ -104,7 +109,8 @@ int allow_transports(struct command_context *ctx, const char * const *vector)
104109

105110
/* autoselect if there's no choice ... */
106111
if (!vector[1]) {
107-
LOG_INFO("only one transport option; autoselecting '%s'", vector[0]);
112+
LOG_DEBUG("only one transport option; autoselecting '%s'", vector[0]);
113+
transport_single_is_autoselected = true;
108114
return transport_select(ctx, vector[0]);
109115
}
110116

@@ -182,6 +188,11 @@ COMMAND_HANDLER(handle_transport_init)
182188
return ERROR_FAIL;
183189
}
184190

191+
if (transport_single_is_autoselected)
192+
LOG_WARNING("DEPRECATED: auto-selecting transport \"%s\". "
193+
"Use 'transport select %s' to suppress this message.",
194+
session->name, session->name);
195+
185196
return session->init(CMD_CTX);
186197
}
187198

@@ -216,8 +227,9 @@ COMMAND_HANDLER(handle_transport_select)
216227
command_print(CMD, "Debug adapter does not support any transports? Check config file order.");
217228
return ERROR_FAIL;
218229
}
219-
LOG_INFO("auto-selecting first available session transport \"%s\". "
220-
"To override use 'transport select <transport>'.", allowed_transports[0]);
230+
LOG_WARNING("DEPRECATED: auto-selecting transport \"%s\". "
231+
"Use 'transport select %s' to suppress this message.",
232+
allowed_transports[0], allowed_transports[0]);
221233
int retval = transport_select(CMD_CTX, allowed_transports[0]);
222234
if (retval != ERROR_OK)
223235
return retval;
@@ -229,6 +241,11 @@ COMMAND_HANDLER(handle_transport_select)
229241
/* assign transport */
230242
if (session) {
231243
if (!strcmp(session->name, CMD_ARGV[0])) {
244+
if (transport_single_is_autoselected) {
245+
/* Nothing to do, but also nothing to complain */
246+
transport_single_is_autoselected = false;
247+
return ERROR_OK;
248+
}
232249
LOG_WARNING("Transport \"%s\" was already selected", session->name);
233250
return ERROR_OK;
234251
}

0 commit comments

Comments
 (0)