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/+/8693
-- gerrit commit 8de62d17b2aa3bc20d7fab55b8cb961a1384dd3d Author: Antonio Borneo <borneo.anto...@gmail.com> Date: Fri Jan 3 16:38:41 2025 +0100 transport: convert procs using_jtag and using_hla to commands To simplify the rework in the transport framework, convert the TCL procs 'using_jtag' and 'using_hla' to OpenOCD commands. Drop the proc 'using_swd' and its only use in the script 'swj-dp'. Document the new commands. Change-Id: I269be45324d995b7a30a0e208dbfacda44c3c13b Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com> diff --git a/doc/openocd.texi b/doc/openocd.texi index b3f8403fb7..2ed3c5cf13 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -3696,6 +3696,18 @@ When invoked with no transport name: @end itemize @end deffn +@deffn {Command} {using_jtag} +Utility command to query if the current transport is using JTAG. + +It returns non-zero on JTAG, zero for other transports. +@end deffn + +@deffn {Command} {using_hla} +Utility command to query if the current transport is based on HLA. + +It returns non-zero on HLA, zero for non-HLA transports. +@end deffn + @subsection JTAG Transport @cindex JTAG JTAG is the original transport supported by OpenOCD, and most diff --git a/src/jtag/hla/hla_transport.c b/src/jtag/hla/hla_transport.c index b826eb0fe6..1778a208ad 100644 --- a/src/jtag/hla/hla_transport.c +++ b/src/jtag/hla/hla_transport.c @@ -237,7 +237,14 @@ static void hl_constructor(void) bool transport_is_hla(void) { - struct transport *t; - t = get_current_transport(); + struct transport *t = get_current_transport(); + return t == &hl_swd_transport || t == &hl_jtag_transport; } + +bool transport_is_hla_jtag(void) +{ + struct transport *t = get_current_transport(); + + return t == &hl_jtag_transport; +} diff --git a/src/target/startup.tcl b/src/target/startup.tcl index e9646097f0..1c6be9e5a1 100644 --- a/src/target/startup.tcl +++ b/src/target/startup.tcl @@ -174,21 +174,6 @@ proc ocd_process_reset_inner { MODE } { } } -proc using_jtag {} { - set _TRANSPORT [ transport select ] - expr { [ string first "jtag" $_TRANSPORT ] != -1 } -} - -proc using_swd {} { - set _TRANSPORT [ transport select ] - expr { [ string first "swd" $_TRANSPORT ] != -1 } -} - -proc using_hla {} { - set _TRANSPORT [ transport select ] - expr { [ string first "hla" $_TRANSPORT ] != -1 } -} - ######### # Target/chain configuration scripts can either execute commands directly diff --git a/src/transport/transport.c b/src/transport/transport.c index 18c0217da4..8bc708e5b1 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -276,6 +276,39 @@ COMMAND_HANDLER(handle_transport_select) return ERROR_FAIL; } +COMMAND_HANDLER(handle_transport_using_jtag) +{ + if (CMD_ARGC) + return ERROR_COMMAND_SYNTAX_ERROR; + + if (!session) { + command_print(CMD, "no transport selected"); + return ERROR_FAIL; + } + + command_print(CMD, "%d", + (transport_is_jtag() || + transport_is_hla_jtag() || + transport_is_dapdirect_jtag()) ? 1 : 0); + + return ERROR_OK; +} + +COMMAND_HANDLER(handle_transport_using_hla) +{ + if (CMD_ARGC) + return ERROR_COMMAND_SYNTAX_ERROR; + + if (!session) { + command_print(CMD, "no transport selected"); + return ERROR_FAIL; + } + + command_print(CMD, "%d", transport_is_hla() ? 1 : 0); + + return ERROR_OK; +} + static const struct command_registration transport_commands[] = { { .name = "init", @@ -313,6 +346,20 @@ static const struct command_registration transport_group[] = { .chain = transport_commands, .usage = "" }, + { + .name = "using_jtag", + .handler = handle_transport_using_jtag, + .mode = COMMAND_ANY, + .help = "Returns 1 when JTAG transport is selected", + .usage = "", + }, + { + .name = "using_hla", + .handler = handle_transport_using_hla, + .mode = COMMAND_ANY, + .help = "Returns 1 when HLA transport is selected", + .usage = "", + }, COMMAND_REGISTRATION_DONE }; diff --git a/src/transport/transport.h b/src/transport/transport.h index 2e3dcc61aa..8ff81fe552 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -87,11 +87,17 @@ bool transport_is_swim(void); #if BUILD_HLADAPTER bool transport_is_hla(void); +bool transport_is_hla_jtag(void); #else static inline bool transport_is_hla(void) { return false; } + +static inline bool transport_is_hla_jtag(void) +{ + return false; +} #endif #endif /* OPENOCD_TRANSPORT_TRANSPORT_H */ diff --git a/tcl/target/swj-dp.tcl b/tcl/target/swj-dp.tcl index f2b233fb78..58df19ad99 100644 --- a/tcl/target/swj-dp.tcl +++ b/tcl/target/swj-dp.tcl @@ -28,10 +28,7 @@ if [catch {transport select}] { proc swj_newdap {chip tag args} { if [using_jtag] { eval jtag newtap $chip $tag $args - } elseif [using_swd] { - eval swd newdap $chip $tag $args } else { - echo "Error: transport '[ transport select ]' not supported by swj_newdap" - shutdown + eval swd newdap $chip $tag $args } } --