summaryrefslogtreecommitdiff
path: root/lib/tpm-v2.c
diff options
context:
space:
mode:
authorIlias Apalodimas <ilias.apalodimas@linaro.org>2024-12-24 08:01:09 -0800
committerIlias Apalodimas <ilias.apalodimas@linaro.org>2025-01-07 15:45:51 +0200
commitffdbf775e71b8160a37ca65bfa38ed037807dbf2 (patch)
tree40bd279ee1ab66014d938f6e499ff162125695ac /lib/tpm-v2.c
parent8dc886ce314282de9d65fac1e8c68ee40d30f678 (diff)
tpm: Keep the active PCRs in the chip private data
We have a lot of code trying to reason about the active TPM PCRs when creating an EventLog. Since changing the active banks can't be done on the fly and requires a TPM reset, let's store them in the chip private data instead. Upcoming patches will use this during the EventLog creation. Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'lib/tpm-v2.c')
-rw-r--r--lib/tpm-v2.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index bac6fd9101b..bc750b7ca19 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -23,6 +23,27 @@
#include "tpm-utils.h"
+static int tpm2_update_active_banks(struct udevice *dev)
+{
+ struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
+ struct tpml_pcr_selection pcrs;
+ int ret, i;
+
+ ret = tpm2_get_pcr_info(dev, &pcrs);
+ if (ret)
+ return ret;
+
+ priv->active_bank_count = 0;
+ for (i = 0; i < pcrs.count; i++) {
+ if (!tpm2_is_active_bank(&pcrs.selection[i]))
+ continue;
+ priv->active_banks[priv->active_bank_count] = pcrs.selection[i].hash;
+ priv->active_bank_count++;
+ }
+
+ return 0;
+}
+
u32 tpm2_startup(struct udevice *dev, enum tpm2_startup_types mode)
{
const u8 command_v2[12] = {
@@ -41,7 +62,7 @@ u32 tpm2_startup(struct udevice *dev, enum tpm2_startup_types mode)
if (ret && ret != TPM2_RC_INITIALIZE)
return ret;
- return 0;
+ return tpm2_update_active_banks(dev);
}
u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no full_test)
@@ -69,8 +90,10 @@ u32 tpm2_auto_start(struct udevice *dev)
rc = tpm2_self_test(dev, TPMI_YES);
}
+ if (rc)
+ return rc;
- return rc;
+ return tpm2_update_active_banks(dev);
}
u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,