From f631c906fa5c2bc23fdd595886d849a258413944 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 29 Nov 2021 17:55:02 -0800 Subject: [PATCH] Don't reexamine targets until it's time. Don't reexamine targets until we're past the examine stage of init(). Earlier than that, examine() will likely fail because the scan chain hasn't been examined yet. This will likely fix #663. Change-Id: I76ee9181f35cedcdb1a3e0f8ac33ab361c68d3af Signed-off-by: Tim Newsome --- src/target/target.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/target/target.c b/src/target/target.c index bc4fbf8df..4491d4a91 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -770,6 +770,12 @@ static int jtag_enable_callback(enum jtag_event event, void *priv) return target_examine_one(target); } +/* When this is true, it's OK to call examine() again in the hopes that this time + * it will work. Earlier than that there is probably other initialization that + * needs to happen (like scanning the JTAG chain) before examine should be + * called. */ +static bool examine_attempted; + /* Targets that correctly implement init + examine, i.e. * no communication with target during init: * @@ -780,6 +786,8 @@ int target_examine(void) int retval = ERROR_OK; struct target *target; + examine_attempted = true; + for (target = all_targets; target; target = target->next) { /* defer examination, but don't skip it */ if (!target->tap->enabled) { @@ -3047,7 +3055,7 @@ static int handle_target(void *priv) */ target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT); } - if (target->backoff.times > 0) { + if (target->backoff.times > 0 && examine_attempted) { LOG_DEBUG("[%s] Polling failed, trying to reexamine", target_name(target)); target_reset_examined(target); retval = target_examine_one(target);