This is an automated email from Gerrit. Tomas Vanek ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/6142
-- gerrit commit f5f1ec56c8a8192f90568ed3fe210f181fa5c6b0 Author: Tomas Vanek <[email protected]> Date: Tue Apr 6 22:30:52 2021 +0200 target/arm_dap: check SWD DAP configuration Raise error if * more than one plain SWD DAPs are defined * plain and multidrop DAPs are mixed * two multidrop DAPs have the same TARGETSEL value Inspired by Graham Sanderson's http://openocd.zylin.com/4935 Change-Id: I7279744464f5cc6477e50695c596be9c5e5507bf Signed-off-by: Tomas Vanek <[email protected]> diff --git a/src/target/arm_dap.c b/src/target/arm_dap.c index 56442f1..08d6778 100644 --- a/src/target/arm_dap.c +++ b/src/target/arm_dap.c @@ -210,6 +210,51 @@ static int dap_configure(Jim_GetOptInfo *goi, struct arm_dap_object *dap) return JIM_OK; } +static int dap_check_config(struct adiv5_dap *dap) +{ + if (transport_is_jtag() || transport_is_dapdirect_jtag() || transport_is_hla()) + return ERROR_OK; + + struct arm_dap_object *obj; + uint32_t targetsel = dap->tap->multidrop_targetsel; + bool had_multidrop = targetsel != DP_TARGETSEL_INVALID; + unsigned int non_multidrop_count = had_multidrop ? 0 : 1; + + list_for_each_entry(obj, &all_dap, lh) { + struct adiv5_dap *dap_it = &obj->dap; + + if (transport_is_swd()) { + if (dap_it->tap->multidrop_targetsel == DP_TARGETSEL_INVALID) { + non_multidrop_count++; + } else { + if (dap_it->tap->multidrop_targetsel == targetsel) { + uint32_t dp_id = targetsel & DP_TARGETSEL_DPID_MASK; + uint32_t instance_id = targetsel >> DP_TARGETSEL_INSTANCEID_SHIFT; + LOG_ERROR("%s and %s have the same multidrop selectors -dp-id 0x%08" + PRIx32 " and -instance-id 0x%1" PRIx32, + obj->name, adiv5_dap_name(dap), + dp_id, instance_id); + return ERROR_FAIL; + } + had_multidrop = true; + } + } else if (transport_is_dapdirect_swd()) { + non_multidrop_count++; + } + } + + if (non_multidrop_count > 1) { + LOG_ERROR("Two or more SWD non multidrop DAPs are not supported"); + return ERROR_FAIL; + } + if (had_multidrop && non_multidrop_count) { + LOG_ERROR("Mixture of SWD multidrop DAPs and non multidrop DAPs is not supported"); + return ERROR_FAIL; + } + + return ERROR_OK; +} + static int dap_create(Jim_GetOptInfo *goi) { struct command_context *cmd_ctx; @@ -273,6 +318,10 @@ static int dap_create(Jim_GetOptInfo *goi) assert(c); command_set_handler_data(c, dap); + e = dap_check_config(&dap->dap); + if (e != ERROR_OK) + return JIM_ERR; + list_add_tail(&dap->lh, &all_dap); return (ERROR_OK == e) ? JIM_OK : JIM_ERR; --
