From a595be3a4af116a9559a3868f81dcad55d01b8dd Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Wed, 25 Jan 2023 12:18:36 +0200 Subject: tpm: add a function that performs selftest + startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As described in [0] if a command requires use of an untested algorithm or functional module, the TPM performs the test and then completes the command actions. Since we don't check for TPM_RC_NEEDS_TEST (which is the return code of the TPM in that case) and even if we would, it would complicate our TPM code for no apparent reason, add a wrapper function that performs both the selftest and the startup sequence of the TPM. It's worth noting that this is implemented on TPMv2.0. The code for 1.2 would look similar, but I don't have a device available to test. [0] https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-1-Architecture-01.07-2014-03-13.pdf ยง12.3 Self-test modes Reviewed-by: Simon Glass Signed-off-by: Ilias Apalodimas --- lib/tpm_api.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/tpm_api.c') diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 7e8df87..5b2c11a 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -35,6 +35,14 @@ u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) } } +u32 tpm_auto_start(struct udevice *dev) +{ + if (tpm_is_v2(dev)) + return tpm2_auto_start(dev); + + return -ENOSYS; +} + u32 tpm_resume(struct udevice *dev) { if (tpm_is_v1(dev)) -- cgit v1.1 From a11be4c303eabb142e074c7ca14b6ae0d293f0cb Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 21 Feb 2023 06:24:52 -0700 Subject: tpm: Implement tpm_auto_start() for TPMv1.2 Add an implementation of this, moving the common call to tpm_init() up into the common API implementation. Add a test. Reviewed-by: Ilias Apalodimas Signed-off-by: Simon Glass Signed-off-by: Ilias Apalodimas --- lib/tpm_api.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/tpm_api.c') diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 5b2c11a..3ef5e81 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -37,10 +37,23 @@ u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) u32 tpm_auto_start(struct udevice *dev) { - if (tpm_is_v2(dev)) - return tpm2_auto_start(dev); + u32 rc; - return -ENOSYS; + /* + * the tpm_init() will return -EBUSY if the init has already happened + * The selftest and startup code can run multiple times with no side + * effects + */ + rc = tpm_init(dev); + if (rc && rc != -EBUSY) + return rc; + + if (tpm_is_v1(dev)) + return tpm1_auto_start(dev); + else if (tpm_is_v2(dev)) + return tpm2_auto_start(dev); + else + return -ENOSYS; } u32 tpm_resume(struct udevice *dev) -- cgit v1.1