1*a2dd13caSAbhi SinghDiscrete TPM drivers 2*a2dd13caSAbhi Singh==================== 3*a2dd13caSAbhi Singh 4*a2dd13caSAbhi SinghThis section focuses on the design and functionality of Discrete TPM drivers 5*a2dd13caSAbhi Singhin |TF-A|. The |TPM| technology is designed to provide 6*a2dd13caSAbhi Singha dedicated, hardware-based solution for storing cryptographic keys and 7*a2dd13caSAbhi Singhperforming security-related operations. 8*a2dd13caSAbhi Singh 9*a2dd13caSAbhi SinghDiscrete TPMs are separate, standalone hardware components that are physically 10*a2dd13caSAbhi Singhisolated from the system's main processor. This isolation helps protect 11*a2dd13caSAbhi Singhsensitive information, such as encryption keys and platform credentials, from 12*a2dd13caSAbhi Singhbeing accessed or tampered with by malicious software or unauthorized users. 13*a2dd13caSAbhi SinghWhen a Discrete TPM interface is implemented correctly, the risk of software 14*a2dd13caSAbhi Singhbased attacks is reduced, further reducing the attack surface. 15*a2dd13caSAbhi Singh 16*a2dd13caSAbhi SinghTPM measurements establish the security posture of a system and are used for 17*a2dd13caSAbhi Singhattestation. Performing measurements using a TPM in TF-A is beneficial from 18*a2dd13caSAbhi Singha security standpoint because it ensures hardware-backed attestation earlier 19*a2dd13caSAbhi Singhin the boot flow, reducing the risk of a compromised root of trust. 20*a2dd13caSAbhi Singh 21*a2dd13caSAbhi SinghThe design implemented in TF-A supports multiple types of TPM hardware interfaces 22*a2dd13caSAbhi Singhand hardware bus types in order to be compatible with different platforms. 23*a2dd13caSAbhi SinghPlatforms opt to use a specific messaging interface, such as |CRB| or |FIFO|, 24*a2dd13caSAbhi Singhand a specific hardware bus interface, such as |I2C| or |SPI|. 25*a2dd13caSAbhi Singh 26*a2dd13caSAbhi SinghDriver architecture 27*a2dd13caSAbhi Singh------------------- 28*a2dd13caSAbhi Singh 29*a2dd13caSAbhi SinghThe Discrete TPM drivers are split up into four layers, each serving a distinct 30*a2dd13caSAbhi Singhpurpose in the overall architecture: 31*a2dd13caSAbhi Singh 32*a2dd13caSAbhi Singh - **Command Layer**: This layer provides various TPM commands based on the 33*a2dd13caSAbhi Singh `TCG TPM 2.0 Library Specification`_. It allows a system to initialize the 34*a2dd13caSAbhi Singh TPM interface, perform a TPM startup, set up a locality for operations like 35*a2dd13caSAbhi Singh PCR extend and read, and release the locality when finished. 36*a2dd13caSAbhi Singh - **Interface Layer**: This layer handles sending and receiving TPM commands 37*a2dd13caSAbhi Singh via a specific TPM interface like FIFO or CRB. It also includes functions 38*a2dd13caSAbhi Singh such as getting information, requesting access, and relinquishing access, 39*a2dd13caSAbhi Singh tailored to the specific interface. 40*a2dd13caSAbhi Singh - **Link Layer**: Discrete TPMs may appear as a SPI, I2C, or memory mapped 41*a2dd13caSAbhi Singh device. The link layer maps the command passed from the interface layer to 42*a2dd13caSAbhi Singh the appropriate bus type. It includes hardware link read and write functions 43*a2dd13caSAbhi Singh that use the platform bus interface to transfer commands. 44*a2dd13caSAbhi Singh - **Platform Layer**: The platform layer implements the details of how to 45*a2dd13caSAbhi Singh communicate to the TPM chip for a specific platform. The link layer uses the 46*a2dd13caSAbhi Singh platform layer to read and write to the TPM. 47*a2dd13caSAbhi Singh 48*a2dd13caSAbhi Singh .. note:: 49*a2dd13caSAbhi Singh The command, interface, and link layers are implemented in common code in 50*a2dd13caSAbhi Singh TF-A. The platform layer is implemented in platform specific code. 51*a2dd13caSAbhi Singh 52*a2dd13caSAbhi SinghThe following diagram illustrates the Discrete TPM driver stack for the Raspberry 53*a2dd13caSAbhi SinghPi 3 platform. 54*a2dd13caSAbhi Singh 55*a2dd13caSAbhi Singh|rpi3 dtpm driver stack| 56*a2dd13caSAbhi Singh 57*a2dd13caSAbhi SinghHeader files 58*a2dd13caSAbhi Singh^^^^^^^^^^^^ 59*a2dd13caSAbhi Singh- TPM Drivers: ``include/drivers/tpm`` 60*a2dd13caSAbhi Singh 61*a2dd13caSAbhi Singh 62*a2dd13caSAbhi SinghSource files 63*a2dd13caSAbhi Singh^^^^^^^^^^^^ 64*a2dd13caSAbhi Singh- TPM Drivers: ``drivers/tpm`` 65*a2dd13caSAbhi Singh 66*a2dd13caSAbhi Singh 67*a2dd13caSAbhi SinghBuild time config options 68*a2dd13caSAbhi Singh------------------------- 69*a2dd13caSAbhi Singh 70*a2dd13caSAbhi Singh- ``MBOOT_TPM_HASH_ALG``: The hash algorithm to be used by the TPM, currently 71*a2dd13caSAbhi Singh the only supported algorithm is ``sha256``. As additional Discrete TPMs are 72*a2dd13caSAbhi Singh tested and integrated in TF-A, support for more algorithms will become 73*a2dd13caSAbhi Singh available. 74*a2dd13caSAbhi Singh- ``DISCRETE_TPM``: Boolean flag to enable Discrete TPM support. Depending 75*a2dd13caSAbhi Singh on the selected TPM interface, the appropriate drivers will be built and 76*a2dd13caSAbhi Singh packaged into firmware. 77*a2dd13caSAbhi Singh- ``TPM_INTERFACE``: This flag is required when ``DISCRETE_TPM=1``, 78*a2dd13caSAbhi Singh currently the only supported interface is ``FIFO_SPI``. 79*a2dd13caSAbhi Singh Ideally there should be four options: 80*a2dd13caSAbhi Singh 81*a2dd13caSAbhi Singh .. code:: shell 82*a2dd13caSAbhi Singh 83*a2dd13caSAbhi Singh FIFO_I2C 84*a2dd13caSAbhi Singh FIFO_SPI 85*a2dd13caSAbhi Singh FIFO_MMIO 86*a2dd13caSAbhi Singh CRB 87*a2dd13caSAbhi Singh 88*a2dd13caSAbhi Singh .. note:: 89*a2dd13caSAbhi Singh ``MBOOT_TPM_HASH_ALG`` will automatically overwrite ``MBOOT_EL_HASH_ALG``. 90*a2dd13caSAbhi Singh This is to ensure the event log and the TPM are using the same hash 91*a2dd13caSAbhi Singh algorithm. 92*a2dd13caSAbhi Singh 93*a2dd13caSAbhi Singh 94*a2dd13caSAbhi SinghDiscrete TPM Initialization 95*a2dd13caSAbhi Singh--------------------------- 96*a2dd13caSAbhi SinghThe TPM needs to be initialized based on the platform, the hardware interfaces 97*a2dd13caSAbhi Singhneed to be set up independently, and once they are setup, the TPM commands 98*a2dd13caSAbhi Singh``tpm_interface_init()`` and subsequently ``tpm_startup()`` can be called. 99*a2dd13caSAbhi Singh``tpm_startup()`` only needs to be called once after startup, or if the system 100*a2dd13caSAbhi Singhis reset. 101*a2dd13caSAbhi Singh 102*a2dd13caSAbhi SinghAn example of platform specific TPM hardware initialization for the rpi3 can be 103*a2dd13caSAbhi Singhfound in ``plat/rpi/rpi3/rpi3_bl1_setup.c`` and ``plat/rpi/rpi3/rpi3_bl1_mboot.c`` 104*a2dd13caSAbhi Singh 105*a2dd13caSAbhi Singh 106*a2dd13caSAbhi SinghDiscrete TPM PCR Extend 107*a2dd13caSAbhi Singh----------------------- 108*a2dd13caSAbhi SinghOnce the TPM is setup, the TPM ``pcr_extend`` operation can be used to extend 109*a2dd13caSAbhi Singhhashes and store them in PCR 0. 110*a2dd13caSAbhi Singh 111*a2dd13caSAbhi SinghAn example of ``pcr_extend`` that is used during rpi3 measured boot can be found 112*a2dd13caSAbhi Singh in ``plat/rpi/rpi3/rpi3_bl1_mboot.c`` and ``plat/rpi/rpi3/rpi3_bl2_mboot.c``. 113*a2dd13caSAbhi Singh 114*a2dd13caSAbhi Singh 115*a2dd13caSAbhi Singh*Copyright (c) 2025, Arm Limited. All rights reserved.* 116*a2dd13caSAbhi Singh 117*a2dd13caSAbhi Singh.. |rpi3 dtpm driver stack| image:: 118*a2dd13caSAbhi Singh ../resources/diagrams/rpi3_dtpm_driver.png 119*a2dd13caSAbhi Singh.. _TCG TPM 2.0 Library Specification: https://trustedcomputinggroup.org/resource/tpm-library-specification/ 120