All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 12/32] tpm: prepare support for TPMv2.x commands
Date: Tue, 15 May 2018 11:57:08 +0200	[thread overview]
Message-ID: <20180515095728.16572-13-miquel.raynal@bootlin.com> (raw)
In-Reply-To: <20180515095728.16572-1-miquel.raynal@bootlin.com>

Choice between v1 and v2 compliant functions is done with the
configuration.

Create the various files that will receive TPMv2-only code on the same
scheme as for the TPMv1 code.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 cmd/Makefile             |   1 +
 cmd/tpm-v2.c             |  33 ++++++++++++
 drivers/tpm/tpm-uclass.c |   2 +
 include/tpm-common.h     |   6 +++
 include/tpm-v2.h         | 128 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/Makefile             |   1 +
 lib/tpm-v2.c             |  11 ++++
 7 files changed, 182 insertions(+)
 create mode 100644 cmd/tpm-v2.c
 create mode 100644 include/tpm-v2.h
 create mode 100644 lib/tpm-v2.c

diff --git a/cmd/Makefile b/cmd/Makefile
index 66732085e8..bdb5475e07 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -120,6 +120,7 @@ obj-$(CONFIG_HUSH_PARSER) += test.o
 obj-$(CONFIG_CMD_TPM) += tpm-common.o
 obj-$(CONFIG_CMD_TPM_V1) += tpm-v1.o
 obj-$(CONFIG_CMD_TPM_TEST) += tpm_test.o
+obj-$(CONFIG_CMD_TPM_V2) += tpm-v2.o
 obj-$(CONFIG_CMD_CROS_EC) += cros_ec.o
 obj-$(CONFIG_CMD_TSI148) += tsi148.o
 obj-$(CONFIG_CMD_UBI) += ubi.o
diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c
new file mode 100644
index 0000000000..606aa92409
--- /dev/null
+++ b/cmd/tpm-v2.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier:	GPL-2.0+
+/*
+ * Copyright (c) 2018 Bootlin
+ * Author: Miquel Raynal <miquel.raynal@bootlin.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <log.h>
+#include <tpm-common.h>
+#include <tpm-v2.h>
+#include "tpm-user-utils.h"
+
+static cmd_tbl_t tpm2_commands[] = {
+	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
+	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
+};
+
+cmd_tbl_t *get_tpm_commands(unsigned int *size)
+{
+	*size = ARRAY_SIZE(tpm2_commands);
+
+	return tpm2_commands;
+}
+
+U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
+"<command> [<arguments>]\n"
+"\n"
+"info\n"
+"    Show information about the TPM.\n"
+"init\n"
+"    Initialize the software stack. Always the first command to issue.\n"
+);
diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index eb0e511c8f..cbf4873cbb 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -10,6 +10,8 @@
 #include <linux/unaligned/be_byteshift.h>
 #if defined(CONFIG_TPM_V1)
 #include <tpm-v1.h>
+#elif defined(CONFIG_TPM_V2)
+#include <tpm-v2.h>
 #endif
 #include "tpm_internal.h"
 
diff --git a/include/tpm-common.h b/include/tpm-common.h
index 6b15466781..94f0f310b4 100644
--- a/include/tpm-common.h
+++ b/include/tpm-common.h
@@ -36,11 +36,17 @@ enum tpm_duration {
  *
  * @duration_ms:	Length of each duration type in milliseconds
  * @retry_time_ms:	Time to wait before retrying receive
+ * @pcr_count:		Number of PCR per bank
+ * @pcr_select_min:	Minimum size in bytes of the pcrSelect array
  * @buf:		Buffer used during the exchanges with the chip
  */
 struct tpm_chip_priv {
 	uint duration_ms[TPM_DURATION_COUNT];
 	uint retry_time_ms;
+#if defined(CONFIG_TPM_V2)
+	uint pcr_count;
+	uint pcr_select_min;
+#endif
 	u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)];  /* Max buffer size + addr */
 };
 
diff --git a/include/tpm-v2.h b/include/tpm-v2.h
new file mode 100644
index 0000000000..09a7a8b183
--- /dev/null
+++ b/include/tpm-v2.h
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier:	GPL-2.0+
+/*
+ * Copyright (c) 2018 Bootlin
+ * Author: Miquel Raynal <miquel.raynal@bootlin.com>
+ */
+
+#ifndef __TPM_V2_H
+#define __TPM_V2_H
+
+#include <tpm-common.h>
+
+#define TPM2_DIGEST_LEN		32
+
+/**
+ * TPM2 Structure Tags for command/response buffers.
+ *
+ * @TPM2_ST_NO_SESSIONS: the command does not need an authentication.
+ * @TPM2_ST_SESSIONS: the command needs an authentication.
+ */
+enum tpm2_structures {
+	TPM2_ST_NO_SESSIONS	= 0x8001,
+	TPM2_ST_SESSIONS	= 0x8002,
+};
+
+/**
+ * TPM2 type of boolean.
+ */
+enum tpm2_yes_no {
+	TPMI_YES		= 1,
+	TPMI_NO			= 0,
+};
+
+/**
+ * TPM2 startup values.
+ *
+ * @TPM2_SU_CLEAR: reset the internal state.
+ * @TPM2_SU_STATE: restore saved state (if any).
+ */
+enum tpm2_startup_types {
+	TPM2_SU_CLEAR		= 0x0000,
+	TPM2_SU_STATE		= 0x0001,
+};
+
+/**
+ * TPM2 permanent handles.
+ *
+ * @TPM2_RH_OWNER: refers to the 'owner' hierarchy.
+ * @TPM2_RS_PW: indicates a password.
+ * @TPM2_RH_LOCKOUT: refers to the 'lockout' hierarchy.
+ * @TPM2_RH_ENDORSEMENT: refers to the 'endorsement' hierarchy.
+ * @TPM2_RH_PLATFORM: refers to the 'platform' hierarchy.
+ */
+enum tpm2_handles {
+	TPM2_RH_OWNER		= 0x40000001,
+	TPM2_RS_PW		= 0x40000009,
+	TPM2_RH_LOCKOUT		= 0x4000000A,
+	TPM2_RH_ENDORSEMENT	= 0x4000000B,
+	TPM2_RH_PLATFORM	= 0x4000000C,
+};
+
+/**
+ * TPM2 command codes used at the beginning of a buffer, gives the command.
+ *
+ * @TPM2_CC_STARTUP: TPM2_Startup().
+ * @TPM2_CC_SELF_TEST: TPM2_SelfTest().
+ * @TPM2_CC_CLEAR: TPM2_Clear().
+ * @TPM2_CC_CLEARCONTROL: TPM2_ClearControl().
+ * @TPM2_CC_HIERCHANGEAUTH: TPM2_HierarchyChangeAuth().
+ * @TPM2_CC_PCR_SETAUTHPOL: TPM2_PCR_SetAuthPolicy().
+ * @TPM2_CC_DAM_RESET: TPM2_DictionaryAttackLockReset().
+ * @TPM2_CC_DAM_PARAMETERS: TPM2_DictionaryAttackParameters().
+ * @TPM2_CC_GET_CAPABILITY: TPM2_GetCapibility().
+ * @TPM2_CC_PCR_READ: TPM2_PCR_Read().
+ * @TPM2_CC_PCR_EXTEND: TPM2_PCR_Extend().
+ * @TPM2_CC_PCR_SETAUTHVAL: TPM2_PCR_SetAuthValue().
+ */
+enum tpm2_command_codes {
+	TPM2_CC_STARTUP		= 0x0144,
+	TPM2_CC_SELF_TEST	= 0x0143,
+	TPM2_CC_CLEAR		= 0x0126,
+	TPM2_CC_CLEARCONTROL	= 0x0127,
+	TPM2_CC_HIERCHANGEAUTH	= 0x0129,
+	TPM2_CC_DAM_RESET	= 0x0139,
+	TPM2_CC_DAM_PARAMETERS	= 0x013A,
+	TPM2_CC_GET_CAPABILITY	= 0x017A,
+	TPM2_CC_PCR_READ	= 0x017E,
+	TPM2_CC_PCR_EXTEND	= 0x0182,
+};
+
+/**
+ * TPM2 return codes.
+ */
+enum tpm2_return_codes {
+	TPM2_RC_SUCCESS		= 0x0000,
+	TPM2_RC_BAD_TAG		= 0x001E,
+	TPM2_RC_FMT1		= 0x0080,
+	TPM2_RC_HASH		= TPM2_RC_FMT1 + 0x0003,
+	TPM2_RC_VALUE		= TPM2_RC_FMT1 + 0x0004,
+	TPM2_RC_SIZE		= TPM2_RC_FMT1 + 0x0015,
+	TPM2_RC_BAD_AUTH	= TPM2_RC_FMT1 + 0x0022,
+	TPM2_RC_HANDLE		= TPM2_RC_FMT1 + 0x000B,
+	TPM2_RC_VER1		= 0x0100,
+	TPM2_RC_INITIALIZE	= TPM2_RC_VER1 + 0x0000,
+	TPM2_RC_FAILURE		= TPM2_RC_VER1 + 0x0001,
+	TPM2_RC_DISABLED	= TPM2_RC_VER1 + 0x0020,
+	TPM2_RC_AUTH_MISSING	= TPM2_RC_VER1 + 0x0025,
+	TPM2_RC_COMMAND_CODE	= TPM2_RC_VER1 + 0x0043,
+	TPM2_RC_AUTHSIZE	= TPM2_RC_VER1 + 0x0044,
+	TPM2_RC_AUTH_CONTEXT	= TPM2_RC_VER1 + 0x0045,
+	TPM2_RC_NEEDS_TEST	= TPM2_RC_VER1 + 0x0053,
+	TPM2_RC_WARN		= 0x0900,
+	TPM2_RC_TESTING		= TPM2_RC_WARN + 0x000A,
+	TPM2_RC_REFERENCE_H0	= TPM2_RC_WARN + 0x0010,
+	TPM2_RC_LOCKOUT		= TPM2_RC_WARN + 0x0021,
+};
+
+/**
+ * TPM2 algorithms.
+ */
+enum tpm2_algorithms {
+	TPM2_ALG_XOR		= 0x0A,
+	TPM2_ALG_SHA256		= 0x0B,
+	TPM2_ALG_SHA384		= 0x0C,
+	TPM2_ALG_SHA512		= 0x0D,
+	TPM2_ALG_NULL		= 0x10,
+};
+
+#endif /* __TPM_V2_H */
diff --git a/lib/Makefile b/lib/Makefile
index 2052954841..ddf8db6be8 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -42,6 +42,7 @@ obj-y += rc4.o
 obj-$(CONFIG_SUPPORT_EMMC_RPMB) += sha256.o
 obj-$(CONFIG_TPM) += tpm-common.o
 obj-$(CONFIG_TPM_V1) += tpm-v1.o
+obj-$(CONFIG_TPM_V2) += tpm-v2.o
 obj-$(CONFIG_RBTREE)	+= rbtree.o
 obj-$(CONFIG_BITREVERSE) += bitrev.o
 obj-y += list_sort.o
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
new file mode 100644
index 0000000000..ef4ebcd8ac
--- /dev/null
+++ b/lib/tpm-v2.c
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier:	GPL-2.0+
+/*
+ * Copyright (c) 2018 Bootlin
+ * Author: Miquel Raynal <miquel.raynal@bootlin.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <tpm-common.h>
+#include <tpm-v2.h>
+#include "tpm-utils.h"
-- 
2.14.1

  parent reply	other threads:[~2018-05-15  9:57 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-15  9:56 [U-Boot] [PATCH v4 00/32] Introduce TPMv2.0 support Miquel Raynal
2018-05-15  9:56 ` [U-Boot] [PATCH v4 01/32] tpm: remove redundant blank line Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-15 16:02   ` Simon Glass
2018-05-26 15:53   ` [U-Boot] [U-Boot,v4,01/32] " Tom Rini
2018-05-15  9:56 ` [U-Boot] [PATCH v4 02/32] tpm: remove extra spaces between a function and its opening bracket Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-15 16:02   ` Simon Glass
2018-05-26 15:53   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:56 ` [U-Boot] [PATCH v4 03/32] tpm: substitute deprecated uint<x>_t types with their u<x> equivalent Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-15 16:04   ` Simon Glass
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 04/32] tpm: align arguments with open parenthesis Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-15 16:02   ` Simon Glass
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 05/32] tpm: use the BIT() macro where applicable Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-15 16:03   ` Simon Glass
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 06/32] tpm: fix spelling Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-15 16:03   ` Simon Glass
2018-05-26 15:54   ` [U-Boot] [U-Boot,v4,06/32] " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 07/32] tpm: add extra blank lines between declarations and code Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-15 16:04   ` Simon Glass
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 08/32] tpm: add Revision ID field in the chip structure Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 09/32] tpm: prepare introduction of TPMv2.x support in Kconfig Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-27 22:22     ` Miquel Raynal
2018-05-15  9:57 ` [U-Boot] [PATCH v4 10/32] tpm: disociate TPMv1.x specific and generic code Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 11/32] tpm: add missing parameter in private data structure description Miquel Raynal
2018-05-15 15:58   ` Tom Rini
2018-05-15 16:04   ` Simon Glass
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` Miquel Raynal [this message]
2018-05-15 15:58   ` [U-Boot] [PATCH v4 12/32] tpm: prepare support for TPMv2.x commands Tom Rini
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 13/32] tpm: add macros to enhance TPM commands readability Miquel Raynal
2018-05-15 15:59   ` Tom Rini
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 14/32] tpm: add possible traces to analyze buffers returned by the TPM Miquel Raynal
2018-05-15 15:59   ` Tom Rini
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 15/32] tpm: report driver error code to upper layer Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:54   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 16/32] tpm: add TPM2_Startup command support Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 17/32] tpm: add TPM2_SelfTest " Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 18/32] tpm: add TPM2_Clear " Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot,v4,18/32] " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 19/32] tpm: add TPM2_PCR_Extend " Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 20/32] tpm: add TPM2_PCR_Read " Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 21/32] tpm: add TPM2_GetCapability " Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 22/32] tpm: add dictionary attack mitigation commands support Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 23/32] tpm: add TPM2_HierarchyChangeAuth command support Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 24/32] tpm: add PCR authentication commands support Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 25/32] tpm: add support for TPMv2.x SPI modules Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-15 16:04   ` Simon Glass
2018-05-15 16:20     ` Miquel Raynal
2018-05-15 16:26       ` Simon Glass
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 26/32] tpm: add the possibility to reset the chip with a gpio Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-15 16:05   ` Simon Glass
2018-05-15 16:32     ` Miquel Raynal
2018-05-15 17:01       ` Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 27/32] doc: device-tree-bindings: add TIS TPMv2.0 SPI module info Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 28/32] test/py: add TPMv2.x test suite Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot,v4,28/32] " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 29/32] tpm: add a Sandbox TPMv2.x driver Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:55   ` [U-Boot] [U-Boot,v4,29/32] " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 30/32] doc: device-tree-bindings: add Sandbox TPMv2.0 module info Miquel Raynal
2018-05-15 16:00   ` Tom Rini
2018-05-26 15:56   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 31/32] sandbox: dts: add Sandbox TPMv2.x node Miquel Raynal
2018-05-15 16:01   ` Tom Rini
2018-05-26 15:56   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15  9:57 ` [U-Boot] [PATCH v4 32/32] configs: add TPMv2.x support in Sandbox Miquel Raynal
2018-05-15 16:01   ` Tom Rini
2018-05-26 15:56   ` [U-Boot] [U-Boot, v4, " Tom Rini
2018-05-15 16:01 ` [U-Boot] [PATCH v4 00/32] Introduce TPMv2.0 support Tom Rini

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=20180515095728.16572-13-miquel.raynal@bootlin.com \
    --to=miquel.raynal@bootlin.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.