feat: provide access to transport errors
Signed-off-by: Matthew Ellis <Matthew.Ellis@arm.com>
Change-Id: I20815f203fe7c91ee8b100dad9fc0ee09a05e5a4
diff --git a/include/tpm2.h b/include/tpm2.h
index 16d22a0..5a29113 100644
--- a/include/tpm2.h
+++ b/include/tpm2.h
@@ -28,6 +28,8 @@
uint64_t (*timeout_init_us)(uint32_t usec);
bool (*timeout_elapsed)(uint64_t cnt);
};
+int tpm_get_last_transport_error(void);
+
int tpm_interface_init(const struct spi_plat *transport,
const struct tpm_timeout_ops *timeout_ops,
struct tpm_chip_data *chip_data, uint8_t locality);
diff --git a/include/tpm2_private.h b/include/tpm2_private.h
index 17e925c..01e304c 100644
--- a/include/tpm2_private.h
+++ b/include/tpm2_private.h
@@ -106,6 +106,7 @@
extern struct tpm_timeout_ops tpm_timeout_ops;
extern const struct spi_plat *tpm_spidev;
+extern int tpm_last_transport_error;
struct interface_ops *tpm_interface_getops(struct tpm_chip_data *chip_data,
uint8_t locality);
diff --git a/src/tpm2_cmds.c b/src/tpm2_cmds.c
index 56fbc55..1ce5afc 100644
--- a/src/tpm2_cmds.c
+++ b/src/tpm2_cmds.c
@@ -19,6 +19,7 @@
static struct interface_ops *interface;
struct tpm_timeout_ops tpm_timeout_ops;
+int tpm_last_transport_error = 0;
static int tpm_xfer(struct tpm_chip_data *chip_data, const tpm_cmd *send,
tpm_cmd *receive)
@@ -40,6 +41,11 @@
return TPM_SUCCESS;
}
+int tpm_get_last_transport_error(void)
+{
+ return tpm_last_transport_error;
+}
+
int tpm_interface_init(const struct spi_plat *transport,
const struct tpm_timeout_ops *timeout_ops,
struct tpm_chip_data *chip_data, uint8_t locality)
diff --git a/src/tpm2_fifo_spi.c b/src/tpm2_fifo_spi.c
index 0b260f7..a72868c 100644
--- a/src/tpm2_fifo_spi.c
+++ b/src/tpm2_fifo_spi.c
@@ -23,7 +23,11 @@
static int tpm2_spi_transfer(const void *data_out, void *data_in, uint8_t len)
{
- return tpm_spidev->ops->xfer(tpm_spidev->priv, len, data_out, data_in);
+ int r = tpm_spidev->ops->xfer(tpm_spidev->priv, len, data_out, data_in);
+ if (r != 0) {
+ tpm_last_transport_error = r;
+ }
+ return r;
}
/*
@@ -132,7 +136,7 @@
(access == TPM_ACCESS_READ) ? val : NULL, len);
if (rc != 0) {
tpm2_spi_end_transaction();
- return rc;
+ return TPM_ERR_TRANSFER;
}
tpm2_spi_end_transaction();