@@ -49,14 +49,16 @@ extern struct command_context *global_cmd_ctx;
4949static 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+
93113static 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