From 55ae2534b35f0c5f2dc4bbe9738b17511f31d6cf Mon Sep 17 00:00:00 2001 From: cgsfv Date: Fri, 26 Apr 2024 17:05:16 -0700 Subject: [PATCH] Handle unavailability when deasserting reset --- src/target/riscv/riscv-013.c | 4 +++- src/target/startup.tcl | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 7a94bc784..44826efa5 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -2979,7 +2979,9 @@ static int deassert_reset(struct target *target) info->dmi_busy_delay = orig_dmi_busy_delay; - if (target->reset_halt) { + if (get_field(dmstatus, DM_DMSTATUS_ALLUNAVAIL)) { + target->state = TARGET_UNAVAILABLE; + } else if (target->reset_halt) { target->state = TARGET_HALTED; target->debug_reason = DBG_REASON_DBGRQ; } else { diff --git a/src/target/startup.tcl b/src/target/startup.tcl index 7a1e245c6..8ddac0cbf 100644 --- a/src/target/startup.tcl +++ b/src/target/startup.tcl @@ -129,9 +129,11 @@ proc ocd_process_reset_inner { MODE } { } else { $t invoke-event examine-end } - if { [$t curstate] == "unavailable" } { - continue - } + } + + # no need to wait for a target that is unavailable anyway + if { [$t curstate] == "unavailable" } { + continue } # Wait up to 1 second for target to halt. Why 1sec? Cause @@ -149,7 +151,7 @@ proc ocd_process_reset_inner { MODE } { continue } if { $s != "halted" } { - return -code error [format "TARGET: %s - Not halted - Maybe unavailable %s" $t $s] + return -code error [format "TARGET: %s - Not halted (%s)" $t $s] } } }