Skip to content

Commit

Permalink
[opentitantool] Support high level TPM commands
Browse files Browse the repository at this point in the history
For a while, opentitanlib has now had the support for manipulating TPM
fifo and status registers, to send arbitrary commands and wait for their
completion before retrieving a response.  This RP exposes that
functionality on the opentitantool command line.

Signed-off-by: Jes B. Klinke <[email protected]>
Change-Id: I7e997dbc0da80c4a88191e9eb804fc9d4ba99ae9
  • Loading branch information
jesultra authored and cfrantz committed Mar 29, 2023
1 parent 82fe851 commit 2155433
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sw/host/opentitantool/src/command/tpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,37 @@ impl CommandDispatch for TpmWriteRegister {
}
}

/// Write to a given TPM register.
#[derive(Debug, StructOpt)]
pub struct TpmExecuteCommand {
#[structopt(short = "d", long, help = "Hex encoding of TPM command to execute.")]
hexdata: String,
}

#[derive(Annotate, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct TpmExecuteCommandResponse {
hexdata: String,
}

impl CommandDispatch for TpmExecuteCommand {
fn run(
&self,
context: &dyn Any,
_transport: &TransportWrapper,
) -> Result<Option<Box<dyn Annotate>>> {
let tpm = context.downcast_ref::<Box<dyn tpm::Driver>>().unwrap();
let resp = tpm.execute_command(&hex::decode(&self.hexdata)?)?;
Ok(Some(Box::new(TpmExecuteCommandResponse {
hexdata: hex::encode(&resp),
})))
}
}

/// Commands for interacting with a TPM. These appear as subcommands of both `opentitantool i2c
/// tpm` and `opentitantool spi tpm`.
#[derive(Debug, StructOpt, CommandDispatch)]
pub enum TpmSubCommand {
ReadRegister(TpmReadRegister),
WriteRegister(TpmWriteRegister),
ExecuteCommand(TpmExecuteCommand),
}

0 comments on commit 2155433

Please sign in to comment.