@@ -1974,18 +1974,35 @@ static int sb_write_address(struct target *target, target_addr_t address)
1974
1974
1975
1975
static int read_sbcs_nonbusy (struct target * target , uint32_t * sbcs )
1976
1976
{
1977
+ uint32_t dmstatus ;
1977
1978
time_t start = time (NULL );
1978
1979
while (1 ) {
1979
1980
if (dmi_read (target , sbcs , DMI_SBCS ) != ERROR_OK )
1980
1981
return ERROR_FAIL ;
1981
1982
if (!get_field (* sbcs , DMI_SBCS_SBBUSY ))
1982
1983
return ERROR_OK ;
1984
+ #if 0
1983
1985
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 ;
1987
2002
}
1988
2003
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 */
1989
2006
LOG_ERROR ("Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
1990
2007
"Increase the timeout with riscv set_command_timeout_sec." ,
1991
2008
riscv_command_timeout_sec , * sbcs );
@@ -1996,10 +2013,12 @@ static int read_sbcs_nonbusy(struct target *target, uint32_t *sbcs)
1996
2013
1997
2014
static int check_sbcs_status (struct target * target , uint32_t * sbcs )
1998
2015
{
2016
+ #if 0
1999
2017
if (dmi_read (target , sbcs , DMI_SBCS ) != ERROR_OK )
2000
2018
return ERROR_FAIL ;
2001
2019
if (get_field (* sbcs , DMI_SBCS_SBBUSYERROR ))
2002
2020
dmi_write (target , DMI_SBCS , DMI_SBCS_SBBUSYERROR );
2021
+ #endif
2003
2022
return ERROR_OK ;
2004
2023
}
2005
2024
@@ -2493,7 +2512,7 @@ static int write_memory_bus_v0(struct target *target, target_addr_t address,
2493
2512
TARGET_PRIxADDR , size , count , address );
2494
2513
dmi_write (target , DMI_SBADDRESS0 , address );
2495
2514
int64_t value = 0 ;
2496
- int64_t access = 0 ;
2515
+ uint32_t access = 0 ;
2497
2516
riscv_addr_t offset = 0 ;
2498
2517
riscv_addr_t t_addr = 0 ;
2499
2518
const uint8_t * t_buffer = buffer + offset ;
0 commit comments