Skip to content

Commit 856b2e5

Browse files
committed
[ot] hw/opentitan: spi_device: fix off-by-one last_read_addr
Read commands automatically increment the address so the last read address register was too high. I don't want to assign to this register before we do the increment because the OpenTitan docs say it's only updated on CS release. Signed-off-by: James Wainwright <[email protected]>
1 parent 996a48e commit 856b2e5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

hw/opentitan/ot_spi_device.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ typedef struct {
394394
unsigned len; /* Meaning depends on command and current state */
395395
unsigned slot; /* Command slot */
396396
uint32_t address; /* Address tracking */
397+
uint32_t last_read_addr; /* Last address read before increment */
397398
uint32_t cmd_info; /* Selected command info slot */
398399
uint8_t *src; /* Selected read data source (alias) */
399400
uint8_t *payload; /* Selected write data sink (alias) */
@@ -706,6 +707,7 @@ static void ot_spi_device_clear_modes(OtSPIDeviceState *s)
706707
timer_del(f->irq_timer);
707708
FLASH_CHANGE_STATE(s, IDLE);
708709
f->address = 0;
710+
f->last_read_addr = 0;
709711
f->cmd_info = UINT32_MAX;
710712
f->pos = 0;
711713
f->len = 0;
@@ -841,9 +843,10 @@ static void ot_spi_device_release(OtSPIDeviceState *s)
841843
* Read SFDP command’s address."
842844
*/
843845
if (ot_spi_device_is_hw_read_command(s) &&
844-
!ot_spi_device_is_mailbox_match(s, f->address)) {
845-
trace_ot_spi_device_update_last_read_addr(s->ot_id, f->address);
846-
s->spi_regs[R_LAST_READ_ADDR] = f->address;
846+
!ot_spi_device_is_mailbox_match(s, f->last_read_addr)) {
847+
trace_ot_spi_device_update_last_read_addr(s->ot_id,
848+
f->last_read_addr);
849+
s->spi_regs[R_LAST_READ_ADDR] = f->last_read_addr;
847850
}
848851
FLASH_CHANGE_STATE(s, IDLE);
849852
break;
@@ -1228,6 +1231,7 @@ static uint8_t ot_spi_device_flash_read_data(OtSPIDeviceState *s)
12281231
}
12291232
}
12301233

1234+
f->last_read_addr = f->address;
12311235
f->address += 1u;
12321236

12331237
/*

0 commit comments

Comments
 (0)