Skip to contentSkip to conversation

tpm: Add driver for cr50

PATCH Superseded Stephen Boyd 2 participants 12 messages Aug 6, 2019 – Aug 15, 2019

Subsystems (3)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover tpm: Add driver for cr50

This patch series adds support for the the H1 secure microcontroller running cr50 firmware found on various recent Chromebooks. This driver is necessary to boot into a ChromeOS userspace environment. It implements support for several functions, including TPM-like functionality over a SPI interface.

The last time this was series sent looks to be [1]. I've looked over the patches and review comments and tried to address any feedback that Andrey didn't address (really minor things like newlines). I've reworked the patches from the last version to layer on top of the existing TPM TIS SPI implementation in tpm_tis_spi.c. Hopefully this is more palatable than combining the two drivers together into one file.

[1] https://lkml.kernel.org/r/[email protected]

TODO:
* Add a patch to spit out WARN_ON() when TPM is suspended and some kernel code attempts to use it
* Rework the i2c driver per Alexander's comments on v2

Changes from v2:
* Sent khwrng thread patch separately
* New patch to expose TPM SPI functionality from tpm_tis_spi.c
* Usage of that new patch in cr50 SPI driver
* Drop i2c version of cr50 SPI driver for now (will resend later)
* New patch to add a TPM chip flag indicating TPM shouldn't be reset over suspend. Allows us to get rid of the cr50 suspend/resume functions that are mostly generic

Changes from v1:
* Dropped symlink and sysfs patches
* Removed 'is_suspended' bits
* Added new patch to freeze khwrng thread
* Moved binding to google,cr50.txt and added Reviewed-by tag from Rob

Cc Andrey Pronin <[email protected]>
Cc Duncan Laurie <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Alexander Steffen <[email protected]>

Andrey Pronin (2):
dt-bindings: tpm: document properties for cr50
tpm: add driver for cr50 on SPI

Stephen Boyd (2):
tpm: Add a flag to indicate TPM power is managed by firmware
tpm: tpm_tis_spi: Export functionality to other drivers

 .../bindings/security/tpm/google,cr50.txt     |  19 +
 drivers/char/tpm/Kconfig                      |   9 +
 drivers/char/tpm/Makefile                     |   1 +
 drivers/char/tpm/cr50_spi.c                   | 373 ++++++++++++++++++
 drivers/char/tpm/tpm-interface.c              |   8 +-
 drivers/char/tpm/tpm.h                        |   1 +
 drivers/char/tpm/tpm_tis_spi.c                |  98 +++--
 drivers/char/tpm/tpm_tis_spi.h                |  37 ++
 8 files changed, 503 insertions(+), 43 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/security/tpm/google,cr50.txt
 create mode 100644 drivers/char/tpm/cr50_spi.c
 create mode 100644 drivers/char/tpm/tpm_tis_spi.h

base-commit: 0ecfebd2b52404ae0c54a878c872bb93363ada36
prerequisite-patch-id: ce0cac49be5e67df1427e4207cf38c6e31091445

Signature · 1 line
Sent by a computer through tubes
#1 lore raw

PATCH v3 1/4 tpm: Add a flag to indicate TPM power is managed by firmware

On some platforms, the TPM power is managed by firmware and therefore we don't need to stop the TPM on suspend when going to a light version of suspend such as S0ix ("freeze" suspend state). Add a chip flag to indicate this so that certain platforms can probe for the usage of this light suspend and avoid touching the TPM state across suspend/resume.

Cc Andrey Pronin <[email protected]>
Cc Duncan Laurie <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Alexander Steffen <[email protected]>
---
 drivers/char/tpm/tpm-interface.c | 8 +++++++-
 drivers/char/tpm/tpm.h           | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm-interface.c +7 -1
index 1b4f95c13e00..9bf3ddee6c8c 100644
@@ -23,6 +23,7 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/spinlock.h>
+#include <linux/suspend.h>
 #include <linux/freezer.h>
 #include <linux/tpm_eventlog.h>
 
@@ -395,7 +396,11 @@ int tpm_pm_suspend(struct device *dev)
 		return -ENODEV;
 
 	if (chip->flags & TPM_CHIP_FLAG_ALWAYS_POWERED)
-		return 0;
+		goto suspended;
+
+	if (chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED)
+		if (!pm_suspend_via_firmware())
+			goto suspended;
 
 	if (!tpm_chip_start(chip)) {
 		if (chip->flags & TPM_CHIP_FLAG_TPM2)
@@ -406,6 +411,7 @@ int tpm_pm_suspend(struct device *dev)
 		tpm_chip_stop(chip);
 	}
 
+suspended:
 	return rc;
 }
 EXPORT_SYMBOL_GPL(tpm_pm_suspend);
drivers/char/tpm/tpm.h +1 -0
index e503ffc3aa39..28f73331aa2e 100644
@@ -162,6 +162,7 @@ enum tpm_chip_flags {
 	TPM_CHIP_FLAG_VIRTUAL		= BIT(3),
 	TPM_CHIP_FLAG_HAVE_TIMEOUTS	= BIT(4),
 	TPM_CHIP_FLAG_ALWAYS_POWERED	= BIT(5),
+	TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED	= BIT(6),
 };
 
 #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)
Signature · 1 line
Sent by a computer through tubes
#2 lore raw

Re: [PATCH v3 1/4] tpm: Add a flag to indicate TPM power is managed by firmware

Quoted 5 lines · Stephen Boyd

On some platforms, the TPM power is managed by firmware and therefore we don't need to stop the TPM on suspend when going to a light version of suspend such as S0ix ("freeze" suspend state). Add a chip flag to indicate this so that certain platforms can probe for the usage of this light suspend and avoid touching the TPM state across suspend/resume.

The commit message should mention the new constant.

drivers/char/tpm/tpm-interface.c int tpm_pm_suspend(struct device *dev) · line 402

Quoted 2 lines
drivers/char/tpm/tpm-interface.c +2 -0
+	if (chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED)
+		if (!pm_suspend_via_firmware())

Why both checks are needed?

If both checks are needed, you could write it as a single conditional statement:

if (chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED &&

    !pm_suspend_via_firmware())

/Jarkko

#3 lore raw

Re: [PATCH v3 1/4] tpm: Add a flag to indicate TPM power is managed by firmware

Quoting Jarkko Sakkinen (2019-08-09 11:02:01)

Quoted 8 lines · Stephen Boyd
Quoted 5 lines

On some platforms, the TPM power is managed by firmware and therefore we don't need to stop the TPM on suspend when going to a light version of suspend such as S0ix ("freeze" suspend state). Add a chip flag to indicate this so that certain platforms can probe for the usage of this light suspend and avoid touching the TPM state across suspend/resume.

The commit message should mention the new constant.

Alright.

Quoted 4 lines

drivers/char/tpm/tpm-interface.c int tpm_pm_suspend(struct device *dev) · line 402

Quoted 3 lines
drivers/char/tpm/tpm-interface.c +2 -0
+     if (chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED)
+             if (!pm_suspend_via_firmware())
Quoted 8 lines

Why both checks are needed?

If both checks are needed, you could write it as a single conditional statement:

if (chip->flags & TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED &&

    !pm_suspend_via_firmware())

Ok. I'll combine them.

#4 lore raw

PATCH v3 2/4 tpm: tpm_tis_spi: Export functionality to other drivers

In reply to Stephen Boyd

We want to use most of the code in this driver, except we want to modify the flow control and idle behavior. Let's "libify" this driver so that another driver can call the code in here and slightly tweak the behavior.

Cc Andrey Pronin <[email protected]>
Cc Duncan Laurie <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Alexander Steffen <[email protected]>
---
 drivers/char/tpm/tpm_tis_spi.c | 98 +++++++++++++++++++---------------
 drivers/char/tpm/tpm_tis_spi.h | 37 +++++++++++++
 2 files changed, 93 insertions(+), 42 deletions(-)
 create mode 100644 drivers/char/tpm/tpm_tis_spi.h
drivers/char/tpm/tpm_tis_spi.c +56 -42
index 19513e622053..fd3fb4f9f506 100644
@@ -36,26 +36,43 @@
 #include <linux/tpm.h>
 #include "tpm.h"
 #include "tpm_tis_core.h"
+#include "tpm_tis_spi.h"
 
 #define MAX_SPI_FRAMESIZE 64
 
-struct tpm_tis_spi_phy {
-	struct tpm_tis_data priv;
-	struct spi_device *spi_device;
-	u8 *iobuf;
-};
-
-static inline struct tpm_tis_spi_phy *to_tpm_tis_spi_phy(struct tpm_tis_data *data)
+static int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy,
+				    struct spi_transfer *spi_xfer)
 {
-	return container_of(data, struct tpm_tis_spi_phy, priv);
+	struct spi_message m;
+	int ret, i;
+
+	if ((phy->iobuf[3] & 0x01) == 0) {
+		// handle SPI wait states
+		phy->iobuf[0] = 0;
+
+		for (i = 0; i < TPM_RETRY; i++) {
+			spi_xfer->len = 1;
+			spi_message_init(&m);
+			spi_message_add_tail(spi_xfer, &m);
+			ret = spi_sync_locked(phy->spi_device, &m);
+			if (ret < 0)
+				return ret;
+			if (phy->iobuf[0] & 0x01)
+				break;
+		}
+
+		if (i == TPM_RETRY)
+			return -ETIMEDOUT;
+	}
+
+	return 0;
 }
 
-static int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
+int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
 				u8 *in, const u8 *out)
 {
 	struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data);
 	int ret = 0;
-	int i;
 	struct spi_message m;
 	struct spi_transfer spi_xfer;
 	u8 transfer_len;
@@ -82,26 +99,9 @@ static int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
 		if (ret < 0)
 			goto exit;
 
-		if ((phy->iobuf[3] & 0x01) == 0) {
-			// handle SPI wait states
-			phy->iobuf[0] = 0;
-
-			for (i = 0; i < TPM_RETRY; i++) {
-				spi_xfer.len = 1;
-				spi_message_init(&m);
-				spi_message_add_tail(&spi_xfer, &m);
-				ret = spi_sync_locked(phy->spi_device, &m);
-				if (ret < 0)
-					goto exit;
-				if (phy->iobuf[0] & 0x01)
-					break;
-			}
-
-			if (i == TPM_RETRY) {
-				ret = -ETIMEDOUT;
-				goto exit;
-			}
-		}
+		ret = phy->flow_control(phy, &spi_xfer);
+		if (ret < 0)
+			goto exit;
 
 		spi_xfer.cs_change = 0;
 		spi_xfer.len = transfer_len;
@@ -117,6 +117,8 @@ static int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
 
 		spi_message_init(&m);
 		spi_message_add_tail(&spi_xfer, &m);
+		if (phy->pre_transfer)
+			phy->pre_transfer(phy);
 		ret = spi_sync_locked(phy->spi_device, &m);
 		if (ret < 0)
 			goto exit;
@@ -133,9 +135,10 @@ static int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
 	spi_bus_unlock(phy->spi_device->master);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(tpm_tis_spi_transfer);
 
-static int tpm_tis_spi_read_bytes(struct tpm_tis_data *data, u32 addr,
-				  u16 len, u8 *result)
+static int tpm_tis_spi_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
+				  u8 *result)
 {
 	return tpm_tis_spi_transfer(data, addr, len, result, NULL);
 }
@@ -146,7 +149,7 @@ static int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr,
 	return tpm_tis_spi_transfer(data, addr, len, NULL, value);
 }
 
-static int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result)
+int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result)
 {
 	__le16 result_le;
 	int rc;
@@ -158,8 +161,9 @@ static int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result)
 
 	return rc;
 }
+EXPORT_SYMBOL_GPL(tpm_tis_spi_read16);
 
-static int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result)
+int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result)
 {
 	__le32 result_le;
 	int rc;
@@ -171,8 +175,9 @@ static int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result)
 
 	return rc;
 }
+EXPORT_SYMBOL_GPL(tpm_tis_spi_read32);
 
-static int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value)
+int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value)
 {
 	__le32 value_le;
 	int rc;
@@ -183,6 +188,20 @@ static int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value)
 
 	return rc;
 }
+EXPORT_SYMBOL_GPL(tpm_tis_spi_write32);
+
+int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy,
+		     int irq, const struct tpm_tis_phy_ops *phy_ops)
+{
+	phy->iobuf = devm_kmalloc(&spi->dev, MAX_SPI_FRAMESIZE, GFP_KERNEL);
+	if (!phy->iobuf)
+		return -ENOMEM;
+
+	phy->spi_device = spi;
+
+	return tpm_tis_core_init(&spi->dev, &phy->priv, irq, phy_ops, NULL);
+}
+EXPORT_SYMBOL_GPL(tpm_tis_spi_init);
 
 static const struct tpm_tis_phy_ops tpm_spi_phy_ops = {
 	.read_bytes = tpm_tis_spi_read_bytes,
@@ -202,11 +221,7 @@ static int tpm_tis_spi_probe(struct spi_device *dev)
 	if (!phy)
 		return -ENOMEM;
 
-	phy->spi_device = dev;
-
-	phy->iobuf = devm_kmalloc(&dev->dev, MAX_SPI_FRAMESIZE, GFP_KERNEL);
-	if (!phy->iobuf)
-		return -ENOMEM;
+	phy->flow_control = tpm_tis_spi_flow_control;
 
 	/* If the SPI device has an IRQ then use that */
 	if (dev->irq > 0)
@@ -214,8 +229,7 @@ static int tpm_tis_spi_probe(struct spi_device *dev)
 	else
 		irq = -1;
 
-	return tpm_tis_core_init(&dev->dev, &phy->priv, irq, &tpm_spi_phy_ops,
-				 NULL);
+	return tpm_tis_spi_init(dev, phy, irq, &tpm_spi_phy_ops);
 }
 
 static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
drivers/char/tpm/tpm_tis_spi.h new file +37 -0
new file mode 100644
index 000000000000..48be5130794a
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2015 Infineon Technologies AG
+ * Copyright (C) 2016 STMicroelectronics SAS
+ */
+
+#ifndef TPM_TIS_SPI_H
+#define TPM_TIS_SPI_H
+
+#include "tpm_tis_core.h"
+
+struct tpm_tis_spi_phy {
+	struct tpm_tis_data priv;
+	struct spi_device *spi_device;
+	int (*flow_control)(struct tpm_tis_spi_phy *phy,
+			     struct spi_transfer *xfer);
+	void (*pre_transfer)(struct tpm_tis_spi_phy *phy);
+
+	u8 *iobuf;
+};
+
+static inline struct tpm_tis_spi_phy *to_tpm_tis_spi_phy(struct tpm_tis_data *data)
+{
+	return container_of(data, struct tpm_tis_spi_phy, priv);
+}
+
+extern int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy,
+			    int irq, const struct tpm_tis_phy_ops *phy_ops);
+
+extern int tpm_tis_spi_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
+				u8 *in, const u8 *out);
+
+extern int tpm_tis_spi_read16(struct tpm_tis_data *data, u32 addr, u16 *result);
+extern int tpm_tis_spi_read32(struct tpm_tis_data *data, u32 addr, u32 *result);
+extern int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value);
+
+#endif
Signature · 1 line
Sent by a computer through tubes
#5 lore raw

Re: [PATCH v3 2/4] tpm: tpm_tis_spi: Export functionality to other drivers

Quoted 4 lines · Stephen Boyd

We want to use most of the code in this driver, except we want to modify the flow control and idle behavior. Let's "libify" this driver so that another driver can call the code in here and slightly tweak the behavior.

Neither "libifying" nor "slightly tweaking" gives an idea what the commit does. A great commit message should be in imperative form describe what it does and why in as plain english as possible.

Often commit messages are seen just as a necessary bad and not much energy is spent on them but for a maitainer solid commit messages have an indispensable value.

drivers/char/tpm/tpm_tis_spi.h line 17

Quoted 1 line
drivers/char/tpm/tpm_tis_spi.h new file +1 -0
+	void (*pre_transfer)(struct tpm_tis_spi_phy *phy);

Adding a new calback should be a commit of its own.

/Jarkko

#6 lore raw

Re: [PATCH v3 2/4] tpm: tpm_tis_spi: Export functionality to other drivers

Quoting Jarkko Sakkinen (2019-08-09 13:28:13)

Quoted 10 lines · Stephen Boyd
Quoted 4 lines

We want to use most of the code in this driver, except we want to modify the flow control and idle behavior. Let's "libify" this driver so that another driver can call the code in here and slightly tweak the behavior.

Neither "libifying" nor "slightly tweaking" gives an idea what the commit does. A great commit message should be in imperative form describe what it does and why in as plain english as possible.

Quoted 8 lines

Often commit messages are seen just as a necessary bad and not much energy is spent on them but for a maitainer solid commit messages have an indispensable value.

Quoted 1 line

+ void (*pre_transfer)(struct tpm_tis_spi_phy *phy);

Adding a new calback should be a commit of its own.

Ok. I will do that and focus the commit message.

#7 lore raw

PATCH v3 3/4 dt-bindings: tpm: document properties for cr50

In reply to Stephen Boyd

From: Andrey Pronin <[email protected]>

Add TPM2.0 PTP FIFO compatible SPI interface for chips with Cr50 firmware.

Cc Andrey Pronin <[email protected]>
Cc Duncan Laurie <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Alexander Steffen <[email protected]>
---
 .../bindings/security/tpm/google,cr50.txt     | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/security/tpm/google,cr50.txt
Documentation/devicetree/bindings/security/tpm/google,cr50.txt new file +19 -0
new file mode 100644
index 000000000000..7aa65224c8b9
@@ -0,0 +1,19 @@
+* H1 Secure Microcontroller with Cr50 Firmware on SPI Bus.
+
+H1 Secure Microcontroller running Cr50 firmware provides several
+functions, including TPM-like functionality. It communicates over
+SPI using the FIFO protocol described in the PTP Spec, section 6.
+
+Required properties:
+- compatible: Should be "google,cr50".
+- spi-max-frequency: Maximum SPI frequency.
+
+Example:
+
+&spi0 {
+        tpm@0 {
+                compatible = "google,cr50";
+                reg = <0>;
+                spi-max-frequency = <800000>;
+        };
+};
Signature · 1 line
Sent by a computer through tubes
#8 lore raw

PATCH v3 4/4 tpm: add driver for cr50 on SPI

In reply to Stephen Boyd

From: Andrey Pronin <[email protected]>

Add TPM2.0 PTP FIFO compatible SPI interface for chips with Cr50 firmware. The firmware running on the currently supported H1 Secure Microcontroller requires a special driver to handle its specifics:

- need to ensure a certain delay between spi transactions, or else the chip may miss some part of the next transaction;
- if there is no spi activity for some time, it may go to sleep, and needs to be waken up before sending further commands;
- access to vendor-specific registers.

Cc Andrey Pronin <[email protected]>
Cc Duncan Laurie <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Alexander Steffen <[email protected]>

[[email protected]: Replace boilerplate with SPDX tag, drop suspended bit and remove ifdef checks in cr50.h, push tpm.h include into cr50.c, migrate to functions exported from tpm_tis_spi.h]

---
 drivers/char/tpm/Kconfig    |   9 +
 drivers/char/tpm/Makefile   |   1 +
 drivers/char/tpm/cr50_spi.c | 373 ++++++++++++++++++++++++++++++++++++
 3 files changed, 383 insertions(+)
 create mode 100644 drivers/char/tpm/cr50_spi.c
drivers/char/tpm/Kconfig +9 -0
index 88a3c06fc153..1fb23f145ef6 100644
@@ -114,6 +114,15 @@ config TCG_ATMEL
 	  will be accessible from within Linux.  To compile this driver 
 	  as a module, choose M here; the module will be called tpm_atmel.
 
+config TCG_CR50_SPI
+	tristate "Cr50 SPI Interface"
+	depends on TCG_TIS_SPI
+	---help---
+	  If you have a H1 secure module running Cr50 firmware on SPI bus,
+	  say Yes and it will be accessible from within Linux. To compile
+	  this driver as a module, choose M here; the module will be called
+	  cr50_spi.
+
 config TCG_INFINEON
 	tristate "Infineon Technologies TPM Interface"
 	depends on PNP
drivers/char/tpm/Makefile +1 -0
index a01c4cab902a..4713e52ce1b0 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o
 obj-$(CONFIG_TCG_TIS_I2C_NUVOTON) += tpm_i2c_nuvoton.o
 obj-$(CONFIG_TCG_NSC) += tpm_nsc.o
 obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o
+obj-$(CONFIG_TCG_CR50_SPI) += cr50_spi.o
 obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o
 obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o
 obj-$(CONFIG_TCG_TIS_ST33ZP24) += st33zp24/
drivers/char/tpm/cr50_spi.c new file +373 -0

373 lines not on this page · raw message

Signature · 1 line
Sent by a computer through tubes
#9 lore raw

Re: [PATCH v3 4/4] tpm: add driver for cr50 on SPI

Quoted 7 lines · Stephen Boyd

From: Andrey Pronin <[email protected]>

Add TPM2.0 PTP FIFO compatible SPI interface for chips with Cr50 firmware. The firmware running on the currently supported H1 Secure Microcontroller requires a special driver to handle its specifics:

Quoted 5 lines

- need to ensure a certain delay between spi transactions, or else the chip may miss some part of the next transaction;
- if there is no spi activity for some time, it may go to sleep, and needs to be waken up before sending further commands;
- access to vendor-specific registers.

Which Chromebook models have this chip?

If I had an access to one, how do I do kernel testing with it i.e. how do I get it to boot initramfs and bzImage from a USB stick?

/Jarkko

#10 lore raw

Re: [PATCH v3 4/4] tpm: add driver for cr50 on SPI

Quoting Jarkko Sakkinen (2019-08-09 13:31:04)

Quoted 8 lines · Stephen Boyd
Quoted 7 lines

From: Andrey Pronin <[email protected]>

Add TPM2.0 PTP FIFO compatible SPI interface for chips with Cr50 firmware. The firmware running on the currently supported H1 Secure Microcontroller requires a special driver to handle its specifics:

Quoted 7 lines
Quoted 5 lines

- need to ensure a certain delay between spi transactions, or else the chip may miss some part of the next transaction;
- if there is no spi activity for some time, it may go to sleep, and needs to be waken up before sending further commands;
- access to vendor-specific registers.

Which Chromebook models have this chip?

Pretty much all Chromebooks released in the last year or two have this chip in them. I don't have an exhaustive list, but you can usually check this by putting your device into dev mode and then looking at the driver attached to the TPM device in sysfs or by grepping the dmesg output for cr50.

Quoted 5 lines

If I had an access to one, how do I do kernel testing with it i.e. how do I get it to boot initramfs and bzImage from a USB stick?

You can follow the developer guide[1] and build a USB image for the board you have. You can usually checkout the latest upstream kernel in place of where the kernel is built from in the chroot, typically ~/trunk/src/third_party/kernel/<version number>. The build should pick up that it's an upstream tree and try to use some default defconfig. This driver isn't upstream yet, so you may need to enable it in the defconfig, located in ~/trunk/src/third_party/chromiumos-overlay/eclass/cros-kernel/ so that the driver is actually built. After that, use 'cros flash' to flash the new kernel image to your USB stick and boot from USB with 'ctrl+u' and you should be on your way to chromeos kernel testing.

[1] https://chromium.googlesource.com/chromiumos/docs/+/master/developer_guide.md

#11 lore raw

Re: [PATCH v3 4/4] tpm: add driver for cr50 on SPI

Quoted 41 lines · Stephen Boyd

Quoting Jarkko Sakkinen (2019-08-09 13:31:04)

Quoted 8 lines · Stephen Boyd
Quoted 7 lines

From: Andrey Pronin <[email protected]>

Add TPM2.0 PTP FIFO compatible SPI interface for chips with Cr50 firmware. The firmware running on the currently supported H1 Secure Microcontroller requires a special driver to handle its specifics:

Quoted 7 lines
Quoted 5 lines

- need to ensure a certain delay between spi transactions, or else the chip may miss some part of the next transaction;
- if there is no spi activity for some time, it may go to sleep, and needs to be waken up before sending further commands;
- access to vendor-specific registers.

Which Chromebook models have this chip?

Pretty much all Chromebooks released in the last year or two have this chip in them. I don't have an exhaustive list, but you can usually check this by putting your device into dev mode and then looking at the driver attached to the TPM device in sysfs or by grepping the dmesg output for cr50.

Quoted 5 lines

If I had an access to one, how do I do kernel testing with it i.e. how do I get it to boot initramfs and bzImage from a USB stick?

You can follow the developer guide[1] and build a USB image for the board you have. You can usually checkout the latest upstream kernel in place of where the kernel is built from in the chroot, typically ~/trunk/src/third_party/kernel/<version number>. The build should pick up that it's an upstream tree and try to use some default defconfig. This driver isn't upstream yet, so you may need to enable it in the defconfig, located in ~/trunk/src/third_party/chromiumos-overlay/eclass/cros-kernel/ so that the driver is actually built. After that, use 'cros flash' to flash the new kernel image to your USB stick and boot from USB with 'ctrl+u' and you should be on your way to chromeos kernel testing.

Quoted 1 line

[1] https://chromium.googlesource.com/chromiumos/docs/+/master/developer_guide.md

Hey, thanks for info! I'll see if I can get my hands on one.

/Jarkko