From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mx.groups.io with SMTP id smtpd.web10.4741.1665396756880691388 for ; Mon, 10 Oct 2022 03:12:36 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=fCauMyH6; spf=pass (domain: ventanamicro.com, ip: 209.85.215.169, mailfrom: sunilvl@ventanamicro.com) Received: by mail-pg1-f169.google.com with SMTP id q9so9927395pgq.8 for ; Mon, 10 Oct 2022 03:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1eeruPUfVusYUS28T+8HE7su0+TT5N19IVLnIL/B4E0=; b=fCauMyH6WC3jlwNN4xvlzh+ooMxQrMBeEF7I2Jh8iH7Rg/3FEbcmnPRyiEHpMs0/OR 2ufvbA4qhhPMvIzWCfvXM+sp9OdtChvlRlkPV65GEcWqGAffJ4CQCKTEpY607kvYmuXo V6FWwP3cDbACfnIIqWHg2efntIbFuicbchv2o3CmZbQuPGoxVn7m1ucCtEN3jssGypXj p7bPD0RNfyAhF+cENuj/GBCBdIPvB9KVqLVXt6fIE89aQeAs8DYU4vq1TLnSFp0xgCZ6 orghR8jh4kTyaTvOAx3dBg0p5bi8quCsHIWxZL99D3+gWNmnlRtK5H+5Mz0nKY1qx8kk udjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1eeruPUfVusYUS28T+8HE7su0+TT5N19IVLnIL/B4E0=; b=O7iT7BRYjdatRcWdz9aKKdfeCTtEOBf8QB2hTzRYJP1xiwdDikHTpWQIcBQ6QEjm6c lFkUSW8hm5o6h3h8n15wYYbGjcq8GoD1JXUTjwFG/+y8G3subhlPeLtcMMQRDrKJjpCe Il0LR/lzHjrgE25kgTwIK6wx3mN3jSzYLpFsDvyLJin045MH0aqs3+3doXm+vwbuXDFx htyHySMBYzw2veQna9lEcUOeWHe1CUZWiThTLmv1UjfPNW9JjZsLDuN5BDcVe+LzrgW0 UFoGsnqpk1cMB9Xt3XksYm1Wv/O4/AXp9sjt1iOiZbF6Ai6bhCpgqOUC4E2eMLRqIvIM 3+/Q== X-Gm-Message-State: ACrzQf0LelvbXvIitQvmQnuzLMX/v6B03XTqJr2Ne4vcd+mfdKvAPitj F52AAH9pX5p7FfFONwLJpmZpXpo+uvdBlA== X-Google-Smtp-Source: AMsMyM7KO+cELWj1A0lkFcoGQxBz/CfsN/JRxrkQ4uMJnkifOdUbw/yF/Qpq+J4NEdlbnI/Cn99D/Q== X-Received: by 2002:a63:2166:0:b0:44e:d2c5:2f98 with SMTP id s38-20020a632166000000b0044ed2c52f98mr16253071pgm.272.1665396755974; Mon, 10 Oct 2022 03:12:35 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([49.206.13.138]) by smtp.gmail.com with ESMTPSA id h17-20020a170902f55100b001788ccecbf5sm6302138plf.31.2022.10.10.03.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 03:12:35 -0700 (PDT) From: "Sunil V L" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Brijesh Singh , Erdem Aktas , James Bottomley , Min Xu , Tom Lendacky Subject: [edk2-staging/RiscV64QemuVirt PATCH 09/29] OvmfPkg/Sec: Refactor to allow other architectures Date: Mon, 10 Oct 2022 15:41:42 +0530 Message-Id: <20221010101202.1146624-10-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221010101202.1146624-1-sunilvl@ventanamicro.com> References: <20221010101202.1146624-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4076 Currently, the Sec module supports only X86 architecture. Refactor the module to allow other CPU architectures. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Min Xu Cc: Tom Lendacky Signed-off-by: Sunil V L --- OvmfPkg/Sec/SecMain.inf | 18 +- OvmfPkg/Sec/{ => Ia32_X64}/AmdSev.h | 0 OvmfPkg/Sec/SecMainCommon.h | 73 ++++++++ OvmfPkg/Sec/{ => Ia32_X64}/AmdSev.c | 0 OvmfPkg/Sec/{ => Ia32_X64}/SecMain.c | 227 +------------------------ OvmfPkg/Sec/SecMainCommon.c | 238 +++++++++++++++++++++++++++ 6 files changed, 323 insertions(+), 233 deletions(-) rename OvmfPkg/Sec/{ => Ia32_X64}/AmdSev.h (100%) create mode 100644 OvmfPkg/Sec/SecMainCommon.h rename OvmfPkg/Sec/{ => Ia32_X64}/AmdSev.c (100%) rename OvmfPkg/Sec/{ => Ia32_X64}/SecMain.c (75%) create mode 100644 OvmfPkg/Sec/SecMainCommon.c diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 561a840f29c5..7c80ecaaf49b 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -21,10 +21,12 @@ [Defines] # VALID_ARCHITECTURES = IA32 X64 EBC # -[Sources] - SecMain.c - AmdSev.c - AmdSev.h +[Sources.IA32, Sources.X64] + SecMainCommon.c + SecMainCommon.h + Ia32_X64/SecMain.c + Ia32_X64/AmdSev.c + Ia32_X64/AmdSev.h [Sources.IA32] Ia32/SecEntry.nasm @@ -42,19 +44,21 @@ [LibraryClasses] BaseLib DebugLib BaseMemoryLib - PeiServicesLib PcdLib CpuLib - UefiCpuLib DebugAgentLib IoLib PeCoffLib PeCoffGetEntryPointLib PeCoffExtraActionLib ExtractGuidedSectionLib + CpuExceptionHandlerLib + +[LibraryClasses.IA32, LibraryClasses.X64] + UefiCpuLib LocalApicLib MemEncryptSevLib - CpuExceptionHandlerLib + PeiServicesLib CcProbeLib [Ppis] diff --git a/OvmfPkg/Sec/AmdSev.h b/OvmfPkg/Sec/Ia32_X64/AmdSev.h similarity index 100% rename from OvmfPkg/Sec/AmdSev.h rename to OvmfPkg/Sec/Ia32_X64/AmdSev.h diff --git a/OvmfPkg/Sec/SecMainCommon.h b/OvmfPkg/Sec/SecMainCommon.h new file mode 100644 index 000000000000..c3cc16e2c8cf --- /dev/null +++ b/OvmfPkg/Sec/SecMainCommon.h @@ -0,0 +1,73 @@ +/** @file + Header file for common functions of Sec. + + Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +/** + Locates a section within a series of sections + with the specified section type. + + The Instance parameter indicates which instance of the section + type to return. (0 is first instance, 1 is second...) + + @param[in] Sections The sections to search + @param[in] SizeOfSections Total size of all sections + @param[in] SectionType The section type to locate + @param[in] Instance The section instance number + @param[out] FoundSection The FFS section if found + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted + +**/ +EFI_STATUS +FindFfsSectionInstance ( + IN VOID *Sections, + IN UINTN SizeOfSections, + IN EFI_SECTION_TYPE SectionType, + IN UINTN Instance, + OUT EFI_COMMON_SECTION_HEADER **FoundSection + ); + +/** + Locates a FFS file with the specified file type and a section + within that file with the specified section type. + + @param[in] Fv The firmware volume to search + @param[in] FileType The file type to locate + @param[in] SectionType The section type to locate + @param[out] FoundSection The FFS section if found + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted + +**/ +EFI_STATUS +FindFfsFileAndSection ( + IN EFI_FIRMWARE_VOLUME_HEADER *Fv, + IN EFI_FV_FILETYPE FileType, + IN EFI_SECTION_TYPE SectionType, + OUT EFI_COMMON_SECTION_HEADER **FoundSection + ); + +/** + Locates the PEI Core entry point address + + @param[in] Fv The firmware volume to search + @param[out] PeiCoreEntryPoint The entry point of the PEI Core image + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted + +**/ +EFI_STATUS +FindPeiCoreImageBaseInFv ( + IN EFI_FIRMWARE_VOLUME_HEADER *Fv, + OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase + ); diff --git a/OvmfPkg/Sec/AmdSev.c b/OvmfPkg/Sec/Ia32_X64/AmdSev.c similarity index 100% rename from OvmfPkg/Sec/AmdSev.c rename to OvmfPkg/Sec/Ia32_X64/AmdSev.c diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/Ia32_X64/SecMain.c similarity index 75% rename from OvmfPkg/Sec/SecMain.c rename to OvmfPkg/Sec/Ia32_X64/SecMain.c index 1167d22a68cc..096bab074f35 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/Ia32_X64/SecMain.c @@ -32,6 +32,7 @@ #include #include #include "AmdSev.h" +#include "SecMainCommon.h" #define SEC_IDT_ENTRY_COUNT 34 @@ -143,189 +144,6 @@ FindMainFv ( } while (TRUE); } -/** - Locates a section within a series of sections - with the specified section type. - - The Instance parameter indicates which instance of the section - type to return. (0 is first instance, 1 is second...) - - @param[in] Sections The sections to search - @param[in] SizeOfSections Total size of all sections - @param[in] SectionType The section type to locate - @param[in] Instance The section instance number - @param[out] FoundSection The FFS section if found - - @retval EFI_SUCCESS The file and section was found - @retval EFI_NOT_FOUND The file and section was not found - @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted - -**/ -EFI_STATUS -FindFfsSectionInstance ( - IN VOID *Sections, - IN UINTN SizeOfSections, - IN EFI_SECTION_TYPE SectionType, - IN UINTN Instance, - OUT EFI_COMMON_SECTION_HEADER **FoundSection - ) -{ - EFI_PHYSICAL_ADDRESS CurrentAddress; - UINT32 Size; - EFI_PHYSICAL_ADDRESS EndOfSections; - EFI_COMMON_SECTION_HEADER *Section; - EFI_PHYSICAL_ADDRESS EndOfSection; - - // - // Loop through the FFS file sections within the PEI Core FFS file - // - EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)Sections; - EndOfSections = EndOfSection + SizeOfSections; - for ( ; ;) { - if (EndOfSection == EndOfSections) { - break; - } - - CurrentAddress = (EndOfSection + 3) & ~(3ULL); - if (CurrentAddress >= EndOfSections) { - return EFI_VOLUME_CORRUPTED; - } - - Section = (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddress; - - Size = SECTION_SIZE (Section); - if (Size < sizeof (*Section)) { - return EFI_VOLUME_CORRUPTED; - } - - EndOfSection = CurrentAddress + Size; - if (EndOfSection > EndOfSections) { - return EFI_VOLUME_CORRUPTED; - } - - // - // Look for the requested section type - // - if (Section->Type == SectionType) { - if (Instance == 0) { - *FoundSection = Section; - return EFI_SUCCESS; - } else { - Instance--; - } - } - } - - return EFI_NOT_FOUND; -} - -/** - Locates a section within a series of sections - with the specified section type. - - @param[in] Sections The sections to search - @param[in] SizeOfSections Total size of all sections - @param[in] SectionType The section type to locate - @param[out] FoundSection The FFS section if found - - @retval EFI_SUCCESS The file and section was found - @retval EFI_NOT_FOUND The file and section was not found - @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted - -**/ -EFI_STATUS -FindFfsSectionInSections ( - IN VOID *Sections, - IN UINTN SizeOfSections, - IN EFI_SECTION_TYPE SectionType, - OUT EFI_COMMON_SECTION_HEADER **FoundSection - ) -{ - return FindFfsSectionInstance ( - Sections, - SizeOfSections, - SectionType, - 0, - FoundSection - ); -} - -/** - Locates a FFS file with the specified file type and a section - within that file with the specified section type. - - @param[in] Fv The firmware volume to search - @param[in] FileType The file type to locate - @param[in] SectionType The section type to locate - @param[out] FoundSection The FFS section if found - - @retval EFI_SUCCESS The file and section was found - @retval EFI_NOT_FOUND The file and section was not found - @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted - -**/ -EFI_STATUS -FindFfsFileAndSection ( - IN EFI_FIRMWARE_VOLUME_HEADER *Fv, - IN EFI_FV_FILETYPE FileType, - IN EFI_SECTION_TYPE SectionType, - OUT EFI_COMMON_SECTION_HEADER **FoundSection - ) -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS CurrentAddress; - EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume; - EFI_FFS_FILE_HEADER *File; - UINT32 Size; - EFI_PHYSICAL_ADDRESS EndOfFile; - - if (Fv->Signature != EFI_FVH_SIGNATURE) { - DEBUG ((DEBUG_ERROR, "FV at %p does not have FV header signature\n", Fv)); - return EFI_VOLUME_CORRUPTED; - } - - CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Fv; - EndOfFirmwareVolume = CurrentAddress + Fv->FvLength; - - // - // Loop through the FFS files in the Boot Firmware Volume - // - for (EndOfFile = CurrentAddress + Fv->HeaderLength; ; ) { - CurrentAddress = (EndOfFile + 7) & ~(7ULL); - if (CurrentAddress > EndOfFirmwareVolume) { - return EFI_VOLUME_CORRUPTED; - } - - File = (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress; - Size = FFS_FILE_SIZE (File); - if (Size < (sizeof (*File) + sizeof (EFI_COMMON_SECTION_HEADER))) { - return EFI_VOLUME_CORRUPTED; - } - - EndOfFile = CurrentAddress + Size; - if (EndOfFile > EndOfFirmwareVolume) { - return EFI_VOLUME_CORRUPTED; - } - - // - // Look for the request file type - // - if (File->Type != FileType) { - continue; - } - - Status = FindFfsSectionInSections ( - (VOID *)(File + 1), - (UINTN)EndOfFile - (UINTN)(File + 1), - SectionType, - FoundSection - ); - if (!EFI_ERROR (Status) || (Status == EFI_VOLUME_CORRUPTED)) { - return Status; - } - } -} - /** Locates the compressed main firmware volume and decompresses it. @@ -474,49 +292,6 @@ DecompressMemFvs ( return EFI_SUCCESS; } -/** - Locates the PEI Core entry point address - - @param[in] Fv The firmware volume to search - @param[out] PeiCoreEntryPoint The entry point of the PEI Core image - - @retval EFI_SUCCESS The file and section was found - @retval EFI_NOT_FOUND The file and section was not found - @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted - -**/ -EFI_STATUS -FindPeiCoreImageBaseInFv ( - IN EFI_FIRMWARE_VOLUME_HEADER *Fv, - OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase - ) -{ - EFI_STATUS Status; - EFI_COMMON_SECTION_HEADER *Section; - - Status = FindFfsFileAndSection ( - Fv, - EFI_FV_FILETYPE_PEI_CORE, - EFI_SECTION_PE32, - &Section - ); - if (EFI_ERROR (Status)) { - Status = FindFfsFileAndSection ( - Fv, - EFI_FV_FILETYPE_PEI_CORE, - EFI_SECTION_TE, - &Section - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "Unable to find PEI Core image\n")); - return Status; - } - } - - *PeiCoreImageBase = (EFI_PHYSICAL_ADDRESS)(UINTN)(Section + 1); - return EFI_SUCCESS; -} - /** Reads 8-bits of CMOS data. diff --git a/OvmfPkg/Sec/SecMainCommon.c b/OvmfPkg/Sec/SecMainCommon.c new file mode 100644 index 000000000000..f360e63a7c26 --- /dev/null +++ b/OvmfPkg/Sec/SecMainCommon.c @@ -0,0 +1,238 @@ +/** @file + Locate the entry point for the PEI Core + + Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include + +/** + Locates a section within a series of sections + with the specified section type. + + The Instance parameter indicates which instance of the section + type to return. (0 is first instance, 1 is second...) + + @param[in] Sections The sections to search + @param[in] SizeOfSections Total size of all sections + @param[in] SectionType The section type to locate + @param[in] Instance The section instance number + @param[out] FoundSection The FFS section if found + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted + +**/ +EFI_STATUS +FindFfsSectionInstance ( + IN VOID *Sections, + IN UINTN SizeOfSections, + IN EFI_SECTION_TYPE SectionType, + IN UINTN Instance, + OUT EFI_COMMON_SECTION_HEADER **FoundSection + ) +{ + EFI_PHYSICAL_ADDRESS CurrentAddress; + UINT32 Size; + EFI_PHYSICAL_ADDRESS EndOfSections; + EFI_COMMON_SECTION_HEADER *Section; + EFI_PHYSICAL_ADDRESS EndOfSection; + + // + // Loop through the FFS file sections within the PEI Core FFS file + // + EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)Sections; + EndOfSections = EndOfSection + SizeOfSections; + for ( ; ;) { + if (EndOfSection == EndOfSections) { + break; + } + + CurrentAddress = (EndOfSection + 3) & ~(3ULL); + if (CurrentAddress >= EndOfSections) { + return EFI_VOLUME_CORRUPTED; + } + + Section = (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddress; + + Size = SECTION_SIZE (Section); + if (Size < sizeof (*Section)) { + return EFI_VOLUME_CORRUPTED; + } + + EndOfSection = CurrentAddress + Size; + if (EndOfSection > EndOfSections) { + return EFI_VOLUME_CORRUPTED; + } + + // + // Look for the requested section type + // + if (Section->Type == SectionType) { + if (Instance == 0) { + *FoundSection = Section; + return EFI_SUCCESS; + } else { + Instance--; + } + } + } + + return EFI_NOT_FOUND; +} + +/** + Locates a section within a series of sections + with the specified section type. + + @param[in] Sections The sections to search + @param[in] SizeOfSections Total size of all sections + @param[in] SectionType The section type to locate + @param[out] FoundSection The FFS section if found + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted + +**/ +EFI_STATUS +FindFfsSectionInSections ( + IN VOID *Sections, + IN UINTN SizeOfSections, + IN EFI_SECTION_TYPE SectionType, + OUT EFI_COMMON_SECTION_HEADER **FoundSection + ) +{ + return FindFfsSectionInstance ( + Sections, + SizeOfSections, + SectionType, + 0, + FoundSection + ); +} + +/** + Locates a FFS file with the specified file type and a section + within that file with the specified section type. + + @param[in] Fv The firmware volume to search + @param[in] FileType The file type to locate + @param[in] SectionType The section type to locate + @param[out] FoundSection The FFS section if found + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted + +**/ +EFI_STATUS +FindFfsFileAndSection ( + IN EFI_FIRMWARE_VOLUME_HEADER *Fv, + IN EFI_FV_FILETYPE FileType, + IN EFI_SECTION_TYPE SectionType, + OUT EFI_COMMON_SECTION_HEADER **FoundSection + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS CurrentAddress; + EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume; + EFI_FFS_FILE_HEADER *File; + UINT32 Size; + EFI_PHYSICAL_ADDRESS EndOfFile; + + if (Fv->Signature != EFI_FVH_SIGNATURE) { + DEBUG ((DEBUG_ERROR, "FV at %p does not have FV header signature\n", Fv)); + return EFI_VOLUME_CORRUPTED; + } + + CurrentAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Fv; + EndOfFirmwareVolume = CurrentAddress + Fv->FvLength; + + // + // Loop through the FFS files in the Boot Firmware Volume + // + for (EndOfFile = CurrentAddress + Fv->HeaderLength; ; ) { + CurrentAddress = (EndOfFile + 7) & ~(7ULL); + if (CurrentAddress > EndOfFirmwareVolume) { + return EFI_VOLUME_CORRUPTED; + } + + File = (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress; + Size = FFS_FILE_SIZE (File); + if (Size < (sizeof (*File) + sizeof (EFI_COMMON_SECTION_HEADER))) { + return EFI_VOLUME_CORRUPTED; + } + + EndOfFile = CurrentAddress + Size; + if (EndOfFile > EndOfFirmwareVolume) { + return EFI_VOLUME_CORRUPTED; + } + + // + // Look for the request file type + // + if (File->Type != FileType) { + continue; + } + + Status = FindFfsSectionInSections ( + (VOID *)(File + 1), + (UINTN)EndOfFile - (UINTN)(File + 1), + SectionType, + FoundSection + ); + if (!EFI_ERROR (Status) || (Status == EFI_VOLUME_CORRUPTED)) { + return Status; + } + } +} + +/** + Locates the PEI Core entry point address + + @param[in] Fv The firmware volume to search + @param[out] PeiCoreEntryPoint The entry point of the PEI Core image + + @retval EFI_SUCCESS The file and section was found + @retval EFI_NOT_FOUND The file and section was not found + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted + +**/ +EFI_STATUS +FindPeiCoreImageBaseInFv ( + IN EFI_FIRMWARE_VOLUME_HEADER *Fv, + OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase + ) +{ + EFI_STATUS Status; + EFI_COMMON_SECTION_HEADER *Section; + + Status = FindFfsFileAndSection ( + Fv, + EFI_FV_FILETYPE_PEI_CORE, + EFI_SECTION_PE32, + &Section + ); + if (EFI_ERROR (Status)) { + Status = FindFfsFileAndSection ( + Fv, + EFI_FV_FILETYPE_PEI_CORE, + EFI_SECTION_TE, + &Section + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to find PEI Core image\n")); + return Status; + } + } + + *PeiCoreImageBase = (EFI_PHYSICAL_ADDRESS)(UINTN)(Section + 1); + return EFI_SUCCESS; +} -- 2.25.1