From a6ec1a0e684ef0d6d3f12d7e2107af6ada15ac42 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 11 Sep 2017 11:35:47 -0700 Subject: [PATCH 1/2] Add timeout to another infinite loop. --- src/target/riscv/riscv-013.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index dbf2ce3db..3068fe0cd 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -574,7 +574,7 @@ static int wait_for_idle(struct target *target, uint32_t *abstractcs) errors[info->cmderr], *abstractcs); } - LOG_ERROR("Timed out after %ds waiting for busy to go low. (abstractcs=0x%x)" + LOG_ERROR("Timed out after %ds waiting for busy to go low (abstractcs=0x%x). " "Increase the timeout with riscv set_command_timeout_sec.", riscv_command_timeout_sec, *abstractcs); @@ -1897,7 +1897,7 @@ void riscv013_reset_current_hart(struct target *target) } if (time(NULL) - start > riscv_reset_timeout_sec) { LOG_ERROR("Hart didn't halt coming out of reset in %ds; " - "dmstatus=0x%x" + "dmstatus=0x%x; " "Increase the timeout with riscv set_reset_timeout_sec.", riscv_reset_timeout_sec, dmstatus); return; @@ -2041,9 +2041,17 @@ int riscv013_debug_buffer_register(struct target *target, riscv_addr_t addr) void riscv013_clear_abstract_error(struct target *target) { // Wait for busy to go away. + time_t start = time(NULL); uint32_t abstractcs = dmi_read(target, DMI_ABSTRACTCS); while (get_field(abstractcs, DMI_ABSTRACTCS_BUSY)) { abstractcs = dmi_read(target, DMI_ABSTRACTCS); + + if (time(NULL) - start > riscv_command_timeout_sec) { + LOG_ERROR("abstractcs.busy is not going low after %d seconds. " + "The target is either really slow, or broken. " + "abstractcs=0x%x", riscv_command_timeout_sec, abstractcs); + break; + } } // Clear the error status. dmi_write(target, DMI_ABSTRACTCS, abstractcs & DMI_ABSTRACTCS_CMDERR); From f9b2549e202c045284d5b9e894e1e2163f6207b0 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 11 Sep 2017 12:11:24 -0700 Subject: [PATCH 2/2] Tell user how to increase timeout. --- src/target/riscv/riscv-013.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 3068fe0cd..4ed87bc5e 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -2047,9 +2047,11 @@ void riscv013_clear_abstract_error(struct target *target) abstractcs = dmi_read(target, DMI_ABSTRACTCS); if (time(NULL) - start > riscv_command_timeout_sec) { - LOG_ERROR("abstractcs.busy is not going low after %d seconds. " - "The target is either really slow, or broken. " - "abstractcs=0x%x", riscv_command_timeout_sec, abstractcs); + LOG_ERROR("abstractcs.busy is not going low after %d seconds " + "(abstractcs=0x%x). The target is either really slow or " + "broken. You could increase the timeout with riscv " + "set_reset_timeout_sec.", + riscv_command_timeout_sec, abstractcs); break; } }