aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPalmer Dabbelt <palmer@dabbelt.com>2017-05-15 17:40:28 -0700
committerPalmer Dabbelt <palmer@dabbelt.com>2017-05-15 17:40:28 -0700
commitc431c0eb251bf6d02959a6f55be3baba04552b5d (patch)
tree430458fd3794012937dad65048fcc6de50375952 /src
parenta8cf04b839b712f42e3ddca4d65a1474e1d486ff (diff)
downloadriscv-openocd-c431c0eb251bf6d02959a6f55be3baba04552b5d.zip
riscv-openocd-c431c0eb251bf6d02959a6f55be3baba04552b5d.tar.gz
riscv-openocd-c431c0eb251bf6d02959a6f55be3baba04552b5d.tar.bz2
Check for abstractcs.busy, not just CMDERR_BUSY
This fixes a race condition when reading/writing memory.
Diffstat (limited to 'src')
-rw-r--r--src/target/riscv/riscv-013.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index b43322e..f24afe1 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -1378,6 +1378,8 @@ static int read_memory(struct target *target, uint32_t address,
// catches the case where no writes went through at all.
uint32_t abstractcs = dmi_read(target, DMI_ABSTRACTCS);
+ while (get_field(abstractcs, DMI_ABSTRACTCS_BUSY))
+ abstractcs = dmi_read(target, DMI_ABSTRACTCS);
switch (get_field(abstractcs, DMI_ABSTRACTCS_CMDERR)) {
case CMDERR_NONE:
LOG_DEBUG("successful (partial?) memory write");
@@ -1560,6 +1562,8 @@ static int write_memory(struct target *target, uint32_t address,
// catches the case where no writes went through at all.
uint32_t abstractcs = dmi_read(target, DMI_ABSTRACTCS);
+ while (get_field(abstractcs, DMI_ABSTRACTCS_BUSY))
+ abstractcs = dmi_read(target, DMI_ABSTRACTCS);
switch (get_field(abstractcs, DMI_ABSTRACTCS_CMDERR)) {
case CMDERR_NONE:
LOG_DEBUG("successful (partial?) memory write");