@@ -998,7 +998,7 @@ ot_spi_device_flash_match_command_slot(OtSPIDeviceState *s, uint8_t cmd)
998998 }
999999 }
10001000
1001- trace_ot_spi_device_flash_ignored_command (s -> ot_id , "unmatched" , cmd );
1001+ trace_ot_spi_device_flash_unmatched_command (s -> ot_id , cmd );
10021002 return false;
10031003}
10041004
@@ -1532,46 +1532,55 @@ static bool ot_spi_device_flash_try_intercept_hw_command(OtSPIDeviceState *s)
15321532 SpiDeviceFlash * f = & s -> flash ;
15331533
15341534 uint32_t intercept_val32 = s -> spi_regs [R_INTERCEPT_EN ];
1535+ bool intercepted = false;
1536+
15351537 switch (f -> slot ) {
15361538 case SLOT_HW_READ_STATUS1 :
15371539 case SLOT_HW_READ_STATUS2 :
15381540 case SLOT_HW_READ_STATUS3 :
15391541 if (FIELD_EX32 (intercept_val32 , INTERCEPT_EN , STATUS )) {
15401542 ot_spi_device_flash_decode_read_status (s );
1541- return true;
1543+ intercepted = true;
15421544 }
1543- return false ;
1545+ break ;
15441546 case SLOT_HW_READ_JEDEC :
15451547 if (FIELD_EX32 (intercept_val32 , INTERCEPT_EN , JEDEC )) {
15461548 ot_spi_device_flash_decode_read_jedec (s );
1547- return true;
1549+ intercepted = true;
15481550 }
1549- return false ;
1551+ break ;
15501552 case SLOT_HW_READ_SFDP :
15511553 if (FIELD_EX32 (intercept_val32 , INTERCEPT_EN , SFDP )) {
15521554 ot_spi_device_flash_decode_read_sfdp (s );
1553- return true;
1555+ intercepted = true;
15541556 }
1555- return false ;
1557+ break ;
15561558 case SLOT_HW_READ_NORMAL :
15571559 case SLOT_HW_READ_FAST :
15581560 case SLOT_HW_READ_DUAL :
15591561 case SLOT_HW_READ_QUAD :
15601562 case SLOT_HW_READ_DUAL_IO :
15611563 case SLOT_HW_READ_QUAD_IO :
15621564 /* We try to intercept at every read after an address is given */
1563- return false ;
1565+ break ;
15641566 case SLOT_HW_EN4B :
15651567 case SLOT_HW_EX4B :
15661568 ot_spi_device_flash_decode_addr4_enable (s );
1567- return true;
1569+ intercepted = true;
1570+ break ;
15681571 case SLOT_HW_WREN :
15691572 case SLOT_HW_WRDI :
15701573 /* These HW commands cannot be intercepted */
1571- return false ;
1574+ break ;
15721575 default :
1573- return false ;
1576+ break ;
15741577 }
1578+
1579+ if (intercepted ) {
1580+ trace_ot_spi_device_flash_intercepted_command (s -> ot_id , f -> slot );
1581+ }
1582+
1583+ return intercepted ;
15751584}
15761585
15771586static void
@@ -1612,9 +1621,13 @@ ot_spi_device_flash_passthrough_addr(OtSPIDeviceState *s, uint8_t rx)
16121621 f -> buffer [f -> pos ] = rx ;
16131622 if (f -> cmd_addr_swap_en ) {
16141623 unsigned byte_sel = (f -> len - f -> pos - 1u );
1615- rx = ot_spi_device_swap_byte_data (rx , byte_sel ,
1616- s -> spi_regs [R_ADDR_SWAP_MASK ],
1617- s -> spi_regs [R_ADDR_SWAP_DATA ]);
1624+ uint8_t swapped_rx =
1625+ ot_spi_device_swap_byte_data (rx , byte_sel ,
1626+ s -> spi_regs [R_ADDR_SWAP_MASK ],
1627+ s -> spi_regs [R_ADDR_SWAP_DATA ]);
1628+ trace_ot_spi_device_flash_swap_byte (s -> ot_id , "address" , byte_sel , rx ,
1629+ swapped_rx );
1630+ rx = swapped_rx ;
16181631 }
16191632
16201633 (void )ot_spi_device_flash_spi_transfer (s , rx );
@@ -1659,9 +1672,13 @@ ot_spi_device_flash_passthrough_payload(OtSPIDeviceState *s, uint8_t rx)
16591672
16601673 g_assert (f -> cmd_payload_swap_en );
16611674
1662- rx = ot_spi_device_swap_byte_data (rx , f -> pos ,
1663- s -> spi_regs [R_PAYLOAD_SWAP_MASK ],
1664- s -> spi_regs [R_PAYLOAD_SWAP_DATA ]);
1675+ uint8_t swapped_rx =
1676+ ot_spi_device_swap_byte_data (rx , f -> pos ,
1677+ s -> spi_regs [R_PAYLOAD_SWAP_MASK ],
1678+ s -> spi_regs [R_PAYLOAD_SWAP_DATA ]);
1679+ trace_ot_spi_device_flash_swap_byte (s -> ot_id , "payload" , f -> pos , rx ,
1680+ swapped_rx );
1681+ rx = swapped_rx ;
16651682
16661683 (void )ot_spi_device_flash_spi_transfer (s , rx );
16671684
@@ -1679,6 +1696,8 @@ static uint8_t ot_spi_device_flash_passthrough_read(OtSPIDeviceState *s)
16791696 if (f -> slot >= SLOT_HW_READ_NORMAL && f -> slot <= SLOT_HW_READ_QUAD_IO ) {
16801697 if (ot_spi_device_get_command_address_size (s ) != 0u ) {
16811698 if (ot_spi_device_is_mailbox_match (s , f -> address )) {
1699+ trace_ot_spi_device_flash_intercept_mailbox (s -> ot_id ,
1700+ f -> address );
16821701 uint8_t * mbx = (uint8_t * )& s -> sram [SPI_SRAM_MBX_OFFSET ];
16831702 uint8_t tx = mbx [f -> address & (SPI_SRAM_MBX_SIZE - 1u )];
16841703 f -> address += 1u ;
@@ -1738,6 +1757,7 @@ ot_spi_device_flash_transfer_passthrough(OtSPIDeviceState *s, uint8_t rx)
17381757
17391758 if (ot_spi_device_flash_passthrough_filter (s , rx )) {
17401759 /* command opcode is filtered, discard all bytes untl next CS */
1760+ trace_ot_spi_device_flash_filtered_command (s -> ot_id , rx );
17411761 FLASH_CHANGE_STATE (s , IDLE );
17421762 BUS_CHANGE_STATE (s , DISCARD );
17431763 break ;
0 commit comments