All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Thirupathaiah Annapureddy <thiruan@linux.microsoft.com>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH v2 03/10] sandbox: tpm: Support the define-space command
Date: Sun, 18 Jul 2021 14:17:59 -0600	[thread overview]
Message-ID: <20210718201806.761202-4-sjg@chromium.org> (raw)
In-Reply-To: <20210718201806.761202-1-sjg@chromium.org>

Add support for this command, moving away from the previous approach of
hard-coding the initial data in the driver, now that the kernel-space data
has to be set up by the higher-level vboot code.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 drivers/tpm/sandbox_common.c  | 11 +++++++++++
 drivers/tpm/sandbox_common.h  | 12 ++++++++++++
 drivers/tpm/tpm_tis_sandbox.c | 11 +++++++++++
 3 files changed, 34 insertions(+)

diff --git a/drivers/tpm/sandbox_common.c b/drivers/tpm/sandbox_common.c
index 13f5e030a5f..7e0b2502e35 100644
--- a/drivers/tpm/sandbox_common.c
+++ b/drivers/tpm/sandbox_common.c
@@ -64,3 +64,14 @@ void sb_tpm_write_data(struct nvdata_state nvdata[NV_SEQ_COUNT],
 	else
 		memcpy(&nvdata[seq].data, buf + data_ofs, length);
 }
+
+void sb_tpm_define_data(struct nvdata_state nvdata[NV_SEQ_COUNT],
+			enum sandbox_nv_space seq, int length)
+{
+	struct nvdata_state *nvd = &nvdata[seq];
+
+	if (length > NV_DATA_SIZE)
+		log_err("Invalid length %x (max %x)\n", length, NV_DATA_SIZE);
+	nvd->length = length;
+	nvd->present = true;
+}
diff --git a/drivers/tpm/sandbox_common.h b/drivers/tpm/sandbox_common.h
index aa5292d7945..e822a200fd3 100644
--- a/drivers/tpm/sandbox_common.h
+++ b/drivers/tpm/sandbox_common.h
@@ -93,4 +93,16 @@ void sb_tpm_write_data(struct nvdata_state nvdata[NV_SEQ_COUNT],
 		       enum sandbox_nv_space seq, const u8 *buf, int data_ofs,
 		       int length);
 
+/**
+ * sb_tpm_define_data() - Set up non-volatile data
+ *
+ * If @length is too large, an error is logged and nothing is written.
+ *
+ * @nvdata: Current nvdata state
+ * @seq: Sequence number to set up
+ * @length: Length of space in bytes
+ */
+void sb_tpm_define_data(struct nvdata_state nvdata[NV_SEQ_COUNT],
+			enum sandbox_nv_space seq, int length);
+
 #endif
diff --git a/drivers/tpm/tpm_tis_sandbox.c b/drivers/tpm/tpm_tis_sandbox.c
index f22ed846f0a..85b22afa4d9 100644
--- a/drivers/tpm/tpm_tis_sandbox.c
+++ b/drivers/tpm/tpm_tis_sandbox.c
@@ -210,6 +210,17 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
 		memset(recvbuf, '\0', *recv_len);
 		break;
 	case TPM_CMD_NV_DEFINE_SPACE:
+		index = get_unaligned_be32(sendbuf + 12);
+		length = get_unaligned_be32(sendbuf + 77);
+		seq = sb_tpm_index_to_seq(index);
+		if (seq < 0)
+			return -EINVAL;
+		printf("tpm: define_space index=%#02x, len=%#02x, seq=%#02x\n",
+		       index, length, seq);
+		sb_tpm_define_data(tpm->nvdata, seq, length);
+		*recv_len = 12;
+		memset(recvbuf, '\0', *recv_len);
+		break;
 	case 0x15: /* pcr read */
 	case 0x5d: /* force clear */
 	case 0x6f: /* physical enable */
-- 
2.32.0.402.g57bb445576-goog


  parent reply	other threads:[~2021-07-18 20:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-18 20:17 [PATCH v2 00/10] tpm: Enhance sandbox tpm2 emulation Simon Glass
2021-07-18 20:17 ` [PATCH v2 01/10] sandbox: tpm: Split out common nvdata code Simon Glass
2021-07-18 20:17 ` [PATCH v2 02/10] sandbox: tpm: Tidy up reading and writing of device state Simon Glass
2021-07-18 20:17 ` Simon Glass [this message]
2021-07-18 20:18 ` [PATCH v2 04/10] sandbox: tpm: Correct handling of get-capability Simon Glass
2021-07-18 20:18 ` [PATCH v2 05/10] sandbox: tpm: Finish comments for struct sandbox_tpm2 Simon Glass
2021-07-18 20:18 ` [PATCH v2 06/10] sandbox: tpm: Track whether the state is valid Simon Glass
2021-07-18 20:18 ` [PATCH v2 07/10] sandbox: tpm: Support nvdata in TPM2 Simon Glass
2021-07-18 20:18 ` [PATCH v2 08/10] sandbox: tpm: Support storing device state in tpm2 Simon Glass
2021-07-18 20:18 ` [PATCH v2 09/10] sandbox: tpm: Correct handling of SANDBOX_TPM_PCR_NB Simon Glass
2021-07-18 20:18 ` [PATCH v2 10/10] sandbox: tpm: Support extending a PCR multiple times Simon Glass
2021-07-24 21:11 ` Simon Glass
2021-07-24 21:12 ` [PATCH v2 09/10] sandbox: tpm: Correct handling of SANDBOX_TPM_PCR_NB Simon Glass
2021-07-24 21:12 ` [PATCH v2 08/10] sandbox: tpm: Support storing device state in tpm2 Simon Glass
2021-07-24 21:12 ` [PATCH v2 07/10] sandbox: tpm: Support nvdata in TPM2 Simon Glass
2021-07-24 21:12 ` [PATCH v2 06/10] sandbox: tpm: Track whether the state is valid Simon Glass
2021-07-24 21:12 ` [PATCH v2 05/10] sandbox: tpm: Finish comments for struct sandbox_tpm2 Simon Glass
2021-07-24 21:12 ` [PATCH v2 04/10] sandbox: tpm: Correct handling of get-capability Simon Glass
2021-07-24 21:12 ` [PATCH v2 03/10] sandbox: tpm: Support the define-space command Simon Glass
2021-07-24 21:12 ` [PATCH v2 02/10] sandbox: tpm: Tidy up reading and writing of device state Simon Glass
2021-07-24 21:12 ` [PATCH v2 01/10] sandbox: tpm: Split out common nvdata code Simon Glass

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=20210718201806.761202-4-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=thiruan@linux.microsoft.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.