summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/tpm-common.c24
-rw-r--r--cmd/tpm-v1.c2
-rw-r--r--cmd/tpm-v2.c4
-rw-r--r--drivers/tpm/Kconfig7
-rw-r--r--drivers/tpm/tpm-uclass.c3
-rw-r--r--drivers/tpm/tpm2_tis_sandbox.c5
-rw-r--r--drivers/tpm/tpm2_tis_spi.c4
-rw-r--r--include/tpm-common.h40
8 files changed, 70 insertions, 19 deletions
diff --git a/cmd/tpm-common.c b/cmd/tpm-common.c
index 6cf9fcc9ac..56443862c2 100644
--- a/cmd/tpm-common.c
+++ b/cmd/tpm-common.c
@@ -273,12 +273,34 @@ int do_tpm_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
cmd_tbl_t *tpm_commands, *cmd;
+ struct tpm_chip_priv *priv;
+ struct udevice *dev;
unsigned int size;
+ int ret;
if (argc < 2)
return CMD_RET_USAGE;
- tpm_commands = get_tpm_commands(&size);
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
+
+ priv = dev_get_uclass_priv(dev);
+
+ /* Below getters return NULL if the desired stack is not built */
+ switch (priv->version) {
+ case TPM_V1:
+ tpm_commands = get_tpm1_commands(&size);
+ break;
+ case TPM_V2:
+ tpm_commands = get_tpm2_commands(&size);
+ break;
+ default:
+ tpm_commands = NULL;
+ }
+
+ if (!tpm_commands)
+ return CMD_RET_USAGE;
cmd = find_cmd_tbl(argv[1], tpm_commands, size);
if (!cmd)
diff --git a/cmd/tpm-v1.c b/cmd/tpm-v1.c
index 0874c4d7ba..69870002d4 100644
--- a/cmd/tpm-v1.c
+++ b/cmd/tpm-v1.c
@@ -608,7 +608,7 @@ static cmd_tbl_t tpm1_commands[] = {
#endif /* CONFIG_TPM_LIST_RESOURCES */
};
-cmd_tbl_t *get_tpm_commands(unsigned int *size)
+cmd_tbl_t *get_tpm1_commands(unsigned int *size)
{
*size = ARRAY_SIZE(tpm1_commands);
diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c
index 38add4f462..ffbf35a75c 100644
--- a/cmd/tpm-v2.c
+++ b/cmd/tpm-v2.c
@@ -319,14 +319,14 @@ static cmd_tbl_t tpm2_commands[] = {
do_tpm_pcr_setauthvalue, "", ""),
};
-cmd_tbl_t *get_tpm_commands(unsigned int *size)
+cmd_tbl_t *get_tpm2_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",
+U_BOOT_CMD(tpm2, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
"<command> [<arguments>]\n"
"\n"
"info\n"
diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
index da1ed8fd87..782a620f91 100644
--- a/drivers/tpm/Kconfig
+++ b/drivers/tpm/Kconfig
@@ -4,9 +4,6 @@
menu "TPM support"
-comment "Please select only one TPM revision"
- depends on TPM_V1 && TPM_V2
-
config TPM_V1
bool "TPMv1.x support"
depends on TPM
@@ -15,7 +12,7 @@ config TPM_V1
Major TPM versions are not compatible at all, choose either
one or the other. This option enables TPMv1.x drivers/commands.
-if TPM_V1 && !TPM_V2
+if TPM_V1
config TPM_TIS_SANDBOX
bool "Enable sandbox TPM driver"
@@ -127,7 +124,7 @@ config TPM_V2
Major TPM versions are not compatible at all, choose either
one or the other. This option enables TPMv2.x drivers/commands.
-if TPM_V2 && !TPM_V1
+if TPM_V2
config TPM2_TIS_SANDBOX
bool "Enable sandbox TPMv2.x driver"
diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index 412697eedc..c83f53ab86 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -7,11 +7,8 @@
#include <common.h>
#include <dm.h>
#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"
int tpm_open(struct udevice *dev)
diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
index 3240cc5dba..66f6c9ba82 100644
--- a/drivers/tpm/tpm2_tis_sandbox.c
+++ b/drivers/tpm/tpm2_tis_sandbox.c
@@ -232,7 +232,7 @@ static int sandbox_tpm2_fill_buf(u8 **recv, size_t *recv_len, u16 tag, u32 rc)
*recv += sizeof(rc);
/* Add trailing \0 */
- *recv = '\0';
+ *recv = NULL;
return 0;
}
@@ -590,6 +590,9 @@ static int sandbox_tpm2_probe(struct udevice *dev)
struct sandbox_tpm2 *tpm = dev_get_priv(dev);
struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
+ /* Use the TPM v2 stack */
+ priv->version = TPM_V2;
+
memset(tpm, 0, sizeof(*tpm));
priv->pcr_count = 32;
diff --git a/drivers/tpm/tpm2_tis_spi.c b/drivers/tpm/tpm2_tis_spi.c
index c5d17a679d..8878130bd7 100644
--- a/drivers/tpm/tpm2_tis_spi.c
+++ b/drivers/tpm/tpm2_tis_spi.c
@@ -510,6 +510,7 @@ static int tpm_tis_spi_cleanup(struct udevice *dev)
static int tpm_tis_spi_open(struct udevice *dev)
{
struct tpm_chip *chip = dev_get_priv(dev);
+ struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
if (chip->is_open)
return -EBUSY;
@@ -575,6 +576,9 @@ static int tpm_tis_spi_probe(struct udevice *dev)
struct tpm_chip *chip = dev_get_priv(dev);
int ret;
+ /* Use the TPM v2 stack */
+ priv->version = TPM_V2;
+
if (IS_ENABLED(CONFIG_DM_GPIO)) {
struct gpio_desc reset_gpio;
diff --git a/include/tpm-common.h b/include/tpm-common.h
index 68bf8fd627..5f8bc6bc52 100644
--- a/include/tpm-common.h
+++ b/include/tpm-common.h
@@ -27,26 +27,39 @@ enum tpm_duration {
#define TPM_DEV_BUFSIZE 1260
/**
+ * enum tpm_version - The version of the TPM stack to be used
+ * @TPM_V1: Use TPM v1.x stack
+ * @TPM_V2: Use TPM v2.x stack
+ */
+enum tpm_version {
+ TPM_V1 = 0,
+ TPM_V2,
+};
+
+/**
* struct tpm_chip_priv - Information about a TPM, stored by the uclass
*
* These values must be set up by the device's probe() method before
* communcation is attempted. If the device has an xfer() method, this is
* not needed. There is no need to set up @buf.
*
+ * @version: TPM stack to be used
* @duration_ms: Length of each duration type in milliseconds
* @retry_time_ms: Time to wait before retrying receive
+ * @buf: Buffer used during the exchanges with the chip
* @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 {
+ enum tpm_version version;
+
uint duration_ms[TPM_DURATION_COUNT];
uint retry_time_ms;
-#if defined(CONFIG_TPM_V2)
+ u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
+
+ /* TPM v2 specific data */
uint pcr_count;
uint pcr_select_min;
-#endif
- u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
};
/**
@@ -208,10 +221,25 @@ int tpm_xfer(struct udevice *dev, const u8 *sendbuf, size_t send_size,
int tpm_init(void);
/**
- * Retrieve the array containing all the commands.
+ * Retrieve the array containing all the v1 (resp. v2) commands.
*
* @return a cmd_tbl_t array.
*/
-cmd_tbl_t *get_tpm_commands(unsigned int *size);
+#if defined(CONFIG_TPM_V1)
+cmd_tbl_t *get_tpm1_commands(unsigned int *size);
+#else
+static inline cmd_tbl_t *get_tpm1_commands(unsigned int *size)
+{
+ return NULL;
+}
+#endif
+#if defined(CONFIG_TPM_V2)
+cmd_tbl_t *get_tpm2_commands(unsigned int *size);
+#else
+static inline cmd_tbl_t *get_tpm2_commands(unsigned int *size)
+{
+ return NULL;
+}
+#endif
#endif /* __TPM_COMMON_H */