[spi_passthru] Test sector_erase Signed-off-by: Chris Frantz <cfrantz@google.com>
diff --git a/sw/host/tests/chip/spi_passthru/src/main.rs b/sw/host/tests/chip/spi_passthru/src/main.rs index 6ecece8..a5c8fa9 100644 --- a/sw/host/tests/chip/spi_passthru/src/main.rs +++ b/sw/host/tests/chip/spi_passthru/src/main.rs
@@ -8,6 +8,7 @@ use opentitanlib::app::TransportWrapper; use opentitanlib::execute_test; +use opentitanlib::io::eeprom::AddressMode; use opentitanlib::io::spi::{Target, Transfer}; use opentitanlib::spiflash::SpiFlash; use opentitanlib::test_utils::init::InitializeTest; @@ -180,7 +181,6 @@ let uart = transport.uart("console")?; let spi = transport.spi(&opts.spi)?; let flash = SpiFlash::default(); - let info = UploadInfo::execute(&*uart, || { flash.chip_erase(&*spi)?; Ok(()) @@ -196,6 +196,37 @@ Ok(()) } +fn test_sector_erase(opts: &Opts, transport: &TransportWrapper, address: u32) -> Result<()> { + let uart = transport.uart("console")?; + let spi = transport.spi(&opts.spi)?; + let mut flash = SpiFlash::default(); + // Double the flash size so we can test 3b and 4b addresses. + flash.size = 32 * 1024 * 1024; + + // Make sure we're in a mode appropriate for the address. + let mode = if address < 0x1000000 { + AddressMode::Mode3b + } else { + AddressMode::Mode4b + }; + flash.set_address_mode(&*spi, mode)?; + let info = UploadInfo::execute(&*uart, || { + flash.erase(&*spi, address, flash.erase_size)?; + Ok(()) + })?; + + assert_eq!(info.opcode, SpiFlash::SECTOR_ERASE); + assert_eq!(info.has_address, true); + assert_eq!(info.addr_4b, mode == AddressMode::Mode4b); + assert_eq!(info.address, address); + assert_eq!(info.data_len, 0); + assert_eq!( + info.flash_status & FLASH_STATUS_STD_BITS, + FLASH_STATUS_WEL | FLASH_STATUS_WIP + ); + Ok(()) +} + fn test_write_status(opts: &Opts, transport: &TransportWrapper, opcode: u8) -> Result<()> { let uart = transport.uart("console")?; let spi = transport.spi(&opts.spi)?; @@ -227,6 +258,8 @@ execute_test!(test_read_status_extended, &opts, &transport); execute_test!(test_read_sfdp, &opts, &transport); execute_test!(test_chip_erase, &opts, &transport); + execute_test!(test_sector_erase, &opts, &transport, 0x0000_4000); + execute_test!(test_sector_erase, &opts, &transport, 0x0100_4000); execute_test!(test_write_status, &opts, &transport, SpiFlash::WRITE_STATUS); execute_test!( test_write_status,