Skip to contentSkip to conversation

x86: coral: Add support for Cr50

PATCH Superseded Simon Glass 3 participants 11 messages Nov 2, 2019 – Nov 4, 2019

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover x86: coral: Add support for Cr50

This series adds a driver for the Cr50 security chip and enables it on coral. This supports the 'tpm' command.

This series is built on the pending 'apollolake' series.

Simon Glass (7):
coral: Update i2c and rtc status
tpm: Add more TPM2 definitions
tpm: Add a driver for H1/Cr50
pci: i2c: designware: Add compatible string
coral: Add I2C and TPM device-tree definitions
i2c: designware: Drop invalid debugging
x86: coral: Enable TPM

 arch/x86/dts/chromebook_coral.dts     |  25 ++
 configs/chromebook_coral_defconfig    |   5 +-
 doc/board/google/chromebook_coral.rst |   2 -
 drivers/i2c/designware_i2c.c          |   1 -
 drivers/i2c/dw_i2c_pci.c              |   6 +
 drivers/tpm/Kconfig                   |  10 +
 drivers/tpm/Makefile                  |   1 +
 drivers/tpm/cr50_i2c.c                | 568 ++++++++++++++++++++++++++
 include/tpm-v2.h                      |  31 ++
 9 files changed, 643 insertions(+), 6 deletions(-)
 create mode 100644 drivers/tpm/cr50_i2c.c
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
#1 lore raw

PATCH 1/7 coral: Update i2c and rtc status

These are actually working correctly, so update the status.

---

 doc/board/google/chromebook_coral.rst | 2 --
 1 file changed, 2 deletions(-)
doc/board/google/chromebook_coral.rst +0 -2
index c583ac2b27..b010cc1ded 100644
@@ -208,9 +208,7 @@ To do
    - left-side USB
    - USB-C
    - Cr50 (security chip: a basic driver is running but not included here)
-   - I2C (driver exists but not enabled in device tree)
    - Sound (Intel I2S support exists, but need da7219 driver)
-   - RTC (driver exists but not enabled in device tree)
    - Various minor features supported by LPC, etc.
 - Booting Chrome OS, e.g. with verified boot
 - Integrate with Chrome OS vboot
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
#2 lore raw

PATCH 2/7 tpm: Add more TPM2 definitions

In reply to Simon Glass

Add definitions for access and status.

Need to drop the mixed case.

---

 include/tpm-v2.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
include/tpm-v2.h +31 -0
index ae00803f6d..d53d2e4023 100644
@@ -161,6 +161,37 @@ enum tpm_index_attrs {
 					TPMA_NV_AUTHWRITE | TPMA_NV_POLICYWRITE,
 };
 
+enum {
+	TPM_ACCESS_VALID		= 1 << 7,
+	TPM_ACCESS_ACTIVE_LOCALITY	= 1 << 5,
+	TPM_ACCESS_REQUEST_PENDING	= 1 << 2,
+	TPM_ACCESS_REQUEST_USE		= 1 << 1,
+	TPM_ACCESS_ESTABLISHMENT	= 1 << 0,
+};
+
+enum {
+	TPM_STS_FAMILY_SHIFT		= 26,
+	TPM_STS_FAMILY_MASK		= 0x3 << TPM_STS_FAMILY_SHIFT,
+	TPM_STS_FAMILY_TPM2		= 1 << TPM_STS_FAMILY_SHIFT,
+	TPM_STS_RESE_TESTABLISMENT_BIT	= 1 << 25,
+	TPM_STS_COMMAND_CANCEL		= 1 << 24,
+	TPM_STS_BURST_COUNT_SHIFT	= 8,
+	TPM_STS_BURST_COUNT_MASK	= 0xffff << TPM_STS_BURST_COUNT_SHIFT,
+	TPM_STS_VALID			= 1 << 7,
+	TPM_STS_COMMAND_READY		= 1 << 6,
+	TPM_STS_GO			= 1 << 5,
+	TPM_STS_DATA_AVAIL		= 1 << 4,
+	TPM_STS_DATA_EXPECT		= 1 << 3,
+	TPM_STS_SELF_TEST_DONE		= 1 << 2,
+	TPM_STS_RESPONSE_RETRY		= 1 << 1,
+};
+
+enum {
+	TPM_CMD_COUNT_OFFSET	= 2,
+	TPM_CMD_ORDINAL_OFFSET	= 6,
+	TPM_MAX_BUF_SIZE	= 1260,
+};
+
 /**
  * Issue a TPM2_Startup command.
  *
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
#3 lore raw

PATCH 3/7 tpm: Add a driver for H1/Cr50

In reply to Simon Glass

H1 is a Google security chip present in recent Chromebooks, Pixel phones and other devices. Cr50 is the name of the software that runs on H1 in Chromebooks.

This chip is used to handle TPM-like functionality and also has quite a few additional features.

Add a driver for this.

---

 drivers/tpm/Kconfig    |  10 +
 drivers/tpm/Makefile   |   1 +
 drivers/tpm/cr50_i2c.c | 568 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 579 insertions(+)
 create mode 100644 drivers/tpm/cr50_i2c.c
drivers/tpm/Kconfig +10 -0
index 94629dffd2..00d7dc8e48 100644
@@ -127,6 +127,16 @@ config TPM_V2
 
 if TPM_V2
 
+config TPM2_CR50_I2C
+	bool "Enable support for Google cr50 TPM"
+	depends on DM_I2C
+	help
+	  Cr50 is an implementation of a TPM on Google's H1 security chip.
+	  This uses the same open-source firmware as the Chromium OS EC.
+	  While Cr50 has other features, its primary role is as the root of
+	  trust for a devuce, It operates like a TPM and can be used with
+	  verified boot. Cr50 is used on recent Chromebooks (since 2017).
+
 config TPM2_TIS_SANDBOX
 	bool "Enable sandbox TPMv2.x driver"
 	depends on TPM_V2 && SANDBOX
drivers/tpm/Makefile +1 -0
index 94c337b8ed..4c866b37c5 100644
@@ -10,5 +10,6 @@ obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
 obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o
 obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o
 
+obj-$(CONFIG_TPM2_CR50_I2C) += cr50_i2c.o
 obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o
 obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.o
drivers/tpm/cr50_i2c.c new file +568 -0

568 lines not on this page · raw message

Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
#4 lore raw

PATCH 3/7 tpm: Add a driver for H1/Cr50

Quoted 31 lines · Simon Glass

H1 is a Google security chip present in recent Chromebooks, Pixel phones and other devices. Cr50 is the name of the software that runs on H1 in Chromebooks.

This chip is used to handle TPM-like functionality and also has quite a few additional features.

Add a driver for this.

drivers/tpm/cr50_i2c.c new file +20 -0
+/* Wait for interrupt to indicate TPM is ready */
+static int cr50_i2c_wait_tpm_ready(struct udevice *dev)
+{
+       struct cr50_priv *priv = dev_get_priv(dev);
+       ulong timeout;
+       int i;
+
+       if (!dm_gpio_is_valid(&priv->ready_gpio)) {
+               /* Fixed delay if interrupt not supported */
+               udelay(TIMEOUT_NO_IRQ_US);
+               return 0;
+       }
+
+       timeout = timer_get_us() + TIMEOUT_IRQ_US;
+
+       i = 0;
+       while (!dm_gpio_get_value(&priv->ready_gpio)) {
+               i++;
+               if (timer_get_us() > timeout) {
+                       printf("Timeout\n");

drivers/tpm/cr50_i2c.c line 67

Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +10 -0
+                       /*
+                        * Use this instead of -ETIMEDOUT which is used by i2c
+                        */
+                       return -ETIME;
+               }
+       }
+
+       return 0;
+}
+

Timeout loops look more naturally if they are done as do {} while. See:

  i = 0;
  do {
    if (dm_gpio_get_value(&priv->ready_gpio))
      return 0;
    i++; /* What is this for? */

} while (timeout >= timer_get_us());

                    printf("Timeout\n");
                    /*
                     * Use this instead of -ETIMEDOUT which is used by i2c
                     */
                    return -ETIME;

}

drivers/tpm/cr50_i2c.c line 135

Quoted 5 lines
drivers/tpm/cr50_i2c.c new file +4 -0
+static int cr50_i2c_write(struct udevice *dev, u8 addr, const u8 *buffer,
+                         size_t len)
+{
 
+       u8 buf[len + 1];

VLA?!

Quoted 11 lines
drivers/tpm/cr50_i2c.c new file +9 -0
+       int ret;
+
+       if (len > CR50_MAX_BUF_SIZE) {
+               log_err("Length %zd is too large\n", len);
+               return -E2BIG;
+       }
 
+}
 
+static int request_locality(struct udevice *dev, int loc)
+{

drivers/tpm/cr50_i2c.c line 231

Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +9 -0
+       struct cr50_priv *priv = dev_get_priv(dev);
+       u8 buf = TPM_ACCESS_REQUEST_USE;
+       ulong timeout;
+       int ret;
+
+       ret = check_locality(dev, loc);
+       if (ret < 0)
+               return ret;
 
+       else if (ret == loc)

Here 'else' is redundant.

drivers/tpm/cr50_i2c.c line 239

Quoted 5 lines
drivers/tpm/cr50_i2c.c new file +3 -0
+               return loc;
 
 
+       timeout = timer_get_us() + TIMEOUT_LONG_US;
+       while (timer_get_us() < timeout) {

Same comment for timeout loops (btw, there is a chance in a while {} loop that it won't do even first iteretation).

Quoted 7 lines
drivers/tpm/cr50_i2c.c new file +7 -0
+               ret = check_locality(dev, loc);
+               if (ret < 0)
+                       return ret;
+               if (ret == loc) {
+                       priv->locality = loc;
+                       log_debug("Set locality to %x\n", loc);
+                       return loc;

drivers/tpm/cr50_i2c.c line 293

Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +9 -0
+               }
+               udelay(TIMEOUT_SHORT_US);
+       }
+       printf("Request locality failed\n");
+
+       return -ETIMEDOUT;
+}
 
+       timeout = timer_get_us() + TIMEOUT_LONG_US;
+       while (timer_get_us() < timeout) {

Ditto for all timeout loop related comments.

Quoted 12 lines
drivers/tpm/cr50_i2c.c new file +11 -0
+               if (cr50_i2c_read(dev, tpm_sts(priv->locality),
+                                 (u8 *)&buf, sizeof(buf)) < 0) {
+                       udelay(TIMEOUT_SHORT_US);
+                       continue;
+               }
 
+       timeout = timer_get_us() + TIMEOUT_LONG_US;
+       do {
+               ret = cr50_i2c_status(dev);
+               if (ret)
+                       goto out_err;
+               if (!(ret & TPM_STS_COMMAND_READY))

drivers/tpm/cr50_i2c.c line 411

Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +9 -0
+                       break;
+
+               if (timer_get_us() > timeout)
+                       goto out_err;
+
+               ret = cr50_i2c_ready(dev);
+               if (ret)
+                       goto out_err;
 
+       } while (1);

Better to have non-infinite loops (i.o.w. loops with understandable exit conditional).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

PATCH 4/7 pci: i2c: designware: Add compatible string

In reply to Simon Glass

Add a compatible string for this driver so that it can have children.

---

 drivers/i2c/dw_i2c_pci.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/i2c/dw_i2c_pci.c +6 -0
index 34cdc7bf59..193ad5225f 100644
@@ -64,9 +64,15 @@ static int designware_i2c_pci_bind(struct udevice *dev)
 	return 0;
 }
 
+static const struct udevice_id designware_i2c_pci_ids[] = {
+	{ .compatible = "snps,designware-i2c-pci" },
+	{ }
+};
+
 U_BOOT_DRIVER(i2c_designware_pci) = {
 	.name	= "i2c_designware_pci",
 	.id	= UCLASS_I2C,
+	.of_match = designware_i2c_pci_ids,
 	.bind	= designware_i2c_pci_bind,
 	.probe	= designware_i2c_pci_probe,
 	.priv_auto_alloc_size = sizeof(struct dw_i2c),
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
#6 lore raw

PATCH 4/7 pci: i2c: designware: Add compatible string

Hello Simon,

Am 02.11.2019 um 14:59 schrieb Simon Glass:

Quoted 7 lines

Add a compatible string for this driver so that it can have children.

---

  drivers/i2c/dw_i2c_pci.c | 6 ++++++
  1 file changed, 6 insertions(+)

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#7 lore raw

PATCH 5/7 coral: Add I2C and TPM device-tree definitions

In reply to Simon Glass

Add a node to the device tree for Cr50. We want this to be on i2c port 2 so add 0 and 1 as well to make this work.

---

 arch/x86/dts/chromebook_coral.dts | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/x86/dts/chromebook_coral.dts +25 -0
index 79b3e60db4..1e6e0e182f 100644
@@ -28,6 +28,9 @@
 		cros-ec0 = &cros_ec;
 		fsp = &fsp_s;
 		spi0 = &spi;
+		i2c0 = &i2c_0;
+		i2c1 = &i2c_1;
+		i2c2 = &i2c_2;
 	};
 
 	config {
@@ -213,6 +216,28 @@
 			};
 		};
 
+		i2c_0: i2c2 at 16,0 {
+			compatible = "snps,designware-i2c-pci";
+			reg = <0x0200b010 0 0 0 0>;
+		};
+
+		i2c_1: i2c2 at 16,1 {
+			compatible = "snps,designware-i2c-pci";
+			reg = <0x0200b110 0 0 0 0>;
+		};
+
+		i2c_2: i2c2 at 16,2 {
+			compatible = "snps,designware-i2c-pci";
+			reg = <0x0200b210 0 0 0 0>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			tpm at 50 {
+				reg = <0x50>;
+				compatible = "google,cr50";
+				u-boot,i2c-offset-len = <0>;
+			};
+		};
+
 		serial: serial at 18,2 {
 			reg = <0x0200c210 0 0 0 0>;
 			u-boot,dm-pre-reloc;
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
#8 lore raw

PATCH 6/7 i2c: designware: Drop invalid debugging

In reply to Simon Glass

This printf() should not be there.

---

 drivers/i2c/designware_i2c.c | 1 -
 1 file changed, 1 deletion(-)
drivers/i2c/designware_i2c.c +0 -1
index 54e4a70c74..b12ad02a43 100644
@@ -540,7 +540,6 @@ static int designware_i2c_ofdata_to_platdata(struct udevice *bus)
 {
 	struct dw_i2c *priv = dev_get_priv(bus);
 
-	printf("bad\n");
 	priv->regs = (struct i2c_regs *)devfdt_get_addr_ptr(bus);
 
 	return 0;
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
#9 lore raw

PATCH 6/7 i2c: designware: Drop invalid debugging

Hello Simon,

Am 02.11.2019 um 14:59 schrieb Simon Glass:

Quoted 7 lines

This printf() should not be there.

---

  drivers/i2c/designware_i2c.c | 1 -
  1 file changed, 1 deletion(-)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#10 lore raw

PATCH 7/7 x86: coral: Enable TPM

In reply to Simon Glass

Enable TPM2 so that we can use cr50.

---

 configs/chromebook_coral_defconfig | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
configs/chromebook_coral_defconfig +2 -3
index 6b586ef3c7..43fb94458b 100644
@@ -53,7 +53,6 @@ CONFIG_CMD_TIME=y
 CONFIG_CMD_SOUND=y
 CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_TPM=y
-CONFIG_CMD_TPM_TEST=y
 CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
@@ -76,7 +75,6 @@ CONFIG_SYS_I2C_DW=y
 CONFIG_TPL_MISC=y
 CONFIG_CROS_EC=y
 CONFIG_CROS_EC_LPC=y
-CONFIG_SPI_FLASH_INTEL_FAST=y
 CONFIG_SPI_FLASH_WINBOND=y
 # CONFIG_X86_PCH7 is not set
 # CONFIG_X86_PCH9 is not set
@@ -89,7 +87,8 @@ CONFIG_SPI=y
 CONFIG_ICH_SPI=y
 CONFIG_TPL_SYSRESET=y
 CONFIG_X86_TSC_ZERO_BASE=y
-CONFIG_TPM_TIS_LPC=y
+# CONFIG_TPM_V1 is not set
+CONFIG_TPM2_CR50_I2C=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_STORAGE=y
 CONFIG_USB_KEYBOARD=y
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog