diff --git a/sw/device/tests/BUILD b/sw/device/tests/BUILD index 79191a69641c6..50346d997186e 100644 --- a/sw/device/tests/BUILD +++ b/sw/device/tests/BUILD @@ -3903,6 +3903,7 @@ opentitan_test( "//hw/top_earlgrey:sim_verilator": None, "//hw/top_earlgrey:fpga_cw340_sival": None, "//hw/top_earlgrey:fpga_cw340_sival_rom_ext": None, + "//hw/top_earlgrey:sim_qemu_rom_with_fake_keys": None, }, ), fpga = fpga_params( @@ -3914,6 +3915,12 @@ opentitan_test( """, test_harness = "//sw/host/tests/chip/spi_device:spi_device_tpm_test", ), + qemu = qemu_params( + test_cmd = """ + "{firmware:elf}" + """, + test_harness = "//sw/host/tests/chip/spi_device:spi_device_tpm_test", + ), silicon = silicon_params( test_cmd = """ --bootstrap="{firmware}" diff --git a/sw/host/opentitanlib/src/app/config/opentitan_qemu.json b/sw/host/opentitanlib/src/app/config/opentitan_qemu.json index dd3e366636cb4..3b1f39bff2b54 100644 --- a/sw/host/opentitanlib/src/app/config/opentitan_qemu.json +++ b/sw/host/opentitanlib/src/app/config/opentitan_qemu.json @@ -66,6 +66,9 @@ } ] }, + { + "name": "SPI_TPM" + } ], "uarts": [ { diff --git a/sw/host/opentitanlib/src/tpm/driver.rs b/sw/host/opentitanlib/src/tpm/driver.rs index 59843a5daffdb..4b8c991880a44 100644 --- a/sw/host/opentitanlib/src/tpm/driver.rs +++ b/sw/host/opentitanlib/src/tpm/driver.rs @@ -277,6 +277,7 @@ impl SpiDriver { if Instant::now().duration_since(start_time) > TIMEOUT { bail!(TpmError::Timeout) } + thread::sleep(Duration::from_millis(1)); } } Ok(()) diff --git a/sw/host/opentitanlib/src/transport/qemu/spi.rs b/sw/host/opentitanlib/src/transport/qemu/spi.rs index e9c4f797ece1a..14c76df2259c1 100644 --- a/sw/host/opentitanlib/src/transport/qemu/spi.rs +++ b/sw/host/opentitanlib/src/transport/qemu/spi.rs @@ -11,7 +11,9 @@ use anyhow::{Context, ensure}; use serialport::TTYPort; use crate::io::gpio; -use crate::io::spi::{AssertChipSelect, MaxSizes, Target, Transfer, TransferMode}; +use crate::io::spi::{ + AssertChipSelect, MaxSizes, Target, TargetChipDeassert, Transfer, TransferMode, +}; use crate::transport::TransportError; use crate::util::voltage::Voltage; @@ -205,7 +207,8 @@ impl Target for QemuSpi { fn assert_cs(self: Rc) -> anyhow::Result { // Could potentially be implemented by sending an empty packet that // holds the CS and another which deasserts when dropped. - Err(TransportError::UnsupportedOperation.into()) + log::warn!("TODO: Implement CS for Qemu"); + Ok(AssertChipSelect::new(self)) } fn set_voltage(&self, _voltage: Voltage) -> anyhow::Result<()> { @@ -216,3 +219,7 @@ impl Target for QemuSpi { Err(TransportError::UnsupportedOperation.into()) } } + +impl TargetChipDeassert for QemuSpi { + fn deassert_cs(&self) {} +}