From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com []) by mx.groups.io with SMTP id smtpd.web08.34931.1624204037148521455 for ; Sun, 20 Jun 2021 08:47:26 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: zhiguang.liu@intel.com) IronPort-SDR: BE7XssR+TiFNipqU7OqWGcFkOqN5d59XTkOUOK5tqwPuiPkMV5GLMkBNqNAbmHmqvlBh11INdf qcBE7r9JVWKw== X-IronPort-AV: E=McAfee;i="6200,9189,10021"; a="194044428" X-IronPort-AV: E=Sophos;i="5.83,287,1616482800"; d="scan'208";a="194044428" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2021 08:47:26 -0700 IronPort-SDR: N3+r+a9O6aImsNxnh9yh1umacqhpizM08BYUURnSCKvPMSV1VaqvwI6hhszSYfQTvzyGPmY07o tNPzIuX9iH3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,287,1616482800"; d="scan'208";a="451932653" Received: from fieedk002.ccr.corp.intel.com ([10.239.158.144]) by orsmga008.jf.intel.com with ESMTP; 20 Jun 2021 08:47:24 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Maurice Ma , Guo Dong , Benjamin You Subject: [PATCH 07/12] UefiPayloadPkg: Fix up UPL Pcd database Date: Sun, 20 Jun 2021 23:46:57 +0800 Message-Id: <20210620154702.2681-8-zhiguang.liu@intel.com> X-Mailer: git-send-email 2.30.0.windows.2 In-Reply-To: <20210620154702.2681-1-zhiguang.liu@intel.com> References: <20210620154702.2681-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Edk2 bootloader will pass the pei pcd database, and UPL also contain a PCD database. Dxe PCD driver has the assumption that the two PCD database can be catenated and the local token number should be successive=E3=80=82 This patch will manually fix up the UPL PCD database to meet that assumption. Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You Signed-off-by: Zhiguang Liu --- UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c | 18 +++++++++++= +------ UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h | 45 +++++++++++= ++++++++++++++++++++++++++++++++++ UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c | 55 +++++++++++= ++++++++++++++++++++++++++++++++++++++++++++ UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf | 2 ++ UefiPayloadPkg/UefiPayloadPkg.dec | 2 ++ UefiPayloadPkg/UefiPayloadPkg.dsc | 1 + 6 files changed, 117 insertions(+), 6 deletions(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c b/UefiPayloadPkg= /UefiPayloadEntry/LoadDxeCore.c index f5d70c59f8..f943a2632c 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c +++ b/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c @@ -114,20 +114,23 @@ LoadPeCoffImage ( }=0D =0D /**=0D - This function searchs a given file type within a valid FV.=0D + This function searchs a given file type with a given Guid within a valid= FV.=0D + If input Guid is NULL, will locate the first section having the given fi= le type=0D =0D @param FvHeader A pointer to firmware volume header that contains= the set of files=0D to be searched.=0D @param FileType File type to be searched.=0D + @param Guid Will ignore if it is NULL.=0D @param FileHeader A pointer to the discovered file, if successful.= =0D =0D @retval EFI_SUCCESS Successfully found FileType=0D @retval EFI_NOT_FOUND File type can't be found.=0D **/=0D EFI_STATUS=0D -FvFindFile (=0D +FvFindFileByTypeGuid (=0D IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader,=0D IN EFI_FV_FILETYPE FileType,=0D + IN EFI_GUID *Guid OPTIONAL,=0D OUT EFI_FFS_FILE_HEADER **FileHeader=0D )=0D {=0D @@ -172,7 +175,10 @@ FvFindFile ( //=0D if (File->Type =3D=3D FileType) {=0D *FileHeader =3D File;=0D - return EFI_SUCCESS;=0D + if (Guid =3D=3D NULL || CompareGuid(&File->Name, Guid)) {=0D + *FileHeader =3D File;=0D + return EFI_SUCCESS;=0D + }=0D }=0D }=0D =0D @@ -266,7 +272,7 @@ LoadDxeCore ( //=0D // DXE FV is inside Payload FV. Here find DXE FV from Payload FV=0D //=0D - Status =3D FvFindFile (PayloadFv, EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,= &FileHeader);=0D + Status =3D FvFindFileByTypeGuid (PayloadFv, EFI_FV_FILETYPE_FIRMWARE_VOL= UME_IMAGE, NULL, &FileHeader);=0D if (EFI_ERROR (Status)) {=0D return Status;=0D }=0D @@ -283,7 +289,7 @@ LoadDxeCore ( //=0D // Find DXE core file from DXE FV=0D //=0D - Status =3D FvFindFile (DxeCoreFv, EFI_FV_FILETYPE_DXE_CORE, &FileHeader)= ;=0D + Status =3D FvFindFileByTypeGuid (DxeCoreFv, EFI_FV_FILETYPE_DXE_CORE, NU= LL, &FileHeader);=0D if (EFI_ERROR (Status)) {=0D return Status;=0D }=0D @@ -330,7 +336,7 @@ UniversalLoadDxeCore ( //=0D // Find DXE core file from DXE FV=0D //=0D - Status =3D FvFindFile (DxeFv, EFI_FV_FILETYPE_DXE_CORE, &FileHeader);=0D + Status =3D FvFindFileByTypeGuid (DxeFv, EFI_FV_FILETYPE_DXE_CORE, NULL, = &FileHeader);=0D if (EFI_ERROR (Status)) {=0D return Status;=0D }=0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h b/UefiPaylo= adPkg/UefiPayloadEntry/UefiPayloadEntry.h index 35098f5141..78a67fa1a5 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h @@ -35,6 +35,7 @@ #include =0D #include =0D #include =0D +#include =0D =0D #define LEGACY_8259_MASK_REGISTER_MASTER 0x21=0D #define LEGACY_8259_MASK_REGISTER_SLAVE 0xA1=0D @@ -149,4 +150,48 @@ HandOffToDxeCore ( IN EFI_PEI_HOB_POINTERS HobList=0D );=0D =0D +EFI_STATUS=0D +FixUpPcdDatabase (=0D + IN EFI_FIRMWARE_VOLUME_HEADER *DxeFv=0D + );=0D +=0D +/**=0D + This function searchs a given section type within a valid FFS file.=0D +=0D + @param FileHeader A pointer to the file header that contains= the set of sections to=0D + be searched.=0D + @param SearchType The value of the section type to search.=0D + @param SectionData A pointer to the discovered section, if su= ccessful.=0D +=0D + @retval EFI_SUCCESS The section was found.=0D + @retval EFI_NOT_FOUND The section was not found.=0D +=0D +**/=0D +EFI_STATUS=0D +FileFindSection (=0D + IN EFI_FFS_FILE_HEADER *FileHeader,=0D + IN EFI_SECTION_TYPE SectionType,=0D + OUT VOID **SectionData=0D + );=0D +=0D +/**=0D + This function searchs a given file type with a given Guid within a valid= FV.=0D + If input Guid is NULL, will locate the first section having the given fi= le type=0D +=0D + @param FvHeader A pointer to firmware volume header that contains= the set of files=0D + to be searched.=0D + @param FileType File type to be searched.=0D + @param Guid Will ignore if it is NULL.=0D + @param FileHeader A pointer to the discovered file, if successful.= =0D +=0D + @retval EFI_SUCCESS Successfully found FileType=0D + @retval EFI_NOT_FOUND File type can't be found.=0D +**/=0D +EFI_STATUS=0D +FvFindFileByTypeGuid (=0D + IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader,=0D + IN EFI_FV_FILETYPE FileType,=0D + IN EFI_GUID *Guid OPTIONAL,=0D + OUT EFI_FFS_FILE_HEADER **FileHeader=0D + );=0D #endif=0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c b/Uefi= PayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c index 9d59454486..dcf750befc 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c @@ -25,6 +25,60 @@ =0D extern VOID *mHobList;=0D =0D +/**=0D + Find DXE core from FV and build DXE core HOBs.=0D +=0D + @param[in] FvBase FV base to load DXE core from=0D + @param[out] DxeCoreEntryPoint DXE core entry point=0D +=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval EFI_NOT_FOUND If it failed to load DXE FV.=0D +**/=0D +EFI_STATUS=0D +FixUpPcdDatabase (=0D + IN EFI_FIRMWARE_VOLUME_HEADER *DxeFv=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_FFS_FILE_HEADER *FileHeader;=0D + VOID *PcdRawData;=0D + PEI_PCD_DATABASE *PeiDatabase;=0D + PEI_PCD_DATABASE *UplDatabase;=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D + DYNAMICEX_MAPPING *ExMapTable;=0D + UINTN Index;=0D +=0D + GuidHob =3D GetFirstGuidHob (&gPcdDataBaseHobGuid);=0D + if (GuidHob =3D=3D NULL) {=0D + //=0D + // No fix-up is needed.=0D + //=0D + return EFI_SUCCESS;=0D + }=0D + PeiDatabase =3D (PEI_PCD_DATABASE *) GET_GUID_HOB_DATA (GuidHob);=0D + DEBUG ((DEBUG_INFO, "Find the Pei PCD data base, the total local token n= umber is %d\n", PeiDatabase->LocalTokenCount));=0D +=0D + Status =3D FvFindFileByTypeGuid (DxeFv, EFI_FV_FILETYPE_DRIVER, PcdGetPt= r (PcdPcdDriverFile), &FileHeader);=0D + ASSERT_EFI_ERROR (Status);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D + Status =3D FileFindSection (FileHeader, EFI_SECTION_RAW, &PcdRawData);=0D + ASSERT_EFI_ERROR (Status);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + UplDatabase =3D (PEI_PCD_DATABASE *) PcdRawData;=0D + ExMapTable =3D (DYNAMICEX_MAPPING *) (UINTN) ((UINTN) PcdRawData + UplD= atabase->ExMapTableOffset);=0D +=0D + for (Index =3D 0; Index < UplDatabase->ExTokenCount; Index++) {=0D + ExMapTable[Index].TokenNumber +=3D PeiDatabase->LocalTokenCount;=0D + }=0D + DEBUG ((DEBUG_INFO, "Fix up UPL PCD database successfully\n"));=0D + return EFI_SUCCESS;=0D +}=0D +=0D /**=0D Add HOB into HOB list=0D =0D @@ -332,6 +386,7 @@ _ModuleEntryPoint ( Status =3D BuildHobs (BootloaderParameter, &DxeFv);=0D ASSERT_EFI_ERROR (Status);=0D =0D + FixUpPcdDatabase (DxeFv);=0D Status =3D UniversalLoadDxeCore (DxeFv, &DxeCoreEntryPoint);=0D ASSERT_EFI_ERROR (Status);=0D =0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf b/Ue= fiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf index 77cd25aafd..76d7e4791c 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf @@ -63,6 +63,7 @@ gEfiAcpiTableGuid=0D gUefiSerialPortInfoGuid=0D gUniversalPayloadExtraDataGuid=0D + gPcdDataBaseHobGuid=0D =0D [FeaturePcd.IA32]=0D gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUME= S=0D @@ -72,6 +73,7 @@ =0D =0D [Pcd.IA32,Pcd.X64]=0D + gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile=0D gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ##= SOMETIMES_CONSUMES=0D gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES=0D gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES=0D diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayload= Pkg.dec index 105e1f5a1c..d84f560995 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPayloadPkg.dec @@ -72,3 +72,5 @@ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServ= icesCode|0x80|UINT32|0x =0D # Size of the region used by UEFI in permanent memory=0D gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x02000000|UIN= T32|0x00000017=0D +=0D +gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0= xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOI= D*|0x00000018=0D diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload= Pkg.dsc index d8277efccd..e3d669a6d6 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -298,6 +298,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable|TRUE=0D gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 }=0D =0D + gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80,= 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }=0D =0D !if $(SOURCE_DEBUG_ENABLE)=0D gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2=0D --=20 2.16.2.windows.1