aboutsummaryrefslogtreecommitdiff
path: root/test/dm/tpm.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-08-30 21:05:36 -0600
committerIlias Apalodimas <ilias.apalodimas@linaro.org>2022-09-03 16:59:05 +0300
commit3bb4db4c3883c66ee0bbf152e9ba1d2504fa8c9f (patch)
treeb94da976937e8039287e79b395ca9068f9f9e34f /test/dm/tpm.c
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 'test/dm/tpm.c')
-rw-r--r--test/dm/tpm.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/dm/tpm.c b/test/dm/tpm.c
new file mode 100644
index 0000000000..0b46f79959
--- /dev/null
+++ b/test/dm/tpm.c
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <tpm_api.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+/* Basic test of the TPM uclass */
+static int dm_test_tpm(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ char buf[50];
+
+ /* check probe success */
+ ut_assertok(uclass_first_device_err(UCLASS_TPM, &dev));
+ ut_assert(tpm_is_v2(dev));
+
+ ut_assert(tpm_report_state(dev, buf, sizeof(buf)));
+ ut_asserteq_str("init_done=0", buf);
+
+ ut_assertok(tpm_init(dev));
+
+ ut_assert(tpm_report_state(dev, buf, sizeof(buf)));
+ ut_asserteq_str("init_done=1", buf);
+
+ return 0;
+}
+DM_TEST(dm_test_tpm, UT_TESTF_SCAN_FDT);