]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tpm: Add TPM2 support for write_lock
authorSimon Glass <sjg@chromium.org>
Sat, 6 Feb 2021 21:23:41 +0000 (14:23 -0700)
committerTom Rini <trini@konsulko.com>
Tue, 2 Mar 2021 20:53:37 +0000 (15:53 -0500)
Implement this API function for TPM2.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
include/tpm-v2.h
lib/tpm-v2.c
lib/tpm_api.c

index b73a2d278e77d9bb59b84b57b833672d67c09e71..fa3296a7b0e47e38959c97482c29cd8608730fc8 100644 (file)
@@ -243,6 +243,7 @@ enum tpm2_command_codes {
        TPM2_CC_NV_DEFINE_SPACE = 0x012a,
        TPM2_CC_PCR_SETAUTHPOL  = 0x012C,
        TPM2_CC_NV_WRITE        = 0x0137,
+       TPM2_CC_NV_WRITELOCK    = 0x0138,
        TPM2_CC_DAM_RESET       = 0x0139,
        TPM2_CC_DAM_PARAMETERS  = 0x013A,
        TPM2_CC_NV_READ         = 0x014E,
@@ -572,4 +573,15 @@ u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw,
  */
 u32 tpm2_get_random(struct udevice *dev, void *data, u32 count);
 
+/**
+ * Lock data in the TPM
+ *
+ * Once locked the data cannot be written until after a reboot
+ *
+ * @dev                TPM device
+ * @index      Index of data to lock
+ * @return code of the operation
+ */
+u32 tpm2_write_lock(struct udevice *dev, u32 index);
+
 #endif /* __TPM_V2_H */
index 9f1699131e1265b83075c05f25803e223dba53a5..b796004930e870d1ba12ce95b69d8fb19b70f076 100644 (file)
@@ -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);
+}
index 687fc8bc7ee807078b8131a63a826a0ba5733631..4c662640a92067f8a3b7310f3c10dfa3df45973c 100644 (file)
@@ -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;
 }