Skip to contentSkip to conversation

TPM: STMicroelectronics u-boot driver I2C

PATCH New Mathias leblanc 2 participants 2 messages Apr 8, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 TPM: STMicroelectronics u-boot driver I2C

From: Mathias Leblanc <[email protected]>

* STMicroelectronics version 1.2.0, Copyright (C) 2013
* STMicroelectronics comes with ABSOLUTELY NO WARRANTY.
* This is free software, and you are welcome to redistribute it
* under certain conditions.

This is the driver for TPM chip from ST Microelectronics.

If you have a TPM security chip from STMicroelectronics working with an I2C, read the README file and add the correct defines regarding the tpm in the configuration file of your board.
This file is located in include/configs/your_board.h

The driver will be accessible from within uboot terminal.

---
 Makefile                       |    2 +-
 README                         |   12 +
 common/cmd_tpm.c               |  176 ++++++++++++
 drivers/tpm/Makefile           |    1 +
 drivers/tpm/compatibility.h    |   52 ++++
 drivers/tpm/tis_i2c.c          |  211 ++++++++++++++
 drivers/tpm/tpm.c              |  472 +++++++++++++++++++++++++++++++
 drivers/tpm/tpm.h              |  164 +++++++++++
 drivers/tpm/tpm_i2c_st.c       |  601 ++++++++++++++++++++++++++++++++++++++++
 include/configs/omap3_beagle.h |    8 +
 include/tpm.h                  |   16 +
 11 files changed, 1714 insertions(+), 1 deletions(-)
 create mode 100644 drivers/tpm/compatibility.h
 create mode 100644 drivers/tpm/tis_i2c.c
 create mode 100644 drivers/tpm/tpm.c
 create mode 100644 drivers/tpm/tpm.h
 create mode 100644 drivers/tpm/tpm_i2c_st.c
Makefile +1 -1
index 12763ce..ef954a4 100644
@@ -314,7 +314,7 @@ endif
 LIBS-y += drivers/rtc/librtc.o
 LIBS-y += drivers/serial/libserial.o
 LIBS-y += drivers/sound/libsound.o
-LIBS-$(CONFIG_GENERIC_LPC_TPM) += drivers/tpm/libtpm.o
+LIBS-$(CONFIG_TPM) += drivers/tpm/libtpm.o
 LIBS-y += drivers/twserial/libtws.o
 LIBS-y += drivers/usb/eth/libusb_eth.o
 LIBS-y += drivers/usb/gadget/libusb_gadget.o
README +12 -0
index 7f2506a..0e497d1 100644
@@ -1210,6 +1210,18 @@ The following options need to be configured:
 			to. Contemporary x86 systems usually map it at
 			0xfed40000.
 
+		CONFIG_ST_TPM_I2C
+		Define to compile the ST TPM I2C DRIVER.
+
+		CONFIG_TPM_I2C_BUS
+		Define the bus number of the board.
+
+		CONFIG_TPM_I2C_ADDR
+		Define the address of the TPM.
+
+		CONFIG_CMD_TPM
+		Define to use some TPM u-boot commands.
+
 - USB Support:
 		At the moment only the UHCI host controller is
 		supported (PIP405, MIP405, MPC5200); define
common/cmd_tpm.c +176 -0

182 lines not on this page · raw message

drivers/tpm/Makefile +1 -0
index be11c8b..802b54e 100644
@@ -24,6 +24,7 @@ include $(TOPDIR)/config.mk
 LIB := $(obj)libtpm.o
 
 COBJS-$(CONFIG_GENERIC_LPC_TPM) = generic_lpc_tpm.o
+COBJS-$(CONFIG_ST_TPM_I2C) = tis_i2c.o tpm.o tpm_i2c_st.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
drivers/tpm/compatibility.h new file +52 -0

52 lines not on this page · raw message

drivers/tpm/tis_i2c.c new file +211 -0

211 lines not on this page · raw message

drivers/tpm/tpm.c new file +472 -0

472 lines not on this page · raw message

drivers/tpm/tpm.h new file +164 -0

164 lines not on this page · raw message

drivers/tpm/tpm_i2c_st.c new file +601 -0

601 lines not on this page · raw message

include/configs/omap3_beagle.h +8 -0
index 48ce4c0..ef381f8 100644
@@ -111,6 +111,14 @@
 #define STATUS_LED_BOOT			STATUS_LED_BIT
 #define STATUS_LED_GREEN		STATUS_LED_BIT1
 
+/* TPM */
+#define CONFIG_CMD_TPM
+#define CONFIG_TPM
+#define CONFIG_ST_TPM_DEBUG
+#define CONFIG_ST_TPM_I2C
+#define CONFIG_TPM_I2C_BUS	1
+#define CONFIG_TPM_I2C_ADDR	0x13
+
 /* Enable Multi Bus support for I2C */
 #define CONFIG_I2C_MULTI_BUS		1
 
include/tpm.h +16 -0
index 6b21e9c..9074885 100644
@@ -68,4 +68,20 @@ int tis_close(void);
 int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
 			size_t *recv_len);
 
+/*
+ * tis_sendrecv_hash()
+ *
+ * Send the requested data to the TPM for hash in LOC 4
+ * and then try to get its response
+ *
+ * @sendbuf - buffer of the data to hash
+ * @send_size size of the data to send
+ * @recvbuf - memory to save the response to
+ * @recv_len - pointer to the size of the response buffer
+ *
+ * Returns 0 on success (and places the number of response bytes at recv_len)
+ * or -1 on failure.
+ */
+int tis_sendrecv_hash(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
+			size_t *recv_len);
 #endif /* _INCLUDE_TPM_H_ */
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 TPM: STMicroelectronics u-boot driver I2C

Dear Mathias leblanc,

Quoted 2 lines · In message <[email protected]> you wrote:

* STMicroelectronics version 1.2.0, Copyright (C) 2013

Who exactly is the copyright holder?

Quoted 3 lines

* STMicroelectronics comes with ABSOLUTELY NO WARRANTY.
* This is free software, and you are welcome to redistribute it
* under certain conditions.

And these would be what exactly?

Sorry, this makes no sense. Such statements must be precise to the finest detail , and they belong into the code, and not into the commit message.

In the next step, please run your patch through checkpatch and fix the reported issues.

Please make sure to get rid of all these "__attribute__ ((packed))" stuff. Make sure that structs are properly aligned, and use explicit conversion where and if necessary.

Makefile endif · line 317

Quoted 10 lines
Makefile +1 -1
index 12763ce..ef954a4 100644
@@ -314,7 +314,7 @@ endif
 LIBS-y += drivers/rtc/librtc.o
 LIBS-y += drivers/serial/libserial.o
 LIBS-y += drivers/sound/libsound.o
-LIBS-$(CONFIG_GENERIC_LPC_TPM) += drivers/tpm/libtpm.o
+LIBS-$(CONFIG_TPM) += drivers/tpm/libtpm.o

If you change this, you must also update the realted documentation (in the README) and _all_ related code (I think you missed at least include/configs/coreboot.h).

ALso please make sure to add the documentation to the proper groups, i. e. CONFIG_CMD_TPM should be added to the CONFIG_CMD_* group.

Makefile endif

Quoted 8 lines
Makefile +8 -0
+	if (tis_init()) {
+		puts("tis_init() failed!\n");
+		return -1;
+	}
+
+	if (tis_open()) {
+		puts("tis_open() failed!\n");
+		return -1;

Can we have some better diagnostics, for example including the rason for the failure?

Makefile

Quoted 7 lines
Makefile +7 -0
+	rv = tis_sendrecv(Startup, sizeof(Startup), &response, &rlength);
+	if (rv) {
+		printf("tpm test Startup failed\n");
+		CHECK(tis_close());
+	}
+
+	rv = tis_sendrecv(SelfTestFull, sizeof(SelfTestFull), &response,

Startup, SelfTestFull, ...

We do not allow CamelCase indentifiers.

Quoted 1 line

+U_BOOT_CMD(tpm_hash, MAX_TRANSACTION_SIZE, 1, do_tpm_hash,

...

Quoted 1 line

+U_BOOT_CMD(tpm_get_flag, 1, 1, do_tpm_get_flag,

Instead of adding a number of different commands, this should be implemented as sub-commands under a common one, i. e. make this:

	tpm_hash     --> tpm hash ...
	tpm_get_flag --> tpm get_flag ...

[eventually there is even a better name than "get_flag"?]

...

Makefile line 4

Quoted 6 lines

+++ b/drivers/tpm/tis_i2c.c

Makefile +4 -0
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.

This is not acceptable. Please be precise here. We need to know exacly which license terms apply. Please see item # 1 at
http://www.denx.de/wiki/view/U-Boot/Patches#Notes for details.

Quoted 8 lines
drivers/tpm/tpm.c new file +2 -0
new file mode 100644
index 0000000..3f4f66e
@@ -0,0 +1,472 @@
+/*
+ * Copyright (C) 2011 Infineon Technologies

drivers/tpm/tpm.c line 12

Quoted 10 lines
drivers/tpm/tpm.c new file +10 -0
+ *
+ * Authors:
+ * Peter Huewe <[email protected]>
+ *
+ * Description:
+ * Device driver for TCG/TCPA TPM (trusted platform module).
+ * Specifications at www.trustedcomputinggroup.org
+ *
+ * It is based on the Linux kernel driver tpm.c from Leendert van
+ * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.

Do you have a more precise reference where the code is coming from? What we would like to see is described in bullet # 4 at
http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It's hard to think of you as the end result of millions of  years  of
evolution.