Skip to contentSkip to conversation

tpm: Add wolfTPM library support for TPM 2.0 00/12] *** SUBJECT HERE ***

PATCH Superseded David Garske 2 participants 16 messages Mar 16 – May 8

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 00/12] *** SUBJECT HERE ***

*** BLURB HERE ***

Aidan (12):
tpm: export tpm_show_device, tpm_set_device, and get_tpm
include: add byteorder macro guards and SHA384 hash wrapper
spi: add BCM2835/BCM2711 hardware SPI controller driver
dts: add TPM device tree nodes for RPi4, QEMU, and sandbox
tpm: add wolfTPM library as git submodule
tpm: add wolfTPM headers and SHA384 glue code
tpm: add wolfTPM driver helpers and Kconfig options
cmd: refactor tpm2 command into frontend/backend architecture
tpm: add sandbox TPM SPI emulator
test: add wolfTPM C unit tests and Python integration tests
doc: add wolfTPM documentation
configs: enable wolfTPM in rpi_4_defconfig

 .gitmodules                              |    3 +
 README                                   |    3 +
 README.wolftpm.md                        |  154 +++
 arch/arm/dts/bcm2711-rpi-4-b-u-boot.dtsi |   54 +
 arch/arm/dts/bcm2711-rpi-4-b.dts         |   20 +
 arch/arm/dts/qemu-arm64.dts              |    4 +
 arch/sandbox/dts/sandbox.dtsi            |   11 +
 cmd/Kconfig                              |   11 +
 cmd/Makefile                             |   10 +-
 cmd/native_tpm2.c                        |  516 ++++++++++
 cmd/tpm-common.c                         |    4 +-
 cmd/tpm-v2.c                             |  559 ++---------
 cmd/tpm2-backend.h                       |   66 ++
 cmd/wolftpm.c                            | 1170 ++++++++++++++++++++++
 configs/rpi_4_defconfig                  |   29 +-
 doc/usage/cmd/wolftpm.rst                |  635 ++++++++++++
 drivers/mtd/spi/sandbox.c                |   30 +-
 drivers/spi/Kconfig                      |    9 +
 drivers/spi/Makefile                     |    1 +
 drivers/spi/bcm2835_spi.c                |  431 ++++++++
 drivers/tpm/Kconfig                      |   44 +
 drivers/tpm/Makefile                     |    9 +
 drivers/tpm/tpm_spi_sandbox.c            |  410 ++++++++
 drivers/tpm/wolftpm_common.c             |  137 +++
 include/configs/user_settings.h          |  118 +++
 include/hash.h                           |   18 +
 include/linux/byteorder/generic.h        |   31 +-
 include/tpm-common.h                     |   22 +
 include/wolftpm.h                        |   34 +
 lib/Kconfig                              |   13 +
 lib/Makefile                             |   18 +
 lib/wolftpm                              |    1 +
 lib/wolftpm.c                            |   56 ++
 test/cmd/Makefile                        |    1 +
 test/cmd/wolftpm.c                       |  364 +++++++
 test/py/tests/test_wolftpm.py            |  375 +++++++
 36 files changed, 4861 insertions(+), 510 deletions(-)
 create mode 100644 .gitmodules
 create mode 100644 README.wolftpm.md
 create mode 100644 arch/arm/dts/bcm2711-rpi-4-b-u-boot.dtsi
 create mode 100644 cmd/native_tpm2.c
 create mode 100644 cmd/tpm2-backend.h
 create mode 100644 cmd/wolftpm.c
 create mode 100644 doc/usage/cmd/wolftpm.rst
 create mode 100644 drivers/spi/bcm2835_spi.c
 create mode 100644 drivers/tpm/tpm_spi_sandbox.c
 create mode 100644 drivers/tpm/wolftpm_common.c
 create mode 100644 include/configs/user_settings.h
 create mode 100644 include/wolftpm.h
 create mode 160000 lib/wolftpm
 create mode 100644 lib/wolftpm.c
 create mode 100644 test/cmd/wolftpm.c
 create mode 100644 test/py/tests/test_wolftpm.py
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 01/12] tpm: export tpm_show_device, tpm_set_device, and get_tpm

From: Aidan <[email protected]>

Remove static scope from tpm_show_device(), tpm_set_device(), and get_tpm() in cmd/tpm-common.c so they can be called from other translation units. Add corresponding declarations to include/tpm-common.h.

wolfTPM's command backend needs these functions for device enumeration and selection when operating through U-Boot's driver model.

---
 cmd/tpm-common.c     |  4 ++--
 include/tpm-common.h | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
cmd/tpm-common.c +2 -2
index 1cd57f901b6..30e99e10758 100644
@@ -234,7 +234,7 @@ int type_string_write_vars(const char *type_str, u8 *data,
 	return 0;
 }
 
-static int tpm_show_device(void)
+int tpm_show_device(void)
 {
 	struct udevice *dev;
 	char buf[80];
@@ -253,7 +253,7 @@ static int tpm_show_device(void)
 	return 0;
 }
 
-static int tpm_set_device(unsigned long num)
+int tpm_set_device(unsigned long num)
 {
 	struct udevice *dev;
 	unsigned long n = 0;
include/tpm-common.h +22 -0
index bfb84a931d1..1ea4463fbbe 100644
@@ -337,4 +337,26 @@ enum tpm_version tpm_get_version(struct udevice *dev);
 /* Iterate on all TPM devices */
 #define for_each_tpm_device(dev) uclass_foreach_dev_probe(UCLASS_TPM, (dev))
 
+/**
+ * tpm_show_device() - Show all TPM devices
+ *
+ * Return: 0 on success, -ve on failure
+ */
+int tpm_show_device(void);
+
+/**
+ * tpm_set_device() - Set the TPM device to use
+ *
+ * @num: The number of the TPM device to use
+ * Return: 0 on success, -ve on failure
+ */
+int tpm_set_device(unsigned long num);
+
+/**
+ * get_tpm() - Get the TPM device
+ *
+ * Return: 0 on success, -ve on failure
+ */
+int get_tpm(struct udevice **devp);
+
 #endif /* __TPM_COMMON_H */
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 02/12] include: add byteorder macro guards and SHA384 hash wrapper

In reply to David Garske

From: Aidan <[email protected]>

Add #ifndef guards around cpu_to_beXX / beXX_to_cpu macro definitions in include/linux/byteorder/generic.h. wolfTPM, wolfCrypt, and U-Boot all define these macros; the guards prevent redefinition warnings when wolfTPM headers are included alongside U-Boot headers.

Add #include <linux/types.h> to include/hash.h so that basic types (u8, u32, etc.) are available to all includers.

Add a wc_Sha384Hash() wrapper declaration in include/hash.h, gated by WOLFTPM2_NO_WOLFCRYPT. When wolfTPM is built without wolfCrypt, this wrapper provides SHA-384 hashing via U-Boot's hash subsystem, which is needed for Infineon TPM firmware update manifest validation.

---
 include/hash.h                    | 18 ++++++++++++++++++
 include/linux/byteorder/generic.h | 31 +++++++++++++++++++++++++------
 2 files changed, 43 insertions(+), 6 deletions(-)
include/hash.h +18 -0
index 8b3f79ec473..26043c43a9c 100644
@@ -6,6 +6,8 @@
 #ifndef _HASH_H
 #define _HASH_H
 
+#include <linux/types.h>
+
 #ifdef USE_HOSTCC
 #include <linux/kconfig.h>
 #endif
@@ -163,4 +165,20 @@ int hash_progressive_lookup_algo(const char *algo_name,
  */
 int hash_parse_string(const char *algo_name, const char *str, uint8_t *result);
 
+#ifdef WOLFTPM2_NO_WOLFCRYPT
+/**
+ * wc_Sha384Hash() - Calculate SHA384 hash
+ * @data:	Data to hash
+ * @len:	Length of data
+ * @hash:	Output buffer for hash
+ *
+ * This is a wrapper function to provide wolfCrypt-compatible SHA384 hashing
+ * when wolfCrypt is not available.
+ *
+ * Return: 0 on success, -1 on error
+ */
+int wc_Sha384Hash(const unsigned char *data, unsigned int len,
+		  unsigned char *hash);
+#endif /* WOLFTPM2_NO_WOLFCRYPT */
+
 #endif
include/linux/byteorder/generic.h +25 -6
index bee0ff60336..def601eed2b 100644
@@ -89,12 +89,6 @@
 #define le32_to_cpu __le32_to_cpu
 #define cpu_to_le16 __cpu_to_le16
 #define le16_to_cpu __le16_to_cpu
-#define cpu_to_be64 __cpu_to_be64
-#define be64_to_cpu __be64_to_cpu
-#define cpu_to_be32 __cpu_to_be32
-#define be32_to_cpu __be32_to_cpu
-#define cpu_to_be16 __cpu_to_be16
-#define be16_to_cpu __be16_to_cpu
 #define cpu_to_le64p __cpu_to_le64p
 #define le64_to_cpup __le64_to_cpup
 #define cpu_to_le32p __cpu_to_le32p
@@ -120,6 +114,31 @@
 #define cpu_to_be16s __cpu_to_be16s
 #define be16_to_cpus __be16_to_cpus
 
+/*
+ * Check if byte-order functions are already defined by the system:
+ * wolfTPM, wolfCrypt, and U-boot all define these functions, so
+ * we need to check if they are already defined before defining
+ * them again.
+ */
+#ifndef cpu_to_be16
+#define cpu_to_be16 __cpu_to_be16
+#endif
+#ifndef cpu_to_be32
+#define cpu_to_be32 __cpu_to_be32
+#endif
+#ifndef cpu_to_be64
+#define cpu_to_be64 __cpu_to_be64
+#endif
+#ifndef be16_to_cpu
+#define be16_to_cpu __be16_to_cpu
+#endif
+#ifndef be32_to_cpu
+#define be32_to_cpu __be32_to_cpu
+#endif
+#ifndef be64_to_cpu
+#define be64_to_cpu __be64_to_cpu
+#endif
+
 /*
  * They have to be macros in order to do the constant folding
  * correctly - if the argument passed into a inline function
Signature · 1 line
2.43.0
#3 lore raw

Re: [[PATCH v2] tpm: Add wolfTPM library support for TPM 2.0 02/12] include: add byteorder macro guards and SHA384 hash wrapper

Quoted 1 line

+ */

[...]

Quoted 10 lines
include/hash.h +4 -0
+int wc_Sha384Hash(const unsigned char *data, unsigned int len,
+		  unsigned char *hash);
+#endif /* WOLFTPM2_NO_WOLFCRYPT */
+
 #endif
include/linux/byteorder/generic.h +0 -0
index bee0ff60336..def601eed2b 100644

include/linux/byteorder/generic.h line 97

Quoted 9 lines
include/linux/byteorder/generic.h +0 -6
@@ -89,12 +89,6 @@
 #define le32_to_cpu __le32_to_cpu
 #define cpu_to_le16 __cpu_to_le16
 #define le16_to_cpu __le16_to_cpu
-#define cpu_to_be64 __cpu_to_be64
-#define be64_to_cpu __be64_to_cpu
-#define cpu_to_be32 __cpu_to_be32
-#define be32_to_cpu __be32_to_cpu
-#define cpu_to_be16 __cpu_to_be16
-#define be16_to_cpu __be16_to_cpu

I'd prefer leaving this as is and add any required ifndefs to the wolfTPM part

Cheers
/Ilias

Quoted 35 lines
include/linux/byteorder/generic.h +25 -0
 #define cpu_to_le64p __cpu_to_le64p
 #define le64_to_cpup __le64_to_cpup
 #define cpu_to_le32p __cpu_to_le32p
@@ -120,6 +114,31 @@
 #define cpu_to_be16s __cpu_to_be16s
 #define be16_to_cpus __be16_to_cpus
 
+/*
+ * Check if byte-order functions are already defined by the system:
+ * wolfTPM, wolfCrypt, and U-boot all define these functions, so
+ * we need to check if they are already defined before defining
+ * them again.
+ */
+#ifndef cpu_to_be16
+#define cpu_to_be16 __cpu_to_be16
+#endif
+#ifndef cpu_to_be32
+#define cpu_to_be32 __cpu_to_be32
+#endif
+#ifndef cpu_to_be64
+#define cpu_to_be64 __cpu_to_be64
+#endif
+#ifndef be16_to_cpu
+#define be16_to_cpu __be16_to_cpu
+#endif
+#ifndef be32_to_cpu
+#define be32_to_cpu __be32_to_cpu
+#endif
+#ifndef be64_to_cpu
+#define be64_to_cpu __be64_to_cpu
+#endif
+
 /*
  * They have to be macros in order to do the constant folding
  * correctly - if the argument passed into a inline function
#4 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 03/12] spi: add BCM2835/BCM2711 hardware SPI controller driver

In reply to David Garske

From: Aidan <[email protected]>

Add a hardware SPI controller driver for the BCM2835/BCM2711 SoC found on Raspberry Pi 3 and Pi 4 boards.

The driver implements:
- Register-based SPI transfers using the BCM2835 SPI0 peripheral
- Software GPIO chip-select control (matching the Linux driver approach) rather than hardware CS, which avoids issues with automatic CS deassertion during multi-byte TPM TIS transactions
- Clock divider calculation for configurable SPI speed
- SPI mode 0/1/2/3 support via CPOL/CPHA configuration
- GPIO pin setup for SPI0 (MISO/MOSI/SCLK as ALT0, CE0/CE1 as output for software CS)
- TPM reset via GPIO4/GPIO24 during probe

This driver is needed for wolfTPM to communicate with SPI-attached TPM chips (e.g., Infineon SLB9670/9672) on Raspberry Pi hardware.

---
 drivers/spi/Kconfig       |   9 +
 drivers/spi/Makefile      |   1 +
 drivers/spi/bcm2835_spi.c | 431 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 441 insertions(+)
 create mode 100644 drivers/spi/bcm2835_spi.c
drivers/spi/Kconfig +9 -0
index 8c6c095a8cf..9625b1e073e 100644
@@ -117,6 +117,15 @@ config ATMEL_SPI
 	  many AT91 (ARM) chips. This driver can be used to access
 	  the SPI Flash, such as AT25DF321.
 
+config BCM2835_SPI
+	bool "BCM2835/BCM2711 SPI driver"
+	depends on ARCH_BCM283X
+	help
+	  Enable the BCM2835/BCM2711 SPI controller driver. This driver
+	  can be used to access SPI devices on Raspberry Pi boards
+	  including Pi 3 and Pi 4. It uses the hardware SPI controller
+	  rather than GPIO bit-banging.
+
 config BCM63XX_HSSPI
 	bool "BCM63XX HSSPI driver"
 	depends on (ARCH_BMIPS || ARCH_BCMBCA)
drivers/spi/Makefile +1 -0
index 0dc2d23e172..47a1c6194b1 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_APPLE_SPI) += apple_spi.o
 obj-$(CONFIG_ATH79_SPI) += ath79_spi.o
 obj-$(CONFIG_ATMEL_QSPI) += atmel-quadspi.o
 obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
+obj-$(CONFIG_BCM2835_SPI) += bcm2835_spi.o
 obj-$(CONFIG_BCM63XX_HSSPI) += bcm63xx_hsspi.o
 obj-$(CONFIG_BCMBCA_HSSPI) += bcmbca_hsspi.o
 obj-$(CONFIG_BCM63XX_SPI) += bcm63xx_spi.o
drivers/spi/bcm2835_spi.c new file +431 -0

431 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 04/12] dts: add TPM device tree nodes for RPi4, QEMU, and sandbox

In reply to David Garske

From: Aidan <[email protected]>

Add device tree entries for TPM devices across three platforms:

bcm2711-rpi-4-b.dts:
Add SPI0 node with Infineon SLB9670/9672 TPM on CE1 (GPIO7), matching the standard Linux tpm-slb9670 overlay. Add spi0 alias so wolfTPM finds the bus at index 0.

bcm2711-rpi-4-b-u-boot.dtsi (new file):
Add soft-SPI (GPIO bit-bang) fallback node for TPM communication. This uses spi-gpio with GPIO11/10/9/7 and provides an alternative to the hardware SPI driver when pinctrl naming differs between U-Boot and Linux device trees.

qemu-arm64.dts:
Add MMIO-based TPM TIS node at 0x0c000000 for QEMU virt machine with swtpm. This allows wolfTPM testing via QEMU without hardware.

sandbox.dtsi:
Add sandbox TPM SPI device (sandbox,tpm-spi) on SPI bus CS1 with a phandle reference to a sandbox TPM SPI emulator node. This enables wolfTPM SPI HAL testing in the sandbox environment.

---
 arch/arm/dts/bcm2711-rpi-4-b-u-boot.dtsi | 54 ++++++++++++++++++++++++
 arch/arm/dts/bcm2711-rpi-4-b.dts         | 20 +++++++++
 arch/arm/dts/qemu-arm64.dts              |  4 ++
 arch/sandbox/dts/sandbox.dtsi            | 11 +++++
 4 files changed, 89 insertions(+)
 create mode 100644 arch/arm/dts/bcm2711-rpi-4-b-u-boot.dtsi
arch/arm/dts/bcm2711-rpi-4-b-u-boot.dtsi new file +54 -0
new file mode 100644
index 00000000000..c38276abee9
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * U-Boot specific additions for Raspberry Pi 4 Model B
+ *
+ * Adds soft SPI support for Infineon SLB9670/9672 TPM HAT
+ * connected to SPI0 CE1 (GPIO 7)
+ *
+ * Uses GPIO bit-banging instead of hardware SPI to avoid
+ * GPIO chip naming issues (pinctrl-bcm2835 vs pinctrl-bcm2711)
+ */
+
+#include "bcm283x-u-boot.dtsi"
+#include <dt-bindings/gpio/gpio.h>
+
+/ {
+	aliases {
+		spi0 = &soft_spi;
+	};
+
+	soft_spi: soft-spi {
+		compatible = "spi-gpio";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		status = "okay";
+		bootph-all;
+
+		/*
+		 * GPIO pins for SPI0 on Raspberry Pi 4:
+		 * GPIO 11 = SCLK
+		 * GPIO 10 = MOSI
+		 * GPIO 9  = MISO
+		 * GPIO 7  = CE1 (chip select for TPM)
+		 */
+		gpio-sck = <&gpio 11 GPIO_ACTIVE_HIGH>;
+		gpio-mosi = <&gpio 10 GPIO_ACTIVE_HIGH>;
+		gpio-miso = <&gpio 9 GPIO_ACTIVE_HIGH>;
+		cs-gpios = <&gpio 7 GPIO_ACTIVE_LOW>;
+		num-chipselects = <1>;
+		spi-delay-us = <1>;
+
+		/* Infineon SLB9672 TPM on CS1 */
+		tpm@0 {
+			compatible = "infineon,slb9672", "tcg,tpm-tis-spi";
+			reg = <0>;
+			spi-max-frequency = <10000000>;
+			status = "okay";
+			bootph-all;
+		};
+	};
+};
+
+&gpio {
+	bootph-all;
+};
arch/arm/dts/bcm2711-rpi-4-b.dts +20 -0
index 72ce80fbf26..a09276dc279 100644
@@ -8,6 +8,11 @@
 	compatible = "raspberrypi,4-model-b", "brcm,bcm2711";
 	model = "Raspberry Pi 4 Model B";
 
+	/* Alias hardware SPI as spi0 so wolfTPM finds it at bus 0 */
+	aliases {
+		spi0 = &spi;
+	};
+
 	chosen {
 		/* 8250 auxiliary UART instead of pl011 */
 		stdout-path = "serial1:115200n8";
@@ -54,6 +59,21 @@
 		enable-active-high;
 		gpio = <&expgpio 6 GPIO_ACTIVE_HIGH>;
 	};
+
+};
+
+/* Hardware SPI with TPM - matches Linux tpm-slb9670 overlay */
+&spi {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&spi0_gpio7>;
+
+	/* Infineon SLB9670/9672 TPM 2.0 on CE1 (GPIO7) */
+	tpm@1 {
+		compatible = "infineon,slb9670", "tcg,tpm_tis-spi";
+		reg = <1>;  /* CE1 */
+		spi-max-frequency = <32000000>;
+	};
 };
 
 &ddc0 {
arch/arm/dts/qemu-arm64.dts +4 -0
index 95fcf53ed74..e74d036a532 100644
@@ -12,4 +12,8 @@
 #endif
 
 / {
+	tpm@0c000000 {
+		compatible = "tcg,tpm-tis-mmio";
+		reg = <0x0 0x0c000000 0x0 0x5000>;
+	};
 };
arch/sandbox/dts/sandbox.dtsi +11 -0
index 02b03894eaf..2fdd7f0e942 100644
@@ -286,6 +286,17 @@
 			spi-max-frequency = <40000000>;
 			sandbox,filename = "spi.bin";
 		};
+
+		tpm_spi: tpm@1 {
+			reg = <1>;
+			compatible = "sandbox,tpm-spi";
+			spi-max-frequency = <10000000>;
+			sandbox,emul = <&tpm_spi_emul>;
+		};
+	};
+
+	tpm_spi_emul: tpm-spi-emul {
+		compatible = "sandbox,tpm-spi-emul";
 	};
 
 	spl-test {
Signature · 1 line
2.43.0
#6 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 05/12] tpm: add wolfTPM library as git submodule

In reply to David Garske

From: Aidan <[email protected]>

Add wolfTPM (https://github.com/wolfSSL/wolfTPM) as a git submodule at lib/wolftpm. wolfTPM is a portable, open-source TPM 2.0 stack licensed under GPLv2, providing native API access to all TPM 2.0 commands and a wrapper API for common operations.

The build system additions:

.gitmodules:
Registers the wolfTPM submodule pointing to the upstream repo.

lib/Kconfig:
Adds CONFIG_TPM_WOLF option under library routines, which selects SHA1 and implies DM_RNG.

lib/Makefile:
When CONFIG_TPM_WOLF and CONFIG_TPM_V2 are both enabled, compiles wolfTPM core source files (tpm2.c, tpm2_packet.c, tpm2_tis.c, tpm2_wrap.c, tpm2_param_enc.c) and the HAL layer (tpm_io.c). Sets -I include paths and -DWOLFTPM_USER_SETTINGS.

---
 .gitmodules  |  3 +++
 lib/Kconfig  | 13 +++++++++++++
 lib/Makefile | 18 ++++++++++++++++++
 lib/wolftpm  |  1 +
 4 files changed, 35 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 lib/wolftpm
.gitmodules new file +3 -0
new file mode 100644
index 00000000000..3f95a7c3eb9
@@ -0,0 +1,3 @@
+[submodule "lib/wolftpm"]
+	path = lib/wolftpm
+	url = https://github.com/wolfssl/wolfTPM.git
lib/Kconfig +13 -0
index 931d5206936..24477ea53c9 100644
@@ -500,6 +500,19 @@ config TPM
 	  If you want a fully functional TPM enable all hashing algorithms.
 	  If you enabled measured boot all hashing algorithms are selected.
 
+config TPM_WOLF
+    bool "Enable wolfTPM support"
+	depends on DM
+	imply DM_RNG
+	select SHA1
+    help
+        This option enables support for wolfTPM in U-Boot. WolfTPM can be
+		used to update ARM specific platforms. Enabling this option allows
+		U-Boot to interact with the TPM using wolfTPM commands such as
+		firmware updates, PCR extend, and more. It is especially useful on
+		platforms that require support for secure boot and other TPM-related
+		functionality.
+
 config SPL_TPM
 	bool "Trusted Platform Module (TPM) Support in SPL"
 	depends on SPL_DM
lib/Makefile +18 -0
index 70667f3728c..76025cc77d8 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_BITREVERSE) += bitrev.o
 obj-y += list_sort.o
 endif
 
+# U-boot TPM
 obj-$(CONFIG_$(PHASE_)TPM) += tpm-common.o
 ifeq ($(CONFIG_$(PHASE_)TPM),y)
 obj-$(CONFIG_TPM) += tpm_api.o
@@ -64,6 +65,23 @@ obj-$(CONFIG_EFI_TCG2_PROTOCOL) += tpm_tcg2.o
 obj-$(CONFIG_MEASURED_BOOT) += tpm_tcg2.o
 endif
 
+# wolfTPM with TPM 2.0 support (including TPM firmware update)
+ifeq ($(CONFIG_TPM_WOLF),y)
+ifeq ($(CONFIG_TPM_V2),y)
+ccflags-y += -I$(srctree)/lib/wolftpm \
+             -I$(srctree)/include/configs \
+             -DWOLFTPM_USER_SETTINGS
+obj-y += wolftpm/hal/tpm_io.o
+obj-$(CONFIG_WOLFTPM_LINUX_DEV) += wolftpm/src/tpm2_linux.o
+obj-y += wolftpm/src/tpm2.o
+obj-y += wolftpm/src/tpm2_packet.o
+obj-y += wolftpm/src/tpm2_tis.o
+obj-y += wolftpm/src/tpm2_wrap.o
+obj-y += wolftpm/src/tpm2_param_enc.o
+obj-y += wolftpm.o
+endif
+endif
+
 obj-$(CONFIG_$(PHASE_)CRC8) += crc8.o
 obj-$(CONFIG_$(PHASE_)CRC16) += crc16.o
 obj-$(CONFIG_$(PHASE_)CRC16) += crc16-ccitt.o
lib/wolftpm new file +1 -0
new file mode 160000
index 00000000000..664db130d57
@@ -0,0 +1 @@
+Subproject commit 664db130d57bfa18a3254a0ddc126da1beeb9895
Signature · 1 line
2.43.0
#7 lore raw

Re: [[PATCH v2] tpm: Add wolfTPM library support for TPM 2.0 05/12] tpm: add wolfTPM library as git submodule

We decided a while back to use subtress for importing external trees. mbedTLS, dts and lwIP work as such, so please convert to a subtree.

tools/update-subtree.sh is what we use to merge the latest updates.

Regards
/Ilias

Quoted 108 lines · David Garske

From: Aidan <[email protected]>

Add wolfTPM (https://github.com/wolfSSL/wolfTPM) as a git submodule at lib/wolftpm. wolfTPM is a portable, open-source TPM 2.0 stack licensed under GPLv2, providing native API access to all TPM 2.0 commands and a wrapper API for common operations.

The build system additions:

.gitmodules:
Registers the wolfTPM submodule pointing to the upstream repo.

lib/Kconfig:
Adds CONFIG_TPM_WOLF option under library routines, which selects SHA1 and implies DM_RNG.

lib/Makefile:
When CONFIG_TPM_WOLF and CONFIG_TPM_V2 are both enabled, compiles wolfTPM core source files (tpm2.c, tpm2_packet.c, tpm2_tis.c, tpm2_wrap.c, tpm2_param_enc.c) and the HAL layer (tpm_io.c). Sets -I include paths and -DWOLFTPM_USER_SETTINGS.

---
 .gitmodules  |  3 +++
 lib/Kconfig  | 13 +++++++++++++
 lib/Makefile | 18 ++++++++++++++++++
 lib/wolftpm  |  1 +
 4 files changed, 35 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 lib/wolftpm
.gitmodules new file +3 -0
new file mode 100644
index 00000000000..3f95a7c3eb9
@@ -0,0 +1,3 @@
+[submodule "lib/wolftpm"]
+	path = lib/wolftpm
+	url = https://github.com/wolfssl/wolfTPM.git
lib/Kconfig +13 -0
index 931d5206936..24477ea53c9 100644
@@ -500,6 +500,19 @@ config TPM
 	  If you want a fully functional TPM enable all hashing algorithms.
 	  If you enabled measured boot all hashing algorithms are selected.
 
+config TPM_WOLF
+    bool "Enable wolfTPM support"
+	depends on DM
+	imply DM_RNG
+	select SHA1
+    help
+        This option enables support for wolfTPM in U-Boot. WolfTPM can be
+		used to update ARM specific platforms. Enabling this option allows
+		U-Boot to interact with the TPM using wolfTPM commands such as
+		firmware updates, PCR extend, and more. It is especially useful on
+		platforms that require support for secure boot and other TPM-related
+		functionality.
+
 config SPL_TPM
 	bool "Trusted Platform Module (TPM) Support in SPL"
 	depends on SPL_DM
lib/Makefile +18 -0
index 70667f3728c..76025cc77d8 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_BITREVERSE) += bitrev.o
 obj-y += list_sort.o
 endif
 
+# U-boot TPM
 obj-$(CONFIG_$(PHASE_)TPM) += tpm-common.o
 ifeq ($(CONFIG_$(PHASE_)TPM),y)
 obj-$(CONFIG_TPM) += tpm_api.o
@@ -64,6 +65,23 @@ obj-$(CONFIG_EFI_TCG2_PROTOCOL) += tpm_tcg2.o
 obj-$(CONFIG_MEASURED_BOOT) += tpm_tcg2.o
 endif
 
+# wolfTPM with TPM 2.0 support (including TPM firmware update)
+ifeq ($(CONFIG_TPM_WOLF),y)
+ifeq ($(CONFIG_TPM_V2),y)
+ccflags-y += -I$(srctree)/lib/wolftpm \
+             -I$(srctree)/include/configs \
+             -DWOLFTPM_USER_SETTINGS
+obj-y += wolftpm/hal/tpm_io.o
+obj-$(CONFIG_WOLFTPM_LINUX_DEV) += wolftpm/src/tpm2_linux.o
+obj-y += wolftpm/src/tpm2.o
+obj-y += wolftpm/src/tpm2_packet.o
+obj-y += wolftpm/src/tpm2_tis.o
+obj-y += wolftpm/src/tpm2_wrap.o
+obj-y += wolftpm/src/tpm2_param_enc.o
+obj-y += wolftpm.o
+endif
+endif
+
 obj-$(CONFIG_$(PHASE_)CRC8) += crc8.o
 obj-$(CONFIG_$(PHASE_)CRC16) += crc16.o
 obj-$(CONFIG_$(PHASE_)CRC16) += crc16-ccitt.o
lib/wolftpm new file +1 -0
new file mode 160000
index 00000000000..664db130d57
@@ -0,0 +1 @@
+Subproject commit 664db130d57bfa18a3254a0ddc126da1beeb9895
#8 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 06/12] tpm: add wolfTPM headers and SHA384 glue code

In reply to David Garske

From: Aidan <[email protected]>

Add the wolfTPM integration headers and hash wrapper needed to bridge wolfTPM with U-Boot's subsystems.

include/wolftpm.h:
Public header exposing TPM2_PCRs_Print(), TPM2_Init_Device(), and Infineon firmware update helpers (TPM2_IFX_FwData_Cb, TPM2_IFX_GetOpModeStr, TPM2_IFX_PrintInfo). Includes the core wolfTPM headers (tpm2.h, tpm2_wrap.h, tpm2_packet.h).

include/configs/user_settings.h:
wolfTPM compile-time configuration. Selects TPM chip type (SLB9672/SLB9673 for real hardware, WOLFTPM_AUTODETECT for swtpm/QEMU), communication mode (native SPI TIS layer for real hardware, WOLFTPM_LINUX_DEV for U-Boot driver model), timeout tuning, and feature flags (WOLFTPM2_NO_WOLFCRYPT, WOLFTPM2_NO_HEAP, WOLFTPM_CHECK_WAIT_STATE).

lib/wolftpm.c:
Provides wc_Sha384Hash() implementation when wolfCrypt is disabled (WOLFTPM2_NO_WOLFCRYPT). Uses U-Boot's hash_lookup_algo("sha384") to compute SHA-384 digests, which is required for Infineon TPM firmware update manifest validation.

---
 include/configs/user_settings.h | 118 ++++++++++++++++++++++++++++++++
 include/wolftpm.h               |  34 +++++++++
 lib/wolftpm.c                   |  56 +++++++++++++++
 3 files changed, 208 insertions(+)
 create mode 100644 include/configs/user_settings.h
 create mode 100644 include/wolftpm.h
 create mode 100644 lib/wolftpm.c
include/configs/user_settings.h new file +118 -0
new file mode 100644
index 00000000000..e62be7a8f30
@@ -0,0 +1,118 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * wolfTPM build configuration for U-Boot
+ *
+ * Copyright (C) 2025 wolfSSL Inc.
+ * Author: Aidan Garske <[email protected]>
+ */
+
+#ifndef USER_SETTINGS_H
+#define USER_SETTINGS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/******************************************************************************/
+/* --- BEGIN wolfTPM U-boot Settings -- */
+/******************************************************************************/
+
+/* =========================================================================
+ * TPM Chip Configuration
+ * =========================================================================
+ *
+ * CONFIG_TPM_AUTODETECT: For swtpm/QEMU testing (no specific chip)
+ * !CONFIG_TPM_AUTODETECT: For real hardware (SLB9672/SLB9673)
+ */
+#ifdef CONFIG_TPM_AUTODETECT
+	#define WOLFTPM_AUTODETECT
+#else
+	/* Real hardware - Infineon SLB9672/SLB9673
+	 * Firmware upgrade only supported by these chips */
+	#define WOLFTPM_FIRMWARE_UPGRADE
+	#define WOLFTPM_SLB9672
+	/* #define WOLFTPM_SLB9673 */
+#endif
+
+/* Include delay.h and types.h for
+ * U-boot time delay and types */
+#include <linux/delay.h>
+#include <linux/types.h>
+#include <stdint.h>
+
+/* wolfCrypt disabled - pcr_setauthpolicy/pcr_setauthvalue not available
+ * To enable wolfCrypt, you would need to:
+ * 1. Uncomment the line below to undefine WOLFTPM2_NO_WOLFCRYPT
+ * 2. Add wolfCrypt source files to the U-Boot build (lib/Makefile)
+ * 3. Add wolfCrypt settings for embedded/no-OS use
+ */
+#undef  WOLFTPM2_NO_WOLFCRYPT
+#define WOLFTPM2_NO_WOLFCRYPT
+
+/* =========================================================================
+ * TPM Communication Mode Selection (Auto-detected based on chip type)
+ * =========================================================================
+ *
+ * For real SPI hardware (SLB9672/SLB9673):
+ *   - Uses wolfTPM's native TIS layer with raw SPI via tpm_io_uboot.c
+ *   - Requires CONFIG_SPI and CONFIG_DM_SPI enabled in U-Boot
+ *
+ * For swtpm/QEMU testing (no specific chip defined):
+ *   - Uses WOLFTPM_LINUX_DEV mode with U-Boot's TPM driver (tpm_xfer())
+ *   - Works with MMIO-based TPM via tpm2_tis_mmio.c
+ */
+
+#if defined(WOLFTPM_SLB9672) || defined(WOLFTPM_SLB9673)
+	/* Real SPI hardware - use native wolfTPM TIS with raw SPI */
+	/* WOLFTPM_LINUX_DEV is NOT defined */
+	#define WOLFTPM_EXAMPLE_HAL
+
+	/* SPI bus and chip select for TPM
+	 * Official Raspberry Pi tpm-slb9670 overlay uses CE1 (GPIO7)
+	 * This matches LetsTrust and most Infineon evaluation boards */
+	#ifndef TPM_SPI_BUS
+		#define TPM_SPI_BUS 0
+	#endif
+	#ifndef TPM_SPI_CS
+		#define TPM_SPI_CS 1   /* CE1/GPIO7 - official RPi TPM overlay setting */
+	#endif
+#else
+	/* swtpm/QEMU - use U-Boot's TPM driver with MMIO communication mode */
+	#define WOLFTPM_LINUX_DEV
+#endif
+
+#define XSLEEP_MS(ms) udelay(ms * 1000)
+
+/* Timeout configuration */
+#ifdef WOLFTPM_FIRMWARE_UPGRADE
+	/* Firmware update requires much longer timeout for TPM processing */
+	#define TPM_TIMEOUT_TRIES 2000000
+#else
+	/* Normal operations - reduce from default 1,000,000 to prevent long hangs */
+	#define TPM_TIMEOUT_TRIES 10000
+#endif
+
+/* Add small delay between poll attempts to avoid tight spin loop */
+#define XTPM_WAIT() udelay(100)
+
+/* Do not include API's that use heap(), they are not required */
+#define WOLFTPM2_NO_HEAP
+
+/* Debugging - disabled for clean output */
+/* #define DEBUG_WOLFTPM */
+/* #define WOLFTPM_DEBUG_VERBOSE */
+/* #define WOLFTPM_DEBUG_IO */
+/* #define WOLFTPM_DEBUG_TIMEOUT */
+
+/* SPI Wait state checking - most TPMs use this */
+#define WOLFTPM_CHECK_WAIT_STATE
+
+/******************************************************************************/
+/* --- END wolfTPM U-boot Settings -- */
+/******************************************************************************/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* USER_SETTINGS_H */
include/wolftpm.h new file +34 -0
new file mode 100644
index 00000000000..a3cd9d0d2dd
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * wolfTPM integration header for U-Boot
+ *
+ * Copyright (C) 2025 wolfSSL Inc.
+ * Author: Aidan Garske <[email protected]>
+ */
+
+#ifndef __WOLFTPM_H__
+#define __WOLFTPM_H__
+
+#include <wolftpm/tpm2.h>
+#include <wolftpm/tpm2_wrap.h>
+#include <wolftpm/tpm2_packet.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef WOLFTPM_FIRMWARE_UPGRADE
+int TPM2_IFX_FwData_Cb(uint8_t *data, uint32_t data_req_sz,
+			uint32_t offset, void *cb_ctx);
+const char *TPM2_IFX_GetOpModeStr(int opMode);
+void TPM2_IFX_PrintInfo(WOLFTPM2_CAPS *caps);
+#endif
+
+int TPM2_PCRs_Print(void);
+int TPM2_Init_Device(WOLFTPM2_DEV *dev, void *userCtx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WOLFTPM_H__ */
lib/wolftpm.c new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.43.0
#9 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 07/12] tpm: add wolfTPM driver helpers and Kconfig options

In reply to David Garske

From: Aidan <[email protected]>

Add wolfTPM helper functions and configuration options to the TPM driver subsystem.

drivers/tpm/wolftpm_common.c:
Shared helper functions used by the wolfTPM command backend:
- TPM2_IFX_FwData_Cb(): firmware data callback for Infineon firmware update streaming
- TPM2_IFX_GetOpModeStr(): converts Infineon operational mode codes to human-readable strings
- TPM2_IFX_PrintInfo(): prints manufacturer, vendor, firmware version, and operational mode from WOLFTPM2_CAPS
- TPM2_PCRs_Print(): enumerates and prints assigned PCR banks and their selected PCR indices
- TPM2_Init_Device(): initializes wolfTPM with the TPM2_IoCb HAL callback

drivers/tpm/Kconfig:
Adds configuration options under TPM_V2:
- TPM2_SPI_SANDBOX: sandbox TPM SPI emulator for testing
- TPM_AUTODETECT: auto-detect TPM chip for swtpm/QEMU
- WOLFTPM_LINUX_DEV: use U-Boot driver model instead of wolfTPM's native TIS layer
- WOLFTPM_SLB9672/SLB9673: Infineon chip-specific features
- WOLFTPM_FIRMWARE_UPGRADE: firmware update support

drivers/tpm/Makefile:
Compiles wolftpm_common.o and sets wolfTPM include paths and -DWOLFTPM_USER_SETTINGS when CONFIG_TPM_WOLF is enabled.

---
 drivers/tpm/Kconfig          |  44 +++++++++++
 drivers/tpm/Makefile         |   9 +++
 drivers/tpm/wolftpm_common.c | 137 +++++++++++++++++++++++++++++++++++
 3 files changed, 190 insertions(+)
 create mode 100644 drivers/tpm/wolftpm_common.c
drivers/tpm/Kconfig +44 -0
index 219ea606b50..a2897a0e040 100644
@@ -158,6 +158,14 @@ config TPM2_TIS_SANDBOX
 	  such as basic configuration, PCR extension and PCR read. Extended
 	  functionalities are not implemented.
 
+config TPM2_SPI_SANDBOX
+	bool "Enable sandbox TPM SPI emulator"
+	depends on TPM_V2 && SANDBOX && DM_SPI
+	help
+	  This driver emulates a TPM connected via SPI for sandbox testing.
+	  It implements the TPM TIS SPI protocol and can be used to test
+	  wolfTPM SPI HAL code without physical hardware.
+
 config TPM2_TIS_SPI
 	bool "Enable support for TPMv2.x SPI chips"
 	depends on TPM_V2 && DM_SPI
@@ -200,6 +208,42 @@ config TPM2_EVENT_LOG_SIZE
 	  allocated twice. One for the eventlog it self and one for the
 	  configuration table that is required from the TCG2 spec
 
+config TPM_AUTODETECT
+    bool "wolfTPM auto-detect TPM chip (for swtpm/QEMU)"
+    depends on TPM_V2 && TPM_WOLF
+    help
+      Enable wolfTPM chip auto-detection instead of using a specific
+      chip type (SLB9672/SLB9673). Use this for swtpm/QEMU testing
+      where no specific hardware chip is present.
+
+config WOLFTPM_LINUX_DEV
+    bool "Use device-level TPM interface (bypass wolfTPM TIS layer)"
+    depends on TPM_V2 && TPM_WOLF
+    default y
+    help
+      Enable wolfTPM to use the underlying TPM driver instead of its own
+      TIS (TPM Interface Specification) layer. On U-Boot, this uses the
+      U-Boot TPM driver model (tpm_xfer). On Linux, this uses /dev/tpm0.
+      This is the recommended setting for U-Boot.
+
+config WOLFTPM_SLB9672
+    bool "Enable support for Infineon SLB9672 TPM"
+    depends on TPM_V2 && TPM_WOLF
+    help
+      Enable support for Infineon SLB9672 TPM features in wolfTPM.
+
+config WOLFTPM_SLB9673
+    bool "Enable support for Infineon SLB9673 TPM"
+    depends on TPM_V2 && TPM_WOLF
+    help
+      Enable support for Infineon SLB9673 TPM features in wolfTPM.
+
+config WOLFTPM_FIRMWARE_UPGRADE
+    bool "Enable firmware upgrade support for wolfTPM"
+    depends on TPM_V2 && TPM_WOLF
+    help
+      Enable support for Infineon TPM firmware upgrade commands in wolfTPM.
+
 endif # TPM_V2
 
 endmenu
drivers/tpm/Makefile +9 -0
index b83ce703ec0..bee4193e9fc 100644
@@ -10,7 +10,16 @@ obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o sandbox_common.o
 
 obj-$(CONFIG_$(PHASE_)TPM2_CR50_I2C) += cr50_i2c.o
 obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o sandbox_common.o
+obj-$(CONFIG_TPM2_SPI_SANDBOX) += tpm_spi_sandbox.o
 obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_core.o tpm2_tis_spi.o
 obj-$(CONFIG_TPM2_TIS_I2C) += tpm2_tis_core.o tpm2_tis_i2c.o
 obj-$(CONFIG_TPM2_FTPM_TEE) += tpm2_ftpm_tee.o
 obj-$(CONFIG_TPM2_MMIO) += tpm2_tis_core.o tpm2_tis_mmio.o
+
+# wolfTPM helper functions
+ifeq ($(CONFIG_TPM_WOLF),y)
+ccflags-y += -I$(srctree)/lib/wolftpm \
+             -I$(srctree)/include/configs \
+             -DWOLFTPM_USER_SETTINGS
+obj-y += wolftpm_common.o
+endif
drivers/tpm/wolftpm_common.c new file +137 -0

137 lines not on this page · raw message

Signature · 1 line
2.43.0
#10 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 08/12] cmd: refactor tpm2 command into frontend/backend architecture

In reply to David Garske

From: Aidan <[email protected]>

Split the tpm2 command implementation into a shared frontend and two selectable backends. This allows wolfTPM to provide its own TPM2 command implementations while keeping the command table, dispatcher, and help text shared.

Architecture:

cmd/tpm-v2.c (frontend - always compiled):
Contains the tpm2_commands[] table, get_tpm2_commands(), the do_tpm2() dispatcher, and the U_BOOT_CMD help text. References backend functions via cmd/tpm2-backend.h. When CONFIG_TPM_WOLF is enabled, additional wolfTPM-only commands (caps, pcr_print, firmware_update, firmware_cancel) are added to the table.

cmd/tpm2-backend.h (new):
Declares all backend function prototypes that both backends must
implement: do_tpm2_device, do_tpm2_info, do_tpm2_init, do_tpm2_startup, do_tpm2_selftest, do_tpm2_clear, do_tpm2_pcr_extend, do_tpm2_pcr_read, do_tpm2_get_capability, do_tpm2_dam_reset, do_tpm2_dam_parameters, do_tpm2_change_auth, do_tpm2_pcr_setauthpolicy, do_tpm2_pcr_setauthvalue, do_tpm2_pcr_allocate, plus wolfTPM-only functions.

cmd/native_tpm2.c (new - native backend):
Contains the original tpm2 command implementations that use U-Boot's TPM driver model (tpm_api.h, tpm-v2.h). Compiled when CONFIG_TPM_WOLF is not set. Common commands delegate to tpm-common.c helpers (do_tpm_device, do_tpm_info, etc.).

cmd/wolftpm.c (new - wolfTPM backend):
Implements all tpm2 commands using wolfTPM library APIs directly (wolfTPM2_Init, wolfTPM2_GetCapabilities, wolfTPM2_ExtendPCR, etc.). Includes Infineon-specific firmware update and cancel commands. Each command initializes its own WOLFTPM2_DEV instance rather than going through U-Boot's driver model.

cmd/Kconfig:
Adds CMD_WOLFTPM option that selects TPM_WOLF and CMD_TPM_V2, providing a single menuconfig toggle for wolfTPM support.

cmd/Makefile:
Conditionally compiles wolftpm.o (when CONFIG_TPM_WOLF=y) or native_tpm2.o (otherwise) alongside the shared tpm-v2.o frontend. Sets wolfTPM include paths and -DWOLFTPM_USER_SETTINGS.

The reason for separate backend files rather than a callback-based approach is that wolfTPM uses fundamentally different types and initialization patterns (WOLFTPM2_DEV vs struct udevice, direct library calls vs driver model ops), making runtime dispatch impractical without heavy abstraction.

---
 cmd/Kconfig        |   11 +
 cmd/Makefile       |   10 +-
 cmd/native_tpm2.c  |  516 +++++++++++++++++++
 cmd/tpm-v2.c       |  559 +++------------------
 cmd/tpm2-backend.h |   66 +++
 cmd/wolftpm.c      | 1170 ++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 1840 insertions(+), 492 deletions(-)
 create mode 100644 cmd/native_tpm2.c
 create mode 100644 cmd/tpm2-backend.h
 create mode 100644 cmd/wolftpm.c
cmd/Kconfig +11 -0
index 322ebe600c5..d9360d5237a 100644
@@ -3202,4 +3202,15 @@ config CMD_SPAWN_NUM_JOBS
 	  When a jobs exits, its identifier is available to be re-used by the next
 	  spawn command.
 
+config CMD_WOLFTPM
+	bool "Use wolfTPM as TPM2 backend"
+	depends on TPM_V2
+	select TPM_WOLF
+	select CMD_TPM_V2
+	help
+	  Use the wolfTPM library as the backend for TPM2 commands instead
+	  of the standard U-Boot TPM2 implementation. wolfTPM offers additional
+	  features including firmware update support for Infineon TPMs and
+	  enhanced capabilities reporting.
+
 endif
cmd/Makefile +9 -1
index 4cd13d4fa6e..2b12b26e61f 100644
@@ -191,9 +191,17 @@ obj-$(CONFIG_CMD_TIMER) += timer.o
 obj-$(CONFIG_CMD_TRACE) += trace.o
 obj-$(CONFIG_HUSH_PARSER) += test.o
 obj-$(CONFIG_CMD_TPM) += tpm-common.o
-obj-$(CONFIG_CMD_TPM_V1) += tpm-v1.o
 obj-$(CONFIG_CMD_TPM_TEST) += tpm_test.o
+obj-$(CONFIG_CMD_TPM_V1) += tpm-v1.o
 obj-$(CONFIG_CMD_TPM_V2) += tpm-v2.o
+ifeq ($(CONFIG_TPM_WOLF),y)
+ccflags-y += -I$(srctree)/lib/wolftpm \
+             -I$(srctree)/include/configs \
+             -DWOLFTPM_USER_SETTINGS
+obj-$(CONFIG_CMD_TPM_V2) += wolftpm.o
+else
+obj-$(CONFIG_CMD_TPM_V2) += native_tpm2.o
+endif
 obj-$(CONFIG_CMD_CROS_EC) += cros_ec.o
 obj-$(CONFIG_CMD_UBI) += ubi.o
 obj-$(CONFIG_CMD_UBIFS) += ubifs.o
cmd/native_tpm2.c new file +516 -0

516 lines not on this page · raw message

cmd/tpm-v2.c +68 -491

599 lines not on this page · raw message

cmd/tpm2-backend.h new file +66 -0

66 lines not on this page · raw message

cmd/wolftpm.c new file +1170 -0

1,170 lines not on this page · raw message

Signature · 1 line
2.43.0
#11 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 09/12] tpm: add sandbox TPM SPI emulator

In reply to David Garske

From: Aidan <[email protected]>

Add a TPM SPI emulator for sandbox testing that implements the TIS (TPM Interface Specification) SPI protocol, allowing wolfTPM's SPI HAL code to be tested without physical hardware.

drivers/tpm/tpm_spi_sandbox.c (new):
Emulates a TPM connected via SPI by implementing the TIS register set and SPI protocol:
- SPI protocol state machine: parses 4-byte TIS SPI headers (R/W bit, transfer length, register address) and handles data phase with immediate ready signaling (no wait states)
- TIS register emulation: TPM_ACCESS (locality request/grant), TPM_STS (command ready, data expect, data available, burst count), TPM_INTF_CAPS, TPM_DID_VID (Infineon SLB9670 IDs), TPM_RID, and TPM_DATA_FIFO (command/response buffering)
- TIS state machine: IDLE -> READY -> RECEPTION -> EXECUTION -> COMPLETION, with command-ready abort support
- Generates simple TPM_RC_SUCCESS responses (a full implementation would integrate the sandbox TPM2 state machine)
- Registers as UCLASS_SPI_EMUL with compatible "sandbox,tpm-spi-emul"
- Also registers a SPI slave driver (UCLASS_SPI_GENERIC) with compatible "sandbox,tpm-spi" for the DTS device node

drivers/mtd/spi/sandbox.c:
Modify sandbox_spi_get_emul() to check for a "sandbox,emul" phandle property on SPI slave devices before falling back to the default SPI flash emulation binding. This allows non-flash SPI devices (like the TPM emulator) to specify their own emulator via device tree phandle.

---
 drivers/mtd/spi/sandbox.c     |  30 ++-
 drivers/tpm/tpm_spi_sandbox.c | 410 ++++++++++++++++++++++++++++++++++
 2 files changed, 431 insertions(+), 9 deletions(-)
 create mode 100644 drivers/tpm/tpm_spi_sandbox.c
drivers/mtd/spi/sandbox.c +21 -9
index e5ebc3479fb..41bd07817aa 100644
@@ -571,16 +571,28 @@ int sandbox_spi_get_emul(struct sandbox_state *state,
 
 	info = &state->spi[busnum][cs];
 	if (!info->emul) {
-		/* Use the same device tree node as the SPI flash device */
-		debug("%s: busnum=%u, cs=%u: binding SPI flash emulation: ",
-		      __func__, busnum, cs);
-		ret = sandbox_sf_bind_emul(state, busnum, cs, bus,
-					   dev_ofnode(slave), slave->name);
-		if (ret) {
-			debug("failed (err=%d)\n", ret);
-			return ret;
+		struct udevice *emul;
+		ofnode node = dev_ofnode(slave);
+
+		/* First check for sandbox,emul phandle property */
+		ret = uclass_get_device_by_phandle(UCLASS_SPI_EMUL, slave,
+						   "sandbox,emul", &emul);
+		if (!ret) {
+			debug("%s: busnum=%u, cs=%u: using phandle emulator\n",
+			      __func__, busnum, cs);
+			info->emul = emul;
+		} else {
+			/* Fall back to SPI flash emulation binding */
+			debug("%s: busnum=%u, cs=%u: binding SPI flash emulation: ",
+			      __func__, busnum, cs);
+			ret = sandbox_sf_bind_emul(state, busnum, cs, bus,
+						   node, slave->name);
+			if (ret) {
+				debug("failed (err=%d)\n", ret);
+				return ret;
+			}
+			debug("OK\n");
 		}
-		debug("OK\n");
 	}
 	*emulp = info->emul;
 
drivers/tpm/tpm_spi_sandbox.c new file +410 -0

410 lines not on this page · raw message

Signature · 1 line
2.43.0
#12 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 10/12] test: add wolfTPM C unit tests and Python integration tests

In reply to David Garske

From: Aidan <[email protected]>

Add comprehensive test suites for wolfTPM commands, modeled after the existing TPM2 test infrastructure.

test/cmd/wolftpm.c (C unit tests):
18 tests using U-Boot's unit test framework (CMD_TEST macro):
- autostart, init, info, state, device: basic lifecycle
- self_test (full and continue): TPM self-test verification
- startup_clear, startup_state: TPM2_Startup modes
- get_capability: read TPM properties
- caps: wolfTPM-enhanced capabilities display
- clear: TPM state reset via LOCKOUT hierarchy
- pcr_read, pcr_extend, pcr_print: PCR operations
- pcr_allocate: PCR bank reconfiguration
- dam_reset, dam_parameters: dictionary attack mitigation
- change_auth: hierarchy password change (requires wolfCrypt)
- cleanup: reset TPM state after tests
Run with: ut cmd cmd_test_wolftpm_*

test/cmd/Makefile:
Adds wolftpm.o when CONFIG_TPM_WOLF is enabled.

test/py/tests/test_wolftpm.py (Python integration tests):
21 tests using pytest with the U-Boot test framework:
- Requires QEMU + swtpm (not sandbox) because wolfTPM bypasses U-Boot's driver model and communicates directly with TPM hardware via its own SPI/MMIO HAL
- Tests mirror the C tests but run end-to-end through the U-Boot console, checking return codes via 'echo $?'
- Includes force_init() helper for TPM reinitialization after test failures
- Skippable via env__wolftpm_device_test_skip config
- Verified: 19 passed, 2 skipped (change_auth requires wolfCrypt, get_capability may skip on some platforms)

---
 test/cmd/Makefile             |   1 +
 test/cmd/wolftpm.c            | 364 +++++++++++++++++++++++++++++++++
 test/py/tests/test_wolftpm.py | 375 ++++++++++++++++++++++++++++++++++
 3 files changed, 740 insertions(+)
 create mode 100644 test/cmd/wolftpm.c
 create mode 100644 test/py/tests/test_wolftpm.py
test/cmd/Makefile +1 -0
index 8c9f112782d..6e346dfa4bf 100644
@@ -48,3 +48,4 @@ obj-$(CONFIG_CMD_SPAWN) += spawn.o
 ifdef CONFIG_CMD_ZIP
 obj-$(CONFIG_CMD_UNZIP) += unzip.o
 endif
+obj-$(CONFIG_TPM_WOLF) += wolftpm.o
test/cmd/wolftpm.c new file +364 -0

364 lines not on this page · raw message

test/py/tests/test_wolftpm.py new file +375 -0

375 lines not on this page · raw message

Signature · 1 line
2.43.0
#13 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 11/12] doc: add wolfTPM documentation

In reply to David Garske

From: Aidan <[email protected]>

Add documentation for wolfTPM integration, commands, and testing.

doc/usage/cmd/wolftpm.rst:
Comprehensive RST documentation covering:
- All wolfTPM tpm2 subcommands with usage and examples
- Infineon TPM firmware update step-by-step guide (extract manifest/firmware, load to RAM, perform update, recovery mode)
- Build instructions for RPi4 and QEMU targets
- Enabling debug output (U-Boot log system + wolfTPM library)
- Complete test suite documentation with test coverage table
- Python test framework setup (QEMU + swtpm instructions, helper scripts, verified test results)

README.wolftpm.md:
Quick-start guide with overview, feature comparison vs standard U-Boot TPM, command reference, build instructions, hardware support details, and file listing.

README:
Add CONFIG_TPM_WOLF reference in the configuration options section alongside existing CONFIG_TPM entries.

---
 README                    |   3 +
 README.wolftpm.md         | 154 +++++++++
 doc/usage/cmd/wolftpm.rst | 635 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 792 insertions(+)
 create mode 100644 README.wolftpm.md
 create mode 100644 doc/usage/cmd/wolftpm.rst
README +3 -0
index 20a73bab802..b9bfe14a1c7 100644
@@ -361,6 +361,9 @@ The following options need to be configured:
 		CONFIG_TPM
 		Support TPM devices.
 
+		CONFIG_TPM_WOLF
+		Enables support for wolfTPM library.
+
 		CONFIG_TPM_TIS_INFINEON
 		Support for Infineon i2c bus TPM devices. Only one device
 		per system is supported at this time.
README.wolftpm.md new file +154 -0

154 lines not on this page · raw message

doc/usage/cmd/wolftpm.rst new file +635 -0

635 lines not on this page · raw message

Signature · 1 line
2.43.0
#14 lore raw

PATCH v2 1/1 tpm: Add wolfTPM library support for TPM 2.0 12/12] configs: enable wolfTPM in rpi_4_defconfig

In reply to David Garske

From: Aidan <[email protected]>

Enable SPI, TPM, and wolfTPM support in the Raspberry Pi 4 default configuration for out-of-the-box TPM 2.0 support with Infineon SLB9670/9672 TPM HATs.

SPI support:
CONFIG_SPI, CONFIG_DM_SPI, CONFIG_BCM2835_SPI, CONFIG_CMD_SPI Enables the BCM2835 hardware SPI driver. Soft SPI is disabled since the hardware driver is used.

TPM and wolfTPM:
CONFIG_TPM, CONFIG_TPM_V2, CONFIG_CMD_TPM: core TPM support
CONFIG_TPM_WOLF: wolfTPM library integration
CONFIG_CMD_WOLFTPM: wolfTPM command backend for tpm2
CONFIG_WOLFTPM_SLB9672: Infineon SLB9672 chip support WOLFTPM_LINUX_DEV disabled: uses native wolfTPM TIS layer with direct SPI communication rather than U-Boot's TPM driver model

Logging:
CONFIG_LOG with level 7 (DEBUG) to enable log_debug() output from wolfTPM commands.

Testing:
CONFIG_UNIT_TEST, CONFIG_CONSOLE_RECORD, CONFIG_HEXDUMP for running the wolfTPM C unit test suite.

---
 configs/rpi_4_defconfig | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
configs/rpi_4_defconfig +28 -1
index 8362242b97f..22280d9b70e 100644
@@ -69,4 +69,31 @@ CONFIG_SYS_WHITE_ON_BLACK=y
 CONFIG_VIDEO_BCM2835=y
 CONFIG_CONSOLE_SCROLL_LINES=10
 CONFIG_PHYS_TO_BUS=y
-# CONFIG_HEXDUMP is not set
+# HEXDUMP enabled for unit tests
+
+# SPI support (hardware SPI - matches Linux tpm-slb9670 overlay)
+CONFIG_SPI=y
+CONFIG_DM_SPI=y
+CONFIG_BCM2835_SPI=y
+# CONFIG_SOFT_SPI is not set
+CONFIG_CMD_SPI=y
+
+# TPM and wolfTPM support
+CONFIG_TPM=y
+CONFIG_TPM_V2=y
+CONFIG_CMD_TPM=y
+CONFIG_TPM_WOLF=y
+# CONFIG_WOLFTPM_LINUX_DEV is not set
+CONFIG_WOLFTPM_SLB9672=y
+CONFIG_CMD_WOLFTPM=y
+
+# Logging (debug level to see log_debug output)
+CONFIG_LOG=y
+CONFIG_LOGLEVEL=7
+CONFIG_LOG_MAX_LEVEL=7
+CONFIG_LOG_DEFAULT_LEVEL=7
+
+# Unit testing support
+CONFIG_UNIT_TEST=y
+CONFIG_CONSOLE_RECORD=y
+CONFIG_HEXDUMP=y
Signature · 1 line
2.43.0
#15 lore raw
In reply to David Garske

Hi David,

Apologies for the very late reply, but I am overloaded and this is going some time to review.

For starters the CI failed to pass the docs. Please have a look and update them properly

https://source.denx.de/u-boot/custodians/u-boot-tpm/-/pipelines/30029

Cheers
/Ilias

Quoted 69 lines · David Garske

*** BLURB HERE ***

Aidan (12):
tpm: export tpm_show_device, tpm_set_device, and get_tpm
include: add byteorder macro guards and SHA384 hash wrapper
spi: add BCM2835/BCM2711 hardware SPI controller driver
dts: add TPM device tree nodes for RPi4, QEMU, and sandbox
tpm: add wolfTPM library as git submodule
tpm: add wolfTPM headers and SHA384 glue code
tpm: add wolfTPM driver helpers and Kconfig options
cmd: refactor tpm2 command into frontend/backend architecture
tpm: add sandbox TPM SPI emulator
test: add wolfTPM C unit tests and Python integration tests
doc: add wolfTPM documentation
configs: enable wolfTPM in rpi_4_defconfig

 .gitmodules                              |    3 +
 README                                   |    3 +
 README.wolftpm.md                        |  154 +++
 arch/arm/dts/bcm2711-rpi-4-b-u-boot.dtsi |   54 +
 arch/arm/dts/bcm2711-rpi-4-b.dts         |   20 +
 arch/arm/dts/qemu-arm64.dts              |    4 +
 arch/sandbox/dts/sandbox.dtsi            |   11 +
 cmd/Kconfig                              |   11 +
 cmd/Makefile                             |   10 +-
 cmd/native_tpm2.c                        |  516 ++++++++++
 cmd/tpm-common.c                         |    4 +-
 cmd/tpm-v2.c                             |  559 ++---------
 cmd/tpm2-backend.h                       |   66 ++
 cmd/wolftpm.c                            | 1170 ++++++++++++++++++++++
 configs/rpi_4_defconfig                  |   29 +-
 doc/usage/cmd/wolftpm.rst                |  635 ++++++++++++
 drivers/mtd/spi/sandbox.c                |   30 +-
 drivers/spi/Kconfig                      |    9 +
 drivers/spi/Makefile                     |    1 +
 drivers/spi/bcm2835_spi.c                |  431 ++++++++
 drivers/tpm/Kconfig                      |   44 +
 drivers/tpm/Makefile                     |    9 +
 drivers/tpm/tpm_spi_sandbox.c            |  410 ++++++++
 drivers/tpm/wolftpm_common.c             |  137 +++
 include/configs/user_settings.h          |  118 +++
 include/hash.h                           |   18 +
 include/linux/byteorder/generic.h        |   31 +-
 include/tpm-common.h                     |   22 +
 include/wolftpm.h                        |   34 +
 lib/Kconfig                              |   13 +
 lib/Makefile                             |   18 +
 lib/wolftpm                              |    1 +
 lib/wolftpm.c                            |   56 ++
 test/cmd/Makefile                        |    1 +
 test/cmd/wolftpm.c                       |  364 +++++++
 test/py/tests/test_wolftpm.py            |  375 +++++++
 36 files changed, 4861 insertions(+), 510 deletions(-)
 create mode 100644 .gitmodules
 create mode 100644 README.wolftpm.md
 create mode 100644 arch/arm/dts/bcm2711-rpi-4-b-u-boot.dtsi
 create mode 100644 cmd/native_tpm2.c
 create mode 100644 cmd/tpm2-backend.h
 create mode 100644 cmd/wolftpm.c
 create mode 100644 doc/usage/cmd/wolftpm.rst
 create mode 100644 drivers/spi/bcm2835_spi.c
 create mode 100644 drivers/tpm/tpm_spi_sandbox.c
 create mode 100644 drivers/tpm/wolftpm_common.c
 create mode 100644 include/configs/user_settings.h
 create mode 100644 include/wolftpm.h
 create mode 160000 lib/wolftpm
 create mode 100644 lib/wolftpm.c
 create mode 100644 test/cmd/wolftpm.c
 create mode 100644 test/py/tests/test_wolftpm.py