[edk2-devel] [PATCH] REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3802
Since PRM module needs to support export table in PE-COFF, we'll enhance GenFw tool to support this. Add one export flag in GenFw tool. If export flag is set: Step1: Scan ELF symbol table based on PRM module descriptor to get descriptor offset address; Step2: Find PRM handlers number and name in COFF file based on the address from step1; Step3: Write PRM info such as handler name and export RVA into COFF export table. PRM option currently only supports DXE RUNTIME driver and X64 arch. Change-Id: I479b7c8b23beea12b5c567677688aef6f7af2085 Cc: Liming Gao Cc: Bob Feng Cc: Yuwei Chen Signed-off-by: Lixia Huang --- BaseTools/Source/C/GenFw/Elf64Convert.c | 242 +- BaseTools/Source/C/GenFw/ElfConvert.c | 8 + BaseTools/Source/C/GenFw/ElfConvert.h | 43 +++- BaseTools/Source/C/GenFw/GenFw.c | 20 +- .../C/Include/IndustryStandard/PeImage.h | 7 + 5 files changed, 315 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c index 0bb3ead228..2aa9bfcc94 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -56,6 +56,12 @@ WriteDebug64 ( VOID ); +STATIC +VOID +WriteExport64 ( + VOID + ); + STATIC VOID SetImageSize64 ( @@ -106,7 +112,7 @@ STATIC UINT32 mCoffAlignment = 0x20; // // PE section alignment. // -STATIC const UINT16 mCoffNbrSections = 4; +STATIC UINT16 mCoffNbrSections = 4; // // ELF sections to offset in Coff file. @@ -122,7 +128,7 @@ STATIC UINT32 mDataOffset; STATIC UINT32 mHiiRsrcOffset; STATIC UINT32 mRelocOffset; STATIC UINT32 mDebugOffset; - +STATIC UINT32 mExportOffset; // // Used for RISC-V relocations. // @@ -132,6 +138,14 @@ STATIC Elf64_Half mRiscVPass1SymSecIndex = 0; STATIC INT32 mRiscVPass1Offset; STATIC INT32 mRiscVPass1GotFixup; +// +// Used for Export section. +// +STATIC UINT32 mExportSize; +STATIC UINT32 mExportRVA[PRM_MODULE_EXPORT_SYMBOL_NUM]; +STATIC UINT32 mExportSymNum; +STATIC CHAR8 mExportSymName[PRM_MODULE_EXPORT_SYMBOL_NUM][PRM_HANDLER_NAME_MAXIMUM_LENGTH]; + // // Initialization Function // @@ -171,6 +185,13 @@ InitializeElf64 ( return FALSE; } + if (mExportFlag) { +if (mEhdr->e_machine != EM_X86_64) { + Error (NULL, 0, 3000, "Unsupported", "--prm option currently only supports X64 arch."); + return FALSE; +} + } + // // Update section header pointers // @@ -200,6 +221,11 @@ InitializeElf64 ( ElfFunctions->SetImageSize = SetImageSize64; ElfFunctions->CleanUp = CleanUp64; + if (mExportFlag) { +mCoffNbrSections ++; +ElfFunctions->WriteExport = WriteExport64; + } + return TRUE; } @@ -263,6 +289,17 @@ IsHiiRsrcShdr ( return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namedr->sh_offset + Shdr->sh_name, ELF_HII_SECTION_NAME) == 0); } +STATIC +BOOLEAN +IsSymbolShdr ( + Elf_Shdr *Shdr + ) +{ + Elf_Shdr *Namehdr = GetShdrByIndex(mEhdr->e_shstrndx); + + return (BOOLEAN) (strcmp((CHAR8*)mEhdr + Namehdr->sh_offset + Shdr->sh_name, ELF_SYMBOL_SECTION_NAME) == 0); +} + STATIC BOOLEAN IsDataShdr ( @@ -335,6 +372,37 @@ GetSymName ( return StrtabContents + Sym->st_name; } +// +// Get Prm Handler number and name +// +STATIC +VOID +FindPrmHandler ( + UINT64 Offset + ) +{ + PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER *PrmExport; + PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT *PrmHandler; + UINT32 HandlerNum; + + PrmExport = (PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER*)((UINT8*)mEhdr + Offset); + PrmHandler = (PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT *)(PrmExport + 1); + + for (HandlerNum = 0; HandlerNum < PrmExport->NumberPrmHandlers; HandlerNum++) { +strcpy(mExportSymName[mExportSymNum], PrmHandler->PrmHandlerName); +mExportSymNum ++; +PrmHandler += 1; + +// +// Check if PRM handler number is larger than (PRM_MODULE_EXPORT_SYMBOL_NUM - 1) +// +if (mExportSymNum >= (PRM_MODULE_EXPORT_SYMBOL_NUM - 1)) { + Error (NULL, 0, 3000, "Invalid", "FindPrmHandler: Number %u is too high.", mExportSymNum); + exit(EXIT_FAILURE); +} + } +} + // // Find the ELF section hosting the GOT from an ELF Rva // of a single GOT entry. Normally, GOT is placed in @@ -717,6 +785,7 @@ ScanSections64 ( UINT32 CoffEntry; UINT32 SectionCount; BOOLEAN FoundSection; + UINT32 Offset; CoffEntry = 0; mCoffOffset = 0; @@ -880,6 +949,82 @@ ScanSections64 ( Warning (NULL, 0, 0, NULL, "Multiple sections in %s are merged into 1 data section. Source level debug might not work correctly.", mInImageName); } + // + // The Symbol sections. + // + if (mExportFlag) { +UINT32 SymIndex; +Elf_Sym *Sym; +UINT64 SymNum; +const UINT8 *SymName; + +mExportOffset = mCoffOffset; +mExportSize = sizeof(EFI_IMAG
Re: [edk2-devel] [PATCH v1 2/7] MdeModulePkg: Invoke GetPhysicalAddressBits() and remove the duplicated code
Mike, Liming, This patch makes MdeModulePkg depend on UefiCpuPkg. But according to https://github.com/tianocore/edk2/blob/master/MdeModulePkg/MdeModulePkg.ci.yaml#L49, such dependency is not allowed. Do you agree to move the UefiCpuLib from UefiCpuPkg to MdePkg? The library header and instance are in following paths: https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/Include/Library/UefiCpuLib.h https://github.com/tianocore/edk2/tree/master/UefiCpuPkg/Library/BaseUefiCpuLib Thanks, Ray -Original Message- From: devel@edk2.groups.io On Behalf Of Yu Pu Sent: Wednesday, March 2, 2022 5:19 PM To: devel@edk2.groups.io Cc: Pu, Yu ; Wang, Jian J ; Gao, Liming Subject: [edk2-devel] [PATCH v1 2/7] MdeModulePkg: Invoke GetPhysicalAddressBits() and remove the duplicated code REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3394 Invoke GetPhysicalAddressBits() defined in UefiCpuPkg for CPU physical address mask calculation and remove the duplicated code in MdeModulePkg. Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Yu Pu --- MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c| 9 ++--- MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c | 14 ++ MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c| 14 ++ MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 2 ++ MdeModulePkg/MdeModulePkg.dsc | 1 + MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf | 2 ++ MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf| 2 ++ 7 files changed, 13 insertions(+), 31 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c index 0700f310b203..78e91e6e9024 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -22,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include #include #include "DxeIpl.h" #include "VirtualMemory.h" @@ -733,13 +734,7 @@ CreateIdentityMappingPageTables ( if (Hob != NULL) { PhysicalAddressBits = ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace; } else { -AsmCpuid (0x8000, &RegEax, NULL, NULL, NULL); -if (RegEax >= 0x8008) { - AsmCpuid (0x8008, &RegEax, NULL, NULL, NULL); - PhysicalAddressBits = (UINT8)RegEax; -} else { - PhysicalAddressBits = 36; -} +PhysicalAddressBits = GetPhysicalAddressBits(NULL, NULL); } Page5LevelSupport = FALSE; diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c index 6b44f50bac70..367bf8cdd1e6 100644 --- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c +++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/X64/SetIdtEntry.c @@ -10,6 +10,7 @@ Copyright (c) 2017, AMD Incorporated. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include #include "ScriptExecute.h" // @@ -51,20 +52,9 @@ HookPageFaultHandler ( IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry ) { - UINT32 RegEax; - UINT8 PhysicalAddressBits; UINTN PageFaultHandlerHookAddress; - AsmCpuid (0x8000, &RegEax, NULL, NULL, NULL); - if (RegEax >= 0x8008) { -AsmCpuid (0x8008, &RegEax, NULL, NULL, NULL); -PhysicalAddressBits = (UINT8)RegEax; - } else { -PhysicalAddressBits = 36; - } - - mPhyMask = LShiftU64 (1, PhysicalAddressBits) - 1; - mPhyMask &= (1ull << 48) - SIZE_4KB; + GetPhysicalAddressBits(NULL, &mPhyMask); // // Set Page Fault entry to catch >4G access diff --git a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c b/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c index 05941f9f8d56..06d6129c5e6d 100644 --- a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c +++ b/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c @@ -12,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include "CommonHeader.h" #define EXCEPTION_VECTOR_NUMBER 0x22 @@ -61,20 +62,9 @@ HookPageFaultHandler ( IN OUT PAGE_FAULT_CONTEXT*PageFaultContext ) { - UINT32 RegEax; - UINT8 PhysicalAddressBits; UINTN PageFaultHandlerHookAddress; - AsmCpuid (0x8000, &RegEax, NULL, NULL, NULL); - if (RegEax >= 0x8008) { -AsmCpuid (0x8008, &RegEax, NULL, NULL, NULL); -PhysicalAddressBits = (UINT8)RegEax; - } else { -PhysicalAddressBits = 36; - } - - PageFaultContext->PhyMask = LShiftU64 (1, PhysicalAddressBits) - 1; - PageFaultContext->PhyMask &= (1ull << 48) - SIZE_4KB; + GetPhysicalAddressBits(NULL, &(PageFaultContext->PhyMask)); // // Set Page Fault entry to catch >4G access diff --git a/MdeMod
Re: [edk2-devel] [PATCH v2] MdeModulePkg: Add a check for metadata size in NvmExpress Driver
Pushed via: PR - https://github.com/tianocore/edk2/pull/2592 Commit - https://github.com/tianocore/edk2/commit/79f2734e5a7bc2e5256eb0e599f45407855159c7 Best Regards, Hao Wu > -Original Message- > From: devel@edk2.groups.io On Behalf Of Wu, Hao > A > Sent: Thursday, March 3, 2022 2:43 PM > To: Ma, Hua ; devel@edk2.groups.io > Cc: Wang, Jian J ; Gao, Liming > ; Ni, Ray > Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg: Add a check for > metadata size in NvmExpress Driver > > Reviewed-by: Hao A Wu > > Best Regards, > Hao Wu > > > -Original Message- > > From: Ma, Hua > > Sent: Thursday, March 3, 2022 1:06 PM > > To: devel@edk2.groups.io > > Cc: Wang, Jian J ; Gao, Liming > > ; Wu, Hao A ; Ni, Ray > > ; Ma, Hua > > Subject: [PATCH v2] MdeModulePkg: Add a check for metadata size in > > NvmExpress Driver > > > > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3856 > > > > Currently this NvmeExpress Driver do not support metadata handling. > > According to the NVME specs, metadata may be transferred to the host > > after the logical block data. It can overrun the input buffer which > > may only be the size of logical block data. > > > > Add a check to return not support for the namespaces formatted with > > metadata. > > > > v2 changes: > > - Change debug log level from INFO to ERROR > > - Change to if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) > > > > v1: https://edk2.groups.io/g/devel/message/87242 > > > > Cc: Jian J Wang > > Cc: Liming Gao > > Cc: Hao A Wu > > Cc: Ray Ni > > > > Signed-off-by: Hua Ma > > --- > > MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c | 15 > > +++ > > .../Bus/Pci/NvmExpressPei/NvmExpressPei.c | 15 +++ > > 2 files changed, 30 insertions(+) > > > > diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c > > b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c > > index 5a1eda8e8d..388583e4d5 100644 > > --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c > > +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c > > @@ -139,6 +139,21 @@ EnumerateNvmeDevNamespace ( > > > > Flbas = NamespaceData->Flbas; > > LbaFmtIdx = Flbas & 0xF; > > + > > +// > > +// Currently this NVME driver only suport Metadata Size == 0 > > +// > > +if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) { > > + DEBUG (( > > +DEBUG_ERROR, > > +"NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n", > > +NamespaceId, > > +NamespaceData->LbaFormat[LbaFmtIdx].Ms > > +)); > > + Status = EFI_UNSUPPORTED; > > + goto Exit; > > +} > > + > > Lbads = NamespaceData->LbaFormat[LbaFmtIdx].Lbads; > > Device->Media.BlockSize = (UINT32)1 << Lbads; > > > > diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c > > b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c > > index f73053fc3f..e8a29f23c7 100644 > > --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c > > +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c > > @@ -104,6 +104,21 @@ EnumerateNvmeDevNamespace ( > >// > >Flbas = NamespaceData->Flbas; > >LbaFmtIdx = Flbas & 0xF; > > + > > + // > > + // Currently this NVME driver only suport Metadata Size == 0 // > > + if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) { > > +DEBUG (( > > + DEBUG_ERROR, > > + "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n", > > + NamespaceId, > > + NamespaceData->LbaFormat[LbaFmtIdx].Ms > > + )); > > +Status = EFI_UNSUPPORTED; > > +goto Exit; > > + } > > + > >Lbads = NamespaceData->LbaFormat[LbaFmtIdx].Lbads; > > > >NamespaceInfo->Media.InterfaceType = MSG_NVME_NAMESPACE_DP; > > -- > > 2.32.0.windows.2 > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#87304): https://edk2.groups.io/g/devel/message/87304 Mute This Topic: https://groups.io/mt/89519902/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-