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