2 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
3 SPDX-License-Identifier: BSD-2-Clause-Patent
7 #include <Library/BaseLib.h>
8 #include <Library/BaseMemoryLib.h>
9 #include <Library/DebugLib.h>
10 #include <IndustryStandard/Tpm20.h>
11 #include <IndustryStandard/UefiTcgPlatform.h>
12 #include <Library/HobLib.h>
13 #include <Library/PrintLib.h>
14 #include <Library/TcgEventLogRecordLib.h>
15 #include <Library/TpmMeasurementLib.h>
17 #include "PeilessStartupInternal.h"
21 #define HANDOFF_TABLE_DESC "TdxTable"
23 UINT8 TableDescriptionSize
;
24 UINT8 TableDescription
[sizeof (HANDOFF_TABLE_DESC
)];
25 UINT64 NumberOfTables
;
26 EFI_CONFIGURATION_TABLE TableEntry
[1];
27 } TDX_HANDOFF_TABLE_POINTERS2
;
31 #define FV_HANDOFF_TABLE_DESC "Fv(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)"
32 typedef PLATFORM_FIRMWARE_BLOB2_STRUCT CFV_HANDOFF_TABLE_POINTERS2
;
35 Measure the Hoblist passed from the VMM.
37 @param[in] VmmHobList The Hoblist pass the firmware
39 @retval EFI_SUCCESS Fv image is measured successfully
40 or it has been already measured.
41 @retval Others Other errors as indicated
46 IN CONST VOID
*VmmHobList
49 EFI_PEI_HOB_POINTERS Hob
;
50 TDX_HANDOFF_TABLE_POINTERS2 HandoffTables
;
53 if (!TdIsEnabled ()) {
55 return EFI_UNSUPPORTED
;
58 Hob
.Raw
= (UINT8
*)VmmHobList
;
61 // Parse the HOB list until end of list.
63 while (!END_OF_HOB_LIST (Hob
)) {
64 Hob
.Raw
= GET_NEXT_HOB (Hob
);
68 // Init the log event for HOB measurement
71 HandoffTables
.TableDescriptionSize
= sizeof (HandoffTables
.TableDescription
);
72 CopyMem (HandoffTables
.TableDescription
, HANDOFF_TABLE_DESC
, sizeof (HandoffTables
.TableDescription
));
73 HandoffTables
.NumberOfTables
= 1;
74 CopyGuid (&(HandoffTables
.TableEntry
[0].VendorGuid
), &gUefiOvmfPkgTokenSpaceGuid
);
75 HandoffTables
.TableEntry
[0].VendorTable
= (VOID
*)VmmHobList
;
77 Status
= TpmMeasureAndLogData (
79 EV_EFI_HANDOFF_TABLES2
, // EventType
80 (VOID
*)&HandoffTables
, // EventData
81 sizeof (HandoffTables
), // EventSize
82 (UINT8
*)(UINTN
)VmmHobList
, // HashData
83 (UINTN
)((UINT8
*)Hob
.Raw
- (UINT8
*)VmmHobList
) // HashDataLen
86 if (EFI_ERROR (Status
)) {
94 Get the FvName from the FV header.
96 Causion: The FV is untrusted input.
98 @param[in] FvBase Base address of FV image.
99 @param[in] FvLength Length of FV image.
101 @return FvName pointer
102 @retval NULL FvName is NOT found
106 IN EFI_PHYSICAL_ADDRESS FvBase
,
110 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
111 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FvExtHeader
;
113 if (FvBase
>= MAX_ADDRESS
) {
117 if (FvLength
>= MAX_ADDRESS
- FvBase
) {
121 if (FvLength
< sizeof (EFI_FIRMWARE_VOLUME_HEADER
)) {
125 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvBase
;
126 if (FvHeader
->ExtHeaderOffset
< sizeof (EFI_FIRMWARE_VOLUME_HEADER
)) {
130 if (FvHeader
->ExtHeaderOffset
+ sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER
) > FvLength
) {
134 FvExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(UINTN
)(FvBase
+ FvHeader
->ExtHeaderOffset
);
136 return &FvExtHeader
->FvName
;
142 @param[in] FvBase Base address of FV image.
143 @param[in] FvLength Length of FV image.
144 @param[in] PcrIndex Index of PCR
146 @retval EFI_SUCCESS Fv image is measured successfully
147 or it has been already measured.
148 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
149 @retval EFI_DEVICE_ERROR The command was unsuccessful.
155 IN EFI_PHYSICAL_ADDRESS FvBase
,
161 CFV_HANDOFF_TABLE_POINTERS2 FvBlob2
;
165 // Init the log event for FV measurement
167 FvBlob2
.BlobDescriptionSize
= sizeof (FvBlob2
.BlobDescription
);
168 CopyMem (FvBlob2
.BlobDescription
, FV_HANDOFF_TABLE_DESC
, sizeof (FvBlob2
.BlobDescription
));
169 FvName
= GetFvName (FvBase
, FvLength
);
170 if (FvName
!= NULL
) {
171 AsciiSPrint ((CHAR8
*)FvBlob2
.BlobDescription
, sizeof (FvBlob2
.BlobDescription
), "Fv(%g)", FvName
);
174 FvBlob2
.BlobBase
= FvBase
;
175 FvBlob2
.BlobLength
= FvLength
;
177 Status
= TpmMeasureAndLogData (
179 EV_EFI_PLATFORM_FIRMWARE_BLOB2
, // EventType
180 (VOID
*)&FvBlob2
, // EventData
181 sizeof (FvBlob2
), // EventSize
182 (UINT8
*)(UINTN
)FvBase
, // HashData
183 (UINTN
)(FvLength
) // HashDataLen
186 if (EFI_ERROR (Status
)) {
187 DEBUG ((DEBUG_ERROR
, "The FV which failed to be measured starts at: 0x%x\n", FvBase
));