VirtualBox

Ignore:
Timestamp:
Mar 12, 2019 12:40:12 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
129295
Message:

EFI: First step in UDK2018 merge. Does not build yet.

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/PeiHobLib/HobLib.c

    r58466 r77662  
    22  Provide Hob Library functions for Pei phase.
    33
    4 Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
     4Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
    55This program and the accompanying materials
    66are licensed and made available under the terms and conditions of the BSD License
     
    475475
    476476/**
     477  Check FV alignment.
     478
     479  @param  BaseAddress   The base address of the Firmware Volume.
     480  @param  Length        The size of the Firmware Volume in bytes.
     481
     482  @retval TRUE          FvImage buffer is at its required alignment.
     483  @retval FALSE         FvImage buffer is not at its required alignment.
     484
     485**/
     486BOOLEAN
     487InternalCheckFvAlignment (
     488  IN EFI_PHYSICAL_ADDRESS       BaseAddress,
     489  IN UINT64                     Length
     490  )
     491{
     492  EFI_FIRMWARE_VOLUME_HEADER    *FwVolHeader;
     493  UINT32                        FvAlignment;
     494
     495  FvAlignment = 0;
     496  FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;
     497
     498  //
     499  // If EFI_FVB2_WEAK_ALIGNMENT is set in the volume header then the first byte of the volume
     500  // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from
     501  // its initial linked location and maintain its alignment.
     502  //
     503  if ((FwVolHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) {
     504    //
     505    // Get FvHeader alignment
     506    //
     507    FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);
     508    //
     509    // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
     510    //
     511    if (FvAlignment < 8) {
     512      FvAlignment = 8;
     513    }
     514    if ((UINTN)BaseAddress % FvAlignment != 0) {
     515      //
     516      // FvImage buffer is not at its required alignment.
     517      //
     518      DEBUG ((
     519        DEBUG_ERROR,
     520        "Unaligned FvImage found at 0x%lx:0x%lx, the required alignment is 0x%x\n",
     521        BaseAddress,
     522        Length,
     523        FvAlignment
     524        ));
     525      return FALSE;
     526    }
     527  }
     528
     529  return TRUE;
     530}
     531
     532/**
    477533  Builds a Firmware Volume HOB.
    478534
     
    482538
    483539  If there is no additional space for HOB creation, then ASSERT().
     540  If the FvImage buffer is not at its required alignment, then ASSERT().
    484541
    485542  @param  BaseAddress   The base address of the Firmware Volume.
     
    496553  EFI_HOB_FIRMWARE_VOLUME  *Hob;
    497554
     555  if (!InternalCheckFvAlignment (BaseAddress, Length)) {
     556    ASSERT (FALSE);
     557    return;
     558  }
     559
    498560  Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));
    499561  if (Hob == NULL) {
     
    513575
    514576  If there is no additional space for HOB creation, then ASSERT().
     577  If the FvImage buffer is not at its required alignment, then ASSERT().
    515578
    516579  @param  BaseAddress   The base address of the Firmware Volume.
     
    531594  EFI_HOB_FIRMWARE_VOLUME2  *Hob;
    532595
     596  if (!InternalCheckFvAlignment (BaseAddress, Length)) {
     597    ASSERT (FALSE);
     598    return;
     599  }
     600
    533601  Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));
    534602  if (Hob == NULL) {
     
    543611
    544612/**
     613  Builds a EFI_HOB_TYPE_FV3 HOB.
     614
     615  This function builds a EFI_HOB_TYPE_FV3 HOB.
     616  It can only be invoked during PEI phase;
     617  for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
     618
     619  If there is no additional space for HOB creation, then ASSERT().
     620  If the FvImage buffer is not at its required alignment, then ASSERT().
     621
     622  @param BaseAddress            The base address of the Firmware Volume.
     623  @param Length                 The size of the Firmware Volume in bytes.
     624  @param AuthenticationStatus   The authentication status.
     625  @param ExtractedFv            TRUE if the FV was extracted as a file within
     626                                another firmware volume. FALSE otherwise.
     627  @param FvName                 The name of the Firmware Volume.
     628                                Valid only if IsExtractedFv is TRUE.
     629  @param FileName               The name of the file.
     630                                Valid only if IsExtractedFv is TRUE.
     631
     632**/
     633VOID
     634EFIAPI
     635BuildFv3Hob (
     636  IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
     637  IN          UINT64                      Length,
     638  IN          UINT32                      AuthenticationStatus,
     639  IN          BOOLEAN                     ExtractedFv,
     640  IN CONST    EFI_GUID                    *FvName, OPTIONAL
     641  IN CONST    EFI_GUID                    *FileName OPTIONAL
     642  )
     643{
     644  EFI_HOB_FIRMWARE_VOLUME3  *Hob;
     645
     646  if (!InternalCheckFvAlignment (BaseAddress, Length)) {
     647    ASSERT (FALSE);
     648    return;
     649  }
     650
     651  Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV3, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME3));
     652  if (Hob == NULL) {
     653    return;
     654  }
     655
     656  Hob->BaseAddress          = BaseAddress;
     657  Hob->Length               = Length;
     658  Hob->AuthenticationStatus = AuthenticationStatus;
     659  Hob->ExtractedFv          = ExtractedFv;
     660  if (ExtractedFv) {
     661    CopyGuid (&Hob->FvName, FvName);
     662    CopyGuid (&Hob->FileName, FileName);
     663  }
     664}
     665
     666/**
    545667  Builds a Capsule Volume HOB.
    546668
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette