This is an automated email from Gerrit. Andreas Färber ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/3088
-- gerrit commit 04a3667ba1f37341138bf11d376bf273a3248e7d Author: Andreas Färber <[email protected]> Date: Mon Sep 7 00:18:15 2015 +0200 adi_v5_swd: Check DAP IDCODE on connect Resolves an old FIXME and ticket #90. Change-Id: I76ebfe2b6775037b9eebc99031ae7d1810f3cb97 Suggested-by: Paul Fertser <[email protected]> Signed-off-by: Andreas Färber <[email protected]> diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index c916fb1..fdccb21 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -548,13 +548,6 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params", pTap->chip, pTap->tapname, pTap->dotted_name, goi->argc); - if (!transport_is_jtag()) { - /* SWD doesn't require any JTAG tap parameters */ - pTap->enabled = true; - jtag_tap_init(pTap); - return JIM_OK; - } - /* IEEE specifies that the two LSBs of an IR scan are 01, so make * that the default. The "-ircapture" and "-irmask" options are only * needed to cope with nonstandard TAPs, or to specify more bits. @@ -576,6 +569,8 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) pTap->disabled_after_reset = false; break; case NTAP_OPT_DISABLED: + if (!transport_is_jtag()) + break; pTap->disabled_after_reset = true; break; case NTAP_OPT_EXPECTED_ID: @@ -589,6 +584,8 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) case NTAP_OPT_IRLEN: case NTAP_OPT_IRMASK: case NTAP_OPT_IRCAPTURE: + if (!transport_is_jtag()) + break; e = jim_newtap_ir_param(n, goi, pTap); if (JIM_OK != e) { free(cp); @@ -606,7 +603,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) pTap->enabled = !pTap->disabled_after_reset; /* Did all the required option bits get cleared? */ - if (pTap->ir_length != 0) { + if (pTap->ir_length != 0 || !transport_is_jtag()) { jtag_tap_init(pTap); return JIM_OK; } diff --git a/src/target/adi_v5_swd.c b/src/target/adi_v5_swd.c index 9030740..fc1e17a 100644 --- a/src/target/adi_v5_swd.c +++ b/src/target/adi_v5_swd.c @@ -97,18 +97,54 @@ static int swd_run_inner(struct adiv5_dap *dap) return retval; } +static void swd_dap_display(enum log_levels level, const char *msg, + const char *name, uint32_t idcode) +{ + log_printf_lf(level, __FILE__, __LINE__, __func__, + "SWD tap: %s %16.16s: 0x%08" PRIx32, + name, msg, + idcode); +} + +static bool swd_match_tap(const struct jtag_tap *tap) +{ + if (tap->expected_ids_cnt == 0) + return true; + + uint32_t mask = ~0; + uint32_t idcode = tap->idcode & mask; + + /* Loop over the expected identification codes and test for a match */ + for (unsigned ii = 0; ii < tap->expected_ids_cnt; ii++) { + uint32_t expected = tap->expected_ids[ii] & mask; + + if (idcode == expected) + return true; + + /* Treat "-expected-id 0" as a "don't-warn" wildcard */ + if (tap->expected_ids[ii] == 0) + return true; + } + + /* If none of the expected IDs matched, warn */ + swd_dap_display(LOG_LVL_WARNING, "UNEXPECTED", + tap->dotted_name, tap->idcode); + for (unsigned ii = 0; ii < tap->expected_ids_cnt; ii++) { + char msg[32]; + + snprintf(msg, sizeof(msg), "expected %u of %u", + ii + 1, tap->expected_ids_cnt); + swd_dap_display(LOG_LVL_ERROR, msg, + tap->dotted_name, tap->expected_ids[ii]); + } + return false; +} + static int swd_connect(struct adiv5_dap *dap) { uint32_t idcode; int status; - /* FIXME validate transport config ... is the - * configured DAP present (check IDCODE)? - * Is *only* one DAP configured? - * - * MUST READ IDCODE - */ - /* Note, debugport_init() does setup too */ jtag_interface->swd->switch_seq(dap, JTAG_TO_SWD); @@ -124,6 +160,10 @@ static int swd_connect(struct adiv5_dap *dap) if (status == ERROR_OK) { LOG_INFO("SWD IDCODE %#8.8" PRIx32, idcode); dap->jtag_info->tap->idcode = idcode; + if (!swd_match_tap(dap->jtag_info->tap)) { + dap->do_reconnect = true; + return ERROR_JTAG_INIT_SOFT_FAIL; + } dap->do_reconnect = false; } else dap->do_reconnect = true; -- ------------------------------------------------------------------------------ _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
