Skip to content

Commit e4a102c

Browse files
committed
[qemu] Enable the tpm_tx_rx test to run with qemu
Signed-off-by: Douglas Reis <[email protected]>
1 parent 2157f68 commit e4a102c

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

sw/device/tests/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3912,6 +3912,8 @@ opentitan_test(
39123912
"//hw/top_earlgrey:sim_verilator": None,
39133913
"//hw/top_earlgrey:fpga_cw340_sival": None,
39143914
"//hw/top_earlgrey:fpga_cw340_sival_rom_ext": None,
3915+
"//hw/top_earlgrey:sim_qemu_rom_with_fake_keys": None,
3916+
"//hw/top_earlgrey:sim_qemu_sival_rom_ext": None,
39153917
},
39163918
),
39173919
fpga = fpga_params(
@@ -3923,6 +3925,12 @@ opentitan_test(
39233925
""",
39243926
test_harness = "//sw/host/tests/chip/spi_device:spi_device_tpm_test",
39253927
),
3928+
qemu = qemu_params(
3929+
test_cmd = """
3930+
"{firmware:elf}"
3931+
""",
3932+
test_harness = "//sw/host/tests/chip/spi_device:spi_device_tpm_test",
3933+
),
39263934
silicon = silicon_params(
39273935
test_cmd = """
39283936
--bootstrap="{firmware}"

sw/host/opentitanlib/src/app/config/opentitan_qemu.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
// For now we model this strap as a no-op without any pins.
8080
"pins": [],
8181
},
82+
{
83+
"name": "SPI_TPM"
84+
}
8285
],
8386
"uarts": [
8487
{

sw/host/opentitanlib/src/tpm/driver.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ impl SpiDriver {
277277
if Instant::now().duration_since(start_time) > TIMEOUT {
278278
bail!(TpmError::Timeout)
279279
}
280+
thread::sleep(Duration::from_millis(1));
280281
}
281282
}
282283
Ok(())

sw/host/opentitanlib/src/transport/qemu/spi.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use anyhow::{Context, ensure};
1111
use serialport::TTYPort;
1212

1313
use crate::io::gpio;
14-
use crate::io::spi::{AssertChipSelect, MaxSizes, Target, Transfer, TransferMode};
14+
use crate::io::spi::{
15+
AssertChipSelect, MaxSizes, Target, TargetChipDeassert, Transfer, TransferMode,
16+
};
1517
use crate::transport::TransportError;
1618
use crate::util::voltage::Voltage;
1719

@@ -205,7 +207,8 @@ impl Target for QemuSpi {
205207
fn assert_cs(self: Rc<Self>) -> anyhow::Result<AssertChipSelect> {
206208
// Could potentially be implemented by sending an empty packet that
207209
// holds the CS and another which deasserts when dropped.
208-
Err(TransportError::UnsupportedOperation.into())
210+
log::warn!("TODO: Implement CS for Qemu");
211+
Ok(AssertChipSelect::new(self))
209212
}
210213

211214
fn set_voltage(&self, _voltage: Voltage) -> anyhow::Result<()> {
@@ -216,3 +219,7 @@ impl Target for QemuSpi {
216219
Err(TransportError::UnsupportedOperation.into())
217220
}
218221
}
222+
223+
impl TargetChipDeassert for QemuSpi {
224+
fn deassert_cs(&self) {}
225+
}

0 commit comments

Comments
 (0)