From nobody Mon Feb 9 22:20:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+76894+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+76894+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1624416776; cv=none; d=zohomail.com; s=zohoarc; b=FNGKBet+RWQXe+WqW4E5s9GVCsCusE/STlaMsLewR6KCCOk/tErMa9/of02QkROSyvkba9Kh8POOfYV0F3/ZnQfZ+BwTtVq4fjjEZCzFcQXBnXIteBYdY0qyjlVvPxcywoBcm5n39iW2lDSJVKKsVUqesmLv7Zy8dnfiPGU49Q8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624416776; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=o0Bg/yZc1BUlOOzVvhQDhQ9FEgMZSNCzla0QIx6DtDk=; b=QVhrHAH8v6jla4Yli6/3IBoWgOZIR8qKatLpNDga5fMn5cWHvdVdHyuVrm6ftmGBqs3houIlg7EnlnOjk0d2HLvFfHPL/k1cRgQ95twvaquDnUXvEnpG+UhFgloUsI08xzkG3J7eGBr6MA79CG/OU1bSeAelHfDuAFogd5u8vCg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+76894+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1624416775951822.8615973262681; Tue, 22 Jun 2021 19:52:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id blPnYY1788612xntjFd5YLYv; Tue, 22 Jun 2021 19:52:54 -0700 X-Received: from mga11.intel.com (mga11.intel.com []) by mx.groups.io with SMTP id smtpd.web11.2469.1624416764968334886 for ; Tue, 22 Jun 2021 19:52:54 -0700 IronPort-SDR: lp6FdD/VtN7OTLv9BbsJ711pAXBKBXYxuIx++PM72yYS+Ewvq/ye77oMsdCEbn2fUfCS6wZfzU uDIAMgCFdXaQ== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="204175529" X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="204175529" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 19:52:53 -0700 IronPort-SDR: pPGaGgXIFxDCJHJpfTcTHaeO1uVtLYHqKmosSSzlAnYrJTeddJE7zCivTw3YRNMIU/NSor4HVe wuEIA+JGPEjQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="487138320" X-Received: from fieedk002.ccr.corp.intel.com ([10.239.158.144]) by orsmga001.jf.intel.com with ESMTP; 22 Jun 2021 19:52:52 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Maurice Ma , Guo Dong , Benjamin You Subject: [edk2-devel] [Patch V2 07/12] UefiPayloadPkg: Fix up UPL Pcd database Date: Wed, 23 Jun 2021 10:52:30 +0800 Message-Id: <20210623025235.3311-8-zhiguang.liu@intel.com> In-Reply-To: <20210623025235.3311-1-zhiguang.liu@intel.com> References: <20210623025235.3311-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhiguang.liu@intel.com X-Gm-Message-State: tlhFOs6bqzNGA9ZLmnPHJa2kx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1624416774; bh=EnUtTKvyoH/mdv3wTjrsqH/qKPCDRyiZEw7ice9xE78=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=ABAAJmAd36w6tVrutKxbhHI7JIp972Huj3H7tzAEH+51XTtwMdClJ4qyMDTQ0TBnaJc 0+Bn3dQkMgpxkR6XhdbOhtTNId/p5Blse9RVmdd8MtYkOvwlJHaoQ1g5KDPCTEZW611L3 R1ZM6iTmka0La2XJUNfsTs8C+0hv0QMelRM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" V1: 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. V2: Update the function comments Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You Signed-off-by: Zhiguang Liu Reviewed-by: Guo Dong --- UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c | 19 +++++++++++= +------- UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h | 45 +++++++++++= ++++++++++++++++++++++++++++++++++ UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c | 57 +++++++++++= ++++++++++++++++++++++++++++++++++++++++++++++ UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf | 2 ++ UefiPayloadPkg/UefiPayloadPkg.dec | 2 ++ UefiPayloadPkg/UefiPayloadPkg.dsc | 1 + 6 files changed, 119 insertions(+), 7 deletions(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c b/UefiPayloadPkg= /UefiPayloadEntry/LoadDxeCore.c index f5d70c59f8..0b6cb47cd0 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c +++ b/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c @@ -114,20 +114,23 @@ LoadPeCoffImage ( } =20 /** - This function searchs a given file type within a valid FV. + This function searchs a given file type with a given Guid within a valid= FV. + If input Guid is NULL, will locate the first section having the given fi= le type =20 @param FvHeader A pointer to firmware volume header that contains= the set of files to be searched. @param FileType File type to be searched. + @param Guid Will ignore if it is NULL. @param FileHeader A pointer to the discovered file, if successful. =20 @retval EFI_SUCCESS Successfully found FileType @retval EFI_NOT_FOUND File type can't be found. **/ EFI_STATUS -FvFindFile ( +FvFindFileByTypeGuid ( IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader, IN EFI_FV_FILETYPE FileType, + IN EFI_GUID *Guid OPTIONAL, OUT EFI_FFS_FILE_HEADER **FileHeader ) { @@ -171,8 +174,10 @@ FvFindFile ( // Look for file type // if (File->Type =3D=3D FileType) { - *FileHeader =3D File; - return EFI_SUCCESS; + if (Guid =3D=3D NULL || CompareGuid(&File->Name, Guid)) { + *FileHeader =3D File; + return EFI_SUCCESS; + } } } =20 @@ -266,7 +271,7 @@ LoadDxeCore ( // // DXE FV is inside Payload FV. Here find DXE FV from Payload FV // - Status =3D FvFindFile (PayloadFv, EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,= &FileHeader); + Status =3D FvFindFileByTypeGuid (PayloadFv, EFI_FV_FILETYPE_FIRMWARE_VOL= UME_IMAGE, NULL, &FileHeader); if (EFI_ERROR (Status)) { return Status; } @@ -283,7 +288,7 @@ LoadDxeCore ( // // Find DXE core file from DXE FV // - Status =3D FvFindFile (DxeCoreFv, EFI_FV_FILETYPE_DXE_CORE, &FileHeader); + Status =3D FvFindFileByTypeGuid (DxeCoreFv, EFI_FV_FILETYPE_DXE_CORE, NU= LL, &FileHeader); if (EFI_ERROR (Status)) { return Status; } @@ -330,7 +335,7 @@ UniversalLoadDxeCore ( // // Find DXE core file from DXE FV // - Status =3D FvFindFile (DxeFv, EFI_FV_FILETYPE_DXE_CORE, &FileHeader); + Status =3D FvFindFileByTypeGuid (DxeFv, EFI_FV_FILETYPE_DXE_CORE, NULL, = &FileHeader); if (EFI_ERROR (Status)) { return Status; } diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h b/UefiPaylo= adPkg/UefiPayloadEntry/UefiPayloadEntry.h index dff7b6b87f..331724c687 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h @@ -35,6 +35,7 @@ #include #include #include +#include =20 #define LEGACY_8259_MASK_REGISTER_MASTER 0x21 #define LEGACY_8259_MASK_REGISTER_SLAVE 0xA1 @@ -159,4 +160,48 @@ HandOffToDxeCore ( IN EFI_PEI_HOB_POINTERS HobList ); =20 +EFI_STATUS +FixUpPcdDatabase ( + IN EFI_FIRMWARE_VOLUME_HEADER *DxeFv + ); + +/** + This function searchs a given section type within a valid FFS file. + + @param FileHeader A pointer to the file header that contains= the set of sections to + be searched. + @param SearchType The value of the section type to search. + @param SectionData A pointer to the discovered section, if su= ccessful. + + @retval EFI_SUCCESS The section was found. + @retval EFI_NOT_FOUND The section was not found. + +**/ +EFI_STATUS +FileFindSection ( + IN EFI_FFS_FILE_HEADER *FileHeader, + IN EFI_SECTION_TYPE SectionType, + OUT VOID **SectionData + ); + +/** + This function searchs a given file type with a given Guid within a valid= FV. + If input Guid is NULL, will locate the first section having the given fi= le type + + @param FvHeader A pointer to firmware volume header that contains= the set of files + to be searched. + @param FileType File type to be searched. + @param Guid Will ignore if it is NULL. + @param FileHeader A pointer to the discovered file, if successful. + + @retval EFI_SUCCESS Successfully found FileType + @retval EFI_NOT_FOUND File type can't be found. +**/ +EFI_STATUS +FvFindFileByTypeGuid ( + IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader, + IN EFI_FV_FILETYPE FileType, + IN EFI_GUID *Guid OPTIONAL, + OUT EFI_FFS_FILE_HEADER **FileHeader + ); #endif diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c b/Uefi= PayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c index 9d59454486..b8c1317df0 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c @@ -25,6 +25,62 @@ =20 extern VOID *mHobList; =20 +/** + Some bootloader may pass a pcd database, and UPL also contain a PCD data= base. + Dxe PCD driver has the assumption that the two PCD database can be caten= ated and + the local token number should be successive=E3=80=82 + This function will fix up the UPL PCD database to meet that assumption. + + @param[in] DxeFv The FV where to find the Universal PCD databa= se. + + @retval EFI_SUCCESS If it completed successfully. + @retval other Failed to fix up. +**/ +EFI_STATUS +FixUpPcdDatabase ( + IN EFI_FIRMWARE_VOLUME_HEADER *DxeFv + ) +{ + EFI_STATUS Status; + EFI_FFS_FILE_HEADER *FileHeader; + VOID *PcdRawData; + PEI_PCD_DATABASE *PeiDatabase; + PEI_PCD_DATABASE *UplDatabase; + EFI_HOB_GUID_TYPE *GuidHob; + DYNAMICEX_MAPPING *ExMapTable; + UINTN Index; + + GuidHob =3D GetFirstGuidHob (&gPcdDataBaseHobGuid); + if (GuidHob =3D=3D NULL) { + // + // No fix-up is needed. + // + return EFI_SUCCESS; + } + PeiDatabase =3D (PEI_PCD_DATABASE *) GET_GUID_HOB_DATA (GuidHob); + DEBUG ((DEBUG_INFO, "Find the Pei PCD data base, the total local token n= umber is %d\n", PeiDatabase->LocalTokenCount)); + + Status =3D FvFindFileByTypeGuid (DxeFv, EFI_FV_FILETYPE_DRIVER, PcdGetPt= r (PcdPcdDriverFile), &FileHeader); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + Status =3D FileFindSection (FileHeader, EFI_SECTION_RAW, &PcdRawData); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + UplDatabase =3D (PEI_PCD_DATABASE *) PcdRawData; + ExMapTable =3D (DYNAMICEX_MAPPING *) (UINTN) ((UINTN) PcdRawData + UplD= atabase->ExMapTableOffset); + + for (Index =3D 0; Index < UplDatabase->ExTokenCount; Index++) { + ExMapTable[Index].TokenNumber +=3D PeiDatabase->LocalTokenCount; + } + DEBUG ((DEBUG_INFO, "Fix up UPL PCD database successfully\n")); + return EFI_SUCCESS; +} + /** Add HOB into HOB list =20 @@ -332,6 +388,7 @@ _ModuleEntryPoint ( Status =3D BuildHobs (BootloaderParameter, &DxeFv); ASSERT_EFI_ERROR (Status); =20 + FixUpPcdDatabase (DxeFv); Status =3D UniversalLoadDxeCore (DxeFv, &DxeCoreEntryPoint); ASSERT_EFI_ERROR (Status); =20 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 gUefiSerialPortInfoGuid gUniversalPayloadExtraDataGuid + gPcdDataBaseHobGuid =20 [FeaturePcd.IA32] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUMES @@ -72,6 +73,7 @@ =20 =20 [Pcd.IA32,Pcd.X64] + gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ##= SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES 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 =20 # Size of the region used by UEFI in permanent memory gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x02000000|UIN= T32|0x00000017 + +gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0= xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOI= D*|0x00000018 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 gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } =20 + gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80,= 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 } =20 !if $(SOURCE_DEBUG_ENABLE) gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugLoadImageMethod|0x2 --=20 2.30.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#76894): https://edk2.groups.io/g/devel/message/76894 Mute This Topic: https://groups.io/mt/83730184/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-