diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 0a68bfe98..64ea8ef4a 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -2056,6 +2056,14 @@ static int examine(struct target *target) enum riscv_hart_state state_at_examine_start; if (riscv_get_hart_state(target, &state_at_examine_start) != ERROR_OK) return ERROR_FAIL; + + /* Skip full examination of hart if it is unavailable */ + const bool hart_unavailable_at_examine_start = state_at_examine_start == RISCV_STATE_UNAVAILABLE; + if (hart_unavailable_at_examine_start) { + LOG_TARGET_INFO(target, "Did not fully examine hart %d as it was unavailable, deferring examine.", info->index); + target->defer_examine = true; + return ERROR_OK; + } const bool hart_halted_at_examine_start = state_at_examine_start == RISCV_STATE_HALTED; if (!hart_halted_at_examine_start) { r->prepped = true; diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 3f35a4f09..0b698197e 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -3214,6 +3214,11 @@ 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 74d1a8ab7..e8f3cbab1 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -686,7 +686,8 @@ int target_examine_one(struct target *target) } LOG_USER("[%s] Target successfully examined.", target_name(target)); - target_set_examined(target); + if (!target->defer_examine) + target_set_examined(target); target_call_event_callbacks(target, TARGET_EVENT_EXAMINE_END); LOG_TARGET_INFO(target, "Examination succeed"); @@ -5267,7 +5268,8 @@ COMMAND_HANDLER(handle_target_examine) return retval; } - target_set_examined(target); + if (!target->defer_examine) + target_set_examined(target); return ERROR_OK; }