From: openocd-gerrit <ope...@us...> - 2025-05-01 15:27:42
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 9643379d30fee381e92200ef9ed0caaeae580dad (commit) via 8485eb141554851d6cfcf6faf47c5934d13bf040 (commit) from a500b2ce67eb80870dfbd5d73118e822ac99ef88 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 9643379d30fee381e92200ef9ed0caaeae580dad Author: Antonio Borneo <bor...@gm...> Date: Tue Dec 31 16:29:46 2024 +0100 transport: use helper/list.h for the list of transports No behavioral change, just use the list's helpers. Change-Id: I69712648ef77689bfe6acc4811adad7293fb9009 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: https://review.openocd.org/c/openocd/+/8684 Reviewed-by: zapb <de...@za...> Tested-by: jenkins diff --git a/src/transport/transport.c b/src/transport/transport.c index 59f76ad31..8a210fe94 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -32,6 +32,7 @@ #include <helper/align.h> #include <helper/bits.h> +#include <helper/list.h> #include <helper/log.h> #include <helper/replacements.h> #include <transport/transport.h> @@ -59,7 +60,7 @@ static const struct { }; /** List of transports registered in OpenOCD. */ -static struct transport *transport_list; +static OOCD_LIST_HEAD(transport_list); /** * Bitmask of transport IDs which the currently selected debug adapter supports. @@ -98,7 +99,8 @@ static int transport_select(struct command_context *ctx, const char *name) { /* 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) { + struct transport *t; + list_for_each_entry(t, &transport_list, lh) { if (!strcmp(transport_name(t->id), name)) { int retval = t->select(ctx); /* select() registers commands specific to this @@ -193,7 +195,7 @@ int transport_register(struct transport *new_transport) return ERROR_FAIL; } - for (t = transport_list; t; t = t->next) { + list_for_each_entry(t, &transport_list, lh) { if (t->id == new_transport->id) { LOG_ERROR("transport '%s' already registered", transport_name(t->id)); @@ -206,8 +208,7 @@ int transport_register(struct transport *new_transport) transport_name(new_transport->id)); /* splice this into the list */ - new_transport->next = transport_list; - transport_list = new_transport; + list_add(&new_transport->lh, &transport_list); LOG_DEBUG("register '%s' (ID %d)", transport_name(new_transport->id), new_transport->id); @@ -270,7 +271,8 @@ COMMAND_HANDLER(handle_transport_list) command_print(CMD, "The following transports are available:"); - for (struct transport *t = transport_list; t; t = t->next) + struct transport *t; + list_for_each_entry(t, &transport_list, lh) command_print(CMD, "\t%s", transport_name(t->id)); return ERROR_OK; diff --git a/src/transport/transport.h b/src/transport/transport.h index f6f0f4f4d..5445bcf3b 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -14,6 +14,7 @@ #include "helper/bits.h" #include "helper/command.h" +#include "helper/list.h" #define TRANSPORT_JTAG BIT(0) #define TRANSPORT_SWD BIT(1) @@ -84,9 +85,9 @@ struct transport { int (*override_target)(const char **targetname); /** - * Transports are stored in a singly linked list. + * Transports are stored in a linked list. */ - struct transport *next; + struct list_head lh; }; int transport_register(struct transport *new_transport); commit 8485eb141554851d6cfcf6faf47c5934d13bf040 Author: Antonio Borneo <bor...@gm...> Date: Sun Dec 22 23:59:19 2024 +0100 transport: validate the transport id's from the driver Verify that it contains only valid transports. While JTAG and SWD are the more permissive transports, the respective 'dapdirect' versions are slightly limited, and the respective 'hla' versions are even more limited. A driver should not provide two version of the same transport. Verify that only one JTAG and only one SWD transport is present. Verify that the preferred transport is valid too. Change-Id: Iace2f881dd65fc763e81b33e6a7113961a7008af Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: https://review.openocd.org/c/openocd/+/8676 Tested-by: jenkins Reviewed-by: zapb <de...@za...> Reviewed-by: Jan Matyas <jan...@co...> diff --git a/src/transport/transport.c b/src/transport/transport.c index b7a3913cc..59f76ad31 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -125,21 +125,37 @@ static int transport_select(struct command_context *ctx, const char *name) int allow_transports(struct command_context *ctx, unsigned int transport_ids, unsigned int transport_preferred_id) { - /* NOTE: caller is required to provide only a list - * of *valid* transports - * - * REVISIT should we validate that? and insist there's - * at least one valid element in that list? - * - * ... allow removals, e.g. external strapping prevents use - * of one transport; C code should be definitive about what - * can be used when all goes well. - */ if (allowed_transports || session) { LOG_ERROR("Can't modify the set of allowed transports."); return ERROR_FAIL; } + /* validate the values in transport_ids and transport_preferred_id */ + if (transport_ids == 0 || (transport_ids & ~TRANSPORT_VALID_MASK) != 0) { + LOG_ERROR("BUG: Unknown transport IDs %lu", transport_ids & ~TRANSPORT_VALID_MASK); + return ERROR_FAIL; + } + + if ((transport_ids & transport_preferred_id) == 0 + || !IS_PWR_OF_2(transport_preferred_id)) { + LOG_ERROR("BUG: Invalid adapter transport_preferred_id"); + return ERROR_FAIL; + } + + unsigned int mask = transport_ids & + (TRANSPORT_JTAG | TRANSPORT_HLA_JTAG | TRANSPORT_DAPDIRECT_JTAG); + if (mask && !IS_PWR_OF_2(mask)) { + LOG_ERROR("BUG: Multiple JTAG transports"); + return ERROR_FAIL; + } + + mask = transport_ids & + (TRANSPORT_SWD | TRANSPORT_HLA_SWD | TRANSPORT_DAPDIRECT_SWD); + if (mask && !IS_PWR_OF_2(mask)) { + LOG_ERROR("BUG: Multiple SWD transports"); + return ERROR_FAIL; + } + allowed_transports = transport_ids; preferred_transport = transport_preferred_id; ----------------------------------------------------------------------- Summary of changes: src/transport/transport.c | 50 ++++++++++++++++++++++++++++++++--------------- src/transport/transport.h | 5 +++-- 2 files changed, 37 insertions(+), 18 deletions(-) hooks/post-receive -- Main OpenOCD repository |