@@ -1887,19 +1887,21 @@ static int reset_dm(struct target *target)
1887
1887
1888
1888
const time_t start = time (NULL );
1889
1889
LOG_TARGET_DEBUG (target , "Waiting for the DM to acknowledge reset." );
1890
- do {
1890
+ while ( 1 ) {
1891
1891
result = dm_read (target , & dmcontrol , DM_DMCONTROL );
1892
1892
if (result != ERROR_OK )
1893
1893
return result ;
1894
-
1894
+ if (!get_field32 (dmcontrol , DM_DMCONTROL_DMACTIVE )) {
1895
+ LOG_TARGET_DEBUG (target , "The DM has just become deactivated (dmcontrol.dmactive: 1 -> 0)." );
1896
+ break ;
1897
+ }
1895
1898
if (time (NULL ) - start > riscv_get_command_timeout_sec ()) {
1896
1899
LOG_TARGET_ERROR (target , "DM didn't acknowledge reset in %d s. "
1897
1900
"Increase the timeout with 'riscv set_command_timeout_sec'." ,
1898
1901
riscv_get_command_timeout_sec ());
1899
1902
return ERROR_TIMEOUT_REACHED ;
1900
1903
}
1901
- } while (get_field32 (dmcontrol , DM_DMCONTROL_DMACTIVE ));
1902
- LOG_TARGET_DEBUG (target , "DM reset initiated." );
1904
+ }
1903
1905
}
1904
1906
/* TODO: Move the code above into `deactivate_dm()` function
1905
1907
* (a logical counterpart to activate_dm()). */
@@ -2999,10 +3001,20 @@ static int deassert_reset(struct target *target)
2999
3001
RISCV_DELAY_BASE );
3000
3002
time_t start = time (NULL );
3001
3003
LOG_TARGET_DEBUG (target , "Waiting for hart to come out of reset." );
3002
- do {
3004
+ while ( 1 ) {
3003
3005
result = dmstatus_read (target , & dmstatus , true);
3004
3006
if (result != ERROR_OK )
3005
3007
return result ;
3008
+ /* Certain debug modules, like the one in GD32VF103
3009
+ * MCUs, violate the specification's requirement that
3010
+ * each hart is in "exactly one of four states" and,
3011
+ * during reset, report harts as both unavailable and
3012
+ * halted/running. To work around this, we check for
3013
+ * the absence of the unavailable state rather than
3014
+ * the presence of any other state. */
3015
+ if (!get_field (dmstatus , DM_DMSTATUS_ALLUNAVAIL ) ||
3016
+ get_field (dmstatus , DM_DMSTATUS_ALLHAVERESET ))
3017
+ break ;
3006
3018
3007
3019
if (time (NULL ) - start > riscv_get_command_timeout_sec ()) {
3008
3020
LOG_TARGET_ERROR (target , "Hart didn't leave reset in %ds; "
@@ -3013,15 +3025,7 @@ static int deassert_reset(struct target *target)
3013
3025
get_field (dmstatus , DM_DMSTATUS_ALLHAVERESET ) ? "true" : "false" );
3014
3026
return ERROR_TIMEOUT_REACHED ;
3015
3027
}
3016
- /* Certain debug modules, like the one in GD32VF103
3017
- * MCUs, violate the specification's requirement that
3018
- * each hart is in "exactly one of four states" and,
3019
- * during reset, report harts as both unavailable and
3020
- * halted/running. To work around this, we check for
3021
- * the absence of the unavailable state rather than
3022
- * the presence of any other state. */
3023
- } while (get_field (dmstatus , DM_DMSTATUS_ALLUNAVAIL ) &&
3024
- !get_field (dmstatus , DM_DMSTATUS_ALLHAVERESET ));
3028
+ }
3025
3029
3026
3030
riscv_scan_set_delay (& info -> learned_delays , RISCV_DELAY_BASE ,
3027
3031
orig_base_delay );
0 commit comments