diff options
author | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
---|---|---|
committer | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
commit | b7c51c9cf4864df6aabb99a1ae843becd577237c (patch) | |
tree | eebe9b0d0ca03062955223097e57da84dd618b9a /Core/EM/PeiRamBoot | |
download | zprj-b7c51c9cf4864df6aabb99a1ae843becd577237c.tar.xz |
Diffstat (limited to 'Core/EM/PeiRamBoot')
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBoot.c | 783 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBoot.chm | bin | 0 -> 33976 bytes | |||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBoot.cif | 19 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBoot.dxs | 66 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBoot.h | 162 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBoot.mak | 242 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBoot.sdl | 196 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBootCacheRdy.c | 114 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBootCacheRdy.dxs | 57 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBootDxe.c | 368 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBootFvHook.c | 184 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBootHook.c | 282 | ||||
-rw-r--r-- | Core/EM/PeiRamBoot/PeiRamBootOfbd.c | 185 |
13 files changed, 2658 insertions, 0 deletions
diff --git a/Core/EM/PeiRamBoot/PeiRamBoot.c b/Core/EM/PeiRamBoot/PeiRamBoot.c new file mode 100644 index 0000000..f1c0acd --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBoot.c @@ -0,0 +1,783 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.c 21 8/28/15 3:55a Tristinchou $ +// +// $Revision: 21 $ +// +// $Date: 8/28/15 3:55a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.c $ +// +// 21 8/28/15 3:55a Tristinchou +// [TAG] EIP235157 +// [Category] Improvement +// [Description] Security vulnerability - PeiRamBoot: Should leave cold +// boot optimization only +// +// 20 10/02/14 4:44a Calvinchen +// [TAG] EIP184075 +// [Category] Improvement +// [Description] [HWR]FtRecovery support for Intel Top Swap +// Modified PeiRamBoot module for multiple Boot Block Volumes support. +// [Files] PeiRamBoot.sdl +// PeiRamBoot.mak +// PeiRamBoot.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 19 7/24/13 6:15a Calvinchen +// Bug Fixed: System hangs at CP60 if LastFfsFile Guild is installed with +// DebugMode "ON". +// +// 18 5/22/13 7:30a Calvinchen +// System hangs if OPTIMIZE_BOOT_FV_COPY = 1 with AMI Debug Rx enabled +// Description : Added Saveing Module Type "EFI_FV_FILETYPE_DRIVER" in +// Optimize Boot FV. +// +// 17 3/15/13 4:39a Calvinchen +// Bug Fixed: System hangs if OPTIMIZE_BOOT_FV_COPY = 1 +// Description : RAW and FREEFORM FFS must be saved in Optimize Boot FV. +// +// 16 2/05/13 12:51a Calvinchen +// +// 15 1/16/13 6:31a Calvinchen +// [TAG] EIPNone +// [Category] Improvement +// [Description] 1. Added support to minimumize Boot FV copy for +// improving POST time. +// 2. Added Last Firmware Volume FFS file Override mechanism. +// [Files] PeiRamBoot.sdl +// PeiRamBoot.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 14 11/29/12 10:48p Calvinchen +// [TAG] EIP106511 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] PI 0.9 and 1.0 in Core 4.6.5.4 +// [RootCause] Build failed if PI 1.0. +// [Files] PeiRamBoot.c +// +// 12 8/08/12 4:25a Calvinchen +// 1. Changed for ReportFv2.c by Artem's suggestion. +// 2. Fixed System hangs if Memory Mapping Changed with warm boot. +// +// 11 7/18/12 3:38a Calvinchen +// [TAG] EIP94448 +// [Category] Improvement +// [Description] Can not Save the DXE IPL Boot time,even add the PEI RAM +// Boot eModule. +// +// 10 2/23/12 9:06a Calvinchen +// Fixed building error. +// +// 9 2/23/12 6:35a Calvinchen +// [TAG] EIP82264 +// [Category] Improvement +// [Description] Need to do cold boot to get the correct data in rom +// hole when changing data in rom hole. +// [Files] PeiRamBoot.sdl +// PeiRamBoot.mak +// PeiRamBoot.h +// PeiRamBoot.c +// PeiRamBootDxe.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 8 5/27/11 7:19a Calvinchen +// [TAG] EIP60320 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] System hangs at CP 0x72 when SMM_THUNK_IN_CSM is 0 on +// Huronriver. +// [RootCause] InSmmFunction is NULL in InitSmmHandlerEx call. +// [Solution] Added dummy InSmmFunction. +// [Files] PeiRamBoot.c +// +// 7 4/22/11 1:27a Calvinchen +// +// 6 3/22/11 7:52a Calvinchen +// [TAG] EIP56322 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] System hangs after changing TPM settings in SETUP. +// [RootCause] System Memory Mappings are changed with warm boot. +// [Solution] BIOS always go cold boot path if system memory mappings +// are changed +// [Files] PeiRamBoot.sdl +// PeiRamBoot.mak +// PeiRamBoot.dxs +// PeiRamBoot.h +// PeiRamBoot.c +// PeiRamBootHook.c +// PeiRamBootDxe.c +// PeiRamBootOfbd.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 5 2/11/11 3:16a Calvinchen +// Bug Fixed : System hangs after reflashed BIOS with warm reset if +// PEI_RAM_BOOT_S3_SUPPORT = 1 with fast warm boot support. +// +// 4 12/29/10 5:35a Calvinchen +// Bug Fixed : DMI structure not update in system memory if +// PEI_RAM_BOOT_S3_SUPPORT = 1 with fast warm boot support. +// +// 3 12/26/10 9:59p Calvinchen +// Bug Fixed: +// 1. Recovery not work if PEI_RAM_BOOT_S3_SUPPORT = 2. +// 2. S4 resume failed if PEI_RAM_BOOT_S3_SUPPORT = 1 with fast warm boot +// support. +// +// 2 12/14/10 2:25a Calvinchen +// Improvement : +// 1. Added an eLink "PeiRamBootList" for fast warm boot support +// (PEI_RAM_BOOT_S3_SUPPORT = 1). If system boots in warm boot state, BIOS +// directly boot to previous copied ROM image in RAM to save time of +// copying ROM. +// 2. Added "PEI_RAM_BOOT_S3_SUPPORT" = "2" for saving runtime memory, it +// only keep necessary PEIM FFS in runtime memory for S3 resume +// improvement. +// +// 1 10/27/10 2:48a Calvinchen +// Initial Check-in. +// +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: PeiRamBoot.c +// +// Description: PEI RAM BOOT Pei driver. +// +//<AMI_FHDR_END> +//********************************************************************** +//---------------------------------------------------------------------------- +// Includes +// Statements that include other files +#include <PEI.h> +#include <AmiPeiLib.h> +//#include <AmiCspLib.h> +#include <ppi\ReadOnlyVariable.h> +#include <ppi\RecoveryModule.h> +#include <RomLayout.h> +#include <Token.h> +#include <PeiRamBoot.h> +#if (PI_SPECIFICATION_VERSION >= 0x0001000A) +#include <PeiCore.h> +#endif +#if defined (SecureBoot_SUPPORT) && SecureBoot_SUPPORT == 1 +#include <AmiCertificate.h> +#endif +//---------------------------------------------------------------------------- +// Function Externs +extern +VOID +SwitchPeiServiceDataToRam ( + IN EFI_PEI_SERVICES **PeiServices, + IN HOB_ROM_IMAGE *HobRomImage +); +#if (PI_SPECIFICATION_VERSION >= 0x0001000A) +extern +BOOLEAN +IsPeimDispatched ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_FFS_FILE_HEADER *FfsFile, + IN UINTN Index +); +#else +extern +UINT64 +GetDispatchedPeimBitMap ( + IN EFI_PEI_SERVICES **PeiServices +); +#endif +extern ROM_AREA RomLayout[]; + +typedef BOOLEAN (PEI_RAM_BOOT_ELINK) (EFI_PEI_SERVICES **PeiServices); +extern PEI_RAM_BOOT_ELINK PEI_RAM_BOOT_LIST EndOfPeiRamBootList; +PEI_RAM_BOOT_ELINK* IsMrcColdBooteLink[] = {PEI_RAM_BOOT_LIST NULL}; + +//---------------------------------------------------------------------------- +// Local prototypes +#define PR_KEY_FFS_FILE_RAW_GUID \ +{ 0x3FEEC852, 0xF14C, 0x4E7F, 0x97, 0xFD, 0x4C, 0x3A, 0x8C, 0x5B, 0xBE, 0xCC } +#define ROM_LAYOUT_FFS_GUID \ +{ 0x0DCA793A, 0xEA96, 0x42d8, 0xBD, 0x7B, 0xDC, 0x7F, 0x68, 0x4E, 0x38, 0xC1 } +#define FID_FFS_FILE_NAME_GUID \ +{ 0x3fd1d3a2, 0x99f7, 0x420b, 0xbc, 0x69, 0x8b, 0xb1, 0xd4, 0x92, 0xa3, 0x32 } +#define PKEY_FILE_GUID \ +{ 0xCC0F8A3F, 0x3DEA, 0x4376, 0x96, 0x79, 0x54, 0x26, 0xba, 0x0a, 0x90, 0x7e } +#define KEK_FILE_GUID \ +{ 0x9fe7de69, 0xaea, 0x470a, 0xb5, 0xa, 0x13, 0x98, 0x13, 0x64, 0x91, 0x89 } +#define DB_FILE_GUID \ +{ 0xfbf95065, 0x427f, 0x47b3, 0x80, 0x77, 0xd1, 0x3c, 0x60, 0x71, 0x9, 0x98 } +#define DBX_FILE_GUID \ +{ 0x9d7a05e9, 0xf740, 0x44c3, 0x85, 0x8b, 0x75, 0x58, 0x6a, 0x8f, 0x9c, 0x8e } + +EFI_GUID gHobRomImageGuid = ROM_IMAGE_MEMORY_HOB_GUID; +EFI_GUID gEfiPeiEndOfPeiPhasePpiGuid = EFI_PEI_END_OF_PEI_PHASE_PPI_GUID; +EFI_GUID gCacheInstallGuid = EFI_PEI_PERMANENT_MEMORY_INSTALLED_PPI; +EFI_GUID gEfiPeiReadOnlyVariablePpiGuid = EFI_PEI_READ_ONLY_VARIABLE_PPI_GUID; +EFI_GUID gEfiPeiRecoveryModePpiGuid = EFI_PEI_BOOT_IN_RECOVERY_MODE_PEIM_PPI; +EFI_GUID gEfiPeiRecoveryModulePpiGuid = EFI_PEI_RECOVERY_MODULE_PPI_GUID; +EFI_GUID gSmbiosFlashDataFfsGuid = SMBIOS_FLASH_DATA_FFS_GUID; +EFI_GUID gRomCacheEnablePpiGuid = ROM_CACHE_ENABLE_PPI_GUID; +EFI_GUID gPrKeyFfsFileRawGuid = PR_KEY_FFS_FILE_RAW_GUID; +EFI_GUID gLastFfsFileOverrideGuid = \ +{0x45B9618F, 0xBAA1, 0x421B, { 0x94, 0xF0, 0xB9, 0xEB, 0xDD, 0x2B, 0xA1, 0x77 }}; + +EFI_STATUS +PeiRamBootMemoryReady ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *NullPpi +); + +EFI_STATUS +PeiRamBootEndOfPei ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *NullPpi +); +static EFI_PEI_NOTIFY_DESCRIPTOR PeiRamBootMemoryReadyNotify[] = +{ + { + EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | \ + EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gCacheInstallGuid, + PeiRamBootMemoryReady + } +}; +static EFI_PEI_NOTIFY_DESCRIPTOR PeiRamBootEndOfPeiNotify[] = +{ + { + EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | \ + EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gEfiPeiEndOfPeiPhasePpiGuid, + PeiRamBootEndOfPei + } +}; +//---------------------------------------------------------------------------- +// Local Variables +UINT32 FvBootBlocksList[] = { + PEI_RAM_BOOT_FV_BOOTBLOCK_LIST + FV_BB_BASE, + { -1 } +}; + +//---------------------------------------------------------------------------- +// Function Definitions + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: IsBootFirmwareVolume +// +// Description: +// +// Input: EFI_PEI_SERVICES** - PeiServices +// EFI_PHYSICAL_ADDRESS - Address +// +// Output: None. +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +BOOLEAN +IsBootBlockFirmwareVolumes ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PHYSICAL_ADDRESS Address +) +{ + UINT8 i; +#if (PI_SPECIFICATION_VERSION >= 0x0001000A) + PEI_CORE_INSTANCE *Private = NULL; + Private = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); + if (Private->Fv[0].FvHeader == (EFI_FIRMWARE_VOLUME_HEADER*)Address) + return TRUE; +#endif + for (i = 0; FvBootBlocksList[i] != -1; i++) + if (Address == (EFI_PHYSICAL_ADDRESS)FvBootBlocksList[i]) return TRUE; + return FALSE; +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PrepareForCopyRomToRam +// +// Description: This procedure allocate memroy buffer for copying rom to ram. +// +// Input: EFI_PEI_SERVICES** - PeiServices +// HOB_ROM_IMAGE - *HobRomImage +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +PrepareForCopyRomToRam ( + IN EFI_PEI_SERVICES **PeiServices, + IN HOB_ROM_IMAGE *HobRomImage +) +{ + UINT8 i; + EFI_STATUS Status = EFI_SUCCESS; + UINTN NumOfPages; + EFI_PHYSICAL_ADDRESS Buffer = 0; + + for (i = 0; i < HobRomImage->NumOfFv; i++) { + NumOfPages = HobRomImage->FvInfo[i].UsedBytes; + if (HobRomImage->FvInfo[i].FvLength != + HobRomImage->FvInfo[i].UsedBytes) { +#if SAVE_ENTIRE_FV_IN_MEM == 0 + // 0x1200 = 1)4k aligned, 2)NULL bytes of FV + NumOfPages = HobRomImage->FvInfo[i].UsedBytes + 0x1200; +#else + NumOfPages = HobRomImage->FvInfo[i].FvLength; +#endif + } + Status = (*PeiServices)->AllocatePages ( PeiServices, + EfiBootServicesData, + NumOfPages >> 12, + &Buffer); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + // If HobValid is "TRUE", it means FV memories aren't destroyed, just + // reserve the necessary memory space for FV then exit. + if (HobRomImage->HobValid == TRUE) continue; + HobRomImage->FvInfo[i].NumOfPages = NumOfPages >> 12; + HobRomImage->FvInfo[i].MemAddress = (UINT32)Buffer; + HobRomImage->FvInfo[i].FvMemReady = FALSE; + } + return EFI_SUCCESS; +} +#if (PI_SPECIFICATION_VERSION >= 0x0001000A) && (OPTIMIZE_BOOT_FV_COPY == 1) +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: MinimumizeBootFv +// +// Description: This routine copy only undispatched PEIM and Preserved FFS Guid +// to memory and FFS Header only if dispatched PEIM. +// +// Input: EFI_PEI_SERVICES** - PeiServices +// HOB_ROM_IMAGE* - HobRomImage, +// UINT8 - Index +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID +MinimumizeBootFv ( + IN EFI_PEI_SERVICES **PeiServices, + IN HOB_ROM_IMAGE *HobRomImage, + IN UINT8 Index +) +{ + UINTN k = 0, n = 0, FfsLength; + UINT8 *p = (UINT8*)HobRomImage->FvInfo[Index].MemAddress; + UINT8 *q = (UINT8*)HobRomImage->FvInfo[Index].FvAddress; + EFI_FFS_FILE_HEADER *FfsFile = NULL; + EFI_GUID *pGuid = NULL; + EFI_STATUS Status = EFI_SUCCESS; + + // 1. Copy Firmware Volume Header to Memory buffer. + (*PeiServices)->CopyMem ( \ + p, q, ((EFI_FIRMWARE_VOLUME_HEADER*)q)->HeaderLength); + p += ((EFI_FIRMWARE_VOLUME_HEADER*)q)->HeaderLength; + do { + Status = (*PeiServices)->FfsFindNextFile (PeiServices, \ + EFI_FV_FILETYPE_ALL, (EFI_FIRMWARE_VOLUME_HEADER*)q, &FfsFile ); + if (EFI_ERROR(Status)) break; + + // calculate file alignment (Align on 8 bytes). + FfsLength = *(UINT32*)FfsFile->Size & 0xffffff; + FfsLength = (FfsLength + 7) & 0xfffffff8; + // Copy undispatched PEIMs and FFS File Header only if dispatched PEIM + if ((FfsFile->Type == EFI_FV_FILETYPE_PEI_CORE) || \ + ((FfsFile->Type == EFI_FV_FILETYPE_PEIM) && \ + (!IsPeimDispatched(PeiServices, FfsFile, k)))) n = FfsLength; + else { + n = sizeof(EFI_FFS_FILE_HEADER); + // Copy RAW and FREEFORM FFS file.. + if ((FfsFile->Type == EFI_FV_FILETYPE_FREEFORM) || \ + (FfsFile->Type == EFI_FV_FILETYPE_DRIVER) || \ + (FfsFile->Type == EFI_FV_FILETYPE_RAW)) n = FfsLength; + } + // Increase PEIM index meeting PEI Core Private Data of PI 1.2 + if (FfsFile->Type == EFI_FV_FILETYPE_PEIM) k++; + (*PeiServices)->CopyMem (p, (UINT8*)FfsFile, n); + p = p + FfsLength; + } while(!EFI_ERROR(Status)); +} +#endif // #if (PI_SPECIFICATION_VERSION >= 0x0001000A) && (OPTIMIZE_BOOT_FV_COPY == 1) +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: CopyFirmwareVolumesToRam +// +// Description: This procedure copy in used Firmware Volume to memroy. +// +// Input: EFI_PEI_SERVICES** - PeiServices +// HOB_ROM_IMAGE* - HobRomImage, +// BOOLEAN - IsEndOfPei +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +CopyFirmwareVolumesToRam ( + IN EFI_PEI_SERVICES **PeiServices, + IN HOB_ROM_IMAGE *HobRomImage, + IN BOOLEAN IsEndOfPei +) +{ + UINT8 i; + EFI_STATUS Status = EFI_SUCCESS; + + for (i = 0; i < HobRomImage->NumOfFv; i++) { + if ((!IsEndOfPei) && (!HobRomImage->FvInfo[i].IsBootFv)) continue; + else if (IsEndOfPei && HobRomImage->FvInfo[i].IsBootFv) continue; + HobRomImage->FvInfo[i].FvMemReady = TRUE; + if (HobRomImage->HobValid) continue; + +#if (PI_SPECIFICATION_VERSION >= 0x0001000A) && (OPTIMIZE_BOOT_FV_COPY == 1) + if (HobRomImage->FvInfo[i].IsBootFv == TRUE) { + MinimumizeBootFv (PeiServices, HobRomImage, i); + } + else +#endif // #if (OPTIMIZE_BOOT_FV_COPY == 1) + { + (*PeiServices)->CopyMem ((UINT8*)HobRomImage->FvInfo[i].MemAddress, \ + (UINT8*)HobRomImage->FvInfo[i].FvAddress, \ + HobRomImage->FvInfo[i].UsedBytes); + } + if (HobRomImage->FvInfo[i].UsedBytes != HobRomImage->FvInfo[i].FvLength) + { + UINT32 NumofNullBytes; +#if SAVE_ENTIRE_FV_IN_MEM == 1 + // Fill Null Bytes after Used Data + NumofNullBytes = HobRomImage->FvInfo[i].FvLength - \ + HobRomImage->FvInfo[i].UsedBytes; +#else + // Fill Max 512 Null Bytes after Used Data + NumofNullBytes = (HobRomImage->FvInfo[i].NumOfPages << 12) - \ + HobRomImage->FvInfo[i].UsedBytes; + if (NumofNullBytes > 512) NumofNullBytes = 512; +#endif // #if SAVE_ENTIRE_FV_IN_MEM == 1 + (*PeiServices)->SetMem ( + (UINT8*)(HobRomImage->FvInfo[i].MemAddress + \ + HobRomImage->FvInfo[i].UsedBytes), \ + NumofNullBytes, FLASH_EMPTY_BYTE ); + } + } + + return EFI_SUCCESS; +} +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: CollectRomImageInfo +// +// Description: +// +// Input: EFI_PEI_SERVICES** - PeiServices +// EFI_PHYSICAL_ADDRESS - Buffer +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +CollectRomImageInfo ( + IN EFI_PEI_SERVICES **PeiServices, + IN HOB_ROM_IMAGE *HobRomImage +) +{ + ROM_AREA *Area; + UINT32 FileSize; + UINT8 i = 0, j = 0, n = 0; + UINTN k = 0; + EFI_STATUS Status = EFI_SUCCESS; + EFI_FFS_FILE_HEADER *FfsFile = NULL, *LastFfsFile = NULL; + BOOLEAN IsDispatched = FALSE; + UINT64 DispatchedPeimBitMap = 0; + EFI_GUID *pGuid = NULL, *pLastFileOvrdeGuid = NULL; + + if (RomLayout == NULL) return EFI_UNSUPPORTED; +#if (PI_SPECIFICATION_VERSION < 0x0001000A) + DispatchedPeimBitMap = GetDispatchedPeimBitMap(PeiServices); +#endif + + // Get Last File Override Guid for skiping unnecessary files copied + // for reducing POST time. + Status = (*PeiServices)->LocatePpi ( PeiServices, \ + &gLastFfsFileOverrideGuid, \ + 0, \ + NULL, \ + &pLastFileOvrdeGuid); + if (EFI_ERROR(Status)) pLastFileOvrdeGuid = NULL; + + // find last ffs file for calculating used rom space for each Firmware Volume. + for (Area = RomLayout; Area->Size != 0; Area++, FfsFile = NULL, FileSize = 0) { + if (Area->Type != RomAreaTypeFv) continue; + if (!(Area->Attributes & (ROM_AREA_FV_PEI_ACCESS + ROM_AREA_FV_DXE))) + continue; + // find last ffs file for calculating used rom space. + do { + IsDispatched = TRUE; + Status = (*PeiServices)->FfsFindNextFile ( + PeiServices, \ + EFI_FV_FILETYPE_ALL, \ + (EFI_FIRMWARE_VOLUME_HEADER*)(Area->Address), \ + &FfsFile ); + if (!EFI_ERROR(Status)) { + // Terminate searching Last File if Last File Override Guid + // is defined and is identified. + if ((pLastFileOvrdeGuid != NULL) && \ + (!guidcmp(&FfsFile->Name, pLastFileOvrdeGuid))) { + FfsFile = LastFfsFile; + Status = EFI_NOT_FOUND; + } else LastFfsFile = FfsFile; + } + + } while(!EFI_ERROR(Status)); + FileSize = *(UINT32*)FfsFile->Size & 0xffffff; + FileSize += ((UINT32)FfsFile - (UINT32)Area->Address); + HobRomImage->FvInfo[i].FvAddress = (UINT32)Area->Address; + HobRomImage->FvInfo[i].FvLength = Area->Size; + HobRomImage->FvInfo[i].UsedBytes = FileSize; + HobRomImage->FvInfo[i].MemAddress = 0; + if (IsBootBlockFirmwareVolumes(PeiServices, Area->Address)) + HobRomImage->FvInfo[i].IsBootFv = TRUE; + else HobRomImage->FvInfo[i].IsBootFv = FALSE; + HobRomImage->NumOfFv = ++i; + } + if (HobRomImage->NumOfFv == 0) return EFI_UNSUPPORTED; + return EFI_SUCCESS; +} +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: FvHobSwitchToRam +// +// Description: This procedure redirect the FV Base Address of FV HOB to RAM. +// +// Input: EFI_PEI_SERVICES** - PeiServices +// EFI_PHYSICAL_ADDRESS - RomImageBuffer +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +FvHobSwitchToRam ( + IN EFI_PEI_SERVICES **PeiServices, + IN HOB_ROM_IMAGE *HobRomImage +) +{ + VOID *p; + EFI_HOB_FIRMWARE_VOLUME *FvHob; + UINT8 i, j = 0; + EFI_BOOT_MODE BootMode; + EFI_STATUS Status = EFI_SUCCESS; +#if (PI_SPECIFICATION_VERSION >= 0x0001000A) + PEI_CORE_INSTANCE *PrivateData; + PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); +#endif + + // Get current Boot Mode. + Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + + // Update FV HOB (BaseAddress) + for ((*PeiServices)->GetHobList(PeiServices,&p); + !(FindNextHobByType(EFI_HOB_TYPE_FV,&p)); ) { + FvHob = (EFI_HOB_FIRMWARE_VOLUME*)p; + for (i = 0; i < HobRomImage->NumOfFv; i++) { + if ((FvHob->BaseAddress == HobRomImage->FvInfo[i].FvAddress) && \ + (FvHob->Length == HobRomImage->FvInfo[i].FvLength) && \ + (HobRomImage->FvInfo[i].MemAddress != 0) && \ + (HobRomImage->FvInfo[i].FvMemReady)) { +#if (PI_SPECIFICATION_VERSION >= 0x0001000A) + for(j = 0; j < PrivateData->AllFvCount; ++j){ + if((UINT32)FvHob->BaseAddress == (UINT32)PrivateData->AllFv[j]) { + PrivateData->AllFv[j] = (EFI_PEI_FV_HANDLE)HobRomImage->FvInfo[i].MemAddress; + } + } +#endif // #if (PI_SPECIFICATION_VERSION >= 0x0001000A) + FvHob->BaseAddress = HobRomImage->FvInfo[i].MemAddress; + break; + } + } + } + return EFI_SUCCESS; +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PeiRamBootEndOfPei +// +// Description: This procedure redirect the FV Base Address of FV HOB to RAM in +// End of PEI Phase PPI. +// +// Input: EFI_PEI_SERVICES** - PeiServices +// EFI_PEI_NOTIFY_DESCRIPTOR* - NotifyDescriptor +// VOID* - NullPpi +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +PeiRamBootEndOfPei ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *NullPpi +) +{ + VOID *p; + INTN Result; + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + + // Update BaseAddress of FV HOB again if new FV is reported. + for ((*PeiServices)->GetHobList(PeiServices,&p); \ + !(FindNextHobByType(EFI_HOB_TYPE_GUID_EXTENSION, &p)); ) { + Result = guidcmp(&((EFI_HOB_GUID_TYPE*)p)->Name, &gHobRomImageGuid); + if (!Result) break; + } + if (Result) return EFI_UNSUPPORTED; + + Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + + if (BootMode != BOOT_ON_S3_RESUME) { + CopyFirmwareVolumesToRam(PeiServices, (HOB_ROM_IMAGE*)p, TRUE); + } + FvHobSwitchToRam (PeiServices, (HOB_ROM_IMAGE*)p); + return EFI_SUCCESS; +} +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PeiRamBootMemoryReady +// +// Description: This procedure allocate a Memory buffer and redirect the FV from +// ROM to RAM in PERMANENT MEMORY INSTALLED PPI; +// +// Input: EFI_PEI_SERVICES** - PeiServices +// EFI_PEI_NOTIFY_DESCRIPTOR* - NotifyDescriptor +// VOID* - NullPpi +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +PeiRamBootMemoryReady ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, + IN VOID *NullPpi +) +{ + EFI_STATUS Status; + HOB_ROM_IMAGE *HobRomImage = NULL; + EFI_BOOT_MODE BootMode; + + // Get current Boot Mode. + Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + // Check Boot mode again, do nothing if recovery mode. + if ((BootMode == BOOT_IN_RECOVERY_MODE) || \ + (BootMode == BOOT_ON_FLASH_UPDATE)) return EFI_SUCCESS; + + Status = (*PeiServices)->CreateHob ( PeiServices, \ + EFI_HOB_TYPE_GUID_EXTENSION, \ + sizeof(HOB_ROM_IMAGE), \ + &HobRomImage ); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + HobRomImage->EfiHobGuidType.Name = gHobRomImageGuid; + + + HobRomImage->HobValid = FALSE; + + HobRomImage->NumOfFv = 0; + Status = CollectRomImageInfo (PeiServices, HobRomImage); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + Status = PrepareForCopyRomToRam (PeiServices, HobRomImage); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + Status = CopyFirmwareVolumesToRam (PeiServices, HobRomImage, FALSE); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + SwitchPeiServiceDataToRam (PeiServices, HobRomImage); + FvHobSwitchToRam (PeiServices, HobRomImage); + return EFI_SUCCESS; +} +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PeiRamBootEntry +// +// Description: PEI Entry Point for PeiRamBoot Driver. +// +// Input: EFI_FFS_FILE_HEADER* - FfsHeader +// EFI_PEI_SERVICES** - PeiServices +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +PeiRamBootEntry ( + IN EFI_FFS_FILE_HEADER *FfsHeader, + IN EFI_PEI_SERVICES **PeiServices +) +{ + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + + Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode); + if (EFI_ERROR(Status)) return Status; + if ((BootMode == BOOT_IN_RECOVERY_MODE) || \ + (BootMode == BOOT_ON_FLASH_UPDATE) || \ + (BootMode == BOOT_ON_S3_RESUME)) return EFI_SUCCESS; + + Status = (*PeiServices)->NotifyPpi ( PeiServices, \ + PeiRamBootMemoryReadyNotify ); + Status = (*PeiServices)->NotifyPpi ( PeiServices, \ + PeiRamBootEndOfPeiNotify ); + + return EFI_SUCCESS; +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//*************************************************************************
\ No newline at end of file diff --git a/Core/EM/PeiRamBoot/PeiRamBoot.chm b/Core/EM/PeiRamBoot/PeiRamBoot.chm Binary files differnew file mode 100644 index 0000000..d8af8be --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBoot.chm diff --git a/Core/EM/PeiRamBoot/PeiRamBoot.cif b/Core/EM/PeiRamBoot/PeiRamBoot.cif new file mode 100644 index 0000000..0277b05 --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBoot.cif @@ -0,0 +1,19 @@ +<component> + name = "PEI Ram Boot" + category = eModule + LocalRoot = "Core\EM\PeiRamBoot" + RefName = "PEI_RAM_BOOT" +[files] +"PeiRamBoot.sdl" +"PeiRamBoot.mak" +"PeiRamBoot.dxs" +"PeiRamBoot.h" +"PeiRamBoot.c" +"PeiRamBootHook.c" +"PeiRamBootDxe.c" +"PeiRamBootOfbd.c" +"PeiRamBootFvHook.c" +"PeiRamBootCacheRdy.c" +"PeiRamBootCacheRdy.dxs" +"PeiRamBoot.chm" +<endComponent> diff --git a/Core/EM/PeiRamBoot/PeiRamBoot.dxs b/Core/EM/PeiRamBoot/PeiRamBoot.dxs new file mode 100644 index 0000000..69c45e6 --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBoot.dxs @@ -0,0 +1,66 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.dxs 2 7/18/12 3:39a Calvinchen $ +// +// $Revision: 2 $ +// +// $Date: 7/18/12 3:39a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.dxs $ +// +// 2 7/18/12 3:39a Calvinchen +// Added changes for AMD AGESA V5. +// +// 1 10/27/10 2:48a Calvinchen +// Initial Check-in. +// +// +//********************************************************************** +#include <pei.h> +#include <token.h> +#include "ppi\CpuIo.h" +#include "ppi\PciCfg.h" +#include "ppi\ReadOnlyVariable.h" +#include "ppi\Stall.h" +#ifdef AMDV5_SUPPORT +#define AGESA_MEM_PPI_GUID \ +{ 0x8ba51c1c, 0x4b30, 0x47df, 0xa4, 0x4e, 0x22, 0x53, 0xe1, 0xa5, 0xd4, 0x2 } +#endif + +DEPENDENCY_START +#ifdef AMDV5_SUPPORT + AGESA_MEM_PPI_GUID AND +#endif + EFI_PEI_CPU_IO_PPI_INSTALLED_GUID AND + EFI_PEI_READ_ONLY_VARIABLE_PPI_GUID AND + EFI_PEI_PCI_CFG_PPI_INSTALLED_GUID AND + EFI_PEI_STALL_PPI_GUID +DEPENDENCY_END +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* diff --git a/Core/EM/PeiRamBoot/PeiRamBoot.h b/Core/EM/PeiRamBoot/PeiRamBoot.h new file mode 100644 index 0000000..58473e2 --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBoot.h @@ -0,0 +1,162 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.h 7 8/08/12 4:25a Calvinchen $ +// +// $Revision: 7 $ +// +// $Date: 8/08/12 4:25a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.h $ +// +// 7 8/08/12 4:25a Calvinchen +// 1. Changed for ReportFv2.c by Artem's suggestion. +// 2. Fixed System hangs if Memory Mapping Changed with warm boot. +// +// 6 7/18/12 3:41a Calvinchen +// +// 5 2/23/12 6:35a Calvinchen +// [TAG] EIP82264 +// [Category] Improvement +// [Description] Need to do cold boot to get the correct data in rom +// hole when changing data in rom hole. +// [Files] PeiRamBoot.sdl +// PeiRamBoot.mak +// PeiRamBoot.h +// PeiRamBoot.c +// PeiRamBootDxe.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 4 4/22/11 1:27a Calvinchen +// +// 3 12/29/10 5:35a Calvinchen +// Bug Fixed : DMI structure not update in system memory if +// PEI_RAM_BOOT_S3_SUPPORT = 1 with fast warm boot support. +// +// 2 12/14/10 2:25a Calvinchen +// Improvement : +// 1. Added an eLink "PeiRamBootList" for fast warm boot support +// (PEI_RAM_BOOT_S3_SUPPORT = 1). If system boots in warm boot state, BIOS +// directly boot to previous copied ROM image in RAM to save time of +// copying ROM. +// 2. Added "PEI_RAM_BOOT_S3_SUPPORT" = "2" for saving runtime memory, it +// only keep necessary PEIM FFS in runtime memory for S3 resume +// improvement. +// +// 1 10/27/10 2:48a Calvinchen +// Initial Check-in. +// +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: PeiRamBoot.h +// +// Description: Definition file for PEI Ram Boot. +// +//<AMI_FHDR_END> +//********************************************************************** + +#ifndef PI_SPECIFICATION_VERSION +#define PI_SPECIFICATION_VERSION 91 +#endif + +#define FLASH_DEVICE_BASE (0xFFFFFFFF - FLASH_SIZE + 1) + +#define ROM_IMAGE_MEMORY_HOB_GUID \ +{ 0xee2f45d2, 0x5ba4, 0x441e, 0x8a, 0x1d, 0xaa, 0x22, 0xdf, 0xa3, 0xb6, 0xc5 } + +#define ROM_IMAGE_ADDRESS_GUID \ +{ 0xDDE1BC72, 0xD45E, 0x4209, 0xAB, 0x85, 0x14, 0x46, 0x2D, 0x2F, 0x50, 0x74 } + +#define SMBIOS_FLASH_DATA_FFS_GUID \ +{ 0xFD44820B, 0xF1AB, 0x41C0, 0xAE, 0x4E, 0x0C, 0x55, 0x55, 0x6E, 0xB9, 0xBD } + +#define ROM_CACHE_ENABLE_PPI_GUID \ +{ 0x36E835BB, 0x661D, 0x4D37, 0x8D, 0xE5, 0x88, 0x53, 0x25, 0xDA, 0xE9, 0x10 } + +#define FLASH_EMPTY_BYTE (UINT8)(-FLASH_ERASE_POLARITY) + +//<AMI_SHDR_START> +//---------------------------------------------------------------------------- +// Name: HOB_ROM_IMAGE +// +// Description: This structure contains information for ROM Image HOB. +// +// Referrals: +// +//---------------------------------------------------------------------------- +//<AMI_SHDR_END> +typedef struct { + UINT32 FvAddress; + UINT32 FvLength; + UINT32 UsedBytes; + UINT32 MemAddress; + UINT16 NumOfPages; + UINT8 FvMemReady; + UINT8 IsBootFv; +} FV_INFO; + +typedef struct { +#if PEI_RAM_BOOT_S3_SUPPORT == 2 + UINT32 PeimAddress; + UINT32 PeimLength; +#else + UINT32 FfsAddress; + UINT8 FfsLength[3]; + UINT8 FvIndex; +#endif +} PEIM_FFS_INFO; + +typedef struct { + UINT32 FvAddress; + UINT32 FvLength; + UINT32 MemAddress; +} NESTED_FV_INFO; + +typedef struct { + EFI_HOB_GUID_TYPE EfiHobGuidType; + BOOLEAN HobValid; + UINT32 SmbiosFlashData; + EFI_PHYSICAL_ADDRESS StolenHobMemory; + UINT8 NumOfFv; + FV_INFO FvInfo[8]; + UINT8 NumOfPeim; +#if PEI_RAM_BOOT_S3_SUPPORT == 2 + PEIM_FFS_INFO PeimFfsInfo[16]; +#else + PEIM_FFS_INFO RsvdFfsInfo[16]; +#endif + UINT8 NestedFvValid; + UINT8 NumOfNestedFv; + NESTED_FV_INFO NestedFvInfo[4]; +} HOB_ROM_IMAGE; + +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//*************************************************************************
\ No newline at end of file diff --git a/Core/EM/PeiRamBoot/PeiRamBoot.mak b/Core/EM/PeiRamBoot/PeiRamBoot.mak new file mode 100644 index 0000000..a0fee27 --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBoot.mak @@ -0,0 +1,242 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2010, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.mak 13 10/02/14 4:44a Calvinchen $ +# +# $Revision: 13 $ +# +# $Date: 10/02/14 4:44a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.mak $ +# +# 13 10/02/14 4:44a Calvinchen +# [TAG] EIP184075 +# [Category] Improvement +# [Description] [HWR]FtRecovery support for Intel Top Swap +# Modified PeiRamBoot module for multiple Boot Block Volumes support. +# [Files] PeiRamBoot.sdl +# PeiRamBoot.mak +# PeiRamBoot.c +# PeiRamBoot.chm +# PeiRamBoot.cif +# +# 12 3/18/13 6:08a Calvinchen +# Bug Fixed : Build failed if Core 4.6.5.5. +# +# 11 7/18/12 3:41a Calvinchen +# +# 10 2/23/12 6:35a Calvinchen +# [TAG] EIP82264 +# [Category] Improvement +# [Description] Need to do cold boot to get the correct data in rom +# hole when changing data in rom hole. +# [Files] PeiRamBoot.sdl +# PeiRamBoot.mak +# PeiRamBoot.h +# PeiRamBoot.c +# PeiRamBootDxe.c +# PeiRamBoot.chm +# PeiRamBoot.cif +# +# 9 6/21/11 2:22a Calvinchen +# ˇP Bug Fixed: +# Bug Fixed: +# 1. Build failed if Core 4.6.4.0. +# 2. System could hang if SAVE_ENTIRE_FV_TO_MEM = 1with AMD platform. +# +# 8 4/22/11 1:27a Calvinchen +# +# 7 2/11/11 3:16a Calvinchen +# Bug Fixed : System hangs after reflashed BIOS with warm reset if +# PEI_RAM_BOOT_S3_SUPPORT = 1 with fast warm boot support. +# +# 6 12/21/10 2:24a Calvinchen +# Added an eLink "PeiRamBootObjectsList" for oem links their obj files +# for fast warm boot support. +# +# 5 12/14/10 2:25a Calvinchen +# Improvement : +# 1. Added an eLink "PeiRamBootList" for fast warm boot support +# (PEI_RAM_BOOT_S3_SUPPORT = 1). If system boots in warm boot state, BIOS +# directly boot to previous copied ROM image in RAM to save time of +# copying ROM. +# 2. Added "PEI_RAM_BOOT_S3_SUPPORT" = "2" for saving runtime memory, it +# only keep necessary PEIM FFS in runtime memory for S3 resume +# improvement. +# +# 4 12/02/10 6:18a Calvinchen +# Bug Fixed : Fixed Update SMBIOS Structures failed with DMI Utility. +# +# 3 10/27/10 3:03a Calvinchen +# Initail check-in. +# +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: PeiRamBoot.mak +# +# Description: Make file for PEI Ram Boot. +# +#<AMI_FHDR_END> +#********************************************************************** +!IFNDEF PI_SPECIFICATION_VERSION +PI_SPECIFICATION_VERSION = 0 +!ENDIF + +all : PeiRamBoot PeiRamBootCacheRdy + +#--------------------------------------------------------------------------- +# Create PEI RAM BOOT dependencies +#--------------------------------------------------------------------------- +$(BUILD_DIR)\PeiRamBoot.mak : $(PeiRamBoot_DIR)\$(@B).cif $(PeiRamBoot_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(PeiRamBoot_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) +#--------------------------------------------------------------------------- +# Create PeiRamBoot PEI Component +#--------------------------------------------------------------------------- +PeiRamBoot: $(BUILD_DIR)\$(PeiRamBoot_DIR)\RomLayout.obj $(BUILD_DIR)\PeiRamBoot.mak PeiRamBootBin + +PEI_RAM_BOOT_INCLUDES =\ +/I$(PeiRamBoot_DIR)\ +/I$(CORE_PEI_DIR)\ +!IF $(PI_SPECIFICATION_VERSION) >= 65546 +/I$(CORE_PEI_DIR)\CORE_PEI_PI\ +!ELSE +/I$(CORE_PEI_DIR)\CORE_PEI_FRAMEWORK\ +!ENDIF +/I$(CORE_DXE_DIR)\ +/I$(CORE_DIR) + +PeiRamBootObjects =\ +$(BUILD_DIR)\$(PeiRamBoot_DIR)\RomLayout.obj\ +$(BUILD_DIR)\$(PeiRamBoot_DIR)\PeiRamBoot.obj\ +$(BUILD_DIR)\$(PeiRamBoot_DIR)\PeiRamBootHook.obj\ +$(PeiRamBootObjectsList) + +PEI_RAM_BOOT_LISTS = \ +/D\"PEI_RAM_BOOT_LIST=$(PeiRamBootList)\"\ +/D\"PEI_RAM_BOOT_FV_BOOTBLOCK_LIST=$(PeiRamBootFvBootBlockList)\"\ +/D\"PEI_RAM_BOOT_FFS_GUID_LIST=$(PeiRamBootFfsGuidList)\" + +PeiRamBootBin : $(AMIPEILIB) $(AMICSPLib) + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\PeiRamBoot.mak all\ + NAME=PeiRamBoot\ + MAKEFILE=$(BUILD_DIR)\PeiRamBoot.mak \ + "CFLAGS=$(CFLAGS) $(PEI_RAM_BOOT_LISTS)"\ + GUID=08efd15d-ec55-4023-b648-7ba40df7d05d \ + OBJECTS="$(PeiRamBootObjects)" \ + ENTRY_POINT=PeiRamBootEntry \ + TYPE=PEIM \ + "MY_INCLUDES=$(PEI_RAM_BOOT_INCLUDES)" \ + "MY_DEFINES=$(PEI_CORE_DEFINES)"\ + DEPEX1=$(PeiRamBoot_DIR)\PeiRamBoot.DXS \ + DEPEX1_TYPE=EFI_SECTION_PEI_DEPEX \ + COMPRESS=0 + +$(BUILD_DIR)\$(PeiRamBoot_DIR)\RomLayout.obj : $(BUILD_DIR)\RomLayout.c + $(CC) /Fo$@ $(CFLAGS) $(BUILD_DIR)\RomLayout.c +#--------------------------------------------------------------------------- +# Create PeiRamBoot DXE Component +#--------------------------------------------------------------------------- +Runtime_LIBBin : $(BUILD_DIR)\PeiRamBootDxe.lib + +$(BUILD_DIR)\PeiRamBootDxe.lib : PeiRamBootDxe + +PeiRamBootDxe: $(BUILD_DIR)\PeiRamBoot.mak PeiRamBootDxeBin + +PeiRamBootDxeObjs =\ +$(BUILD_DIR)\$(PeiRamBoot_DIR)\PeiRamBootDxe.obj + +PeiRamBootDxeBin : $(AMIDXELIB) $(AMICSPLib) + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\PeiRamBoot.mak all\ + NAME=PeiRamBoot\ + "CFLAGS=$(CFLAGS) /I$(PeiRamBoot_DIR)"\ + OBJECTS="$(PeiRamBootDxeObjs)" \ + TYPE=LIBRARY \ + LIBRARY_NAME=$(BUILD_DIR)\PeiRamBootDxe.lib + +#--------------------------------------------------------------------------- +# Create PEIRamBoot OFBD Lib Component +#--------------------------------------------------------------------------- +!IF "$(PEI_RAM_BOOT_S3_SUPPORT)"=="1" +PeiRamBootOfbd : $(BUILD_DIR)\PeiRamBoot.mak PeiRamBootOfbdBin + +PeiRamBootOfbdObjs = $(BUILD_DIR)\$(PeiRamBoot_DIR)\PeiRamBootOfbd.obj + +PeiRamBootOfbdBin : $(AMIDXELIB) + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\PeiRamBoot.mak all\ + "CFLAGS=$(CFLAGS:/W4=/W3) /I$(OFBD_DIR)" \ + OBJECTS="$(PeiRamBootOfbdObjs)" \ + NAME=PeiRamBoot \ + TYPE=LIBRARY LIBRARY_NAME=$(PEIRAMBOOT_OFBD_LIB) + +$(PEIRAMBOOT_OFBD_LIB) : PeiRamBootOfbd +!ENDIF +#--------------------------------------------------------------------------- +# Create PeiRamBoot PEI Component +#--------------------------------------------------------------------------- +!IF "$(SAVE_ENTIRE_FV_IN_MEM)"=="1" +PeiRamBootCacheRdy: $(BUILD_DIR)\PeiRamBoot.mak PeiRamBootCacheRdyBin + +PeiRamBootCacheRdyObjects =\ +$(BUILD_DIR)\$(PeiRamBoot_DIR)\PeiRamBootCacheRdy.obj + +PeiRamBootCacheRdyBin : $(AMIPEILIB) $(AMICSPLib) + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\PeiRamBoot.mak all\ + NAME=PeiRamBootCacheRdy\ + MAKEFILE=$(BUILD_DIR)\PeiRamBoot.mak \ + "CFLAGS=$(CFLAGS) /I$(PeiRamBoot_DIR)"\ + GUID=a6a3a962-c591-4701-9d25-73d0226d89dc\ + OBJECTS="$(PeiRamBootCacheRdyObjects)" \ + ENTRY_POINT=PeiRamBootCacheRdyEntry \ + TYPE=PEIM \ + DEPEX1=$(PeiRamBoot_DIR)\PeiRamBootCacheRdy.DXS \ + DEPEX1_TYPE=EFI_SECTION_PEI_DEPEX \ + COMPRESS=1 +!ELSE +PeiRamBootCacheRdy: +!ENDIF +#--------------------------------------------------------------------------- +!IF "$(PRESERVE_NESTED_FV_IN_MEM)"=="1" +$(BUILD_DIR)\$(PeiRamBoot_DIR)\PeiRamBootFvHook.obj : $(PeiRamBoot_DIR)\PeiRamBootFvHook.c +!IF !EXIST($(BUILD_DIR)\$(PeiRamBoot_DIR)) + mkdir $(BUILD_DIR)\$(PeiRamBoot_DIR) +!ENDIF + $(CC) /Fo$@ $(CFLAGS) /I$(PeiRamBoot_DIR) $(PeiRamBoot_DIR)\PeiRamBootFvHook.c + +CORE_PEIBin : $(BUILD_DIR)\$(PeiRamBoot_DIR)\PeiRamBootFvHook.obj +RecoveryBin : $(BUILD_DIR)\$(PeiRamBoot_DIR)\PeiRamBootFvHook.obj +FwCapsuleRecoveryPPIBin : $(BUILD_DIR)\$(PeiRamBoot_DIR)\PeiRamBootFvHook.obj +!ENDIF + +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2010, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#*************************************************************************
\ No newline at end of file diff --git a/Core/EM/PeiRamBoot/PeiRamBoot.sdl b/Core/EM/PeiRamBoot/PeiRamBoot.sdl new file mode 100644 index 0000000..1854e8f --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBoot.sdl @@ -0,0 +1,196 @@ +#**************************************************************************** +#**************************************************************************** +#** ** +#** (C)Copyright 1985-2010, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30071 ** +#** ** +#** Phone (770)-246-8600 ** +#** ** +#**************************************************************************** +#**************************************************************************** +#**************************************************************************** +# $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.sdl 16 8/28/15 3:54a Tristinchou $ +# +# $Revision: 16 $ +# +# $Date: 8/28/15 3:54a $ +# +#**************************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBoot.sdl $ +# +# 16 8/28/15 3:54a Tristinchou +# [TAG] EIP235157 +# [Category] Improvement +# [Description] Security vulnerability - PeiRamBoot: Should leave cold +# boot optimization only +# +# 15 10/02/14 4:44a Calvinchen +# [TAG] EIP184075 +# [Category] Improvement +# [Description] [HWR]FtRecovery support for Intel Top Swap +# Modified PeiRamBoot module for multiple Boot Block Volumes support. +# [Files] PeiRamBoot.sdl +# PeiRamBoot.mak +# PeiRamBoot.c +# PeiRamBoot.chm +# PeiRamBoot.cif +# +# 14 6/18/14 11:57p Calvinchen +# Bug Fixed: System hangs with using AFU. +# +# 13 1/16/13 6:31a Calvinchen +# [TAG] EIPNone +# [Category] Improvement +# [Description] 1. Added support to minimumize Boot FV copy for +# improving POST time. +# 2. Added Last Firmware Volume FFS file Override mechanism. +# [Files] PeiRamBoot.sdl +# PeiRamBoot.c +# PeiRamBoot.chm +# PeiRamBoot.cif +# +# 12 7/18/12 5:25a Calvinchen +# Missing "PeiRamBootNestedFvPublishing" eLink in sdl file. +# +# 11 7/18/12 4:18a Calvinchen +# PRESERVE_NESTED_FV_IN_MEM = 0 (Default) +# +# 10 7/18/12 3:41a Calvinchen +# +# 9 2/23/12 6:34a Calvinchen +# [TAG] EIP82264 +# [Category] Improvement +# [Description] Need to do cold boot to get the correct data in rom +# hole when changing data in rom hole. +# [Files] PeiRamBoot.sdl +# PeiRamBoot.mak +# PeiRamBoot.h +# PeiRamBoot.c +# PeiRamBootDxe.c +# PeiRamBoot.chm +# PeiRamBoot.cif +# +# 8 6/21/11 2:22a Calvinchen +# ˇP Bug Fixed: +# Bug Fixed: +# 1. Build failed if Core 4.6.4.0. +# 2. System could hang if SAVE_ENTIRE_FV_TO_MEM = 1with AMD platform. +# +# 7 5/27/11 7:16a Calvinchen +# Added "WARM_BOOT_VERIFY_CHECKSUM" for verifying FV/FFS checksum if +# Warmboot support. +# +# 6 4/22/11 1:22a Calvinchen +# +# 5 2/11/11 3:16a Calvinchen +# Bug Fixed : System hangs after reflashed BIOS with warm reset if +# PEI_RAM_BOOT_S3_SUPPORT = 1 with fast warm boot support. +# +# 4 12/21/10 2:24a Calvinchen +# Added an eLink "PeiRamBootObjectsList" for oem links their obj files +# for fast warm boot support. +# +# 3 12/14/10 2:25a Calvinchen +# Improvement : +# 1. Added an eLink "PeiRamBootList" for fast warm boot support +# (PEI_RAM_BOOT_S3_SUPPORT = 1). If system boots in warm boot state, BIOS +# directly boot to previous copied ROM image in RAM to save time of +# copying ROM. +# 2. Added "PEI_RAM_BOOT_S3_SUPPORT" = "2" for saving runtime memory, it +# only keep necessary PEIM FFS in runtime memory for S3 resume +# improvement. +# +# 2 12/02/10 6:18a Calvinchen +# Bug Fixed : Fixed Update SMBIOS Structures failed with DMI Utility. +# +# 1 10/27/10 2:48a Calvinchen +# Initial Check-in. +# +# +#**************************************************************************** +TOKEN + Name = "PeiRamBootSupport" + Value = "1" + Help = "Main switch to enable PEI RAM Boot support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + TargetH = Yes + Master = Yes +End + + +TOKEN + Name = "SAVE_ENTIRE_FV_IN_MEM" + Value = "0" + Help = "Switch to enable to copy Entire Firmware Volume to Ram." + TokenType = Boolean + TargetMAK = Yes + TargetH = Yes +End + +TOKEN + Name = "OPTIMIZE_BOOT_FV_COPY" + Value = "0" + Help = "Switch to enable to optimize(Minimumize) Boot FV copy." + TokenType = Boolean + TargetMAK = Yes + TargetH = Yes +End + + +PATH + Name = "PeiRamBoot_DIR" +End + +MODULE + Help = "Includes PeiRamBoot.mak to Project" + File = "PeiRamBoot.mak" +End + +ELINK + Name = "PeiRamBootDxeEntry," + Parent = "RuntimeSmmInitialize" + InvokeOrder = AfterParent +End + +ELINK + Name = "$(BUILD_DIR)\PeiRamBoot.ffs" + Parent = "FV_BB" + InvokeOrder = AfterParent +End + +ELINK + Name = "$(BUILD_DIR)\PeiRamBootCacheRdy.ffs" + Parent = "$(BUILD_DIR)\CPUPEI.ffs" + Token = "SAVE_ENTIRE_FV_IN_MEM" "=" "1" + InvokeOrder = AfterParent +End + + + +ELINK + Name = "PeiRamBootList" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "PeiRamBootFvBootBlockList" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "PeiRamBootFfsGuidList" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "PeiRamBootObjectsList" + InvokeOrder = ReplaceParent +End + diff --git a/Core/EM/PeiRamBoot/PeiRamBootCacheRdy.c b/Core/EM/PeiRamBoot/PeiRamBootCacheRdy.c new file mode 100644 index 0000000..1f7c5bf --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBootCacheRdy.c @@ -0,0 +1,114 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootCacheRdy.c 2 8/28/15 3:53a Tristinchou $ +// +// $Revision: 2 $ +// +// $Date: 8/28/15 3:53a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootCacheRdy.c $ +// +// 2 8/28/15 3:53a Tristinchou +// [TAG] EIP235157 +// [Category] Improvement +// [Description] Security vulnerability - PeiRamBoot: Should leave cold +// boot optimization only +// +// 1 4/22/11 1:39a Calvinchen +// Added Token "SAVE_ENTIRE_FV_TO_MEM" for OEM measure FV if needed. +// +// +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: PeiRamBootCacheRdy.c +// +// Description: PEI RAM BOOT Pei driver. +// +//<AMI_FHDR_END> +//********************************************************************** +//---------------------------------------------------------------------------- +// Includes +// Statements that include other files +#include <PEI.h> +#include <AmiPeiLib.h> +#include <AmiCspLib.h> +#include <PeiRamBoot.h> +//---------------------------------------------------------------------------- +// Function Externs +//---------------------------------------------------------------------------- +// Local prototypes +EFI_GUID gRomCacheEnablePpiGuid = ROM_CACHE_ENABLE_PPI_GUID; + +// PPI to be installed +EFI_PEI_PPI_DESCRIPTOR RomCacheEnablePpiList[] = { + { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gRomCacheEnablePpiGuid, NULL + } +}; +//---------------------------------------------------------------------------- +// Local Variables + +//---------------------------------------------------------------------------- +// Function Definitions +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PeiRamBootCacheRdyEntry +// +// Description: PEI Entry Point for PeiRamBootCacheRdy Driver. +// +// Input: EFI_FFS_FILE_HEADER* - FfsHeader +// EFI_PEI_SERVICES** - PeiServices +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +PeiRamBootCacheRdyEntry ( + IN EFI_FFS_FILE_HEADER *FfsHeader, + IN EFI_PEI_SERVICES **PeiServices +) +{ + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + + Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode); + if (EFI_ERROR(Status)) return Status; + if ((BootMode == BOOT_ON_FLASH_UPDATE) || (BootMode == BOOT_ON_S3_RESUME) || \ + (BootMode == BOOT_IN_RECOVERY_MODE)) return Status; + Status = (*PeiServices)->InstallPpi (PeiServices, RomCacheEnablePpiList); + return Status; + +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//*************************************************************************
\ No newline at end of file diff --git a/Core/EM/PeiRamBoot/PeiRamBootCacheRdy.dxs b/Core/EM/PeiRamBoot/PeiRamBootCacheRdy.dxs new file mode 100644 index 0000000..812d727 --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBootCacheRdy.dxs @@ -0,0 +1,57 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootCacheRdy.dxs 1 4/22/11 1:39a Calvinchen $ +// +// $Revision: 1 $ +// +// $Date: 4/22/11 1:39a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootCacheRdy.dxs $ +// +// 1 4/22/11 1:39a Calvinchen +// Added Token "SAVE_ENTIRE_FV_TO_MEM" for OEM measure FV if needed. +// +// +// +//********************************************************************** +#include <pei.h> +#include "ppi\CpuIo.h" +#include "ppi\PciCfg.h" +#include "ppi\ReadOnlyVariable.h" +#include "ppi\Stall.h" + +DEPENDENCY_START + EFI_PEI_PERMANENT_MEMORY_INSTALLED_PPI AND + EFI_PEI_CPU_IO_PPI_INSTALLED_GUID AND + EFI_PEI_READ_ONLY_VARIABLE_PPI_GUID AND + EFI_PEI_PCI_CFG_PPI_INSTALLED_GUID AND + EFI_PEI_STALL_PPI_GUID +DEPENDENCY_END +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* diff --git a/Core/EM/PeiRamBoot/PeiRamBootDxe.c b/Core/EM/PeiRamBoot/PeiRamBootDxe.c new file mode 100644 index 0000000..57c9ac9 --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBootDxe.c @@ -0,0 +1,368 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootDxe.c 12 8/28/15 3:52a Tristinchou $ +// +// $Revision: 12 $ +// +// $Date: 8/28/15 3:52a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootDxe.c $ +// +// 12 8/28/15 3:52a Tristinchou +// [TAG] EIP235157 +// [Category] Improvement +// [Description] Security vulnerability - PeiRamBoot: Should leave cold +// boot optimization only +// +// 11 5/05/14 5:03a Calvinchen +// [TAG] EIP166551 +// [Category] Spec Update +// [Severity] Important +// [Description] Runtime attribute set for the some of the variable used +// by PEI Ram Boot driver and needs to be reviewed +// [Files] PeiRamBootDxe.c +// PeiRamBootOfbd.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 10 1/16/13 4:54a Calvinchen +// [TAG] EIP108319 +// [Category] Bug Fix +// [Severity] Minor +// [Symptom] When we enable PEI RAM BOOT module and set the token +// ˇ§PEI_RAM_S3_SUPPOTˇ¨ to 0, smbios will not be writable, system will +// hang up when writing smbios under DOS using DMI tool. +// [RootCause] Don't Restore the Base Address of Firmware Volume Block +// Protocol from RAM to ROM. +// [Solution] Restore the Base Address of Firmware Volume Block Protocol +// from RAM to ROM. +// [Files] PeiRamBootDxe.c +// +// 9 8/08/12 4:53a Calvinchen +// 1. Changed for ReportFv2.c by Artem's suggestion. +// 2. Fixed System hangs if Memory Mapping Changed with warm boot. +// +// 8 5/04/12 5:03a Calvinchen +// [TAG] EIP88796 +// [Category] Bug Fix +// [Severity] Minor +// [Symptom] (JP0005-Q208)When define more than two FV which has the +// same CUSTOM_SIZE, GetPhysicalAddress() returns invalid value. +// [RootCause] Coding mistake. +// [Solution] (JP0005-Q208)When define more than two FV which has the +// same CUSTOM_SIZE, GetPhysicalAddress() returns invalid value. +// [Files] PeiRamBootDxe.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 7 2/23/12 6:35a Calvinchen +// [TAG] EIP82264 +// [Category] Improvement +// [Description] Need to do cold boot to get the correct data in rom +// hole when changing data in rom hole. +// [Files] PeiRamBoot.sdl +// PeiRamBoot.mak +// PeiRamBoot.h +// PeiRamBoot.c +// PeiRamBootDxe.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 6 5/27/11 7:22a Calvinchen +// Delete HobRomImage Variable if Recovery mode. +// +// 5 4/22/11 1:28a Calvinchen +// +// 4 3/22/11 7:52a Calvinchen +// [TAG] EIP56322 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] System hangs after changing TPM settings in SETUP. +// [RootCause] System Memory Mappings are changed with warm boot. +// [Solution] BIOS always go cold boot path if system memory mappings +// are changed +// [Files] PeiRamBoot.sdl +// PeiRamBoot.mak +// PeiRamBoot.dxs +// PeiRamBoot.h +// PeiRamBoot.c +// PeiRamBootHook.c +// PeiRamBootDxe.c +// PeiRamBootOfbd.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 3 12/14/10 2:25a Calvinchen +// Improvement : +// 1. Added an eLink "PeiRamBootList" for fast warm boot support +// (PEI_RAM_BOOT_S3_SUPPORT = 1). If system boots in warm boot state, BIOS +// directly boot to previous copied ROM image in RAM to save time of +// copying ROM. +// 2. Added "PEI_RAM_BOOT_S3_SUPPORT" = "2" for saving runtime memory, it +// only keep necessary PEIM FFS in runtime memory for S3 resume +// improvement. +// +// 2 12/02/10 6:18a Calvinchen +// Bug Fixed : Fixed Update SMBIOS Structures failed with DMI Utility. +// +// 1 10/27/10 2:48a Calvinchen +// Initial Check-in. +// +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: PeiRamBootDxe.c +// +// Description: PEI RAM BOOT DXE driver. +// +//<AMI_FHDR_END> +//********************************************************************** +//---------------------------------------------------------------------------- +// Includes +// Statements that include other files +#include <AmiDxeLib.h> +#include <AmiCspLib.h> +#include <PeiRamBoot.h> +#include <Protocol\FirmwareVolumeBlock.h> + +//---------------------------------------------------------------------------- +// Function Externs + +//---------------------------------------------------------------------------- +// Local prototypes +typedef struct { + UINTN Base; + UINTN Length; +} LBA_CACHE; + +typedef struct { + MEMMAP_DEVICE_PATH MemMapDevPath; + EFI_DEVICE_PATH_PROTOCOL EndDevPath; +} FV_DEVICE_PATH; + + +typedef struct { + UINTN Signature; + EFI_HANDLE Handle; + FV_DEVICE_PATH DevicePath; + EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL FwVolBlockInstance; + UINTN NumBlocks; + LBA_CACHE *LbaCache; + UINT32 FvbAttributes; + EFI_PHYSICAL_ADDRESS BaseAddress; +} EFI_FW_VOL_BLOCK_DEVICE; + +#define FVB_DEVICE_SIGNATURE EFI_SIGNATURE_32('_','F','V','B') + +#ifndef _CR +#define _CR(Record, TYPE, Field) ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field))) +#endif +#ifndef CR +#define CR(Record, TYPE, Field, Signature) _CR (Record, TYPE, Field) +#endif +#ifndef EFI_FVB_MEMORY_MAPPED +#define EFI_FVB_MEMORY_MAPPED EFI_FVB2_MEMORY_MAPPED +#endif + +#define FVB_DEVICE_FROM_THIS(a) \ + CR(a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE) + +EFI_GUID gEfiFirmwareVolumeBlockProtocolGuid = FW_VOLUME_BLOCK_PROTOCOL_GUID; + +//---------------------------------------------------------------------------- +// Local Variables +//---------------------------------------------------------------------------- +// Function Definitions +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: DeleteHobRomImageVariable +// +// Description: Delete HobRomImage Variable event. +// +// Input: None. +// +// Output: None. +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +DeleteHobRomImageVariable ( + IN EFI_EVENT Event, + IN VOID *ParentImageHandle +) +{ + EFI_GUID RomImageAddressGuid = ROM_IMAGE_ADDRESS_GUID; + + pRS->SetVariable ( L"HobRomImage", + &RomImageAddressGuid, \ + EFI_VARIABLE_NON_VOLATILE | \ + EFI_VARIABLE_BOOTSERVICE_ACCESS, \ + 0, \ + ParentImageHandle ); + return EFI_SUCCESS; +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PeiRamBootDxeInit +// +// Description: DXE Entry Point for PeiRamBoot Driver. +// +// Input: EFI_HANDLE - ImageHandle +// EFI_SYSTEM_TABLE* - SystemTable +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +PeiRamBootDxeInit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable +) +{ + EFI_GUID GuidHob = HOB_LIST_GUID; + EFI_STATUS Status; + EFI_GUID RomImageHobGuid = ROM_IMAGE_MEMORY_HOB_GUID; + EFI_GUID RomImageAddressGuid = ROM_IMAGE_ADDRESS_GUID; + UINTN VarSize = 0, NumHandles; + UINT8 i, j; + EFI_PHYSICAL_ADDRESS HobRomImageAddress = 0; + VOID *p = NULL; + EFI_HOB_FIRMWARE_VOLUME *FvHob = NULL; + HOB_ROM_IMAGE *HobRomImage; + EFI_HANDLE *HandleBuffer; + EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; + EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock; + EFI_EVENT EvtSetupChange = NULL; + VOID *RgnSetupChange = NULL; + EFI_GUID AmitseSetupNvramUpdateGuid = \ + {0xd84beff0, 0x159a, 0x4b60, 0x9a, 0xb9, 0xac, 0x5c, 0x47, 0x4b, 0xd3, 0xb1}; + + InitAmiLib(ImageHandle, SystemTable); + + // Get RamBoot Informatoin from HOB. + HobRomImage = (HOB_ROM_IMAGE*)GetEfiConfigurationTable (pST, &GuidHob); + Status = FindNextHobByGuid (&RomImageHobGuid, (VOID**)&HobRomImage); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + + // Redirect the FV address to RAM and Free memory. + for (p = GetEfiConfigurationTable (pST, &GuidHob); + !(FindNextHobByType(EFI_HOB_TYPE_FV,&p)); ) { + FvHob = (EFI_HOB_FIRMWARE_VOLUME*)p; + for (i = 0; i < HobRomImage->NumOfFv; i++) { + if ((FvHob->BaseAddress == HobRomImage->FvInfo[i].MemAddress) && \ + (FvHob->Length == HobRomImage->FvInfo[i].FvLength)) { + FvHob->BaseAddress = HobRomImage->FvInfo[i].FvAddress; + pBS->FreePages (HobRomImage->FvInfo[i].MemAddress, \ + HobRomImage->FvInfo[i].NumOfPages); + break; + } + } + } + + // Restore the Base Address of Firmware Volume Block Protocol from RAM + // to ROM. + Status = pBS->LocateHandleBuffer ( ByProtocol, \ + &gEfiFirmwareVolumeBlockProtocolGuid, \ + NULL, \ + &NumHandles, \ + &HandleBuffer ); + if (EFI_ERROR(Status)) return Status; + + for (i = 0; i < NumHandles; ++i) { + Status = pBS->HandleProtocol ( HandleBuffer[i], \ + &gEfiFirmwareVolumeBlockProtocolGuid, \ + &FvBlock ); + if (EFI_ERROR(Status)) continue; + FvbDevice = FVB_DEVICE_FROM_THIS (FvBlock); + if (!(FvbDevice->FvbAttributes & EFI_FVB_MEMORY_MAPPED)) continue; +//-TRACE((-1, "FvBaseAddress[%02X] = %08X\n", i, FvbDevice->BaseAddress)); + for (j = 0; j < HobRomImage->NumOfFv; j++) { + if ((FvbDevice->BaseAddress == HobRomImage->FvInfo[j].MemAddress) && \ + (FvbDevice->NumBlocks == \ + (HobRomImage->FvInfo[j].FvLength / FLASH_BLOCK_SIZE))) { + FvbDevice->BaseAddress = HobRomImage->FvInfo[j].FvAddress; + } + } + } + + return EFI_SUCCESS; +} +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PeiRamBootSmmInit +// +// Description: PeiRamBoot InSmm Function. +// +// Input: EFI_HANDLE - ImageHandle +// EFI_SYSTEM_TABLE* - SystemTable +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +PeiRamBootDxeSmmInit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable +) +{ + return EFI_SUCCESS; +} +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PeiRamBootDxeEntry +// +// Description: DXE Entry Point for PeiRamBoot Driver. +// +// Input: EFI_HANDLE - ImageHandle +// EFI_SYSTEM_TABLE* - SystemTable +// +// Output: EFI_STATUS +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +PeiRamBootDxeEntry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable +) +{ + InitAmiLib(ImageHandle,SystemTable); + return InitSmmHandlerEx(ImageHandle, \ + SystemTable, PeiRamBootDxeSmmInit, PeiRamBootDxeInit); +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2009, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//*************************************************************************
\ No newline at end of file diff --git a/Core/EM/PeiRamBoot/PeiRamBootFvHook.c b/Core/EM/PeiRamBoot/PeiRamBootFvHook.c new file mode 100644 index 0000000..bab5415 --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBootFvHook.c @@ -0,0 +1,184 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootFvHook.c 4 1/16/13 6:33a Calvinchen $ +// +// $Revision: 4 $ +// +// $Date: 1/16/13 6:33a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootFvHook.c $ +// +// 4 1/16/13 6:33a Calvinchen +// Update Header. +// +// 3 8/08/12 4:25a Calvinchen +// 1. Changed for ReportFv2.c by Artem's suggestion. +// 2. Fixed System hangs if Memory Mapping Changed with warm boot. +// +// 2 7/18/12 3:41a Calvinchen +// +// 1 7/18/12 3:33a Calvinchen +// [TAG] EIPNone +// [Category] New Feature +// [Description] Added support for Nested Firmware Volume. +// +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: PeiRamBootFvHook.c +// +// Description: Hook File for Report Firmware Volume. +// +//<AMI_FHDR_END> +//********************************************************************** +//---------------------------------------------------------------------------- +// Includes +// Statements that include other files +#include <RomLayout.h> +#include <Token.h> +#include <AmiPeiLib.h> +#include <AmiCspLib.h> +#include <PeiRamBoot.h> +//---------------------------------------------------------------------------- +// Function Externs +extern +EFI_STATUS PublishFv( + IN EFI_PEI_SERVICES **PeiServices, + IN ROM_AREA *Area, + IN BOOLEAN Nested +); +extern +EFI_STATUS CreateFvHob2( + IN EFI_PEI_SERVICES **PeiServices, + IN ROM_AREA *Area, + IN EFI_GUID *FvName, + IN EFI_GUID *FfsName +); +extern +EFI_STATUS CreateFvInfoPpi( + IN EFI_PEI_SERVICES **PeiServices, + IN ROM_AREA *Area, + IN EFI_GUID *FvName OPTIONAL, + IN EFI_GUID *FfsName OPTIONAL +); +//---------------------------------------------------------------------------- +// Local prototypes + +//---------------------------------------------------------------------------- +// Local Variables + +//---------------------------------------------------------------------------- +// Function Definitions +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PeiRamBootNestedFvPublishing +// +// Description: +// +// Input: EFI_PEI_SERVICES** - PeiServices +// ROM_AREA* - Area +// +// Output: EFI_STATUS +// ROM_AREA* - Area +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +EFI_STATUS +PeiRamBootNestedFvPublishing ( + IN EFI_PEI_SERVICES **PeiServices, + IN OUT ROM_AREA *Area, + OUT EFI_FIRMWARE_VOLUME_HEADER **Fv, + OUT EFI_FIRMWARE_VOLUME_HEADER **NewFv, + OUT EFI_FFS_FILE_HEADER **Nfv +) +{ + VOID *p, *p2; + static UINT8 NestedFvIndex = 0; + INTN Result; + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + EFI_GUID HobRomImageGuid = ROM_IMAGE_MEMORY_HOB_GUID; + EFI_PHYSICAL_ADDRESS NestedFvBuffer = 0, NestedFvInMem = 0, TopOfMemory = 0; + UINT32 NestedFvLength = 0; + EFI_FIRMWARE_VOLUME_HEADER *pFv; + + Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode); + if (EFI_ERROR(Status) || \ + (BootMode == BOOT_IN_RECOVERY_MODE) || \ + (BootMode == BOOT_ON_FLASH_UPDATE)) return EFI_UNSUPPORTED; + + for ((*PeiServices)->GetHobList(PeiServices,&p); \ + !(FindNextHobByType(EFI_HOB_TYPE_GUID_EXTENSION, &p)); ) { + Result = guidcmp(&((EFI_HOB_GUID_TYPE*)p)->Name, &HobRomImageGuid); + if (!Result) break; + } + if (Result) return EFI_UNSUPPORTED; + if (((HOB_ROM_IMAGE*)p)->HobValid == 0) { + // Try to decompress the Nested FV from memory if possible + UINT8 i; + ((HOB_ROM_IMAGE*)p)->NestedFvValid = 0; + for (i = 0; i < ((HOB_ROM_IMAGE*)p)->NumOfFv; i++) { + if ((Area->Address == ((HOB_ROM_IMAGE*)p)->FvInfo[i].FvAddress) && \ + (((HOB_ROM_IMAGE*)p)->FvInfo[i].FvMemReady == TRUE)) + *Fv = (EFI_FIRMWARE_VOLUME_HEADER*)((HOB_ROM_IMAGE*)p)->FvInfo[i].MemAddress; + } + return EFI_UNSUPPORTED; + } + pFv = (EFI_FIRMWARE_VOLUME_HEADER*)Area->Address; + NestedFvLength = ((HOB_ROM_IMAGE*)p)->NestedFvInfo[NestedFvIndex].FvLength; + NestedFvInMem = (EFI_PHYSICAL_ADDRESS)((HOB_ROM_IMAGE*)p)->NestedFvInfo[NestedFvIndex++].MemAddress; + // check whether NestFv memory is valid. + for ((*PeiServices)->GetHobList(PeiServices,&p2); \ + !(FindNextHobByType(EFI_HOB_TYPE_MEMORY_ALLOCATION, &p2)); ) { + TopOfMemory = ((EFI_HOB_MEMORY_ALLOCATION*)p2)->AllocDescriptor.MemoryBaseAddress; + } + if (TopOfMemory != ((NestedFvInMem & (EFI_PHYSICAL_ADDRESS)~0xfff) + NestedFvLength + 0x1000)) { + // Memory Mapping changed, decompress Nested FV and re-collect Nested FV information + ((HOB_ROM_IMAGE*)p)->NestedFvValid = 0; + return EFI_UNSUPPORTED; + } + + Status = (*PeiServices)->FfsFindNextFile (PeiServices, \ + EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, pFv, Nfv); + if(EFI_ERROR(Status)) return Status; + + Status = (*PeiServices)->AllocatePages(PeiServices, \ + EfiRuntimeServicesData, (NestedFvLength >> 12) + 1, &NestedFvBuffer); + if (EFI_ERROR(Status)) return EFI_UNSUPPORTED; + if ((NestedFvInMem & (EFI_PHYSICAL_ADDRESS)~0xfff) != NestedFvBuffer) { + return EFI_UNSUPPORTED; + } + *NewFv = (EFI_FIRMWARE_VOLUME_HEADER*)(EFI_PHYSICAL_ADDRESS)NestedFvInMem; + ((HOB_ROM_IMAGE*)p)->NestedFvValid = 1; + return EFI_SUCCESS; +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2012, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//*************************************************************************
\ No newline at end of file diff --git a/Core/EM/PeiRamBoot/PeiRamBootHook.c b/Core/EM/PeiRamBoot/PeiRamBootHook.c new file mode 100644 index 0000000..c01e103 --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBootHook.c @@ -0,0 +1,282 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootHook.c 8 8/28/15 3:51a Tristinchou $ +// +// $Revision: 8 $ +// +// $Date: 8/28/15 3:51a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootHook.c $ +// +// 8 8/28/15 3:51a Tristinchou +// [TAG] EIP235157 +// [Category] Improvement +// [Description] Security vulnerability - PeiRamBoot: Should leave cold +// boot optimization only +// +// 7 6/21/11 2:22a Calvinchen +// ˇP Bug Fixed: +// Bug Fixed: +// 1. Build failed if Core 4.6.4.0. +// 2. System could hang if SAVE_ENTIRE_FV_TO_MEM = 1with AMD platform. +// +// 6 5/27/11 7:22a Calvinchen +// Build failed if Core 4.6.4.1. +// +// 5 4/25/11 3:59a Calvinchen +// Build failed if Core version greater than 4.6.4.1 with PI 0.91. +// +// 4 4/22/11 1:27a Calvinchen +// +// 3 3/22/11 7:52a Calvinchen +// [TAG] EIP56322 +// [Category] Bug Fix +// [Severity] Normal +// [Symptom] System hangs after changing TPM settings in SETUP. +// [RootCause] System Memory Mappings are changed with warm boot. +// [Solution] BIOS always go cold boot path if system memory mappings +// are changed +// [Files] PeiRamBoot.sdl +// PeiRamBoot.mak +// PeiRamBoot.dxs +// PeiRamBoot.h +// PeiRamBoot.c +// PeiRamBootHook.c +// PeiRamBootDxe.c +// PeiRamBootOfbd.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 2 12/14/10 2:25a Calvinchen +// Improvement : +// 1. Added an eLink "PeiRamBootList" for fast warm boot support +// (PEI_RAM_BOOT_S3_SUPPORT = 1). If system boots in warm boot state, BIOS +// directly boot to previous copied ROM image in RAM to save time of +// copying ROM. +// 2. Added "PEI_RAM_BOOT_S3_SUPPORT" = "2" for saving runtime memory, it +// only keep necessary PEIM FFS in runtime memory for S3 resume +// improvement. +// +// 1 10/27/10 2:48a Calvinchen +// Initial Check-in. +// +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: PeiRamBootHook.c +// +// Description: Hook file for PEI Ram Boot module. +// +//<AMI_FHDR_END> +//********************************************************************** +//---------------------------------------------------------------------------- +// Includes +// Statements that include other files +#include <Tiano.h> +#include <PeiCore.h> +#include <Token.h> +#include <PeiRamBoot.h> + +//---------------------------------------------------------------------------- +// Function Externs + +//---------------------------------------------------------------------------- +// Local prototypes + +//---------------------------------------------------------------------------- +// Local Variables + +//---------------------------------------------------------------------------- +// Function Definitions +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: PeiDebugPrint +// +// Description: Worker function for debug print. +// +// Input: EFI_PEI_SERVICES** - PeiServices +// UINTN - ErrorLevel +// CHAR8* - Format +// +// Output: None. +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +#ifdef EFI_DEBUG + VOID + PeiDebugPrint ( +#if ((PI_SPECIFICATION_VERSION >= 0x0001000A) || (CORE_COMBINED_VERSION > 262785)) +#if (CORE_COMBINED_VERSION > 262785) + IN CONST EFI_PEI_SERVICES **PeiServices, +#else + IN EFI_PEI_SERVICES **PeiServices, +#endif +#else + IN EFI_PEI_SERVICES **PeiServices, +#endif + IN UINTN ErrorLevel, + IN CHAR8 *Format, + IN ... + ) + { + CHAR8 Buffer[256]; + va_list ArgList = va_start(ArgList,Format); + PrepareStatusCodeString( Buffer, sizeof(Buffer), Format, ArgList ); + (*PeiServices)->ReportStatusCode ( + (EFI_PEI_SERVICES**)PeiServices, EFI_DEBUG_CODE, + EFI_SOFTWARE_UNSPECIFIED, 0, NULL, + (EFI_STATUS_CODE_DATA *)Buffer + ); + va_end(ArgList); + } +#endif +#if (PI_SPECIFICATION_VERSION >= 0x0001000A) +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: IsPeimDispatched +// +// Description: +// +// Input: EFI_PEI_SERVICES** - PeiServices +// EFI_PHYSICAL_ADDRESS - Buffer +// +// Output: None. +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +BOOLEAN +IsPeimDispatched ( + IN EFI_PEI_SERVICES **PeiServices, + IN EFI_FFS_FILE_HEADER *FfsFile, + IN UINTN Index +) +{ + PEI_CORE_INSTANCE *Private = NULL; + Private = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); + return Private->Fv[Private->CurrentPeimFvCount].PeimState[Index]; +} +#else +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: GetDispatchedPeimBitMap +// +// Description: This procedure gets current PEIM dispatched BitMap from +// DispatchedData of Privatedata of PeiService. +// +// Input: EFI_PEI_SERVICES** - PeiServices +// EFI_PHYSICAL_ADDRESS - Buffer +// +// Output: None. +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +UINT64 +GetDispatchedPeimBitMap ( + IN EFI_PEI_SERVICES **PeiServices +) +{ + PEI_CORE_INSTANCE *PrivateData = NULL; + PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); + return PrivateData->DispatchData.DispatchedPeimBitMap; +} +#endif +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// +// Procedure: SwitchPeiServiceDataToRam +// +// Description: This procedure redirect the FV Bass Address of Private data of +// PEI Service from ROM to RAM. +// +// Input: EFI_PEI_SERVICES** - PeiServices +// EFI_PHYSICAL_ADDRESS - Buffer +// +// Output: None. +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID +SwitchPeiServiceDataToRam ( + IN EFI_PEI_SERVICES **PeiServices, + IN HOB_ROM_IMAGE *HobRomImage +) +{ + PEI_CORE_INSTANCE *PrivateData = NULL; + EFI_PHYSICAL_ADDRESS FvAddress = 0, PeimAddress = 0, Buffer = 0; + EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList = NULL; + UINTN i = 0, j = 0, Index; + EFI_STATUS Status = EFI_SUCCESS; + EFI_FFS_FILE_HEADER *FfsFile = NULL; + + + PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); +#if defined(PI_SPECIFICATION_VERSION) && (PI_SPECIFICATION_VERSION >= 0x0001000A) + for (i = 0, Index = 0; i < HobRomImage->NumOfFv; i++) { + Index = PrivateData->CurrentPeimFvCount; + FvAddress = \ + (EFI_PHYSICAL_ADDRESS)PrivateData->Fv[Index].FvHeader; + if ((UINT32)FvAddress != HobRomImage->FvInfo[i].FvAddress) continue; + Buffer = HobRomImage->FvInfo[i].MemAddress; + PrivateData->Fv[Index].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Buffer; + for (j = 0; (j < PEI_CORE_MAX_PEIM_PER_FV) && \ + (PrivateData->CurrentFvFileHandles[j] != NULL); j++) { + PrivateData->CurrentFvFileHandles[j] = \ + (EFI_PEI_FILE_HANDLE)(((UINTN)PrivateData->CurrentFvFileHandles[j] - \ + (UINTN)FvAddress) + Buffer); + PrivateData->Fv[Index].FvFileHandles[j] = \ + (EFI_PEI_FILE_HANDLE)(((UINTN)PrivateData->Fv[Index].FvFileHandles[j] - \ + (UINTN)FvAddress) + Buffer); + } + } +#else // // PI 0.9 & 1.0 + // Update PrivateData.DispatchData of PeiService. + FvAddress = (EFI_PHYSICAL_ADDRESS)PrivateData->DispatchData.BootFvAddress; + for (i = 0, Index = 0; i < HobRomImage->NumOfFv; i++) { + if ((UINT32)FvAddress != HobRomImage->FvInfo[i].FvAddress) continue; + Buffer = HobRomImage->FvInfo[i].MemAddress; + PrivateData->DispatchData.BootFvAddress = \ + (EFI_FIRMWARE_VOLUME_HEADER*)(Buffer); + PrivateData->DispatchData.CurrentFvAddress = \ + (EFI_FIRMWARE_VOLUME_HEADER*)(Buffer); + // CurrentPeimAddress point to last PEIM, so, dispatcher will start at + // the 1st in next time. + // find last FFS.. + PeimAddress = (EFI_PHYSICAL_ADDRESS)PrivateData->DispatchData.CurrentPeimAddress; + PrivateData->DispatchData.CurrentPeimAddress = \ + (EFI_FFS_FILE_HEADER*)(Buffer + (PeimAddress - FvAddress)); + break; + } +#endif // PI 0.9 & 1.0 +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2009, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//*************************************************************************
\ No newline at end of file diff --git a/Core/EM/PeiRamBoot/PeiRamBootOfbd.c b/Core/EM/PeiRamBoot/PeiRamBootOfbd.c new file mode 100644 index 0000000..8d324d8 --- /dev/null +++ b/Core/EM/PeiRamBoot/PeiRamBootOfbd.c @@ -0,0 +1,185 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootOfbd.c 3 6/18/14 11:57p Calvinchen $ +// +// $Revision: 3 $ +// +// $Date: 6/18/14 11:57p $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootOfbd.c $ +// +// 3 6/18/14 11:57p Calvinchen +// Bug Fixed: System hangs with using AFU. +// +// 2 5/05/14 5:03a Calvinchen +// [TAG] EIP166551 +// [Category] Spec Update +// [Severity] Important +// [Description] Runtime attribute set for the some of the variable used +// by PEI Ram Boot driver and needs to be reviewed +// [Files] PeiRamBootDxe.c +// PeiRamBootOfbd.c +// PeiRamBoot.chm +// PeiRamBoot.cif +// +// 1 2/11/11 3:15a Calvinchen +// Bug Fixed : System hangs after reflashed BIOS with warm reset if +// PEI_RAM_BOOT_S3_SUPPORT = 1 with fast warm boot support. +// +// +//********************************************************************** +//<AMI_FHDR_START> +// +// Name: PeiRamBootOfbd.c +// +// Description: If system updated BIOS with warm reset, PeiRamBoot module +// will not copy rom to ram in sequence boot, and, it could +// cause system crashed. For avoiding this situation, BIOS +// delete the PEI RAM Boot related variables if system executed +// AFU. +// +//<AMI_FHDR_END> +//********************************************************************** +//---------------------------------------------------------------------------- +// Includes +// Statements that include other files +#include <AmiLib.h> +#include <AmiDxeLib.h> +#include <Setup.h> +#include <HOB.h> +#include "PeiRamBoot.h" +#include "OFBD.h" +//---------------------------------------------------------------------------- +// Function Externs + +//---------------------------------------------------------------------------- +// Local prototypes +typedef EFI_STATUS (*SHOW_BOOT_TIME_VARIABLES)(BOOLEAN Show); +typedef struct{ + SHOW_BOOT_TIME_VARIABLES ShowBootTimeVariables; +} AMI_NVRAM_CONTROL_PROTOCOL; +static AMI_NVRAM_CONTROL_PROTOCOL *gpNvramControl = NULL; + +//---------------------------------------------------------------------------- +// Local Variables + +//---------------------------------------------------------------------------- +// Function Definitions +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// Procedure: PeiRamBootOfbdEntry +// +// Description: +// +// Input: +// IN VOID *Buffer +// IN OUT UINT8 *pOFBDDataHandled +// Output: +// VOID +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID PeiRamBootOfbdEntry ( + IN VOID *Buffer, + IN OUT UINT8 *pOFBDDataHandled ) +{ + EFI_GUID RomImageAddressGuid = ROM_IMAGE_ADDRESS_GUID; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS HobRomImageAddress; + UINTN VariableSize; + static BOOLEAN blIsProcessed = FALSE; + + if (blIsProcessed == FALSE) blIsProcessed = TRUE; + else return; + + // Temporarily enable Nvram Variable Boot Time Access permission. + if (gpNvramControl) gpNvramControl->ShowBootTimeVariables(TRUE); + + VariableSize = sizeof(EFI_PHYSICAL_ADDRESS); + Status = pRS->GetVariable ( L"HobRomImage", \ + &RomImageAddressGuid, \ + NULL, \ + &VariableSize, \ + &HobRomImageAddress ); + if (!EFI_ERROR(Status)) { + // Delete HobRomImage Variable if system is executing AFU for forcing BIOS + // copy rom to image in sequence boot. + VariableSize = 0; + Status = pRS->SetVariable ( L"HobRomImage", \ + &RomImageAddressGuid, \ + EFI_VARIABLE_NON_VOLATILE | \ + EFI_VARIABLE_BOOTSERVICE_ACCESS, + VariableSize, \ + &HobRomImageAddress ); + } + // Disable Nvram Variable Boot Time Access permission. + if (gpNvramControl) gpNvramControl->ShowBootTimeVariables(FALSE); + return; +} + +//<AMI_PHDR_START> +//---------------------------------------------------------------------------- +// Procedure: PeiRamBootOfbdInSmm +// +// Description: +// +// Input: +// VOID +// +// Output: +// VOID +// +//---------------------------------------------------------------------------- +//<AMI_PHDR_END> +VOID PeiRamBootOfbdInSmm (VOID) +{ + EFI_STATUS Status; + EFI_SMM_BASE2_PROTOCOL *pSmmBase2; + EFI_SMM_SYSTEM_TABLE2 *mSmst; + UINTN i; + EFI_CONFIGURATION_TABLE *Table; + static EFI_GUID gAmiNvramControlProtocolGuid = \ + { 0xf7ca7568, 0x5a09, 0x4d2c, { 0x8a, 0x9b, 0x75, 0x84, 0x68, 0x59, 0x2a, 0xe2 } }; + + Status = pBS->LocateProtocol(&gEfiSmmBase2ProtocolGuid, NULL, &pSmmBase2); + if (EFI_ERROR(Status)) return ; + + Status = pSmmBase2->GetSmstLocation (pSmmBase2, &mSmst); + if (EFI_ERROR(Status)) return ; + + Table = mSmst->SmmConfigurationTable; + for (i = mSmst->NumberOfTableEntries; i; --i, ++Table) { + if (guidcmp(&Table->VendorGuid, &gAmiNvramControlProtocolGuid)) continue; + gpNvramControl = (AMI_NVRAM_CONTROL_PROTOCOL*)Table->VendorTable; + break; + } + return; +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2011, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* |