trunks: ftdi: implement SendAndWait
To send a command to the TPM FIFO the master is supposed to first
inform the TPM about the incoming command. The spec states that the
TPM *may* reply to this with setting the .Expect bit in the status
register. The Infineon device this code was tested with does not set
this bit, so its polling is not implemented.
TPM status register also allows to check when the device has finished
processing the command and the response is ready in the FIFO register.
This patch adds the code which follows this protocol: sends a command
to the TPM and then expects the response by polling the status
register. A method is being added to poll the status register for a
certain state, and a bug in ReadTpmSts() is fixed.
BUG=chromium:498861
TEST=after connecting the TPM2 setup using the USB-FTDI-SPI dongle run
the following commands inside chroot:
$ sudo emerge trunks
# suppressed portage output here....
$ sudo trunks_client --ftdi --startup
Connected to device vid:did:rid of 15d1:001b:10
$
Change-Id: I315f2b873d87d6c4730aa0d3e13ebaa124ce58ff
Signed-off-by: Vadim Bendebury <[email protected]>
Reviewed-on: https://chromium-review.googlesource.com/277318
Reviewed-by: Utkarsh Sanghi <[email protected]>
Commit-Queue: Bill Richardson <[email protected]>
Trybot-Ready: Bill Richardson <[email protected]>
diff --git a/trunks_ftdi_spi.h b/trunks_ftdi_spi.h
index 8122d5e..2aece21 100644
--- a/trunks_ftdi_spi.h
+++ b/trunks_ftdi_spi.h
@@ -56,6 +56,10 @@
// accessors for it,
bool ReadTpmSts(uint32_t *status);
bool WriteTpmSts(uint32_t status);
+ // Poll status register until the required value is read or the timeout
+ // expires.
+ bool WaitForStatus(uint32_t statusMask,
+ uint32_t statusExpected, int timeout_ms = 100);
DISALLOW_COPY_AND_ASSIGN(TrunksFtdiSpi);
};