Skip to content

Commit 59ce92a

Browse files
authored
Merge pull request riscv-collab#1083 from en-sc/en-sc/deprecate-reset-timeout
target/riscv: deprecate `riscv set_reset_timeout_sec`
2 parents f34e531 + f3abfe4 commit 59ce92a

File tree

5 files changed

+41
-77
lines changed

5 files changed

+41
-77
lines changed

doc/openocd.texi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11290,11 +11290,6 @@ Set the wall-clock timeout (in seconds) for individual commands. The default
1129011290
should work fine for all but the slowest targets (eg. simulators).
1129111291
@end deffn
1129211292

11293-
@deffn {Command} {riscv set_reset_timeout_sec} [seconds]
11294-
Set the maximum time to wait for a hart to come out of reset after reset is
11295-
deasserted.
11296-
@end deffn
11297-
1129811293
@deffn {Command} {riscv set_mem_access} method1 [method2] [method3]
1129911294
Specify which RISC-V memory access method(s) shall be used, and in which order
1130011295
of priority. At least one method must be specified.

src/target/riscv/riscv-011.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ static int wait_for_debugint_clear(struct target *target, bool ignore_first)
741741

742742
if (!bits.interrupt)
743743
return ERROR_OK;
744-
if (time(NULL) - start > riscv_command_timeout_sec) {
744+
if (time(NULL) - start > riscv_get_command_timeout_sec()) {
745745
LOG_ERROR("Timed out waiting for debug int to clear."
746746
"Increase timeout with riscv set_command_timeout_sec.");
747747
return ERROR_FAIL;
@@ -1025,7 +1025,7 @@ static int wait_for_state(struct target *target, enum target_state state)
10251025
return result;
10261026
if (target->state == state)
10271027
return ERROR_OK;
1028-
if (time(NULL) - start > riscv_command_timeout_sec) {
1028+
if (time(NULL) - start > riscv_get_command_timeout_sec()) {
10291029
LOG_ERROR("Timed out waiting for state %d. "
10301030
"Increase timeout with riscv set_command_timeout_sec.", state);
10311031
return ERROR_FAIL;
@@ -1186,7 +1186,7 @@ static int full_step(struct target *target, bool announce)
11861186
return result;
11871187
if (target->state != TARGET_DEBUG_RUNNING)
11881188
break;
1189-
if (time(NULL) - start > riscv_command_timeout_sec) {
1189+
if (time(NULL) - start > riscv_get_command_timeout_sec()) {
11901190
LOG_ERROR("Timed out waiting for step to complete."
11911191
"Increase timeout with riscv set_command_timeout_sec");
11921192
return ERROR_FAIL;
@@ -2344,10 +2344,10 @@ static int wait_for_authbusy(struct target *target)
23442344
uint32_t dminfo = dbus_read(target, DMINFO);
23452345
if (!get_field(dminfo, DMINFO_AUTHBUSY))
23462346
break;
2347-
if (time(NULL) - start > riscv_command_timeout_sec) {
2347+
if (time(NULL) - start > riscv_get_command_timeout_sec()) {
23482348
LOG_ERROR("Timed out after %ds waiting for authbusy to go low (dminfo=0x%x). "
23492349
"Increase the timeout with riscv set_command_timeout_sec.",
2350-
riscv_command_timeout_sec,
2350+
riscv_get_command_timeout_sec(),
23512351
dminfo);
23522352
return ERROR_FAIL;
23532353
}

src/target/riscv/riscv-013.c

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
745734
static 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-
843818
static 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
}

src/target/riscv/riscv.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,15 @@ struct tdata1_cache {
140140
};
141141

142142
/* Wall-clock timeout for a command/access. Settable via RISC-V Target commands.*/
143-
int riscv_command_timeout_sec = DEFAULT_COMMAND_TIMEOUT_SEC;
143+
static int riscv_command_timeout_sec_value = DEFAULT_COMMAND_TIMEOUT_SEC;
144144

145-
/* Wall-clock timeout after reset. Settable via RISC-V Target commands.*/
146-
int riscv_reset_timeout_sec = DEFAULT_RESET_TIMEOUT_SEC;
145+
/* DEPRECATED Wall-clock timeout after reset. Settable via RISC-V Target commands.*/
146+
static int riscv_reset_timeout_sec = DEFAULT_COMMAND_TIMEOUT_SEC;
147+
148+
int riscv_get_command_timeout_sec(void)
149+
{
150+
return MAX(riscv_command_timeout_sec_value, riscv_reset_timeout_sec);
151+
}
147152

148153
static bool riscv_enable_virt2phys = true;
149154

@@ -3853,13 +3858,14 @@ COMMAND_HANDLER(riscv_set_command_timeout_sec)
38533858
return ERROR_FAIL;
38543859
}
38553860

3856-
riscv_command_timeout_sec = timeout;
3861+
riscv_command_timeout_sec_value = timeout;
38573862

38583863
return ERROR_OK;
38593864
}
38603865

38613866
COMMAND_HANDLER(riscv_set_reset_timeout_sec)
38623867
{
3868+
LOG_WARNING("The command 'riscv set_reset_timeout_sec' is deprecated! Please, use 'riscv set_command_timeout_sec'.");
38633869
if (CMD_ARGC != 1) {
38643870
LOG_ERROR("Command takes exactly 1 parameter.");
38653871
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -5066,7 +5072,7 @@ static const struct command_registration riscv_exec_command_handlers[] = {
50665072
.handler = riscv_set_reset_timeout_sec,
50675073
.mode = COMMAND_ANY,
50685074
.usage = "[sec]",
5069-
.help = "Set the wall-clock timeout (in seconds) after reset is deasserted"
5075+
.help = "DEPRECATED. Use 'riscv set_command_timeout_sec' instead."
50705076
},
50715077
{
50725078
.name = "set_mem_access",

src/target/riscv/riscv.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ struct riscv_program;
2222
#define RISCV_MAX_HWBPS 16
2323
#define RISCV_MAX_DMS 100
2424

25-
#define DEFAULT_COMMAND_TIMEOUT_SEC 2
26-
#define DEFAULT_RESET_TIMEOUT_SEC 30
25+
#define DEFAULT_COMMAND_TIMEOUT_SEC 5
2726

2827
#define RISCV_SATP_MODE(xlen) ((xlen) == 32 ? SATP32_MODE : SATP64_MODE)
2928
#define RISCV_SATP_PPN(xlen) ((xlen) == 32 ? SATP32_PPN : SATP64_PPN)
@@ -340,10 +339,7 @@ typedef struct {
340339
} virt2phys_info_t;
341340

342341
/* Wall-clock timeout for a command/access. Settable via RISC-V Target commands.*/
343-
extern int riscv_command_timeout_sec;
344-
345-
/* Wall-clock timeout after reset. Settable via RISC-V Target commands.*/
346-
extern int riscv_reset_timeout_sec;
342+
int riscv_get_command_timeout_sec(void);
347343

348344
extern bool riscv_enable_virtual;
349345

0 commit comments

Comments
 (0)