Skip to content

Commit

Permalink
SecureBootVariableProvisionLib.c: fix typo in debug log
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Król <[email protected]>
  • Loading branch information
pietrushnic committed Oct 26, 2023
1 parent 481a292 commit 3c3f7e3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
74 changes: 73 additions & 1 deletion OvmfPkg/PlatformPei/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,71 @@ MiscInitialization (
}
}

EFI_STATUS
ValidateFvHeader (
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader
)
/*++
Routine Description:
Check the integrity of firmware volume header
Arguments:
FwVolHeader - A pointer to a firmware volume header
Returns:
EFI_SUCCESS - The firmware volume is consistent
EFI_NOT_FOUND - The firmware volume has corrupted. So it is not an
FV
--*/
{
UINT16 Checksum;

//
// Verify the header revision, header signature, length
// Length of FvBlock cannot be 2**64-1
// HeaderLength cannot be an odd number
//
if ((FwVolHeader->Revision != EFI_FVH_REVISION) ||
(FwVolHeader->Signature != EFI_FVH_SIGNATURE) ||
(FwVolHeader->FvLength == ((UINTN) -1)) ||
((FwVolHeader->HeaderLength & 0x01) != 0)
) {
return EFI_NOT_FOUND;
}

//
// Verify the header checksum
//

Checksum = CalculateSum16 ((UINT16 *) FwVolHeader,
FwVolHeader->HeaderLength);
if (Checksum != 0) {
UINT16 Expected;

Expected =
(UINT16) (((UINTN) FwVolHeader->Checksum + 0x10000 - Checksum) & 0xffff);

DEBUG ((EFI_D_INFO, "FV@%p Checksum is 0x%x, expected 0x%x\n",
FwVolHeader, FwVolHeader->Checksum, Expected));
return EFI_NOT_FOUND;
}

return EFI_SUCCESS;
}

VOID
BootModeInitialization (
VOID
)
{
EFI_STATUS Status;
EFI_STATUS Status;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;

FwVolHeader =
(EFI_FIRMWARE_VOLUME_HEADER *) (UINTN)
PcdGet32 (PcdOvmfFlashNvStorageVariableBase);

if (CmosRead8 (0xF) == 0xFE) {
mBootMode = BOOT_ON_S3_RESUME;
Expand All @@ -470,6 +528,20 @@ BootModeInitialization (

Status = PeiServicesInstallPpi (mPpiBootMode);
ASSERT_EFI_ERROR (Status);

//
// Create guid hob for SMMSTORE
//
Status = ValidateFvHeader (FwVolHeader);
if (EFI_ERROR (Status)) {
Status = PeiServicesSetBootMode (BOOT_WITH_DEFAULT_SETTINGS);
DEBUG ((DEBUG_INFO, "BootMode: Boot with default settings\n"));
ASSERT_EFI_ERROR (Status);
} else {
Status = PeiServicesSetBootMode (BOOT_ASSUMING_NO_CONFIGURATION_CHANGES);
DEBUG ((DEBUG_INFO, "BootMode: Boot boot assuming no configuration changes\n"));
ASSERT_EFI_ERROR (Status);
}
}


Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/PlatformPei/PlatformPei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
PcdLib

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ EnrollFromDefault (
DataSize = 0;
Status = GetVariable2 (DefaultName, &gEfiGlobalVariableGuid, &Data, &DataSize);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "error: GetVariable (\"%s): %r\n", DefaultName, Status));
DEBUG ((DEBUG_ERROR, "error: GetVariable (\"%s\"): %r\n", DefaultName, Status));
return Status;
}

Expand Down

0 comments on commit 3c3f7e3

Please sign in to comment.