From c428ed72a4905bb9041cb3ea52eb8f3ba0e4bb09 Mon Sep 17 00:00:00 2001 From: cgsfv Date: Mon, 26 Feb 2024 17:14:41 -0800 Subject: [PATCH] Added cleaner handling of unexamined harts --- src/target/riscv/riscv.c | 21 +++++++-------------- src/target/target.c | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 0b698197e..0b2963c47 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -535,7 +535,7 @@ static void riscv_deinit_target(struct target *target) LOG_TARGET_DEBUG(target, "riscv_deinit_target()"); /* No need to deinit a target that has not been examined */ - if (!target->examined) + if (!target_was_examined(target)) return; struct riscv_info *info = target->arch_info; @@ -1930,27 +1930,25 @@ int riscv_halt(struct target *target) struct target_list *tlist; foreach_smp_target(tlist, target->smp_targets) { struct target *t = tlist->target; - if (t->examined) { + if (target_was_examined(t)) if (halt_prep(t) != ERROR_OK) result = ERROR_FAIL; - } } foreach_smp_target(tlist, target->smp_targets) { struct target *t = tlist->target; struct riscv_info *i = riscv_info(t); - if (t->examined && i->prepped) { - if (halt_go(t) != ERROR_OK) - result = ERROR_FAIL; - } + if (target_was_examined(t)) + if (i->prepped) + if (halt_go(t) != ERROR_OK) + result = ERROR_FAIL; } foreach_smp_target(tlist, target->smp_targets) { struct target *t = tlist->target; - if (t->examined) { + if (target_was_examined(t)) if (halt_finish(t) != ERROR_OK) return ERROR_FAIL; - } } } else { @@ -3214,11 +3212,6 @@ int riscv_openocd_poll(struct target *target) if (!target_was_examined(t)) continue; - if (target->defer_examine) { - target->examined = false; - continue; - } - enum riscv_next_action next_action; if (riscv_poll_hart(t, &next_action) != ERROR_OK) return ERROR_FAIL; diff --git a/src/target/target.c b/src/target/target.c index e8f3cbab1..e7d043fe7 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -676,6 +676,7 @@ int target_examine_one(struct target *target) target_call_event_callbacks(target, TARGET_EVENT_EXAMINE_START); + bool defer_state = target->defer_examine; int retval = target->type->examine(target); if (retval != ERROR_OK) { LOG_TARGET_ERROR(target, "Examination failed"); @@ -685,9 +686,14 @@ int target_examine_one(struct target *target) return retval; } - LOG_USER("[%s] Target successfully examined.", target_name(target)); - if (!target->defer_examine) + if (target->defer_examine) { + LOG_USER("[%s] Target unavailable for full examination.", target_name(target)); + target->defer_examine = defer_state; + target_reset_examined(target); + } else { + LOG_USER("[%s] Target successfully examined.", target_name(target)); target_set_examined(target); + } target_call_event_callbacks(target, TARGET_EVENT_EXAMINE_END); LOG_TARGET_INFO(target, "Examination succeed"); @@ -2979,7 +2985,7 @@ static int handle_target(void *priv) * schedule for now+polling_interval, the next poll won't * actually happen until a polling_interval later. */ bool poll_needed = timeval_ms() + polling_interval / 2 >= target->backoff.next_attempt; - if (!target->examined || !target->tap->enabled || power_dropout || srst_asserted || !poll_needed) + if (!target->tap->enabled || power_dropout || srst_asserted || !poll_needed) continue; /* polling may fail silently until the target has been examined */ @@ -5262,13 +5268,18 @@ COMMAND_HANDLER(handle_target_examine) return ERROR_OK; } + bool defer_state = target->defer_examine; int retval = target->type->examine(target); if (retval != ERROR_OK) { target_reset_examined(target); return retval; } - if (!target->defer_examine) + if (target->defer_examine) { + LOG_INFO("Unable to do full examination of %s", target_name(target)); + target->defer_examine = defer_state; + target_reset_examined(target); + } else target_set_examined(target); return ERROR_OK;