xref: /arm-trusted-firmware/docs/design_documents/measured_boot_poc.rst (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700SchasingluluInteraction between Measured Boot and an fTPM (PoC)
2*91f16700Schasinglulu===================================================
3*91f16700Schasinglulu
4*91f16700SchasingluluMeasured Boot is the process of cryptographically measuring the code and
5*91f16700Schasinglulucritical data used at boot time, for example using a TPM, so that the
6*91f16700Schasinglulusecurity state can be attested later.
7*91f16700Schasinglulu
8*91f16700SchasingluluThe current implementation of the driver included in |TF-A| supports several
9*91f16700Schasinglulubackends and each has a different means to store the measurements.
10*91f16700SchasingluluThis section focuses on the `TCG event log`_ backend, which stores measurements
11*91f16700Schasingluluin secure memory.
12*91f16700Schasinglulu
13*91f16700SchasingluluSee details of :ref:`Measured Boot Design`.
14*91f16700Schasinglulu
15*91f16700SchasingluluThe driver also provides mechanisms to pass the Event Log to normal world if
16*91f16700Schasingluluneeded.
17*91f16700Schasinglulu
18*91f16700SchasingluluThis manual provides instructions to build a proof of concept (PoC) with the
19*91f16700Schasinglulusole intention of showing how Measured Boot can be used in conjunction with
20*91f16700Schasinglulua firmware TPM (fTPM) service implemented on top of OP-TEE.
21*91f16700Schasinglulu
22*91f16700Schasinglulu.. note::
23*91f16700Schasinglulu   The instructions given in this document are meant to be used to build
24*91f16700Schasinglulu   a PoC to show how Measured Boot on TF-A can interact with a third
25*91f16700Schasinglulu   party (f)TPM service and they try to be as general as possible. Different
26*91f16700Schasinglulu   platforms might have different needs and configurations (e.g. different
27*91f16700Schasinglulu   SHA algorithms) and they might also use different types of TPM services
28*91f16700Schasinglulu   (or even a different type of service to provide the attestation)
29*91f16700Schasinglulu   and therefore the instructions given here might not apply in such scenarios.
30*91f16700Schasinglulu
31*91f16700SchasingluluComponents
32*91f16700Schasinglulu~~~~~~~~~~
33*91f16700Schasinglulu
34*91f16700SchasingluluThe PoC is built on top of the `OP-TEE Toolkit`_, which has support to build
35*91f16700SchasingluluTF-A with support for Measured Boot enabled (and run it on a Foundation Model)
36*91f16700Schasinglulusince commit cf56848.
37*91f16700Schasinglulu
38*91f16700SchasingluluThe aforementioned toolkit builds a set of images that contain all the components
39*91f16700Schasingluluneeded to test that the Event Log was properly created. One of these images will
40*91f16700Schasinglulucontain a third party fTPM service which in turn will be used to process the
41*91f16700SchasingluluEvent Log.
42*91f16700Schasinglulu
43*91f16700SchasingluluThe reason to choose OP-TEE Toolkit to build our PoC around it is mostly
44*91f16700Schasinglulufor convenience. As the fTPM service used is an OP-TEE TA, it was easy to add
45*91f16700Schasinglulubuild support for it to the toolkit and then build the PoC around it.
46*91f16700Schasinglulu
47*91f16700SchasingluluThe most relevant components installed in the image that are closely related to
48*91f16700SchasingluluMeasured Boot/fTPM functionality are:
49*91f16700Schasinglulu
50*91f16700Schasinglulu   - **OP-TEE**: As stated earlier, the fTPM service used in this PoC is built as an
51*91f16700Schasinglulu     OP-TEE TA and therefore we need to include the OP-TEE OS image.
52*91f16700Schasinglulu     Support to interfacing with Measured Boot was added to version 3.9.0 of
53*91f16700Schasinglulu     OP-TEE by implementing the ``PTA_SYSTEM_GET_TPM_EVENT_LOG`` syscall, which
54*91f16700Schasinglulu     allows the former to pass a copy of the Event Log to any TA requesting it.
55*91f16700Schasinglulu     OP-TEE knows the location of the Event Log by reading the DTB bindings
56*91f16700Schasinglulu     received from TF-A. Visit :ref:`DTB binding for Event Log properties`
57*91f16700Schasinglulu     for more details on this.
58*91f16700Schasinglulu
59*91f16700Schasinglulu   - **fTPM Service**: We use a third party fTPM service in order to validate
60*91f16700Schasinglulu     the Measured Boot functionality. The chosen fTPM service is a sample
61*91f16700Schasinglulu     implementation for Aarch32 architecture included on the `ms-tpm-20-ref`_
62*91f16700Schasinglulu     reference implementation from Microsoft. The service was updated in order
63*91f16700Schasinglulu     to extend the Measured Boot Event Log at boot up and it uses the
64*91f16700Schasinglulu     aforementioned ``PTA_SYSTEM_GET_TPM_EVENT_LOG`` call to retrieve a copy
65*91f16700Schasinglulu     of the former.
66*91f16700Schasinglulu
67*91f16700Schasinglulu   .. note::
68*91f16700Schasinglulu      Arm does not provide an fTPM implementation. The fTPM service used here
69*91f16700Schasinglulu      is a third party one which has been updated to support Measured Boot
70*91f16700Schasinglulu      service as provided by TF-A. As such, it is beyond the scope of this
71*91f16700Schasinglulu      manual to test and verify the correctness of the output generated by the
72*91f16700Schasinglulu      fTPM service.
73*91f16700Schasinglulu
74*91f16700Schasinglulu   - **TPM Kernel module**: In order to interact with the fTPM service, we need
75*91f16700Schasinglulu     a kernel module to forward the request from user space to the secure world.
76*91f16700Schasinglulu
77*91f16700Schasinglulu   - `tpm2-tools`_: This is a set of tools that allow to interact with the
78*91f16700Schasinglulu     fTPM service. We use this in order to read the PCRs with the measurements.
79*91f16700Schasinglulu
80*91f16700SchasingluluBuilding the PoC for the Arm FVP platform
81*91f16700Schasinglulu~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82*91f16700Schasinglulu
83*91f16700SchasingluluAs mentioned before, this PoC is based on the OP-TEE Toolkit with some
84*91f16700Schasingluluextensions to enable Measured Boot and an fTPM service. Therefore, we can rely
85*91f16700Schasingluluon the instructions to build the original OP-TEE Toolkit. As a general rule,
86*91f16700Schasingluluthe following steps should suffice:
87*91f16700Schasinglulu
88*91f16700Schasinglulu(1) Start by following the `Get and build the solution`_ instructions to build
89*91f16700Schasinglulu    the OP-TEE toolkit. On step 3, you need to get the manifest for FVP
90*91f16700Schasinglulu    platform from the main branch:
91*91f16700Schasinglulu
92*91f16700Schasinglulu    .. code:: shell
93*91f16700Schasinglulu
94*91f16700Schasinglulu       $ repo init -u https://github.com/OP-TEE/manifest.git -m fvp.xml
95*91f16700Schasinglulu
96*91f16700Schasinglulu    Then proceed synching the repos as stated in step 3. Continue following
97*91f16700Schasinglulu    the instructions and stop before step 5.
98*91f16700Schasinglulu
99*91f16700Schasinglulu(2) Next you should obtain the `Armv8-A Foundation Platform (For Linux Hosts Only)`_.
100*91f16700Schasinglulu    The binary should be untar'ed to the root of the repo tree, i.e., like
101*91f16700Schasinglulu    this: ``<fvp-project>/Foundation_Platformpkg``. In the end, after cloning
102*91f16700Schasinglulu    all source code, getting the toolchains and "installing"
103*91f16700Schasinglulu    Foundation_Platformpkg, you should have a folder structure that looks like
104*91f16700Schasinglulu    this:
105*91f16700Schasinglulu
106*91f16700Schasinglulu    .. code:: shell
107*91f16700Schasinglulu
108*91f16700Schasinglulu       $ ls -la
109*91f16700Schasinglulu       total 80
110*91f16700Schasinglulu       drwxrwxr-x 20 tf-a_user tf-a_user 4096 Jul  1 12:16 .
111*91f16700Schasinglulu       drwxr-xr-x 23 tf-a_user tf-a_user 4096 Jul  1 10:40 ..
112*91f16700Schasinglulu       drwxrwxr-x 12 tf-a_user tf-a_user 4096 Jul  1 10:45 build
113*91f16700Schasinglulu       drwxrwxr-x 16 tf-a_user tf-a_user 4096 Jul  1 12:16 buildroot
114*91f16700Schasinglulu       drwxrwxr-x 51 tf-a_user tf-a_user 4096 Jul  1 10:45 edk2
115*91f16700Schasinglulu       drwxrwxr-x  6 tf-a_user tf-a_user 4096 Jul  1 12:14 edk2-platforms
116*91f16700Schasinglulu       drwxr-xr-x  7 tf-a_user tf-a_user 4096 Jul  1 10:52 Foundation_Platformpkg
117*91f16700Schasinglulu       drwxrwxr-x 17 tf-a_user tf-a_user 4096 Jul  2 10:40 grub
118*91f16700Schasinglulu       drwxrwxr-x 25 tf-a_user tf-a_user 4096 Jul  2 10:39 linux
119*91f16700Schasinglulu       drwxrwxr-x 15 tf-a_user tf-a_user 4096 Jul  1 10:45 mbedtls
120*91f16700Schasinglulu       drwxrwxr-x  6 tf-a_user tf-a_user 4096 Jul  1 10:45 ms-tpm-20-ref
121*91f16700Schasinglulu       drwxrwxr-x  8 tf-a_user tf-a_user 4096 Jul  1 10:45 optee_client
122*91f16700Schasinglulu       drwxrwxr-x 10 tf-a_user tf-a_user 4096 Jul  1 10:45 optee_examples
123*91f16700Schasinglulu       drwxrwxr-x 12 tf-a_user tf-a_user 4096 Jul  1 12:13 optee_os
124*91f16700Schasinglulu       drwxrwxr-x  8 tf-a_user tf-a_user 4096 Jul  1 10:45 optee_test
125*91f16700Schasinglulu       drwxrwxr-x  7 tf-a_user tf-a_user 4096 Jul  1 10:45 .repo
126*91f16700Schasinglulu       drwxrwxr-x  4 tf-a_user tf-a_user 4096 Jul  1 12:12 toolchains
127*91f16700Schasinglulu       drwxrwxr-x 21 tf-a_user tf-a_user 4096 Jul  1 12:15 trusted-firmware-a
128*91f16700Schasinglulu
129*91f16700Schasinglulu(3) Now enter into ``ms-tpm-20-ref`` and get its dependencies:
130*91f16700Schasinglulu
131*91f16700Schasinglulu   .. code:: shell
132*91f16700Schasinglulu
133*91f16700Schasinglulu      $ cd ms-tpm-20-ref
134*91f16700Schasinglulu      $ git submodule init
135*91f16700Schasinglulu      $ git submodule update
136*91f16700Schasinglulu      Submodule path 'external/wolfssl': checked out '9c87f979a7f1d3a6d786b260653d566c1d31a1c4'
137*91f16700Schasinglulu
138*91f16700Schasinglulu(4) Now, you should be able to continue with step 5 in "`Get and build the solution`_"
139*91f16700Schasinglulu    instructions. In order to enable support for Measured Boot, you need to
140*91f16700Schasinglulu    set the following build options:
141*91f16700Schasinglulu
142*91f16700Schasinglulu    .. code:: shell
143*91f16700Schasinglulu
144*91f16700Schasinglulu       $ MEASURED_BOOT=y MEASURED_BOOT_FTPM=y make -j `nproc`
145*91f16700Schasinglulu
146*91f16700Schasinglulu    .. note::
147*91f16700Schasinglulu       The build process will likely take a long time. It is strongly recommended to
148*91f16700Schasinglulu       pass the ``-j`` option to make to run the process faster.
149*91f16700Schasinglulu
150*91f16700Schasinglulu   After this step, you should be ready to run the image.
151*91f16700Schasinglulu
152*91f16700SchasingluluRunning and using the PoC on the Armv8-A Foundation AEM FVP
153*91f16700Schasinglulu~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154*91f16700Schasinglulu
155*91f16700SchasingluluWith everything built, you can now run the image:
156*91f16700Schasinglulu
157*91f16700Schasinglulu.. code:: shell
158*91f16700Schasinglulu
159*91f16700Schasinglulu   $ make run-only
160*91f16700Schasinglulu
161*91f16700Schasinglulu.. note::
162*91f16700Schasinglulu   Using ``make run`` will build and run the image and it can be used instead
163*91f16700Schasinglulu   of simply ``make``. However, once the image is built, it is recommended to
164*91f16700Schasinglulu   use ``make run-only`` to avoid re-running all the building rules, which
165*91f16700Schasinglulu   would take time.
166*91f16700Schasinglulu
167*91f16700SchasingluluWhen FVP is launched, two terminal windows will appear. ``FVP terminal_0``
168*91f16700Schasingluluis the userspace terminal whereas ``FVP terminal_1`` is the counterpart for
169*91f16700Schasingluluthe secure world (where TAs will print their logs, for instance).
170*91f16700Schasinglulu
171*91f16700SchasingluluLog into the image shell with user ``root``, no password will be required.
172*91f16700SchasingluluThen we can issue the ``ftpm`` command, which is an alias that
173*91f16700Schasinglulu
174*91f16700Schasinglulu(1) loads the ftpm kernel module and
175*91f16700Schasinglulu
176*91f16700Schasinglulu(2) calls ``tpm2_pcrread``, which will access the fTPM service to read the
177*91f16700Schasinglulu    PCRs.
178*91f16700Schasinglulu
179*91f16700SchasingluluWhen loading the ftpm kernel module, the fTPM TA is loaded into the secure
180*91f16700Schasingluluworld. This TA then requests a copy of the Event Log generated during the
181*91f16700Schasinglulubooting process so it can retrieve all the entries on the log and record them
182*91f16700Schasinglulufirst thing.
183*91f16700Schasinglulu
184*91f16700Schasinglulu.. note::
185*91f16700Schasinglulu   For this PoC, nothing loaded after BL33 and NT_FW_CONFIG is recorded
186*91f16700Schasinglulu   in the Event Log.
187*91f16700Schasinglulu
188*91f16700SchasingluluThe secure world terminal should show the debug logs for the fTPM service,
189*91f16700Schasingluluincluding all the measurements available in the Event Log as they are being
190*91f16700Schasingluluprocessed:
191*91f16700Schasinglulu
192*91f16700Schasinglulu.. code:: shell
193*91f16700Schasinglulu
194*91f16700Schasinglulu	M/TA: Preparing to extend the following TPM Event Log:
195*91f16700Schasinglulu	M/TA: TCG_EfiSpecIDEvent:
196*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
197*91f16700Schasinglulu	M/TA:   EventType          : 3
198*91f16700Schasinglulu	M/TA:   Digest             : 00
199*91f16700Schasinglulu	M/TA: 			   : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
200*91f16700Schasinglulu	M/TA: 			   : 00 00 00
201*91f16700Schasinglulu	M/TA:   EventSize          : 33
202*91f16700Schasinglulu	M/TA:   Signature          : Spec ID Event03
203*91f16700Schasinglulu	M/TA:   PlatformClass      : 0
204*91f16700Schasinglulu	M/TA:   SpecVersion        : 2.0.2
205*91f16700Schasinglulu	M/TA:   UintnSize          : 1
206*91f16700Schasinglulu	M/TA:   NumberOfAlgorithms : 1
207*91f16700Schasinglulu	M/TA:   DigestSizes        :
208*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
209*91f16700Schasinglulu	M/TA:        DigestSize    : 32
210*91f16700Schasinglulu	M/TA:   VendorInfoSize     : 0
211*91f16700Schasinglulu	M/TA: PCR_Event2:
212*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
213*91f16700Schasinglulu	M/TA:   EventType          : 3
214*91f16700Schasinglulu	M/TA:   Digests Count      : 1
215*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
216*91f16700Schasinglulu	M/TA:        Digest        : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
217*91f16700Schasinglulu	M/TA: 			   : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
218*91f16700Schasinglulu	M/TA:   EventSize          : 17
219*91f16700Schasinglulu	M/TA:   Signature          : StartupLocality
220*91f16700Schasinglulu	M/TA:   StartupLocality    : 0
221*91f16700Schasinglulu	M/TA: PCR_Event2:
222*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
223*91f16700Schasinglulu	M/TA:   EventType          : 1
224*91f16700Schasinglulu	M/TA:   Digests Count      : 1
225*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
226*91f16700Schasinglulu	M/TA:        Digest        : 58 26 32 6e 64 45 64 da 45 de 35 db 96 fd ed 63
227*91f16700Schasinglulu	M/TA: 			   : 2a 6a d4 0d aa 94 b0 b1 55 e4 72 e7 1f 0a e0 d5
228*91f16700Schasinglulu	M/TA:   EventSize          : 5
229*91f16700Schasinglulu	M/TA:   Event              : BL_2
230*91f16700Schasinglulu	M/TA: PCR_Event2:
231*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
232*91f16700Schasinglulu	M/TA:   EventType          : 1
233*91f16700Schasinglulu	M/TA:   Digests Count      : 1
234*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
235*91f16700Schasinglulu	M/TA:        Digest        : cf f9 7d a3 5c 73 ac cb 7b a0 25 80 6a 6e 50 a5
236*91f16700Schasinglulu	M/TA: 			   : 6b 2e d2 8c c9 36 92 7d 46 c5 b9 c3 a4 6c 51 7c
237*91f16700Schasinglulu	M/TA:   EventSize          : 6
238*91f16700Schasinglulu	M/TA:   Event              : BL_31
239*91f16700Schasinglulu	M/TA: PCR_Event2:
240*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
241*91f16700Schasinglulu	M/TA:   EventType          : 1
242*91f16700Schasinglulu	M/TA:   Digests Count      : 1
243*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
244*91f16700Schasinglulu	M/TA:        Digest        : 23 b0 a3 5d 54 d9 43 1a 5c b9 89 63 1c da 06 c2
245*91f16700Schasinglulu	M/TA: 			   : e5 de e7 7e 99 17 52 12 7d f7 45 ca 4f 4a 39 c0
246*91f16700Schasinglulu	M/TA:   EventSize          : 10
247*91f16700Schasinglulu	M/TA:   Event              : HW_CONFIG
248*91f16700Schasinglulu	M/TA: PCR_Event2:
249*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
250*91f16700Schasinglulu	M/TA:   EventType          : 1
251*91f16700Schasinglulu	M/TA:   Digests Count      : 1
252*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
253*91f16700Schasinglulu	M/TA:        Digest        : 4e e4 8e 5a e6 50 ed e0 b5 a3 54 8a 1f d6 0e 8a
254*91f16700Schasinglulu	M/TA: 			   : ea 0e 71 75 0e a4 3f 82 76 ce af cd 7c b0 91 e0
255*91f16700Schasinglulu	M/TA:   EventSize          : 14
256*91f16700Schasinglulu	M/TA:   Event              : SOC_FW_CONFIG
257*91f16700Schasinglulu	M/TA: PCR_Event2:
258*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
259*91f16700Schasinglulu	M/TA:   EventType          : 1
260*91f16700Schasinglulu	M/TA:   Digests Count      : 1
261*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
262*91f16700Schasinglulu	M/TA:        Digest        : 01 b0 80 47 a1 ce 86 cd df 89 d2 1f 2e fc 6c 22
263*91f16700Schasinglulu	M/TA: 			   : f8 19 ec 6e 1e ec 73 ba 5a be d0 96 e3 5f 6d 75
264*91f16700Schasinglulu	M/TA:   EventSize          : 6
265*91f16700Schasinglulu	M/TA:   Event              : BL_32
266*91f16700Schasinglulu	M/TA: PCR_Event2:
267*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
268*91f16700Schasinglulu	M/TA:   EventType          : 1
269*91f16700Schasinglulu	M/TA:   Digests Count      : 1
270*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
271*91f16700Schasinglulu	M/TA:        Digest        : 5d c6 ef 35 5a 90 81 b4 37 e6 3b 52 da 92 ab 8e
272*91f16700Schasinglulu	M/TA: 			   : d9 6e 93 98 2d 40 87 96 1b 5a a7 ee f1 f4 40 63
273*91f16700Schasinglulu	M/TA:   EventSize          : 18
274*91f16700Schasinglulu	M/TA:   Event              : BL32_EXTRA1_IMAGE
275*91f16700Schasinglulu	M/TA: PCR_Event2:
276*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
277*91f16700Schasinglulu	M/TA:   EventType          : 1
278*91f16700Schasinglulu	M/TA:   Digests Count      : 1
279*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
280*91f16700Schasinglulu	M/TA:        Digest        : 39 b7 13 b9 93 db 32 2f 1b 48 30 eb 2c f2 5c 25
281*91f16700Schasinglulu	M/TA: 			   : 00 0f 38 dc 8e c8 02 cd 79 f2 48 d2 2c 25 ab e2
282*91f16700Schasinglulu	M/TA:   EventSize          : 6
283*91f16700Schasinglulu	M/TA:   Event              : BL_33
284*91f16700Schasinglulu	M/TA: PCR_Event2:
285*91f16700Schasinglulu	M/TA:   PCRIndex           : 0
286*91f16700Schasinglulu	M/TA:   EventType          : 1
287*91f16700Schasinglulu	M/TA:   Digests Count      : 1
288*91f16700Schasinglulu	M/TA:     #0 AlgorithmId   : SHA256
289*91f16700Schasinglulu	M/TA:        Digest        : 25 10 60 5d d4 bc 9d 82 7a 16 9f 8a cc 47 95 a6
290*91f16700Schasinglulu	M/TA: 			   : fd ca a0 c1 2b c9 99 8f 51 20 ff c6 ed 74 68 5a
291*91f16700Schasinglulu	M/TA:   EventSize          : 13
292*91f16700Schasinglulu	M/TA:   Event              : NT_FW_CONFIG
293*91f16700Schasinglulu
294*91f16700SchasingluluThese logs correspond to the measurements stored by TF-A during the measured
295*91f16700Schasingluluboot process and therefore, they should match the logs dumped by the former
296*91f16700Schasingluluduring the boot up process. These can be seen on the terminal_0:
297*91f16700Schasinglulu
298*91f16700Schasinglulu.. code:: shell
299*91f16700Schasinglulu
300*91f16700Schasinglulu	NOTICE:  Booting Trusted Firmware
301*91f16700Schasinglulu	NOTICE:  BL1: v2.5(release):v2.5
302*91f16700Schasinglulu	NOTICE:  BL1: Built : 10:41:20, Jul  2 2021
303*91f16700Schasinglulu	NOTICE:  BL1: Booting BL2
304*91f16700Schasinglulu	NOTICE:  BL2: v2.5(release):v2.5
305*91f16700Schasinglulu	NOTICE:  BL2: Built : 10:41:20, Jul  2 2021
306*91f16700Schasinglulu	NOTICE:  TCG_EfiSpecIDEvent:
307*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
308*91f16700Schasinglulu	NOTICE:    EventType          : 3
309*91f16700Schasinglulu	NOTICE:    Digest             : 00
310*91f16700Schasinglulu	NOTICE:  		      : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
311*91f16700Schasinglulu	NOTICE:  		      : 00 00 00
312*91f16700Schasinglulu	NOTICE:    EventSize          : 33
313*91f16700Schasinglulu	NOTICE:    Signature          : Spec ID Event03
314*91f16700Schasinglulu	NOTICE:    PlatformClass      : 0
315*91f16700Schasinglulu	NOTICE:    SpecVersion        : 2.0.2
316*91f16700Schasinglulu	NOTICE:    UintnSize          : 1
317*91f16700Schasinglulu	NOTICE:    NumberOfAlgorithms : 1
318*91f16700Schasinglulu	NOTICE:    DigestSizes        :
319*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
320*91f16700Schasinglulu	NOTICE:         DigestSize    : 32
321*91f16700Schasinglulu	NOTICE:    VendorInfoSize     : 0
322*91f16700Schasinglulu	NOTICE:  PCR_Event2:
323*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
324*91f16700Schasinglulu	NOTICE:    EventType          : 3
325*91f16700Schasinglulu	NOTICE:    Digests Count      : 1
326*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
327*91f16700Schasinglulu	NOTICE:         Digest        : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
328*91f16700Schasinglulu	NOTICE:  		      : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
329*91f16700Schasinglulu	NOTICE:    EventSize          : 17
330*91f16700Schasinglulu	NOTICE:    Signature          : StartupLocality
331*91f16700Schasinglulu	NOTICE:    StartupLocality    : 0
332*91f16700Schasinglulu	NOTICE:  PCR_Event2:
333*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
334*91f16700Schasinglulu	NOTICE:    EventType          : 1
335*91f16700Schasinglulu	NOTICE:    Digests Count      : 1
336*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
337*91f16700Schasinglulu	NOTICE:         Digest        : 58 26 32 6e 64 45 64 da 45 de 35 db 96 fd ed 63
338*91f16700Schasinglulu	NOTICE:  		      : 2a 6a d4 0d aa 94 b0 b1 55 e4 72 e7 1f 0a e0 d5
339*91f16700Schasinglulu	NOTICE:    EventSize          : 5
340*91f16700Schasinglulu	NOTICE:    Event              : BL_2
341*91f16700Schasinglulu	NOTICE:  PCR_Event2:
342*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
343*91f16700Schasinglulu	NOTICE:    EventType          : 1
344*91f16700Schasinglulu	NOTICE:    Digests Count      : 1
345*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
346*91f16700Schasinglulu	NOTICE:         Digest        : cf f9 7d a3 5c 73 ac cb 7b a0 25 80 6a 6e 50 a5
347*91f16700Schasinglulu	NOTICE:  		      : 6b 2e d2 8c c9 36 92 7d 46 c5 b9 c3 a4 6c 51 7c
348*91f16700Schasinglulu	NOTICE:    EventSize          : 6
349*91f16700Schasinglulu	NOTICE:    Event              : BL_31
350*91f16700Schasinglulu	NOTICE:  PCR_Event2:
351*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
352*91f16700Schasinglulu	NOTICE:    EventType          : 1
353*91f16700Schasinglulu	NOTICE:    Digests Count      : 1
354*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
355*91f16700Schasinglulu	NOTICE:         Digest        : 23 b0 a3 5d 54 d9 43 1a 5c b9 89 63 1c da 06 c2
356*91f16700Schasinglulu	NOTICE:  		      : e5 de e7 7e 99 17 52 12 7d f7 45 ca 4f 4a 39 c0
357*91f16700Schasinglulu	NOTICE:    EventSize          : 10
358*91f16700Schasinglulu	NOTICE:    Event              : HW_CONFIG
359*91f16700Schasinglulu	NOTICE:  PCR_Event2:
360*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
361*91f16700Schasinglulu	NOTICE:    EventType          : 1
362*91f16700Schasinglulu	NOTICE:    Digests Count      : 1
363*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
364*91f16700Schasinglulu	NOTICE:         Digest        : 4e e4 8e 5a e6 50 ed e0 b5 a3 54 8a 1f d6 0e 8a
365*91f16700Schasinglulu	NOTICE:  		      : ea 0e 71 75 0e a4 3f 82 76 ce af cd 7c b0 91 e0
366*91f16700Schasinglulu	NOTICE:    EventSize          : 14
367*91f16700Schasinglulu	NOTICE:    Event              : SOC_FW_CONFIG
368*91f16700Schasinglulu	NOTICE:  PCR_Event2:
369*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
370*91f16700Schasinglulu	NOTICE:    EventType          : 1
371*91f16700Schasinglulu	NOTICE:    Digests Count      : 1
372*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
373*91f16700Schasinglulu	NOTICE:         Digest        : 01 b0 80 47 a1 ce 86 cd df 89 d2 1f 2e fc 6c 22
374*91f16700Schasinglulu	NOTICE:  		      : f8 19 ec 6e 1e ec 73 ba 5a be d0 96 e3 5f 6d 75
375*91f16700Schasinglulu	NOTICE:    EventSize          : 6
376*91f16700Schasinglulu	NOTICE:    Event              : BL_32
377*91f16700Schasinglulu	NOTICE:  PCR_Event2:
378*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
379*91f16700Schasinglulu	NOTICE:    EventType          : 1
380*91f16700Schasinglulu	NOTICE:    Digests Count      : 1
381*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
382*91f16700Schasinglulu	NOTICE:         Digest        : 5d c6 ef 35 5a 90 81 b4 37 e6 3b 52 da 92 ab 8e
383*91f16700Schasinglulu	NOTICE:  		      : d9 6e 93 98 2d 40 87 96 1b 5a a7 ee f1 f4 40 63
384*91f16700Schasinglulu	NOTICE:    EventSize          : 18
385*91f16700Schasinglulu	NOTICE:    Event              : BL32_EXTRA1_IMAGE
386*91f16700Schasinglulu	NOTICE:  PCR_Event2:
387*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
388*91f16700Schasinglulu	NOTICE:    EventType          : 1
389*91f16700Schasinglulu	NOTICE:    Digests Count      : 1
390*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
391*91f16700Schasinglulu	NOTICE:         Digest        : 39 b7 13 b9 93 db 32 2f 1b 48 30 eb 2c f2 5c 25
392*91f16700Schasinglulu	NOTICE:  		      : 00 0f 38 dc 8e c8 02 cd 79 f2 48 d2 2c 25 ab e2
393*91f16700Schasinglulu	NOTICE:    EventSize          : 6
394*91f16700Schasinglulu	NOTICE:    Event              : BL_33
395*91f16700Schasinglulu	NOTICE:  PCR_Event2:
396*91f16700Schasinglulu	NOTICE:    PCRIndex           : 0
397*91f16700Schasinglulu	NOTICE:    EventType          : 1
398*91f16700Schasinglulu	NOTICE:    Digests Count      : 1
399*91f16700Schasinglulu	NOTICE:      #0 AlgorithmId   : SHA256
400*91f16700Schasinglulu	NOTICE:         Digest        : 25 10 60 5d d4 bc 9d 82 7a 16 9f 8a cc 47 95 a6
401*91f16700Schasinglulu	NOTICE:  		      : fd ca a0 c1 2b c9 99 8f 51 20 ff c6 ed 74 68 5a
402*91f16700Schasinglulu	NOTICE:    EventSize          : 13
403*91f16700Schasinglulu	NOTICE:    Event              : NT_FW_CONFIG
404*91f16700Schasinglulu	NOTICE:  BL1: Booting BL31
405*91f16700Schasinglulu	NOTICE:  BL31: v2.5(release):v2.5
406*91f16700Schasinglulu	NOTICE:  BL31: Built : 10:41:20, Jul  2 2021
407*91f16700Schasinglulu
408*91f16700SchasingluluFollowing up with the fTPM startup process, we can see that all the
409*91f16700Schasinglulumeasurements in the Event Log are extended and recorded in the appropriate PCR:
410*91f16700Schasinglulu
411*91f16700Schasinglulu.. code:: shell
412*91f16700Schasinglulu
413*91f16700Schasinglulu	M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
414*91f16700Schasinglulu	M/TA: 	ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
415*91f16700Schasinglulu	M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
416*91f16700Schasinglulu	M/TA: 	ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
417*91f16700Schasinglulu	M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
418*91f16700Schasinglulu	M/TA: 	ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
419*91f16700Schasinglulu	M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
420*91f16700Schasinglulu	M/TA: 	ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
421*91f16700Schasinglulu	M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
422*91f16700Schasinglulu	M/TA: 	ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
423*91f16700Schasinglulu	M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
424*91f16700Schasinglulu	M/TA: 	ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
425*91f16700Schasinglulu	M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
426*91f16700Schasinglulu	M/TA: 	ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
427*91f16700Schasinglulu	M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
428*91f16700Schasinglulu	M/TA: 	ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
429*91f16700Schasinglulu	M/TA: TPM2_PCR_EXTEND_COMMAND returned value:
430*91f16700Schasinglulu	M/TA: 	ret_tag = 0x8002, size = 0x00000013, rc = 0x00000000
431*91f16700Schasinglulu	M/TA: 9 Event logs processed
432*91f16700Schasinglulu
433*91f16700SchasingluluAfter the fTPM TA is loaded, the call to ``insmod`` issued by the ``ftpm``
434*91f16700Schasinglulualias to load the ftpm kernel module returns, and then the TPM PCRs are read
435*91f16700Schasingluluby means of ``tpm_pcrread`` command. Note that we are only interested in the
436*91f16700SchasingluluSHA256 logs here, as this is the algorithm we used on TF-A for the measurements
437*91f16700Schasinglulu(see the field ``AlgorithmId`` on the logs above):
438*91f16700Schasinglulu
439*91f16700Schasinglulu.. code:: shell
440*91f16700Schasinglulu
441*91f16700Schasinglulu	sha256:
442*91f16700Schasinglulu	0 : 0xA6EB3A7417B8CFA9EBA2E7C22AD5A4C03CDB8F3FBDD7667F9C3EF2EA285A8C9F
443*91f16700Schasinglulu	1 : 0x0000000000000000000000000000000000000000000000000000000000000000
444*91f16700Schasinglulu	2 : 0x0000000000000000000000000000000000000000000000000000000000000000
445*91f16700Schasinglulu	3 : 0x0000000000000000000000000000000000000000000000000000000000000000
446*91f16700Schasinglulu	4 : 0x0000000000000000000000000000000000000000000000000000000000000000
447*91f16700Schasinglulu	5 : 0x0000000000000000000000000000000000000000000000000000000000000000
448*91f16700Schasinglulu	6 : 0x0000000000000000000000000000000000000000000000000000000000000000
449*91f16700Schasinglulu	7 : 0x0000000000000000000000000000000000000000000000000000000000000000
450*91f16700Schasinglulu	8 : 0x0000000000000000000000000000000000000000000000000000000000000000
451*91f16700Schasinglulu	9 : 0x0000000000000000000000000000000000000000000000000000000000000000
452*91f16700Schasinglulu	10: 0x0000000000000000000000000000000000000000000000000000000000000000
453*91f16700Schasinglulu	11: 0x0000000000000000000000000000000000000000000000000000000000000000
454*91f16700Schasinglulu	12: 0x0000000000000000000000000000000000000000000000000000000000000000
455*91f16700Schasinglulu	13: 0x0000000000000000000000000000000000000000000000000000000000000000
456*91f16700Schasinglulu	14: 0x0000000000000000000000000000000000000000000000000000000000000000
457*91f16700Schasinglulu	15: 0x0000000000000000000000000000000000000000000000000000000000000000
458*91f16700Schasinglulu	16: 0x0000000000000000000000000000000000000000000000000000000000000000
459*91f16700Schasinglulu	17: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
460*91f16700Schasinglulu	18: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
461*91f16700Schasinglulu	19: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
462*91f16700Schasinglulu	20: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
463*91f16700Schasinglulu	21: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
464*91f16700Schasinglulu	22: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
465*91f16700Schasinglulu	23: 0x0000000000000000000000000000000000000000000000000000000000000000
466*91f16700Schasinglulu
467*91f16700SchasingluluIn this PoC we are only interested in PCR0, which must be non-null. This is
468*91f16700Schasinglulubecause the boot process records all the images in this PCR (see field ``PCRIndex``
469*91f16700Schasingluluon the Event Log above). The rest of the records must be 0 at this point.
470*91f16700Schasinglulu
471*91f16700Schasinglulu.. note::
472*91f16700Schasinglulu   The fTPM service used has support only for 16 PCRs, therefore the content
473*91f16700Schasinglulu   of PCRs above 15 can be ignored.
474*91f16700Schasinglulu
475*91f16700Schasinglulu.. note::
476*91f16700Schasinglulu   As stated earlier, Arm does not provide an fTPM implementation and therefore
477*91f16700Schasinglulu   we do not validate here if the content of PCR0 is correct or not. For this
478*91f16700Schasinglulu   PoC, we are only focused on the fact that the event log could be passed to a third
479*91f16700Schasinglulu   party fTPM and its records were properly extended.
480*91f16700Schasinglulu
481*91f16700SchasingluluFine-tuning the fTPM TA
482*91f16700Schasinglulu~~~~~~~~~~~~~~~~~~~~~~~
483*91f16700Schasinglulu
484*91f16700SchasingluluAs stated earlier, the OP-TEE Toolkit includes support to build a third party fTPM
485*91f16700Schasingluluservice. The build options for this service are tailored for the PoC and defined in
486*91f16700Schasingluluthe build environment variable ``FTPM_FLAGS`` (see ``<toolkit_home>/build/common.mk``)
487*91f16700Schasinglulubut they can be modified if needed to better adapt it to a specific scenario.
488*91f16700Schasinglulu
489*91f16700SchasingluluThe most relevant options for Measured Boot support are:
490*91f16700Schasinglulu
491*91f16700Schasinglulu   - **CFG_TA_DEBUG**: Enables debug logs in the Terminal_1 console.
492*91f16700Schasinglulu   - **CFG_TEE_TA_LOG_LEVEL**: Defines the log level used for the debug messages.
493*91f16700Schasinglulu   - **CFG_TA_MEASURED_BOOT**: Enables support for measured boot on the fTPM.
494*91f16700Schasinglulu   - **CFG_TA_EVENT_LOG_SIZE**: Defines the size, in bytes, of the larger event log that
495*91f16700Schasinglulu     the fTPM is able to store, as this buffer is allocated at build time. This must be at
496*91f16700Schasinglulu     least the same as the size of the event log generated by TF-A. If this build option
497*91f16700Schasinglulu     is not defined, the fTPM falls back to a default value of 1024 bytes, which is enough
498*91f16700Schasinglulu     for this PoC, so this variable is not defined in FTPM_FLAGS.
499*91f16700Schasinglulu
500*91f16700Schasinglulu--------------
501*91f16700Schasinglulu
502*91f16700Schasinglulu*Copyright (c) 2021-2023, Arm Limited. All rights reserved.*
503*91f16700Schasinglulu
504*91f16700Schasinglulu.. _OP-TEE Toolkit: https://github.com/OP-TEE/build
505*91f16700Schasinglulu.. _ms-tpm-20-ref: https://github.com/microsoft/ms-tpm-20-ref
506*91f16700Schasinglulu.. _Get and build the solution: https://optee.readthedocs.io/en/latest/building/gits/build.html#get-and-build-the-solution
507*91f16700Schasinglulu.. _Armv8-A Foundation Platform (For Linux Hosts Only): https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms/arm-ecosystem-models
508*91f16700Schasinglulu.. _tpm2-tools: https://github.com/tpm2-software/tpm2-tools
509*91f16700Schasinglulu.. _TCG event log: https://trustedcomputinggroup.org/resource/tcg-efi-platform-specification/
510