@@ -695,12 +695,12 @@ static int dmi_op(struct target *target, uint32_t *data_in,
695695 uint32_t data_out , bool exec , bool ensure_success )
696696{
697697 int result = dmi_op_timeout (target , data_in , dmi_busy_encountered , op ,
698- address , data_out , riscv_command_timeout_sec , exec , ensure_success );
698+ address , data_out , riscv_get_command_timeout_sec () , exec , ensure_success );
699699 if (result == ERROR_TIMEOUT_REACHED ) {
700700 LOG_TARGET_ERROR (target , "DMI operation didn't complete in %d seconds. The target is "
701701 "either really slow or broken. You could increase the "
702702 "timeout with riscv set_command_timeout_sec." ,
703- riscv_command_timeout_sec );
703+ riscv_get_command_timeout_sec () );
704704 return ERROR_FAIL ;
705705 }
706706 return result ;
@@ -731,17 +731,6 @@ static uint32_t riscv013_get_dmi_address(const struct target *target, uint32_t a
731731 return address + base ;
732732}
733733
734- static int dm_op_timeout (struct target * target , uint32_t * data_in ,
735- bool * dmi_busy_encountered , int op , uint32_t address ,
736- uint32_t data_out , int timeout_sec , bool exec , bool ensure_success )
737- {
738- dm013_info_t * dm = get_dm (target );
739- if (!dm )
740- return ERROR_FAIL ;
741- return dmi_op_timeout (target , data_in , dmi_busy_encountered , op , address + dm -> base ,
742- data_out , timeout_sec , exec , ensure_success );
743- }
744-
745734static int dm_op (struct target * target , uint32_t * data_in ,
746735 bool * dmi_busy_encountered , int op , uint32_t address ,
747736 uint32_t data_out , bool exec , bool ensure_success )
@@ -805,11 +794,10 @@ static bool check_dbgbase_exists(struct target *target)
805794 return false;
806795}
807796
808- static int dmstatus_read_timeout (struct target * target , uint32_t * dmstatus ,
809- bool authenticated , unsigned timeout_sec )
797+ static int dmstatus_read (struct target * target , uint32_t * dmstatus ,
798+ bool authenticated )
810799{
811- int result = dm_op_timeout (target , dmstatus , NULL , DMI_OP_READ ,
812- DM_DMSTATUS , 0 , timeout_sec , false, true);
800+ int result = dm_read (target , dmstatus , DM_DMSTATUS );
813801 if (result != ERROR_OK )
814802 return result ;
815803 int dmstatus_version = get_field (* dmstatus , DM_DMSTATUS_VERSION );
@@ -827,19 +815,6 @@ static int dmstatus_read_timeout(struct target *target, uint32_t *dmstatus,
827815 return ERROR_OK ;
828816}
829817
830- static int dmstatus_read (struct target * target , uint32_t * dmstatus ,
831- bool authenticated )
832- {
833- int result = dmstatus_read_timeout (target , dmstatus , authenticated ,
834- riscv_command_timeout_sec );
835- if (result == ERROR_TIMEOUT_REACHED )
836- LOG_TARGET_ERROR (target , "DMSTATUS read didn't complete in %d seconds. The target is "
837- "either really slow or broken. You could increase the "
838- "timeout with `riscv set_command_timeout_sec`." ,
839- riscv_command_timeout_sec );
840- return result ;
841- }
842-
843818static int increase_ac_busy_delay (struct target * target )
844819{
845820 riscv013_info_t * info = get_info (target );
@@ -890,12 +865,12 @@ static int wait_for_idle(struct target *target, uint32_t *abstractcs)
890865 dm -> abstract_cmd_maybe_busy = false;
891866 return ERROR_OK ;
892867 }
893- } while ((time (NULL ) - start ) < riscv_command_timeout_sec );
868+ } while ((time (NULL ) - start ) < riscv_get_command_timeout_sec () );
894869
895870 LOG_TARGET_ERROR (target ,
896871 "Timed out after %ds waiting for busy to go low (abstractcs=0x%" PRIx32 "). "
897872 "Increase the timeout with riscv set_command_timeout_sec." ,
898- riscv_command_timeout_sec ,
873+ riscv_get_command_timeout_sec () ,
899874 * abstractcs );
900875
901876 if (!dm -> abstract_cmd_maybe_busy )
@@ -1898,10 +1873,10 @@ static int wait_for_authbusy(struct target *target, uint32_t *dmstatus)
18981873 * dmstatus = value ;
18991874 if (!get_field (value , DM_DMSTATUS_AUTHBUSY ))
19001875 break ;
1901- if (time (NULL ) - start > riscv_command_timeout_sec ) {
1876+ if (time (NULL ) - start > riscv_get_command_timeout_sec () ) {
19021877 LOG_TARGET_ERROR (target , "Timed out after %ds waiting for authbusy to go low (dmstatus=0x%x). "
19031878 "Increase the timeout with riscv set_command_timeout_sec." ,
1904- riscv_command_timeout_sec ,
1879+ riscv_get_command_timeout_sec () ,
19051880 value );
19061881 return ERROR_FAIL ;
19071882 }
@@ -2091,11 +2066,10 @@ static int reset_dm(struct target *target)
20912066 if (result != ERROR_OK )
20922067 return result ;
20932068
2094- if (time (NULL ) - start > riscv_reset_timeout_sec ) {
2095- /* TODO: Introduce a separate timeout for this. */
2069+ if (time (NULL ) - start > riscv_get_command_timeout_sec ()) {
20962070 LOG_TARGET_ERROR (target , "DM didn't acknowledge reset in %d s. "
2097- "Increase the timeout with 'riscv set_reset_timeout_sec '." ,
2098- riscv_reset_timeout_sec );
2071+ "Increase the timeout with 'riscv set_command_timeout_sec '." ,
2072+ riscv_get_command_timeout_sec () );
20992073 return ERROR_TIMEOUT_REACHED ;
21002074 }
21012075 } while (get_field32 (dmcontrol , DM_DMCONTROL_DMACTIVE ));
@@ -2114,11 +2088,10 @@ static int reset_dm(struct target *target)
21142088 if (result != ERROR_OK )
21152089 return result ;
21162090
2117- if (time (NULL ) - start > riscv_reset_timeout_sec ) {
2118- /* TODO: Introduce a separate timeout for this. */
2091+ if (time (NULL ) - start > riscv_get_command_timeout_sec ()) {
21192092 LOG_TARGET_ERROR (target , "Debug Module did not become active in %d s. "
2120- "Increase the timeout with 'riscv set_reset_timeout_sec '." ,
2121- riscv_reset_timeout_sec );
2093+ "Increase the timeout with 'riscv set_command_timeout_sec '." ,
2094+ riscv_get_command_timeout_sec () );
21222095 return ERROR_TIMEOUT_REACHED ;
21232096 }
21242097 } while (!get_field32 (dmcontrol , DM_DMCONTROL_DMACTIVE ));
@@ -2810,7 +2783,7 @@ static int batch_run_timeout(struct target *target, struct riscv_batch *batch)
28102783 result = increase_dmi_busy_delay (target );
28112784 if (result != ERROR_OK )
28122785 return result ;
2813- } while (time (NULL ) - start < riscv_command_timeout_sec );
2786+ } while (time (NULL ) - start < riscv_get_command_timeout_sec () );
28142787
28152788 assert (result == ERROR_OK );
28162789 assert (riscv_batch_was_batch_busy (batch ));
@@ -2825,7 +2798,7 @@ static int batch_run_timeout(struct target *target, struct riscv_batch *batch)
28252798 LOG_TARGET_ERROR (target , "DMI operation didn't complete in %d seconds. "
28262799 "The target is either really slow or broken. You could increase "
28272800 "the timeout with riscv set_command_timeout_sec." ,
2828- riscv_command_timeout_sec );
2801+ riscv_get_command_timeout_sec () );
28292802 return ERROR_TIMEOUT_REACHED ;
28302803}
28312804
@@ -3225,21 +3198,15 @@ static int deassert_reset(struct target *target)
32253198 time_t start = time (NULL );
32263199 LOG_TARGET_DEBUG (target , "Waiting for hart to come out of reset." );
32273200 do {
3228- result = dmstatus_read_timeout (target , & dmstatus , true,
3229- riscv_reset_timeout_sec );
3230- if (result == ERROR_TIMEOUT_REACHED )
3231- LOG_TARGET_ERROR (target , "Hart didn't complete a DMI read coming "
3232- "out of reset in %ds; Increase the timeout with riscv "
3233- "set_reset_timeout_sec." ,
3234- riscv_reset_timeout_sec );
3201+ result = dmstatus_read (target , & dmstatus , true);
32353202 if (result != ERROR_OK )
32363203 return result ;
32373204
3238- if (time (NULL ) - start > riscv_reset_timeout_sec ) {
3205+ if (time (NULL ) - start > riscv_get_command_timeout_sec () ) {
32393206 LOG_TARGET_ERROR (target , "Hart didn't leave reset in %ds; "
32403207 "dmstatus=0x%x (allunavail=%s, allhavereset=%s); "
3241- "Increase the timeout with riscv set_reset_timeout_sec ." ,
3242- riscv_reset_timeout_sec , dmstatus ,
3208+ "Increase the timeout with riscv set_command_timeout_sec ." ,
3209+ riscv_get_command_timeout_sec () , dmstatus ,
32433210 get_field (dmstatus , DM_DMSTATUS_ALLUNAVAIL ) ? "true" : "false" ,
32443211 get_field (dmstatus , DM_DMSTATUS_ALLHAVERESET ) ? "true" : "false" );
32453212 return ERROR_TIMEOUT_REACHED ;
@@ -3425,10 +3392,10 @@ static int read_sbcs_nonbusy(struct target *target, uint32_t *sbcs)
34253392 return ERROR_FAIL ;
34263393 if (!get_field (* sbcs , DM_SBCS_SBBUSY ))
34273394 return ERROR_OK ;
3428- if (time (NULL ) - start > riscv_command_timeout_sec ) {
3395+ if (time (NULL ) - start > riscv_get_command_timeout_sec () ) {
34293396 LOG_TARGET_ERROR (target , "Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
34303397 "Increase the timeout with riscv set_command_timeout_sec." ,
3431- riscv_command_timeout_sec , * sbcs );
3398+ riscv_get_command_timeout_sec () , * sbcs );
34323399 return ERROR_FAIL ;
34333400 }
34343401 }
0 commit comments