[U-Boot] [PATCH 2/2] i2c: ST33ZP24 I2C TPM driver
This driver add support for STMicroelectronics ST33ZP24 I2C TPM. --- README |6 + drivers/tpm/Makefile |1 + drivers/tpm/tpm_i2c_stm_st33.c | 633 3 files changed, 640 insertions(+) create mode 100644 drivers/tpm/tpm_i2c_stm_st33.c diff --git a/README b/README index a4aa28a..c4463d8 100644 --- a/README +++ b/README @@ -1426,6 +1426,12 @@ The following options need to be configured: TPM1_SPI_CS Define SPI Chip Select ID connected to TPM + CONFIG_TPM_ST_I2C + Support I2C STMicroelectronics TPM. Require I2C support + + CONFIG_TPM_I2C_BUS + Define the i2c bus number for the TPM device + - USB Support: At the moment only the UHCI host controller is supported (PIP405, MIP405, MPC5200); define diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile index 1ee707e..29e1f80 100644 --- a/drivers/tpm/Makefile +++ b/drivers/tpm/Makefile @@ -10,3 +10,4 @@ obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o obj-$(CONFIG_TPM_ST_SPI) += tpm_spi_stm_st33.o +obj-$(CONFIG_TPM_ST_I2C) += tpm_i2c_stm_st33.o diff --git a/drivers/tpm/tpm_i2c_stm_st33.c b/drivers/tpm/tpm_i2c_stm_st33.c new file mode 100644 index 000..6e20f8c --- /dev/null +++ b/drivers/tpm/tpm_i2c_stm_st33.c @@ -0,0 +1,633 @@ +/* + * STMicroelectronics TPM I2C UBOOT Linux driver for TPM ST33ZP24 + * Copyright (C) 2014 STMicroelectronics + * + * Description: Device driver for ST33ZP24 I2C TPM TCG. + * + * This device driver implements the TPM interface as defined in + * the TCG TPM Interface Spec version 1.21, revision 1.0 and the + * STMicroelectronics I2C Protocol Stack Specification version 1.2.0. + * + * SPDX-License-Identifier:GPL-2.0+ + * + * @Author: Jean-Luc BLANC + * + * @File: tpm_i2c_stm_st33.c + */ + +#include +#include +#include +#include +#include +#include + +#define MINOR_NUM_I2C 224 + +#define TPM_ACCESS 0x0 +#define TPM_STS0x18 +#define TPM_HASH_END 0x20 +#define TPM_DATA_FIFO 0x24 +#define TPM_HASH_DATA 0x24 +#define TPM_HASH_START 0x28 +#define TPM_INTF_CAPABILITY0x14 +#define TPM_INT_STATUS 0x10 +#define TPM_INT_ENABLE 0x08 + +#define TPM_DUMMY_BYTE 0xAA +#define TPM_WRITE_DIRECTION0x80 +#define TPM_HEADER_SIZE10 +#define TPM_BUFSIZE2048 + +#define LOCALITY0 0 +#define LOCALITY4 4 +#define LOCALITY0_I2C_ADDR 0x13 +#define LOCALITY4_I2C_ADDR 0x1B + +/* Index of Count field in TPM response buffer */ +#define TPM_RSP_SIZE_BYTE 2 + +/* Maximum command duration */ +#define TPM_MAX_COMMAND_DURATION_MS12 + +enum stm33zp24_access { + TPM_ACCESS_VALID = 0x80, + TPM_ACCESS_ACTIVE_LOCALITY = 0x20, + TPM_ACCESS_REQUEST_PENDING = 0x04, + TPM_ACCESS_REQUEST_USE = 0x02, +}; + +enum stm33zp24_status { + TPM_STS_VALID = 0x80, + TPM_STS_COMMAND_READY = 0x40, + TPM_STS_GO = 0x20, + TPM_STS_DATA_AVAIL = 0x10, + TPM_STS_DATA_EXPECT = 0x08, +}; + +enum stm33zp24_int_flags { + TPM_GLOBAL_INT_ENABLE = 0x80, + TPM_INTF_CMD_READY_INT = 0x080, + TPM_INTF_FIFO_AVALAIBLE_INT = 0x040, + TPM_INTF_WAKE_UP_READY_INT = 0x020, + TPM_INTF_LOCTPM_BUFSIZE4SOFTRELEASE_INT = 0x008, + TPM_INTF_LOCALITY_CHANGE_INT = 0x004, + TPM_INTF_STS_VALID_INT = 0x002, + TPM_INTF_DATA_AVAIL_INT = 0x001, +}; + +enum tis_defaults { + TIS_SHORT_TIMEOUT_MS = 750, /* ms */ + TIS_LONG_TIMEOUT_MS = 2000, /* 2 sec */ +}; + +/** + * @addr: TPM I2C address + * @i2c_bus: I2C bus ID the TPM is connected to + * @is_open: TPM connection establishment information + * @locality: active locality of the TPM (0 OR 4) + * @buf: command/response buffer + * @timeout_*: timeouts for TPM states changes + * @duration: maximum time for a TPM command processing + */ +struct tpm_chip { + uint addr; + uint i2c_bus; + int is_open; + u8 buf[TPM_BUFSIZE]; + int locality; + unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */ + unsigned long duration; /* msec */ +}; + +static struct tpm_chip tpm_dev; + +/* + * write8_reg(): Send byte to the TIS register according to I2C TPM protocol. + * @tpm_register, the tpm tis register where the data should be written + * @tpm_data, the tpm_data to write inside the tpm_register + * @tpm_size, The length of the data + * @return: Returns zero in case of success else the negative error code. + */ +static int write8_reg(u8 addr, u8 tpm_register
[U-Boot] [PATCH 1/2] spi: ST33ZP24 SPI TPM driver
- Add a new measurement to a PCR. Update PCR with the 20-bytes\n" " \n" +#ifdef CONFIG_TPM_ST +" hash_loc4 digest_hex_string\n" +"- Add a mesurement in PCR17. Update PCR 17 with the digest\n" +" of \n" +#endif /* CONFIG_TPM_ST */ " pcr_read index addr count\n" "- Read bytes from PCR to memory address .\n" #ifdef CONFIG_TPM_AUTH_SESSIONS @@ -754,4 +809,10 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "- Read from space to environment variables .\n" " nv_write types_string index values...\n" "- Write to space from values .\n" +#ifdef CONFIG_TPM_ST_2TPM +"TPM Select Command:\n" +" spi_select \n" +"- In platform with multiple SPI TPM, activate for coming\n" +" TPM operations. 0 or 1 are recognized \n" +#endif /* CONFIG_TPM_ST_2TPM */ ); diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile index 150570e..1ee707e 100644 --- a/drivers/tpm/Makefile +++ b/drivers/tpm/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_TPM_TIS_I2C) += tpm.o obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o +obj-$(CONFIG_TPM_ST_SPI) += tpm_spi_stm_st33.o diff --git a/drivers/tpm/tpm_spi_stm_st33.c b/drivers/tpm/tpm_spi_stm_st33.c new file mode 100644 index 000..f65adff --- /dev/null +++ b/drivers/tpm/tpm_spi_stm_st33.c @@ -0,0 +1,724 @@ +/* + * STMicroelectronics TPM SPI UBOOT Linux driver for TPM ST33ZP24 + * Copyright (C) 2014 STMicroelectronics + * + * + * Description: Device driver for ST33ZP24 SPI TPM TCG. + * + * This device driver implements the TPM interface as defined in + * the TCG TPM Interface Spec version 1.21, revision 1.0 and the + * STMicroelectronics SPI Protocol Stack Specification version 1.2.0. + * + * SPDX-License-Identifier:GPL-2.0+ + * + * @Author: Jean-Luc BLANC + * + * @File: tpm_spi_stm_st33.c + */ + +#include +#include +#include +#include +#include +#include + +#define TPM_ACCESS 0x0 +#define TPM_STS0x18 +#define TPM_HASH_END 0x20 +#define TPM_DATA_FIFO 0x24 +#define TPM_HASH_DATA 0x24 +#define TPM_HASH_START 0x28 +#define TPM_INTF_CAPABILITY0x14 +#define TPM_INT_STATUS 0x10 +#define TPM_INT_ENABLE 0x08 + +#define TPM_DUMMY_BYTE 0x00 +#define TPM_WRITE_DIRECTION0x80 +#define TPM_HEADER_SIZE10 +#define TPM_BUFSIZE2048 + +#define LOCALITY0 0 +#define LOCALITY1 1 +#define LOCALITY2 2 +#define LOCALITY3 3 +#define LOCALITY4 4 +#define NB_LOCALITIES 5 + +/* Index of Count field in TPM response buffer */ +#define TPM_RSP_SIZE_BYTE 2 + +#define SPI_WRITE_HEADER_SIZE 4 + +/** + * @latency: number of latency bytes TPM need to decode I2C register request + * and provide answer + * @is_open: TPM connection establishment information + * @locality: active locality of the TPM (0 to 4) + * @buf: command/response buffer + * @timeout_*: timeouts for TPM states changes + * @duration: maximum time for a TPM command processing + */ +struct tpm_chip { + int latency; + int is_open; + int locality; + u8 buf[TPM_BUFSIZE]; + unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */ + unsigned long duration; /* msec */ + struct spi_slave *tpm_dev_spi_info; +}; + +#ifdef CONFIG_TPM_ST_2TPM /* 2 TPM on board */ +struct tpm_chip tpm_st33_spi_board_info[CONFIG_TPM_ST_2TPM]; +#else /* Only 1 TPM on board */ +struct tpm_chip tpm_st33_spi_board_info[1]; +#endif + +struct tpm_chip *active_tpm; + +/* Maximum command duration */ +#define TPM_MAX_COMMAND_DURATION_MS12 + +enum stm33zp24_access { + TPM_ACCESS_VALID = 0x80, + TPM_ACCESS_ACTIVE_LOCALITY = 0x20, + TPM_ACCESS_REQUEST_PENDING = 0x04, + TPM_ACCESS_REQUEST_USE = 0x02, +}; + +enum stm33zp24_status { + TPM_STS_VALID = 0x80, + TPM_STS_COMMAND_READY = 0x40, + TPM_STS_GO = 0x20, + TPM_STS_DATA_AVAIL = 0x10, + TPM_STS_DATA_EXPECT = 0x08, +}; + +enum stm33zp24_int_flags { + TPM_GLOBAL_INT_ENABLE = 0x80, + TPM_INTF_CMD_READY_INT = 0x80, + TPM_INTF_FIFO_AVALAIBLE_INT = 0x40, + TPM_INTF_WAKE_UP_READY_INT = 0x20, + TPM_INTF_LOC4SOFTRELEASE_INT = 0x08, + TPM_INTF_LOCALITY_CHANGE_INT = 0x04, + TPM_INTF_STS_VALID_INT = 0x02, + TPM_INTF_DATA_AVAIL_INT = 0x01, +}; + +enum tis_defaults { + TIS_SHORT_TIMEOUT_MS = 750, /* ms */ + TIS_LONG_TIMEOUT_MS = 2000, /* 2 sec */ +}; + +/* + * spi_write8_reg - Send byte to the TIS register according to the ST33ZP24 + * SPI protocol. + * @tpm, the chip description + * @tpm_register, the tpm tis register where the d
[U-Boot] [PATCH 3/4] spi: ST33ZP24 SPI: Patch driver to support hash in locality 4
Add the support of direct hash function in locality 4. hash_loc4() command added in TPM command set. Signed-off-by: Jean-Luc BLANC --- README |4 common/cmd_tpm.c | 32 drivers/tpm/tpm_spi_stm_st33.c | 18 ++ include/tis.h | 11 ++- include/tpm.h | 12 lib/tpm.c | 13 + 6 files changed, 89 insertions(+), 1 deletion(-) diff --git a/README b/README index ef66550..56c398a 100644 --- a/README +++ b/README @@ -1347,6 +1347,10 @@ The following options need to be configured: TPM1_SPI_CS Define SPI Chip Select ID connected to TPM + CONFIG_TPM_ST + Support additional hash in locality 4 command for + STMicroelectronics TPMs (SPI or I2C). Require CONFIG_CMD_TPM. + - USB Support: At the moment only the UHCI host controller is supported (PIP405, MIP405, MPC5200); define diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c index 3085d34..7ca9257 100644 --- a/common/cmd_tpm.c +++ b/common/cmd_tpm.c @@ -334,6 +334,29 @@ static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag, return convert_return_code(rc); } +#ifdef CONFIG_TPM_ST +static int do_tpm_hash_loc4(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + uint32_t rc; + size_t count; + void *data; + + if (argc != 2) + return CMD_RET_USAGE; + + data = parse_byte_string(argv[1], NULL, &count); + if (!data) { + printf("Couldn't parse byte string %s\n", argv[1]); + return CMD_RET_FAILURE; + } + + rc = tpm_hash_loc4(data, count); + free(data); + return convert_return_code(rc); +} +#endif /* CONFIG_TPM_ST */ + static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -650,6 +673,10 @@ static cmd_tbl_t tpm_commands[] = { do_tpm_nv_write_value, "", ""), U_BOOT_CMD_MKENT(extend, 0, 1, do_tpm_extend, "", ""), +#ifdef CONFIG_TPM_ST + U_BOOT_CMD_MKENT(hash_loc4, 0, 1, + do_tpm_hash_loc4, "", ""), +#endif /* CONFIG_TPM_ST */ U_BOOT_CMD_MKENT(pcr_read, 0, 1, do_tpm_pcr_read, "", ""), #ifdef CONFIG_TPM_ST_2TPM @@ -748,6 +775,11 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, " extend index digest_hex_string\n" "- Add a new measurement to a PCR. Update PCR with the 20-bytes\n" " \n" +#ifdef CONFIG_TPM_ST +" hash_loc4 digest_hex_string\n" +"- Add a mesurement in PCR17. Update PCR 17 with the digest\n" +" of \n" +#endif /* CONFIG_TPM_ST */ " pcr_read index addr count\n" "- Read bytes from PCR to memory address .\n" #ifdef CONFIG_TPM_AUTH_SESSIONS diff --git a/drivers/tpm/tpm_spi_stm_st33.c b/drivers/tpm/tpm_spi_stm_st33.c index d7b4d65..34746f2 100644 --- a/drivers/tpm/tpm_spi_stm_st33.c +++ b/drivers/tpm/tpm_spi_stm_st33.c @@ -668,6 +668,24 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, } /* tis_sendrecv() */ /* + * tis_sendhashloc4() perform a hash in locality 4 in order to extend PCR17 + * @param: sendbuf - buffer of the data to send + * @param: send_size size of the data to send + * @return: 0 on success or -TPM_DRIVER_ERR on failure. + */ +int tis_sendhashloc4(const uint8_t *sendbuf, size_t sbuf_size) +{ + int ret; + + if (active_tpm->is_open == 0) { + printf("TPM not yet initialized, perform \"tpm init\" first\n"); + return -TPM_DRIVER_ERR; + } + ret = tpm_stm_spi_send_hash(active_tpm, sendbuf, sbuf_size); + return ret; +} /* tis_sendhashloc4() */ + +/* * tis_open() requests access to locality 0. After all commands have been * completed the caller is supposed to call tis_close(). * @param: chip_number, the tpm chip to activate (0 or 1) diff --git a/include/tis.h b/include/tis.h index 40a1f86..f2b2df3 100644 --- a/include/tis.h +++ b/include/tis.h @@ -53,5 +53,14 @@ int tis_close(void); */ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf, size_t *recv_len); - +#ifdef CONFIG_TPM_ST +/* + * tis_sendhashloc4() perform a hash in locality 4 in order to extend PCR17 + * @param: sendbuf - buffer of the data to send + * @param: send_size size of the data to send + * + * @return: 0 on success or -TPM_DRIVER_ERR on failure. + */ +int tis_sendhashloc4(const uint8_t *sendbuf, size_t sbuf_size); +#endif /* CONFIG_TPM_ST */ #endif /* __TIS_H */ diff --git a/include/tpm.h b/include/tpm.h index b726
[U-Boot] [PATCH 2/4] spi: ST33ZP24 SPI: Patch driver to support 2 TPMs
In order to support 2 SPI TPMs on same platform, add spi_select() to tpm command set. Selection is done at driver level to keep compatibility with standard tpm commands. --- README | 13 common/cmd_tpm.c | 31 drivers/tpm/tpm_spi_stm_st33.c | 44 include/tpm.h | 10 + lib/tpm.c | 13 5 files changed, 111 insertions(+) diff --git a/README b/README index e04866d..ef66550 100644 --- a/README +++ b/README @@ -1334,6 +1334,19 @@ The following options need to be configured: TPM0_SPI_CS Define SPI Chip Select ID connected to TPM + CONFIG_TPM_ST_2TPM + Support additional STMicoelectronics SPI TPM. + Require CONFIG_TPM_ST_SPI + + TPM1_SPI_MAX_SPEED + Define SPI frequency for TPM, 1000 Hz max + + TPM1_SPI_BUS_NUM + Define SPI Bus ID connected to TPM + + TPM1_SPI_CS + Define SPI Chip Select ID connected to TPM + - USB Support: At the moment only the UHCI host controller is supported (PIP405, MIP405, MPC5200); define diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c index 0294952..3085d34 100644 --- a/common/cmd_tpm.c +++ b/common/cmd_tpm.c @@ -355,6 +355,27 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, return convert_return_code(rc); } +#ifdef CONFIG_TPM_ST_2TPM +static int do_tpm_spi_select(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + uint32_t rc, spi_number; + + if (argc != 2) + return CMD_RET_USAGE; + + spi_number = simple_strtoul(argv[1], NULL, 0); + + if ((spi_number == 0) | (spi_number == 1)) { + rc = tpm_spi_select(spi_number); + } else { + printf("Couldn't parse argument %s\n", argv[1]); + return CMD_RET_FAILURE; + } + return convert_return_code(rc); +} +#endif /* CONFIG_TPM_ST_2TPM */ + static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -631,6 +652,10 @@ static cmd_tbl_t tpm_commands[] = { do_tpm_extend, "", ""), U_BOOT_CMD_MKENT(pcr_read, 0, 1, do_tpm_pcr_read, "", ""), +#ifdef CONFIG_TPM_ST_2TPM + U_BOOT_CMD_MKENT(spi_select, 0, 1, + do_tpm_spi_select, "", ""), +#endif /* CONFIG_TPM_ST_2TPM */ U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1, do_tpm_tsc_physical_presence, "", ""), U_BOOT_CMD_MKENT(read_pubek, 0, 1, @@ -754,4 +779,10 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "- Read from space to environment variables .\n" " nv_write types_string index values...\n" "- Write to space from values .\n" +#ifdef CONFIG_TPM_ST_2TPM +"TPM Select Command:\n" +" spi_select \n" +"- In platform with multiple SPI TPM, activate for coming\n" +" TPM operations. 0 or 1 are recognized \n" +#endif /* CONFIG_TPM_ST_2TPM */ ); diff --git a/drivers/tpm/tpm_spi_stm_st33.c b/drivers/tpm/tpm_spi_stm_st33.c index 78a4e54..d7b4d65 100644 --- a/drivers/tpm/tpm_spi_stm_st33.c +++ b/drivers/tpm/tpm_spi_stm_st33.c @@ -62,7 +62,11 @@ struct tpm_chip { struct spi_slave *tpm_dev_spi_info; }; +#ifdef CONFIG_TPM_ST_2TPM /* 2 TPM on board */ +struct tpm_chip tpm_st33_spi_board_info[2]; +#else /* Only 1 TPM on board */ struct tpm_chip tpm_st33_spi_board_info[1]; +#endif struct tpm_chip *active_tpm; @@ -589,6 +593,30 @@ int tis_init(void) active_tpm->is_open = 1; printf("ST33ZP24 SPI TPM from STMicroelectronics found\n"); } +#ifdef CONFIG_TPM_ST_2TPM + slave = spi_setup_slave(TPM1_SPI_BUS_NUM, TPM1_SPI_CS, + TPM1_SPI_MAX_SPEED, SPI_MODE_0); + if (slave != NULL) { + active_tpm = &tpm_st33_spi_board_info[1]; + active_tpm->timeout_a = TIS_SHORT_TIMEOUT; + active_tpm->timeout_b = TIS_LONG_TIMEOUT; + active_tpm->timeout_c = TIS_SHORT_TIMEOUT; + active_tpm->timeout_d = TIS_SHORT_TIMEOUT; + active_tpm->locality = LOCALITY0; + active_tpm->duration = TPM_MAX_COMMAND_DURATION; + active_tpm->tpm_dev_spi_info = slave; + active_tpm->latency = 2; + if (spi_read8_reg(active_tpm, active_tpm->locality, + TPM_ACCESS, active_tpm->buf, 1) != 0) { + rc = -TPM_DRIVER_ERR; + active_tpm->is_open = 0; + goto out_err; + } + active_tpm->is_open = 1;
[U-Boot] [PATCH 4/4] i2c: Add ST33ZP24 I2C TPM support
This driver add support to STMicroelectronics ST33ZP24 I2C TPM. Signed-off-by: Jean-Luc BLANC --- README |7 + drivers/tpm/tpm_i2c_stm_st33.c | 659 2 files changed, 666 insertions(+) create mode 100644 drivers/tpm/tpm_i2c_stm_st33.c diff --git a/README b/README index 56c398a..a1eae3e 100644 --- a/README +++ b/README @@ -1351,6 +1351,13 @@ The following options need to be configured: Support additional hash in locality 4 command for STMicroelectronics TPMs (SPI or I2C). Require CONFIG_CMD_TPM. + CONFIG_TPM_ST_I2C + Support I2C STMicroelectronics TPM. Require I2C support + + CONFIG_TPM_I2C_BUS + Define the i2c bus number for the TPM device + + - USB Support: At the moment only the UHCI host controller is supported (PIP405, MIP405, MPC5200); define diff --git a/drivers/tpm/tpm_i2c_stm_st33.c b/drivers/tpm/tpm_i2c_stm_st33.c new file mode 100644 index 000..ff257af --- /dev/null +++ b/drivers/tpm/tpm_i2c_stm_st33.c @@ -0,0 +1,659 @@ +/* + * STMicroelectronics TPM I2C UBOOT Linux driver for TPM ST33ZP24 + * Copyright (C) 2014 STMicroelectronics + + * + * Description: Device driver for ST33ZP24 I2C TPM TCG. + * + * This device driver implements the TPM interface as defined in + * the TCG TPM Interface Spec version 1.21, revision 1.0 and the + * STMicroelectronics I2C Protocol Stack Specification version 1.2.0. + * + * SPDX-License-Identifier:GPL-2.0+ + * + * @Author: Jean-Luc BLANC + * + * @File: tpm_i2c_stm_st33.c + */ + +#include +#include +#include +#include +#include +#include + +#define MINOR_NUM_I2C 224 + +#define TPM_ACCESS (0x0) +#define TPM_STS(0x18) +#define TPM_HASH_END (0x20) +#define TPM_DATA_FIFO (0x24) +#define TPM_HASH_DATA (0x24) +#define TPM_HASH_START (0x28) +#define TPM_INTF_CAPABILITY(0x14) +#define TPM_INT_STATUS (0x10) +#define TPM_INT_ENABLE (0x08) + +#define TPM_DUMMY_BYTE 0xAA +#define TPM_WRITE_DIRECTION0x80 +#define TPM_HEADER_SIZE10 +#define TPM_BUFSIZE2048 + +#define LOCALITY0 0 +#define LOCALITY4 4 +#define LOCALITY0_I2C_ADDR 0x13 +#define LOCALITY4_I2C_ADDR 0x1B + +/* Index of Count field in TPM response buffer */ +#define TPM_RSP_SIZE_BYTE 2 + +/* Error value returned on various TPM driver errors. */ +#define TPM_DRIVER_ERR (1) + +/* Maximum command duration */ +#define TPM_MAX_COMMAND_DURATION 12 + +enum stm33zp24_access { + TPM_ACCESS_VALID = 0x80, + TPM_ACCESS_ACTIVE_LOCALITY = 0x20, + TPM_ACCESS_REQUEST_PENDING = 0x04, + TPM_ACCESS_REQUEST_USE = 0x02, +}; + +enum stm33zp24_status { + TPM_STS_VALID = 0x80, + TPM_STS_COMMAND_READY = 0x40, + TPM_STS_GO = 0x20, + TPM_STS_DATA_AVAIL = 0x10, + TPM_STS_DATA_EXPECT = 0x08, +}; + +enum stm33zp24_int_flags { + TPM_GLOBAL_INT_ENABLE = 0x80, + TPM_INTF_CMD_READY_INT = 0x080, + TPM_INTF_FIFO_AVALAIBLE_INT = 0x040, + TPM_INTF_WAKE_UP_READY_INT = 0x020, + TPM_INTF_LOCTPM_BUFSIZE4SOFTRELEASE_INT = 0x008, + TPM_INTF_LOCALITY_CHANGE_INT = 0x004, + TPM_INTF_STS_VALID_INT = 0x002, + TPM_INTF_DATA_AVAIL_INT = 0x001, +}; + +enum tis_defaults { + TIS_SHORT_TIMEOUT = 750,/* ms */ + TIS_LONG_TIMEOUT = 2000,/* 2 sec */ +}; + +struct tpm_chip { + uint addr; + uint i2c_bus; + int is_open; + u8 buf[TPM_BUFSIZE]; + int locality; + unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */ + unsigned long duration; /* msec */ +}; + +static struct tpm_chip tpm_dev; + +/* + * write8_reg + * Send byte to the TIS register according to the ST33ZP24 I2C protocol. + * @param: tpm_register, the tpm tis register where the data should be written + * @param: tpm_data, the tpm_data to write inside the tpm_register + * @param: tpm_size, The length of the data + * @return: Returns zero in case of success else the negative error code. + */ +static int write8_reg(u8 addr, u8 tpm_register, +const u8 *tpm_data, u16 tpm_size) +{ + u8 data; + + data = tpm_register; + memcpy(&(tpm_dev.buf[0]), &data, sizeof(data)); + memcpy(&(tpm_dev.buf[0])+1, tpm_data, tpm_size); + return i2c_write(addr, 0, 0, &tpm_dev.buf[0], + tpm_size + 1); +} /* write8_reg() */ + +/* +* read8_reg +* Recv byte from the TIS register according to the ST33ZP24 I2C protocol. +* @param: tpm_register, the tpm tis re
[U-Boot] tpm: Add ST33ZP24 TPM SPI & SPI drivers
This set of patch offer ST33ZP24 TPM support to U-Boot. There is SPI and I2C driver. Best Regards, Jean-Luc BLANC TPM Application STMicroelectronics ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 2/4] spi: ST33ZP24 SPI: Patch driver to support 2 TPMs
In order to support 2 SPI TPMs on same platform, add spi_select() to tpm command set. Selection is done at driver level to keep compatibility with standard tpm commands. --- README | 13 common/cmd_tpm.c | 31 drivers/tpm/tpm_spi_stm_st33.c | 44 include/tpm.h | 10 + lib/tpm.c | 13 5 files changed, 111 insertions(+) diff --git a/README b/README index e04866d..ef66550 100644 --- a/README +++ b/README @@ -1334,6 +1334,19 @@ The following options need to be configured: TPM0_SPI_CS Define SPI Chip Select ID connected to TPM + CONFIG_TPM_ST_2TPM + Support additional STMicoelectronics SPI TPM. + Require CONFIG_TPM_ST_SPI + + TPM1_SPI_MAX_SPEED + Define SPI frequency for TPM, 1000 Hz max + + TPM1_SPI_BUS_NUM + Define SPI Bus ID connected to TPM + + TPM1_SPI_CS + Define SPI Chip Select ID connected to TPM + - USB Support: At the moment only the UHCI host controller is supported (PIP405, MIP405, MPC5200); define diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c index 0294952..3085d34 100644 --- a/common/cmd_tpm.c +++ b/common/cmd_tpm.c @@ -355,6 +355,27 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, return convert_return_code(rc); } +#ifdef CONFIG_TPM_ST_2TPM +static int do_tpm_spi_select(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + uint32_t rc, spi_number; + + if (argc != 2) + return CMD_RET_USAGE; + + spi_number = simple_strtoul(argv[1], NULL, 0); + + if ((spi_number == 0) | (spi_number == 1)) { + rc = tpm_spi_select(spi_number); + } else { + printf("Couldn't parse argument %s\n", argv[1]); + return CMD_RET_FAILURE; + } + return convert_return_code(rc); +} +#endif /* CONFIG_TPM_ST_2TPM */ + static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -631,6 +652,10 @@ static cmd_tbl_t tpm_commands[] = { do_tpm_extend, "", ""), U_BOOT_CMD_MKENT(pcr_read, 0, 1, do_tpm_pcr_read, "", ""), +#ifdef CONFIG_TPM_ST_2TPM + U_BOOT_CMD_MKENT(spi_select, 0, 1, + do_tpm_spi_select, "", ""), +#endif /* CONFIG_TPM_ST_2TPM */ U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1, do_tpm_tsc_physical_presence, "", ""), U_BOOT_CMD_MKENT(read_pubek, 0, 1, @@ -754,4 +779,10 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "- Read from space to environment variables .\n" " nv_write types_string index values...\n" "- Write to space from values .\n" +#ifdef CONFIG_TPM_ST_2TPM +"TPM Select Command:\n" +" spi_select \n" +"- In platform with multiple SPI TPM, activate for coming\n" +" TPM operations. 0 or 1 are recognized \n" +#endif /* CONFIG_TPM_ST_2TPM */ ); diff --git a/drivers/tpm/tpm_spi_stm_st33.c b/drivers/tpm/tpm_spi_stm_st33.c index 78a4e54..d7b4d65 100644 --- a/drivers/tpm/tpm_spi_stm_st33.c +++ b/drivers/tpm/tpm_spi_stm_st33.c @@ -62,7 +62,11 @@ struct tpm_chip { struct spi_slave *tpm_dev_spi_info; }; +#ifdef CONFIG_TPM_ST_2TPM /* 2 TPM on board */ +struct tpm_chip tpm_st33_spi_board_info[2]; +#else /* Only 1 TPM on board */ struct tpm_chip tpm_st33_spi_board_info[1]; +#endif struct tpm_chip *active_tpm; @@ -589,6 +593,30 @@ int tis_init(void) active_tpm->is_open = 1; printf("ST33ZP24 SPI TPM from STMicroelectronics found\n"); } +#ifdef CONFIG_TPM_ST_2TPM + slave = spi_setup_slave(TPM1_SPI_BUS_NUM, TPM1_SPI_CS, + TPM1_SPI_MAX_SPEED, SPI_MODE_0); + if (slave != NULL) { + active_tpm = &tpm_st33_spi_board_info[1]; + active_tpm->timeout_a = TIS_SHORT_TIMEOUT; + active_tpm->timeout_b = TIS_LONG_TIMEOUT; + active_tpm->timeout_c = TIS_SHORT_TIMEOUT; + active_tpm->timeout_d = TIS_SHORT_TIMEOUT; + active_tpm->locality = LOCALITY0; + active_tpm->duration = TPM_MAX_COMMAND_DURATION; + active_tpm->tpm_dev_spi_info = slave; + active_tpm->latency = 2; + if (spi_read8_reg(active_tpm, active_tpm->locality, + TPM_ACCESS, active_tpm->buf, 1) != 0) { + rc = -TPM_DRIVER_ERR; + active_tpm->is_open = 0; + goto out_err; + } + active_tpm->is_open = 1;
[U-Boot] [PATCH 1/4] [PATCH] spi: Add ST33ZP24 SPI TPM support
This driver add support to STMicroelectronics ST33ZP24 SPI TPM. Signed-off-by: Jean-Luc BLANC --- README | 12 + drivers/tpm/Makefile |1 + drivers/tpm/tpm_spi_stm_st33.c | 671 3 files changed, 684 insertions(+) create mode 100644 drivers/tpm/tpm_spi_stm_st33.c diff --git a/README b/README index aea82be..e04866d 100644 --- a/README +++ b/README @@ -1322,6 +1322,18 @@ The following options need to be configured: Define this to enable authorized functions in the TPM library. Requires CONFIG_TPM and CONFIG_SHA1. + CONFIG_TPM_ST_SPI + Support SPI STMicroelectronics TPM. Require SPI support + + TPM0_SPI_MAX_SPEED + Define SPI frequency for TPM, 1000 Hz max + + TPM0_SPI_BUS_NUM + Define SPI Bus ID connected to TPM + + TPM0_SPI_CS + Define SPI Chip Select ID connected to TPM + - USB Support: At the moment only the UHCI host controller is supported (PIP405, MIP405, MPC5200); define diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile index 150570e..1ee707e 100644 --- a/drivers/tpm/Makefile +++ b/drivers/tpm/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_TPM_TIS_I2C) += tpm.o obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o +obj-$(CONFIG_TPM_ST_SPI) += tpm_spi_stm_st33.o diff --git a/drivers/tpm/tpm_spi_stm_st33.c b/drivers/tpm/tpm_spi_stm_st33.c new file mode 100644 index 000..78a4e54 --- /dev/null +++ b/drivers/tpm/tpm_spi_stm_st33.c @@ -0,0 +1,671 @@ +/* + * STMicroelectronics TPM SPI UBOOT Linux driver for TPM ST33ZP24 + * Copyright (C) 2014 STMicroelectronics + + * + * Description: Device driver for ST33ZP24 SPI TPM TCG. + * + * This device driver implements the TPM interface as defined in + * the TCG TPM Interface Spec version 1.21, revision 1.0 and the + * STMicroelectronics SPI Protocol Stack Specification version 1.2.0. + * + * SPDX-License-Identifier:GPL-2.0+ + * + * @Author: Jean-Luc BLANC + * + * @File: tpm_spi_stm_st33.c + */ + +#include +#include +#include +#include +#include +#include + +#define TPM_ACCESS (0x0) +#define TPM_STS(0x18) +#define TPM_HASH_END (0x20) +#define TPM_DATA_FIFO (0x24) +#define TPM_HASH_DATA (0x24) +#define TPM_HASH_START (0x28) +#define TPM_INTF_CAPABILITY(0x14) +#define TPM_INT_STATUS (0x10) +#define TPM_INT_ENABLE (0x08) + +#define TPM_DUMMY_BYTE 0x00 +#define TPM_WRITE_DIRECTION0x80 +#define TPM_HEADER_SIZE10 +#define TPM_BUFSIZE2048 + +#define LOCALITY0 0 +#define LOCALITY1 1 +#define LOCALITY2 2 +#define LOCALITY3 3 +#define LOCALITY4 4 + +/* Index of Count field in TPM response buffer */ +#define TPM_RSP_SIZE_BYTE 2 + +#define MAX_NUMBER_TPM_ONBOARD 2 + +#define SPI_WRITE_HEADER_SIZE 4 + +struct tpm_chip { + int latency; + int is_open; + bool bchipf; + int locality; + u8 buf[TPM_BUFSIZE]; + unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */ + unsigned long duration; /* msec */ + struct spi_slave *tpm_dev_spi_info; +}; + +struct tpm_chip tpm_st33_spi_board_info[1]; + +struct tpm_chip *active_tpm; + +/* Error value returned on various TPM driver errors. */ +#define TPM_DRIVER_ERR (1) + +/* Maximum command duration */ +#define TPM_MAX_COMMAND_DURATION 12 + +#define min_t(type, x, y) ({ \ + type __min1 = (x); \ + type __min2 = (y); \ + __min1 < __min2 ? __min1 : __min2; }) + +enum stm33zp24_access { + TPM_ACCESS_VALID = 0x80, + TPM_ACCESS_ACTIVE_LOCALITY = 0x20, + TPM_ACCESS_REQUEST_PENDING = 0x04, + TPM_ACCESS_REQUEST_USE = 0x02, +}; + +enum stm33zp24_status { + TPM_STS_VALID = 0x80, + TPM_STS_COMMAND_READY = 0x40, + TPM_STS_GO = 0x20, + TPM_STS_DATA_AVAIL = 0x10, + TPM_STS_DATA_EXPECT = 0x08, +}; + +enum stm33zp24_int_flags { + TPM_GLOBAL_INT_ENABLE = 0x80, + TPM_INTF_CMD_READY_INT = 0x80, + TPM_INTF_FIFO_AVALAIBLE_INT = 0x40, + TPM_INTF_WAKE_UP_READY_INT = 0x20, + TPM_INTF_LOC4SOFTRELEASE_INT = 0x08, + TPM_INTF_LOCALITY_CHANGE_INT = 0x04, + TPM_INTF_STS_VALID_
[U-Boot] [PATCH 1/4] [PATCH] spi: Add ST33ZP24 SPI TPM support
This driver add support to STMicroelectronics ST33ZP24 SPI TPM. Signed-off-by: Jean-Luc BLANC --- README | 12 + drivers/tpm/Makefile |1 + drivers/tpm/tpm_spi_stm_st33.c | 671 3 files changed, 684 insertions(+) create mode 100644 drivers/tpm/tpm_spi_stm_st33.c diff --git a/README b/README index aea82be..e04866d 100644 --- a/README +++ b/README @@ -1322,6 +1322,18 @@ The following options need to be configured: Define this to enable authorized functions in the TPM library. Requires CONFIG_TPM and CONFIG_SHA1. + CONFIG_TPM_ST_SPI + Support SPI STMicroelectronics TPM. Require SPI support + + TPM0_SPI_MAX_SPEED + Define SPI frequency for TPM, 1000 Hz max + + TPM0_SPI_BUS_NUM + Define SPI Bus ID connected to TPM + + TPM0_SPI_CS + Define SPI Chip Select ID connected to TPM + - USB Support: At the moment only the UHCI host controller is supported (PIP405, MIP405, MPC5200); define diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile index 150570e..1ee707e 100644 --- a/drivers/tpm/Makefile +++ b/drivers/tpm/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_TPM_TIS_I2C) += tpm.o obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o +obj-$(CONFIG_TPM_ST_SPI) += tpm_spi_stm_st33.o diff --git a/drivers/tpm/tpm_spi_stm_st33.c b/drivers/tpm/tpm_spi_stm_st33.c new file mode 100644 index 000..78a4e54 --- /dev/null +++ b/drivers/tpm/tpm_spi_stm_st33.c @@ -0,0 +1,671 @@ +/* + * STMicroelectronics TPM SPI UBOOT Linux driver for TPM ST33ZP24 + * Copyright (C) 2014 STMicroelectronics + + * + * Description: Device driver for ST33ZP24 SPI TPM TCG. + * + * This device driver implements the TPM interface as defined in + * the TCG TPM Interface Spec version 1.21, revision 1.0 and the + * STMicroelectronics SPI Protocol Stack Specification version 1.2.0. + * + * SPDX-License-Identifier:GPL-2.0+ + * + * @Author: Jean-Luc BLANC + * + * @File: tpm_spi_stm_st33.c + */ + +#include +#include +#include +#include +#include +#include + +#define TPM_ACCESS (0x0) +#define TPM_STS(0x18) +#define TPM_HASH_END (0x20) +#define TPM_DATA_FIFO (0x24) +#define TPM_HASH_DATA (0x24) +#define TPM_HASH_START (0x28) +#define TPM_INTF_CAPABILITY(0x14) +#define TPM_INT_STATUS (0x10) +#define TPM_INT_ENABLE (0x08) + +#define TPM_DUMMY_BYTE 0x00 +#define TPM_WRITE_DIRECTION0x80 +#define TPM_HEADER_SIZE10 +#define TPM_BUFSIZE2048 + +#define LOCALITY0 0 +#define LOCALITY1 1 +#define LOCALITY2 2 +#define LOCALITY3 3 +#define LOCALITY4 4 + +/* Index of Count field in TPM response buffer */ +#define TPM_RSP_SIZE_BYTE 2 + +#define MAX_NUMBER_TPM_ONBOARD 2 + +#define SPI_WRITE_HEADER_SIZE 4 + +struct tpm_chip { + int latency; + int is_open; + bool bchipf; + int locality; + u8 buf[TPM_BUFSIZE]; + unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */ + unsigned long duration; /* msec */ + struct spi_slave *tpm_dev_spi_info; +}; + +struct tpm_chip tpm_st33_spi_board_info[1]; + +struct tpm_chip *active_tpm; + +/* Error value returned on various TPM driver errors. */ +#define TPM_DRIVER_ERR (1) + +/* Maximum command duration */ +#define TPM_MAX_COMMAND_DURATION 12 + +#define min_t(type, x, y) ({ \ + type __min1 = (x); \ + type __min2 = (y); \ + __min1 < __min2 ? __min1 : __min2; }) + +enum stm33zp24_access { + TPM_ACCESS_VALID = 0x80, + TPM_ACCESS_ACTIVE_LOCALITY = 0x20, + TPM_ACCESS_REQUEST_PENDING = 0x04, + TPM_ACCESS_REQUEST_USE = 0x02, +}; + +enum stm33zp24_status { + TPM_STS_VALID = 0x80, + TPM_STS_COMMAND_READY = 0x40, + TPM_STS_GO = 0x20, + TPM_STS_DATA_AVAIL = 0x10, + TPM_STS_DATA_EXPECT = 0x08, +}; + +enum stm33zp24_int_flags { + TPM_GLOBAL_INT_ENABLE = 0x80, + TPM_INTF_CMD_READY_INT = 0x80, + TPM_INTF_FIFO_AVALAIBLE_INT = 0x40, + TPM_INTF_WAKE_UP_READY_INT = 0x20, + TPM_INTF_LOC4SOFTRELEASE_INT = 0x08, + TPM_INTF_LOCALITY_CHANGE_INT = 0x04, + TPM_INTF_STS_VALID_
[U-Boot] tpm: Add ST33ZP24 TPM SPI & SPI drivers
Hello, This set of patch offer ST33ZP24 TPM support to U-Boot. There is SPI and I2C driver. Best Regards, Jean-Luc BLANC TPM Application STMicroelectronics ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot