aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSimon Glass2022-08-30 21:05:36 -0600
committerIlias Apalodimas2022-09-03 16:59:05 +0300
commit3bb4db4c3883c66ee0bbf152e9ba1d2504fa8c9f (patch)
treeb94da976937e8039287e79b395ca9068f9f9e34f /drivers
parent6694c997b210656fc3e6ce63ba780bc9bf97c077 (diff)
tpm: Allow reporting the internal state
It is useful to read information about the current TPM state, where supported, e.g. for debugging purposes when verified boot fails. Add support for this to the TPM interface as well as Cr50. Add a simple sandbox test. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/tpm/tpm-uclass.c10
-rw-r--r--drivers/tpm/tpm2_tis_sandbox.c11
2 files changed, 21 insertions, 0 deletions
diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index 0eb35f50c4e..5ff0cd3958c 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -49,6 +49,16 @@ int tpm_get_desc(struct udevice *dev, char *buf, int size)
return ops->get_desc(dev, buf, size);
}
+int tpm_report_state(struct udevice *dev, char *buf, int size)
+{
+ struct tpm_ops *ops = tpm_get_ops(dev);
+
+ if (!ops->report_state)
+ return -ENOSYS;
+
+ return ops->report_state(dev, buf, size);
+}
+
/* Returns max number of milliseconds to wait */
static ulong tpm_tis_i2c_calc_ordinal_duration(struct tpm_chip_priv *priv,
u32 ordinal)
diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
index c26f5d35abf..dd94bdc31fb 100644
--- a/drivers/tpm/tpm2_tis_sandbox.c
+++ b/drivers/tpm/tpm2_tis_sandbox.c
@@ -795,6 +795,16 @@ static int sandbox_tpm2_get_desc(struct udevice *dev, char *buf, int size)
return snprintf(buf, size, "Sandbox TPM2.x");
}
+static int sandbox_tpm2_report_state(struct udevice *dev, char *buf, int size)
+{
+ struct sandbox_tpm2 *priv = dev_get_priv(dev);
+
+ if (size < 40)
+ return -ENOSPC;
+
+ return snprintf(buf, size, "init_done=%d", priv->init_done);
+}
+
static int sandbox_tpm2_open(struct udevice *dev)
{
struct sandbox_tpm2 *tpm = dev_get_priv(dev);
@@ -834,6 +844,7 @@ static const struct tpm_ops sandbox_tpm2_ops = {
.open = sandbox_tpm2_open,
.close = sandbox_tpm2_close,
.get_desc = sandbox_tpm2_get_desc,
+ .report_state = sandbox_tpm2_report_state,
.xfer = sandbox_tpm2_xfer,
};