From ee4b3f812f53f00c322bb5198f69df3544da2892 Mon Sep 17 00:00:00 2001 From: Guo Dong Date: Tue, 22 Jan 2019 11:54:51 -0700 Subject: [PATCH] Add SMM support to UEFI payload Build a new SMM info HOB to payload to report SMM info. Add UEFI payload variable region into flash map. TEST=Tested on LeafHill with UEFI payload. Signed-off-by: Guo Dong --- BootloaderCommonPkg/BootloaderCommonPkg.dec | 1 + .../Include/Guid/FlashMapInfoGuid.h | 1 + .../Include/Guid/SmmInformationGuid.h | 31 +++++++++++++++++++ .../Include/Library/BootloaderCommonLib.h | 1 + BootloaderCorePkg/Stage2/Stage2.h | 1 + BootloaderCorePkg/Stage2/Stage2.inf | 3 +- BootloaderCorePkg/Stage2/Stage2Support.c | 7 +++++ BootloaderCorePkg/Tools/BuildUtility.py | 1 + BuildLoader.py | 4 +++ Platform/ApollolakeBoardPkg/BoardConfig.py | 17 +++++++--- .../Stage2BoardInitLib/Stage2BoardInitLib.c | 26 +++++++++++++++- .../Stage2BoardInitLib/Stage2BoardInitLib.h | 2 ++ .../Stage2BoardInitLib/Stage2BoardInitLib.inf | 1 + .../ApollolakeBoardPkg/Script/StitchLoader.py | 4 ++- Silicon/ApollolakePkg/Include/SaRegs.h | 3 ++ 15 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 BootloaderCommonPkg/Include/Guid/SmmInformationGuid.h diff --git a/BootloaderCommonPkg/BootloaderCommonPkg.dec b/BootloaderCommonPkg/BootloaderCommonPkg.dec index 4422f410..2d8f2053 100644 --- a/BootloaderCommonPkg/BootloaderCommonPkg.dec +++ b/BootloaderCommonPkg/BootloaderCommonPkg.dec @@ -44,6 +44,7 @@ gBootLoaderVersionFileGuid = { 0x3473a022, 0xc3c2, 0x4964, { 0xb3, 0x09, 0x22, 0xb3, 0xdf, 0xb0, 0xb6, 0xca } } gEfiDebugAgentGuid = { 0x865a5a9b, 0xb85d, 0x474c, { 0x84, 0x55, 0x65, 0xd1, 0xbe, 0x84, 0x4b, 0xe2 } } gDeviceTableHobGuid = { 0xd21fc32c, 0x7fd2, 0x435b, { 0xb8, 0xef, 0xc0, 0x42, 0x66, 0xa8, 0xf4, 0xf5 } } + gSmmInformationGuid = { 0x2d939d66, 0xceec, 0x4244, { 0x94, 0x97, 0x6e, 0x1c, 0x6f, 0x92, 0x54, 0x2c } } [PcdsFixedAtBuild] gPlatformCommonLibTokenSpaceGuid.PcdMaxLibraryDataEntry | 8 | UINT32 | 0x20000100 diff --git a/BootloaderCommonPkg/Include/Guid/FlashMapInfoGuid.h b/BootloaderCommonPkg/Include/Guid/FlashMapInfoGuid.h index a202837e..17b9ba69 100644 --- a/BootloaderCommonPkg/Include/Guid/FlashMapInfoGuid.h +++ b/BootloaderCommonPkg/Include/Guid/FlashMapInfoGuid.h @@ -30,6 +30,7 @@ extern EFI_GUID gFlashMapInfoGuid; #define FLASH_MAP_SIG_UCODE SIGNATURE_32 ('U', 'C', 'O', 'D') #define FLASH_MAP_SIG_MRCDATA SIGNATURE_32 ('M', 'R', 'C', 'D') #define FLASH_MAP_SIG_VARIABLE SIGNATURE_32 ('V', 'A', 'R', 'S') +#define FLASH_MAP_SIG_UEFIVARIABLE SIGNATURE_32 ('U', 'V', 'A', 'R') #define FLASH_MAP_SIG_PAYLOAD SIGNATURE_32 ('P', 'Y', 'L', 'D') #define FLASH_MAP_SIG_EPAYLOAD SIGNATURE_32 ('E', 'P', 'L', 'D') #define FLASH_MAP_SIG_SPI_IAS1 SIGNATURE_32 ('I', 'A', 'S', '1') diff --git a/BootloaderCommonPkg/Include/Guid/SmmInformationGuid.h b/BootloaderCommonPkg/Include/Guid/SmmInformationGuid.h new file mode 100644 index 00000000..f223c9a7 --- /dev/null +++ b/BootloaderCommonPkg/Include/Guid/SmmInformationGuid.h @@ -0,0 +1,31 @@ +/** @file + This file defines the hob structure for the SMM related info. + + Copyright (c) 2019, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __SMM_INFORMATION_GUID_H__ +#define __SMM_INFORMATION_GUID_H__ + +/// +/// Serial Port Information GUID +/// +extern EFI_GUID gSmmInformationGuid; + +typedef struct { + UINT8 Revision; + UINT8 Flags; + UINT8 Reserved[2]; + UINT32 SmmBase; + UINT32 SmmSize; +} SMM_INFORMATION; + +#endif diff --git a/BootloaderCommonPkg/Include/Library/BootloaderCommonLib.h b/BootloaderCommonPkg/Include/Library/BootloaderCommonLib.h index 642bc974..04374a8d 100644 --- a/BootloaderCommonPkg/Include/Library/BootloaderCommonLib.h +++ b/BootloaderCommonPkg/Include/Library/BootloaderCommonLib.h @@ -21,6 +21,7 @@ #include #define STACK_DEBUG_FILL_PATTERN 0x5AA55AA5 +#define UEFI_PAYLOAD_ID_SIGNATURE SIGNATURE_32('U', 'E', 'F', 'I') #define ALIGN_UP(address, align) (((address) + ((align) - 1)) & ~((align)-1)) #define ALIGN_DOWN(address, align) ((address) & ~((align)-1)) diff --git a/BootloaderCorePkg/Stage2/Stage2.h b/BootloaderCorePkg/Stage2/Stage2.h index 114cf65a..64a2f4fa 100644 --- a/BootloaderCorePkg/Stage2/Stage2.h +++ b/BootloaderCorePkg/Stage2/Stage2.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include diff --git a/BootloaderCorePkg/Stage2/Stage2.inf b/BootloaderCorePkg/Stage2/Stage2.inf index a3a56ed7..d46f7370 100755 --- a/BootloaderCorePkg/Stage2/Stage2.inf +++ b/BootloaderCorePkg/Stage2/Stage2.inf @@ -92,6 +92,7 @@ gSeedListInfoHobGuid gLoaderPlatformDataGuid gDeviceTableHobGuid + gSmmInformationGuid [Pcd] gPlatformCommonLibTokenSpaceGuid.PcdMaxLibraryDataEntry @@ -126,6 +127,6 @@ gPlatformCommonLibTokenSpaceGuid.PcdMeasuredBootEnabled gPlatformModuleTokenSpaceGuid.PcdSeedListBufferSize gPlatformCommonLibTokenSpaceGuid.PcdSeedListEnabled - + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress [Depex] TRUE diff --git a/BootloaderCorePkg/Stage2/Stage2Support.c b/BootloaderCorePkg/Stage2/Stage2Support.c index 6531e5bd..f6fbe8c0 100644 --- a/BootloaderCorePkg/Stage2/Stage2Support.c +++ b/BootloaderCorePkg/Stage2/Stage2Support.c @@ -524,6 +524,7 @@ BuildExtraInfoHob ( SEED_LIST_INFO_HOB *SeedListInfoHob; PLT_DEVICE_TABLE *DeviceTable; VOID *DeviceTableHob; + SMM_INFORMATION *SmmInfoHob; LdrGlobal = (LOADER_GLOBAL_DATA *)GetLoaderGlobalDataPointer(); S3Data = (S3_DATA *)LdrGlobal->S3DataPtr; @@ -617,6 +618,12 @@ BuildExtraInfoHob ( CopyMem (DeviceTableHob, DeviceTable, Length); } + // Build SMMRAM info Hob + SmmInfoHob = BuildGuidHob (&gSmmInformationGuid, sizeof (SMM_INFORMATION)); + if (SmmInfoHob != NULL) { + PlatformUpdateHobInfo (&gSmmInformationGuid, SmmInfoHob); + } + // Build Performance Hob Count = LdrGlobal->PerfData.PerfIndex; Length = sizeof (PERFORMANCE_INFO) + sizeof (UINT64) * Count; diff --git a/BootloaderCorePkg/Tools/BuildUtility.py b/BootloaderCorePkg/Tools/BuildUtility.py index f418f657..f5f534d3 100644 --- a/BootloaderCorePkg/Tools/BuildUtility.py +++ b/BootloaderCorePkg/Tools/BuildUtility.py @@ -198,6 +198,7 @@ class FlashMap(Structure): "VARIABLE" : "VARS", "PAYLOAD" : "PYLD", "EPAYLOAD" : "EPLD", + "UEFIVARIABLE" : "UVAR", "SPI_IAS1" : "IAS1", "SPI_IAS2" : "IAS2", "FWUPDATE" : "FWUP", diff --git a/BuildLoader.py b/BuildLoader.py index b79a2de6..ef99e743 100755 --- a/BuildLoader.py +++ b/BuildLoader.py @@ -192,6 +192,7 @@ class BaseBoard(object): self.CFGDATA_SIZE = 0 self.MRCDATA_SIZE = 0 self.VARIABLE_SIZE = 0 + self.UEFI_VARIABLE_SIZE = 0 self.FWUPDATE_SIZE = 0 self.SPI_IAS1_SIZE = 0 @@ -1076,6 +1077,9 @@ class Build(object): # create bootloader reserved binary of 4K size gen_file_with_size (os.path.join(self._fv_dir, 'SBLRSVD.bin'), 0x1000) + # create variable region for UEFI payload + if self._board.UEFI_VARIABLE_SIZE > 0: + gen_file_with_size (os.path.join(self._fv_dir, 'UEFIVARIABLE.bin'), self._board.UEFI_VARIABLE_SIZE) # create ACM binary if self._board.ACM_SIZE > 0: diff --git a/Platform/ApollolakeBoardPkg/BoardConfig.py b/Platform/ApollolakeBoardPkg/BoardConfig.py index 2acfa420..711d1225 100755 --- a/Platform/ApollolakeBoardPkg/BoardConfig.py +++ b/Platform/ApollolakeBoardPkg/BoardConfig.py @@ -98,10 +98,12 @@ class Board(BaseBoard): if len(self._PAYLOAD_NAME.split(';')) > 1: # EPAYLOAD is specified - self.EPAYLOAD_SIZE = 0x00120000 + self.EPAYLOAD_SIZE = 0x00130000 + self.UEFI_VARIABLE_SIZE = 0x00040000 else: # EPAYLOAD does not exist, create a dummy one self.EPAYLOAD_SIZE = 0x1000 + self.UEFI_VARIABLE_SIZE = 0x1000 if self.FSPDEBUG_MODE == 1: self.STAGE1B_SIZE += 0x00009000 @@ -134,15 +136,19 @@ class Board(BaseBoard): self.PLD_HEAP_SIZE = 0x08000000 - self.FWUPDATE_SIZE = 0x00030000 + self.FWUPDATE_SIZE = 0x00020000 self.CFGDATA_SIZE = 0x00004000 self.CFG_DATABASE_SIZE = self.CFGDATA_SIZE self.MRCDATA_SIZE = 0x00004000 self.VARIABLE_SIZE = 0x00002000 - self.SPI_IAS1_SIZE = 0x00150000 self.S3_DEBUG = 0 self.SBLRSVD_SIZE = 0x00001000 + if len(self._PAYLOAD_NAME.split(';')) > 1: + self.SPI_IAS1_SIZE = 0x00001000 + else: + self.SPI_IAS1_SIZE = 0x00150000 + self._CFGDATA_INT_FILE = ['CfgData_Int_LeafHill.dlt'] self._CFGDATA_EXT_FILE = ['CfgData_Ext_Gpmrb.dlt', 'CfgData_Ext_Up2.dlt','CfgData_Ext_OxbHill.dlt','CfgData_Ext_MB3.dlt','CfgData_Ext_JuniperHill.dlt'] @@ -244,10 +250,13 @@ class Board(BaseBoard): ), ('Stitch_IBBL.bin', [ ('STAGE1A.fd', '', self.STAGE1A_SIZE, STITCH_OPS.MODE_FILE_NOP, STITCH_OPS.MODE_POS_TAIL)] - ), + ), ('Stitch_EPLD.bin', [ ('EPAYLOAD.bin', '', self.EPAYLOAD_SIZE, STITCH_OPS.MODE_FILE_PAD, STITCH_OPS.MODE_POS_TAIL)] ), + ('Stitch_UVAR.bin', [ + ('UEFIVARIABLE.bin', '', self.UEFI_VARIABLE_SIZE, STITCH_OPS.MODE_FILE_NOP, STITCH_OPS.MODE_POS_TAIL)], + ), ]) return img_list diff --git a/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.c b/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.c index 390632c8..d14e6922 100644 --- a/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.c +++ b/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.c @@ -676,7 +676,7 @@ BoardInit ( SpiBaseAddress = GetDeviceAddr (OsBootDeviceSpi, 0); SpiBaseAddress = TO_MM_PCI_ADDRESS (SpiBaseAddress); - if ((GetBootMode() != BOOT_ON_FLASH_UPDATE) && (GetPayloadId() != 0)) { + if ((GetBootMode() != BOOT_ON_FLASH_UPDATE) && (GetPayloadId() != 0) && (GetPayloadId() != UEFI_PAYLOAD_ID_SIGNATURE)) { // Set the BIOS Lock Enable and EISS bits MmioOr8 (SpiBaseAddress + R_SPI_BCR, (UINT8) (B_SPI_BCR_BLE | B_SPI_BCR_EISS)); @@ -1304,6 +1304,28 @@ UpdateLoaderPlatformInfo ( } } + + +/** + Update loader SMM info. + + @param[out] SmmInfoHob pointer to SMM information HOB + +**/ +VOID +UpdateSmmInfo ( + OUT SMM_INFORMATION *SmmInfoHob +) +{ + + SmmInfoHob->SmmBase = MmioRead32 (TO_MM_PCI_ADDRESS (0x00000000) + TSEG) & ~0xF; + SmmInfoHob->SmmSize = MmioRead32 (TO_MM_PCI_ADDRESS (0x00000000) + BGSM) & ~0xF; + SmmInfoHob->SmmSize -= SmmInfoHob->SmmBase; + SmmInfoHob->Flags = 0; + DEBUG ((EFI_D_INFO, "SmmRamBase = 0x%x, SmmRamSize = 0x%x\n", SmmInfoHob->SmmBase, SmmInfoHob->SmmSize)); +} + + /** Update Hob Info with platform specific data @@ -1336,6 +1358,8 @@ PlatformUpdateHobInfo ( if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "Error caused while appending seeds to HOB: %r\n", Status)); } + } else if (Guid == &gSmmInformationGuid) { + UpdateSmmInfo (HobInfo); } } diff --git a/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.h b/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.h index c3e5a3c6..c97de2d8 100644 --- a/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.h +++ b/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.h @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,7 @@ #include #include #include +#include #define IOC_UART_PPR_CLK_N_DIV 0x64 #define IOC_UART_PPR_CLK_M_DIV 0x40 diff --git a/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.inf b/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.inf index f9cc5ce3..1a11abaa 100644 --- a/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.inf +++ b/Platform/ApollolakeBoardPkg/Library/Stage2BoardInitLib/Stage2BoardInitLib.inf @@ -67,6 +67,7 @@ gFspVariableNvDataHobGuid gEfiHeciMbpDataHobGuid gReservedMemoryResourceHobTsegGuid + gSmmInformationGuid [Pcd] gPlatformModuleTokenSpaceGuid.PcdPciResourceIoBase diff --git a/Platform/ApollolakeBoardPkg/Script/StitchLoader.py b/Platform/ApollolakeBoardPkg/Script/StitchLoader.py index ddeb7632..986924ba 100755 --- a/Platform/ApollolakeBoardPkg/Script/StitchLoader.py +++ b/Platform/ApollolakeBoardPkg/Script/StitchLoader.py @@ -371,6 +371,7 @@ def PatchFlashMap (ImageData, PlatformData = 0xffffffff): 'RSVD' : 'ROOT/IFWI/BP1/SBPDT/BpdtObb/RSVD', 'IAS1' : 'ROOT/IFWI/BP1/SBPDT/BpdtObb/PROV', 'EPLD' : 'ROOT/IFWI/BP1/SBPDT/BpdtObb/EPLD', + 'UVAR' : 'ROOT/IFWI/BP1/SBPDT/BpdtObb/UVAR', 'PYLD' : 'ROOT/IFWI/BP0/BPDT/BpdtIbb/PLD', 'VARS' : 'ROOT/IFWI/BP0/BPDT/BpdtIbb/VAR', 'MRCD' : 'ROOT/IFWI/BP0/BPDT/BpdtIbb/MRCD', @@ -812,6 +813,7 @@ def CreateIfwiImage (IfwiIn, IfwiOut, BiosOut, PlatformData, NonRedundant, Stitc ObbList = [ ('PROV' , 'FB'), ('EPLD' , 'EPLD'), + ('UVAR' , 'UVAR'), ('PLD' , 'PLD'), ] @@ -837,7 +839,7 @@ def CreateIfwiImage (IfwiIn, IfwiOut, BiosOut, PlatformData, NonRedundant, Stitc FilePath = '' else: FilePath = os.path.join(StitchDir, 'Stitch_%s.bin' % FileName) - if CompName == 'EPLD' and not os.path.exists(FilePath): + if (CompName == 'EPLD' or CompName == 'UVAR') and not os.path.exists(FilePath): Ret = 0 else: Ret = ManipulateIfwi ('ADD', Bp1Sbpdt + CompName, IfwiData, FilePath) diff --git a/Silicon/ApollolakePkg/Include/SaRegs.h b/Silicon/ApollolakePkg/Include/SaRegs.h index e0e94b7d..2019653c 100644 --- a/Silicon/ApollolakePkg/Include/SaRegs.h +++ b/Silicon/ApollolakePkg/Include/SaRegs.h @@ -299,4 +299,7 @@ #define IGD_SWSCI_OFFSET 0x00E0 #define IGD_ASLS_OFFSET 0x00FC +#define TSEG 0xb8 // TSEG base +#define BGSM 0xb4 // Base GTT Stolen Memory + #endif