summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-02-06 14:23:41 -0700
committerTom Rini <trini@konsulko.com>2021-03-02 15:53:37 -0500
commit7785bc1d5f94d28497bef6935ecbaa1b0ddd3e26 (patch)
tree27f83962679608c05adcb0ee964b6bf6f28c6177 /lib
parent6719cbe31afef2cba4bc10b33350b38c4a51c3ac (diff)
tpm: Add TPM2 support for write_lock
Implement this API function for TPM2. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/tpm-v2.c23
-rw-r--r--lib/tpm_api.c2
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 9f1699131e..b796004930 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -601,3 +601,26 @@ u32 tpm2_get_random(struct udevice *dev, void *data, u32 count)
return 0;
}
+
+u32 tpm2_write_lock(struct udevice *dev, u32 index)
+{
+ u8 command_v2[COMMAND_BUFFER_SIZE] = {
+ /* header 10 bytes */
+ tpm_u16(TPM2_ST_SESSIONS), /* TAG */
+ tpm_u32(10 + 8 + 13), /* Length */
+ tpm_u32(TPM2_CC_NV_WRITELOCK), /* Command code */
+
+ /* handles 8 bytes */
+ tpm_u32(TPM2_RH_PLATFORM), /* Primary platform seed */
+ tpm_u32(HR_NV_INDEX + index), /* Password authorisation */
+
+ /* session header 9 bytes */
+ tpm_u32(9), /* Header size */
+ tpm_u32(TPM2_RS_PW), /* Password authorisation */
+ tpm_u16(0), /* nonce_size */
+ 0, /* session_attrs */
+ tpm_u16(0), /* auth_size */
+ };
+
+ return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
+}
diff --git a/lib/tpm_api.c b/lib/tpm_api.c
index 687fc8bc7e..4c662640a9 100644
--- a/lib/tpm_api.c
+++ b/lib/tpm_api.c
@@ -144,7 +144,7 @@ u32 tpm_write_lock(struct udevice *dev, u32 index)
if (is_tpm1(dev))
return -ENOSYS;
else if (is_tpm2(dev))
- return -ENOSYS;
+ return tpm2_write_lock(dev, index);
else
return -ENOSYS;
}