public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH v3 10/11] tpm: Add TPM2 support for write_lock
Date: Mon, 25 Jan 2021 10:38:06 +0200	[thread overview]
Message-ID: <YA6DbtTyYVXnnfFE@apalos.home> (raw)
In-Reply-To: <20210123172607.2879600-9-sjg@chromium.org>

On Sat, Jan 23, 2021 at 10:26:06AM -0700, Simon Glass wrote:
> Implement this API function for TPM2.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> (no changes since v1)
> 
>  include/tpm-v2.h | 12 ++++++++++++
>  lib/tpm-v2.c     | 23 +++++++++++++++++++++++
>  lib/tpm_api.c    |  2 +-
>  3 files changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/include/tpm-v2.h b/include/tpm-v2.h
> index 6a400771af1..1ca1e7e2011 100644
> --- a/include/tpm-v2.h
> +++ b/include/tpm-v2.h
> @@ -241,6 +241,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,
> @@ -570,4 +571,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 */
> diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
> index 7bf43264ab0..35f3917aeb5 100644
> --- a/lib/tpm-v2.c
> +++ b/lib/tpm-v2.c
> @@ -602,3 +602,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 687fc8bc7ee..4c662640a92 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;
>  }
> -- 
> 2.30.0.280.ga3ce27912f-goog
> 
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

  reply	other threads:[~2021-01-25  8:38 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-23 17:25 [PATCH v3 00/11] tpm: Support using TPM1 and TPM2 from a single API Simon Glass
2021-01-23 17:25 ` [PATCH v3 01/11] tpm: Don't include cr50 in TPL/SPL Simon Glass
2021-01-25  8:26   ` Ilias Apalodimas
2021-01-23 17:25 ` [PATCH v3 02/11] tpm: Use logging in the uclass Simon Glass
2021-01-25  8:26   ` Ilias Apalodimas
2021-01-23 17:25 ` [PATCH v3 03/11] tpm: Add debugging of request in tpm_sendrecv_command() Simon Glass
2021-01-25  8:28   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 04/11] tpm: Add an API that can support v1.2 and v2 Simon Glass
2021-01-25  8:31   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 05/11] tpm: Switch TPMv1 over to use the new API Simon Glass
2021-01-25  8:32   ` Ilias Apalodimas
2021-02-07 14:37     ` Simon Glass
2021-01-23 17:26 ` [PATCH v3 06/11] tpm: Add a basic API implementation for TPMv2 Simon Glass
2021-01-25  8:33   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 07/11] tpm: Reduce duplication in a few functions Simon Glass
2021-01-25  8:34   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 08/11] tpm: Add an implementation of define_space Simon Glass
2021-01-25  8:36   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 09/11] tpm: Add TPM2 support for read/write values Simon Glass
2021-01-25  8:37   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 10/11] tpm: Add TPM2 support for write_lock Simon Glass
2021-01-25  8:38   ` Ilias Apalodimas [this message]
2021-01-23 17:26 ` [PATCH v3 11/11] tpm: Allow disabling platform hierarchy with TPM2 Simon Glass
2021-01-25  8:38   ` Ilias Apalodimas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YA6DbtTyYVXnnfFE@apalos.home \
    --to=ilias.apalodimas@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox