-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[spi_dev, dv] Adapt the tpm test for sival
Signed-off-by: Douglas Reis <[email protected]>
- Loading branch information
Showing
4 changed files
with
126 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright lowRISC contributors. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load("@rules_rust//rust:defs.bzl", "rust_binary") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
rust_binary( | ||
name = "spi_device_tpm_test", | ||
srcs = [ | ||
"src/main.rs", | ||
], | ||
deps = [ | ||
"//sw/host/opentitanlib", | ||
"//third_party/rust/crates:anyhow", | ||
"//third_party/rust/crates:clap", | ||
"//third_party/rust/crates:humantime", | ||
"//third_party/rust/crates:log", | ||
"//third_party/rust/crates:regex", | ||
"@crate_index//:object", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright lowRISC contributors. | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use anyhow::{bail, Result}; | ||
use clap::Parser; | ||
use regex::Regex; | ||
use std::path::PathBuf; | ||
use std::time::Duration; | ||
|
||
use opentitanlib::app::TransportWrapper; | ||
use opentitanlib::execute_test; | ||
use opentitanlib::test_utils::init::InitializeTest; | ||
use opentitanlib::tpm::{self, Driver}; | ||
use opentitanlib::uart::console::{ExitStatus, UartConsole}; | ||
|
||
#[derive(Debug, Parser)] | ||
struct Opts { | ||
#[command(flatten)] | ||
init: InitializeTest, | ||
|
||
/// Console receive timeout. | ||
#[arg(long, value_parser = humantime::parse_duration, default_value = "600s")] | ||
timeout: Duration, | ||
|
||
/// Name of the SPI interface to connect to the OTTF console. | ||
#[arg(long, default_value = "TPM")] | ||
spi: String, | ||
|
||
/// Path to the firmware's ELF file, for querying symbol addresses. | ||
#[arg(value_name = "FIRMWARE_ELF")] | ||
firmware_elf: PathBuf, | ||
} | ||
|
||
fn tpm_read_test( | ||
opts: &Opts, | ||
transport: &TransportWrapper, | ||
) -> Result<()> { | ||
let uart = transport.uart("console")?; | ||
let spi = transport.spi(&opts.spi)?; | ||
transport.pin_strapping("SPI_TPM")?.apply()?; | ||
|
||
/* Wait sync message. */ | ||
let _ = UartConsole::wait_for(&*uart, r"SYNC: Begin TPM Test\r\n", opts.timeout)?; | ||
let tpm = tpm::SpiDriver::new(spi); | ||
let test_data = [0xA5;10]; | ||
|
||
for _ in 0..10{ | ||
tpm.write_register(tpm::Register::DATA_FIFO, &test_data)?; | ||
let _ = UartConsole::wait_for(&*uart, r"SYNC: Waiting Read\r\n", opts.timeout)?; | ||
let mut buffer = [0xFFu8;10]; | ||
tpm.read_register(tpm::Register::DATA_FIFO, &mut buffer)?; | ||
assert_eq!(buffer, test_data); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let opts = Opts::parse(); | ||
opts.init.init_logging(); | ||
|
||
let transport = opts.init.init_target()?; | ||
execute_test!( | ||
tpm_read_test, | ||
&opts, | ||
&transport, | ||
); | ||
|
||
let uart = transport.uart("console")?; | ||
let mut console = UartConsole { | ||
timeout: Some(opts.timeout), | ||
exit_success: Some(Regex::new(r"PASS!\r\n")?), | ||
exit_failure: Some(Regex::new(r"FAIL:")?), | ||
..Default::default() | ||
}; | ||
|
||
// Now watch the console for the exit conditions. | ||
let result = console.interact(&*uart, None, Some(&mut std::io::stdout()))?; | ||
if result != ExitStatus::ExitSuccess { | ||
bail!("FAIL: {:?}", result); | ||
}; | ||
|
||
Ok(()) | ||
} |