transport: make 'transport select' auto-select the first available transport if not set

This should allow most of the existing configurations for older
versions to remain compatible without forcing the user to change his
or her config to explicitly select transport.

Also in some circumstances can remove the need to chain a "-c transport
select X" when building custom configs on the command line, which seems
like a common new user pitfall.

Change-Id: Ic87a38c0b9b88e88fb6d106385efce2f39381d3d
Suggested-by: Petteri Aimonen <jpa@git.mail.kapsi.fi>
Signed-off-by: Angus Gratton <gus@projectgus.com>
Reviewed-on: http://openocd.zylin.com/2551
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
This commit is contained in:
Angus Gratton 2015-02-25 08:19:15 +11:00 committed by Spencer Oliver
parent 492bab62ab
commit d90b86d8e3
3 changed files with 50 additions and 20 deletions

View File

@ -3088,6 +3088,7 @@ which are not currently documented here.
@end quotation
@end deffn
@anchor{hla_interface}
@deffn {Interface Driver} {hla}
This is a driver that supports multiple High Level Adapters.
This type of adapter does not expose some of the lower level api's
@ -3170,11 +3171,20 @@ displays the names of the transports supported by this
version of OpenOCD.
@end deffn
@deffn Command {transport select} transport_name
@deffn Command {transport select} @option{transport_name}
Select which of the supported transports to use in this OpenOCD session.
The transport must be supported by the debug adapter hardware and by the
version of OpenOCD you are using (including the adapter's driver).
No arguments: returns name of session's selected transport.
When invoked with @option{transport_name}, attempts to select the named
transport. The transport must be supported by the debug adapter
hardware and by the version of OpenOCD you are using (including the
adapter's driver).
If no transport has been selected and no @option{transport_name} is
provided, @command{transport select} auto-selects the first transport
supported by the debug adapter.
@command{transport select} always returns the name of the session's selected
transport, if any.
@end deffn
@subsection JTAG Transport
@ -3185,6 +3195,12 @@ JTAG transports expose a chain of one or more Test Access Points (TAPs),
each of which must be explicitly declared.
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 @ref{hla_interface,the hla interface
driver}, in which case the command is @command{transport select
hla_jtag}.
@subsection SWD Transport
@cindex SWD
@cindex Serial Wire Debug
@ -3194,6 +3210,12 @@ Debug Access Point (DAP, which must be explicitly declared.
SWD is debug-oriented, and does not support boundary scan testing.
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 @ref{hla_interface,the hla interface
driver}, in which case the command is @command{transport select
hla_swd}.
@deffn Command {swd newdap} ...
Declares a single DAP which uses SWD transport.
Parameters are currently the same as "jtag newtap" but this is
@ -3205,11 +3227,6 @@ Wire Control Register (WCR).
No parameters: displays current settings.
@end deffn
@subsection CMSIS-DAP Transport
@cindex CMSIS-DAP
CMSIS-DAP is an ARM-specific transport that is used to connect to
compilant debuggers.
@subsection SPI Transport
@cindex SPI
@cindex Serial Peripheral Interface

View File

@ -275,20 +275,28 @@ COMMAND_HANDLER(handle_transport_list)
*/
static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
int res;
switch (argc) {
case 1: /* return/display */
case 1: /* autoselect if necessary, then return/display current config */
if (!session) {
LOG_ERROR("session transport was not selected. Use 'transport select <transport>'");
if (!allowed_transports) {
LOG_ERROR("Debug adapter does not support any transports? Check config file order.");
return JIM_ERR;
} else {
}
LOG_INFO("auto-selecting first available session transport \"%s\". "
"To override use 'transport select <transport>'.", allowed_transports[0]);
res = transport_select(global_cmd_ctx, allowed_transports[0]);
if (res != JIM_OK)
return res;
}
Jim_SetResultString(interp, session->name, -1);
return JIM_OK;
}
break;
case 2: /* assign */
if (session) {
if (!strcmp(session->name, argv[1]->bytes)) {
LOG_WARNING("Transport \"%s\" was already selected", session->name);
Jim_SetResultString(interp, session->name, -1);
return JIM_OK;
} else {
LOG_ERROR("Can't change session's transport after the initial selection was made");
@ -309,8 +317,13 @@ static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj * const *a
for (unsigned i = 0; allowed_transports[i]; i++) {
if (strcmp(allowed_transports[i], argv[1]->bytes) == 0)
return transport_select(global_cmd_ctx, argv[1]->bytes);
if (strcmp(allowed_transports[i], argv[1]->bytes) == 0) {
if (transport_select(global_cmd_ctx, argv[1]->bytes) == ERROR_OK) {
Jim_SetResultString(interp, session->name, -1);
return JIM_OK;
}
return JIM_ERR;
}
}
LOG_ERROR("Debug adapter doesn't support '%s' transport", argv[1]->bytes);

View File

@ -19,8 +19,8 @@
# them more uniformly irlen too...)
if [catch {transport select}] {
echo "Info : session transport was not selected, defaulting to JTAG"
transport select jtag
echo "Error: unable to select a session transport. Can't continue."
shutdown
}
proc swj_newdap {chip tag args} {