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"
19 #define FV_HANDOFF_TABLE_DESC "Fv(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)"
20 typedef PLATFORM_FIRMWARE_BLOB2_STRUCT CFV_HANDOFF_TABLE_POINTERS2
;
23 Get the FvName from the FV header.
25 Causion: The FV is untrusted input.
27 @param[in] FvBase Base address of FV image.
28 @param[in] FvLength Length of FV image.
30 @return FvName pointer
31 @retval NULL FvName is NOT found
35 IN EFI_PHYSICAL_ADDRESS FvBase
,
39 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
40 EFI_FIRMWARE_VOLUME_EXT_HEADER
*FvExtHeader
;
42 if (FvBase
>= MAX_ADDRESS
) {
46 if (FvLength
>= MAX_ADDRESS
- FvBase
) {
50 if (FvLength
< sizeof (EFI_FIRMWARE_VOLUME_HEADER
)) {
54 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)FvBase
;
55 if (FvHeader
->ExtHeaderOffset
< sizeof (EFI_FIRMWARE_VOLUME_HEADER
)) {
59 if (FvHeader
->ExtHeaderOffset
+ sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER
) > FvLength
) {
63 FvExtHeader
= (EFI_FIRMWARE_VOLUME_EXT_HEADER
*)(UINTN
)(FvBase
+ FvHeader
->ExtHeaderOffset
);
65 return &FvExtHeader
->FvName
;
71 @param[in] FvBase Base address of FV image.
72 @param[in] FvLength Length of FV image.
73 @param[in] PcrIndex Index of PCR
75 @retval EFI_SUCCESS Fv image is measured successfully
76 or it has been already measured.
77 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
78 @retval EFI_DEVICE_ERROR The command was unsuccessful.
84 IN EFI_PHYSICAL_ADDRESS FvBase
,
90 CFV_HANDOFF_TABLE_POINTERS2 FvBlob2
;
94 // Init the log event for FV measurement
96 FvBlob2
.BlobDescriptionSize
= sizeof (FvBlob2
.BlobDescription
);
97 CopyMem (FvBlob2
.BlobDescription
, FV_HANDOFF_TABLE_DESC
, sizeof (FvBlob2
.BlobDescription
));
98 FvName
= GetFvName (FvBase
, FvLength
);
100 AsciiSPrint ((CHAR8
*)FvBlob2
.BlobDescription
, sizeof (FvBlob2
.BlobDescription
), "Fv(%g)", FvName
);
103 FvBlob2
.BlobBase
= FvBase
;
104 FvBlob2
.BlobLength
= FvLength
;
106 Status
= TpmMeasureAndLogData (
108 EV_EFI_PLATFORM_FIRMWARE_BLOB2
, // EventType
109 (VOID
*)&FvBlob2
, // EventData
110 sizeof (FvBlob2
), // EventSize
111 (UINT8
*)(UINTN
)FvBase
, // HashData
112 (UINTN
)(FvLength
) // HashDataLen
115 if (EFI_ERROR (Status
)) {
116 DEBUG ((DEBUG_ERROR
, "The FV which failed to be measured starts at: 0x%x\n", FvBase
));