Skip to content

Commit 9e6a7a2

Browse files
author
Kongou Hikari
committed
riscv-013: Fix SBA hang on unexpectedly reset
1 parent 11618c6 commit 9e6a7a2

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/target/riscv/riscv-013.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,18 +1974,35 @@ static int sb_write_address(struct target *target, target_addr_t address)
19741974

19751975
static int read_sbcs_nonbusy(struct target *target, uint32_t *sbcs)
19761976
{
1977+
uint32_t dmstatus;
19771978
time_t start = time(NULL);
19781979
while (1) {
19791980
if (dmi_read(target, sbcs, DMI_SBCS) != ERROR_OK)
19801981
return ERROR_FAIL;
19811982
if (!get_field(*sbcs, DMI_SBCS_SBBUSY))
19821983
return ERROR_OK;
1984+
#if 0
19831985
if (get_field(*sbcs, DMI_SBCS_SBBUSYERROR)) {
1984-
LOG_ERROR("The transmission will try later because sbbusyerror is high (sbcs=0x%x).",
1985-
riscv_command_timeout_sec, *sbcs);
1986-
return ERROR_OK;
1986+
LOG_ERROR("The transmission end because sbbusyerror is high (sbcs=0x%x).",
1987+
*sbcs);
1988+
dmi_write(target, DMI_SBCS, DMI_SBCS_SBBUSYERROR);
1989+
return ERROR_FAIL;
1990+
}
1991+
#endif
1992+
if (dmstatus_read(target, &dmstatus, true) == ERROR_OK) {
1993+
if(get_field(dmstatus, DMI_DMSTATUS_ANYHAVERESET)) {
1994+
LOG_ERROR("Please don't reset core when accessing memory!");
1995+
dmi_write(target, DMI_DMCONTROL, 0);
1996+
dmi_write(target, DMI_DMCONTROL, DMI_DMCONTROL_DMACTIVE); /* Reset DM logic */
1997+
return ERROR_FAIL;
1998+
}
1999+
}
2000+
else {
2001+
return ERROR_FAIL;
19872002
}
19882003
if (time(NULL) - start > riscv_command_timeout_sec) {
2004+
dmi_write(target, DMI_DMCONTROL, 0);
2005+
dmi_write(target, DMI_DMCONTROL, DMI_DMCONTROL_DMACTIVE); /* Reset DM logic */
19892006
LOG_ERROR("Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
19902007
"Increase the timeout with riscv set_command_timeout_sec.",
19912008
riscv_command_timeout_sec, *sbcs);
@@ -1996,10 +2013,12 @@ static int read_sbcs_nonbusy(struct target *target, uint32_t *sbcs)
19962013

19972014
static int check_sbcs_status(struct target *target, uint32_t *sbcs)
19982015
{
2016+
#if 0
19992017
if (dmi_read(target, sbcs, DMI_SBCS) != ERROR_OK)
20002018
return ERROR_FAIL;
20012019
if(get_field(*sbcs, DMI_SBCS_SBBUSYERROR))
20022020
dmi_write(target, DMI_SBCS, DMI_SBCS_SBBUSYERROR);
2021+
#endif
20032022
return ERROR_OK;
20042023
}
20052024

@@ -2493,7 +2512,7 @@ static int write_memory_bus_v0(struct target *target, target_addr_t address,
24932512
TARGET_PRIxADDR, size, count, address);
24942513
dmi_write(target, DMI_SBADDRESS0, address);
24952514
int64_t value = 0;
2496-
int64_t access = 0;
2515+
uint32_t access = 0;
24972516
riscv_addr_t offset = 0;
24982517
riscv_addr_t t_addr = 0;
24992518
const uint8_t *t_buffer = buffer + offset;

0 commit comments

Comments
 (0)