Reviewed-by: Chao Li Thanks, Chao 在 2023/3/23 19:17, Gerd Hoffmann 写道: > Use the newer versions of the machine #defines. > > Signed-off-by: Gerd Hoffmann > --- > BaseTools/Source/C/EfiRom/EfiRom.h | 10 ++--- > .../C/Include/IndustryStandard/PeImage.h | 1 + > BaseTools/Source/C/Common/BasePeCoff.c | 28 ++++++------- > BaseTools/Source/C/GenFv/GenFvInternalLib.c | 42 +++++++++---------- > BaseTools/Source/C/GenFw/Elf32Convert.c | 6 +-- > BaseTools/Source/C/GenFw/Elf64Convert.c | 10 ++--- > BaseTools/Source/C/GenFw/GenFw.c | 8 +--- > 7 files changed, 50 insertions(+), 55 deletions(-) > > diff --git a/BaseTools/Source/C/EfiRom/EfiRom.h b/BaseTools/Source/C/EfiRom/EfiRom.h > index 0b39e2af2e0c..887a6a51e25b 100644 > --- a/BaseTools/Source/C/EfiRom/EfiRom.h > +++ b/BaseTools/Source/C/EfiRom/EfiRom.h > @@ -108,11 +108,11 @@ typedef struct { > // Machine Types > // > static STRING_LOOKUP mMachineTypes[] = { > - { EFI_IMAGE_MACHINE_IA32, "IA32" }, > - { EFI_IMAGE_MACHINE_X64, "X64" }, > - { EFI_IMAGE_MACHINE_EBC, "EBC" }, > - { EFI_IMAGE_MACHINE_ARMT, "ARM" }, > - { EFI_IMAGE_MACHINE_AARCH64, "AA64" }, > + { IMAGE_FILE_MACHINE_I386, "IA32" }, > + { IMAGE_FILE_MACHINE_X64, "X64" }, > + { IMAGE_FILE_MACHINE_EBC, "EBC" }, > + { IMAGE_FILE_MACHINE_ARMTHUMB_MIXED, "ARM" }, > + { IMAGE_FILE_MACHINE_ARM64, "AA64" }, > { 0, NULL } > }; > > diff --git a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h > index 77ded3f61139..6e044938f5c6 100644 > --- a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h > +++ b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h > @@ -42,6 +42,7 @@ > #define IMAGE_FILE_MACHINE_X64 0x8664 > #define IMAGE_FILE_MACHINE_ARM 0x01c0 // Thumb only > #define IMAGE_FILE_MACHINE_ARMT 0x01c2 // 32bit Mixed ARM and Thumb/Thumb 2 Little Endian > +#define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED IMAGE_FILE_MACHINE_ARMT > #define IMAGE_FILE_MACHINE_ARM64 0xAA64 // 64bit ARM Architecture, Little Endian > #define IMAGE_FILE_MACHINE_RISCV64 0x5064 // 64bit RISC-V ISA > #define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 // 64bit LoongArch Architecture > diff --git a/BaseTools/Source/C/Common/BasePeCoff.c b/BaseTools/Source/C/Common/BasePeCoff.c > index 78ef072bc354..bd410fb97d3d 100644 > --- a/BaseTools/Source/C/Common/BasePeCoff.c > +++ b/BaseTools/Source/C/Common/BasePeCoff.c > @@ -188,13 +188,13 @@ Routine Description: > ImageContext->Machine = TeHdr->Machine; > } > > - if (ImageContext->Machine != EFI_IMAGE_MACHINE_IA32 && \ > - ImageContext->Machine != EFI_IMAGE_MACHINE_X64 && \ > - ImageContext->Machine != EFI_IMAGE_MACHINE_ARMT && \ > - ImageContext->Machine != EFI_IMAGE_MACHINE_EBC && \ > - ImageContext->Machine != EFI_IMAGE_MACHINE_AARCH64 && \ > - ImageContext->Machine != EFI_IMAGE_MACHINE_RISCV64 && \ > - ImageContext->Machine != EFI_IMAGE_MACHINE_LOONGARCH64) { > + if (ImageContext->Machine != IMAGE_FILE_MACHINE_I386 && \ > + ImageContext->Machine != IMAGE_FILE_MACHINE_X64 && \ > + ImageContext->Machine != IMAGE_FILE_MACHINE_ARMTHUMB_MIXED && \ > + ImageContext->Machine != IMAGE_FILE_MACHINE_EBC && \ > + ImageContext->Machine != IMAGE_FILE_MACHINE_ARM64 && \ > + ImageContext->Machine != IMAGE_FILE_MACHINE_RISCV64 && \ > + ImageContext->Machine != IMAGE_FILE_MACHINE_LOONGARCH64) { > // > // unsupported PeImage machine type > // > @@ -801,16 +801,16 @@ Routine Description: > > default: > switch (MachineType) { > - case EFI_IMAGE_MACHINE_IA32: > + case IMAGE_FILE_MACHINE_I386: > Status = PeCoffLoaderRelocateIa32Image (Reloc, Fixup, &FixupData, Adjust); > break; > - case EFI_IMAGE_MACHINE_ARMT: > + case IMAGE_FILE_MACHINE_ARMTHUMB_MIXED: > Status = PeCoffLoaderRelocateArmImage (&Reloc, Fixup, &FixupData, Adjust); > break; > - case EFI_IMAGE_MACHINE_RISCV64: > + case IMAGE_FILE_MACHINE_RISCV64: > Status = PeCoffLoaderRelocateRiscVImage (Reloc, Fixup, &FixupData, Adjust); > break; > - case EFI_IMAGE_MACHINE_LOONGARCH64: > + case IMAGE_FILE_MACHINE_LOONGARCH64: > Status = PeCoffLoaderRelocateLoongArch64Image (Reloc, Fixup, &FixupData, Adjust); > break; > default: > @@ -1305,14 +1305,14 @@ PeCoffLoaderGetPdbPointer ( > // generate PE32+ image with PE32 Magic. > // > switch (Hdr.Pe32->FileHeader.Machine) { > - case EFI_IMAGE_MACHINE_IA32: > - case EFI_IMAGE_MACHINE_ARMT: > + case IMAGE_FILE_MACHINE_I386: > + case IMAGE_FILE_MACHINE_ARMTHUMB_MIXED: > // > // Assume PE32 image with IA32 Machine field. > // > Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC; > break; > - case EFI_IMAGE_MACHINE_X64: > + case IMAGE_FILE_MACHINE_X64: > // > // Assume PE32+ image with X64 Machine field > // > diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c > index c8d5cac8e26e..f466324d6192 100644 > --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c > +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c > @@ -1655,8 +1655,8 @@ Routine Description: > > if ( > Vtf0Detected && > - (MachineType == EFI_IMAGE_MACHINE_IA32 || > - MachineType == EFI_IMAGE_MACHINE_X64) > + (MachineType == IMAGE_FILE_MACHINE_I386 || > + MachineType == IMAGE_FILE_MACHINE_X64) > ) { > // > // If the SEC core code is IA32 or X64 and the VTF-0 signature > @@ -1714,7 +1714,7 @@ Routine Description: > DebugMsg (NULL, 0, 9, "PeiCore physical entry point address", "Address = 0x%llX", (unsigned long long) PeiCorePhysicalAddress); > } > > -if (MachineType == EFI_IMAGE_MACHINE_IA32 || MachineType == EFI_IMAGE_MACHINE_X64) { > +if (MachineType == IMAGE_FILE_MACHINE_I386 || MachineType == IMAGE_FILE_MACHINE_X64) { > if (PeiCorePhysicalAddress != 0) { > // > // Get the location to update > @@ -1804,12 +1804,12 @@ if (MachineType == EFI_IMAGE_MACHINE_IA32 || MachineType == EFI_IMAGE_MACHINE_X6 > // > Ia32ResetAddressPtr = (UINT32 *) ((UINTN) FvImage->Eof - 8); > *Ia32ResetAddressPtr = IpiVector; > - } else if (MachineType == EFI_IMAGE_MACHINE_ARMT) { > + } else if (MachineType == IMAGE_FILE_MACHINE_ARMTHUMB_MIXED) { > // > // Since the ARM reset vector is in the FV Header you really don't need a > // Volume Top File, but if you have one for some reason don't crash... > // > - } else if (MachineType == EFI_IMAGE_MACHINE_AARCH64) { > + } else if (MachineType == IMAGE_FILE_MACHINE_ARM64) { > // > // Since the AArch64 reset vector is in the FV Header you really don't need a > // Volume Top File, but if you have one for some reason don't crash... > @@ -2204,7 +2204,7 @@ Routine Description: > return EFI_SUCCESS; > } > > - if (MachineType == EFI_IMAGE_MACHINE_ARMT) { > + if (MachineType == IMAGE_FILE_MACHINE_ARMTHUMB_MIXED) { > // ARM: Array of 4 UINT32s: > // 0 - is branch relative to SEC entry point > // 1 - PEI Entry Point > @@ -2258,7 +2258,7 @@ Routine Description: > // > memcpy(FvImage->FileImage, ResetVector, sizeof (ResetVector)); > > - } else if (MachineType == EFI_IMAGE_MACHINE_AARCH64) { > + } else if (MachineType == IMAGE_FILE_MACHINE_ARM64) { > // AArch64: Used as UINT64 ResetVector[2] > // 0 - is branch relative to SEC entry point > // 1 - PEI Entry Point > @@ -2377,7 +2377,7 @@ Routine Description: > return EFI_ABORTED; > } > > - if (MachineType != EFI_IMAGE_MACHINE_RISCV64) { > + if (MachineType != IMAGE_FILE_MACHINE_RISCV64) { > Error(NULL, 0, 3000, "Invalid", "Could not update SEC core because Machine type is not RiscV."); > return EFI_ABORTED; > } > @@ -2478,7 +2478,7 @@ Routine Description: > if (!UpdateVectorSec) > return EFI_SUCCESS; > > - if (MachineType == EFI_IMAGE_MACHINE_LOONGARCH64) { > + if (MachineType == IMAGE_FILE_MACHINE_LOONGARCH64) { > UINT32 ResetVector[1]; > > memset(ResetVector, 0, sizeof (ResetVector)); > @@ -2595,9 +2595,9 @@ Routine Description: > // > // Verify machine type is supported > // > - if ((*MachineType != EFI_IMAGE_MACHINE_IA32) && (*MachineType != EFI_IMAGE_MACHINE_X64) && (*MachineType != EFI_IMAGE_MACHINE_EBC) && > - (*MachineType != EFI_IMAGE_MACHINE_ARMT) && (*MachineType != EFI_IMAGE_MACHINE_AARCH64) && > - (*MachineType != EFI_IMAGE_MACHINE_RISCV64) && (*MachineType != EFI_IMAGE_MACHINE_LOONGARCH64)) { > + if ((*MachineType != IMAGE_FILE_MACHINE_I386) && (*MachineType != IMAGE_FILE_MACHINE_X64) && (*MachineType != IMAGE_FILE_MACHINE_EBC) && > + (*MachineType != IMAGE_FILE_MACHINE_ARMTHUMB_MIXED) && (*MachineType != IMAGE_FILE_MACHINE_ARM64) && > + (*MachineType != IMAGE_FILE_MACHINE_RISCV64) && (*MachineType != IMAGE_FILE_MACHINE_LOONGARCH64)) { > Error (NULL, 0, 3000, "Invalid", "Unrecognized machine type in the PE32 file."); > return EFI_UNSUPPORTED; > } > @@ -3547,13 +3547,13 @@ Routine Description: > } > > // machine type is ARM, set a flag so ARM reset vector processing occurs > - if ((MachineType == EFI_IMAGE_MACHINE_ARMT) || (MachineType == EFI_IMAGE_MACHINE_AARCH64)) { > + if ((MachineType == IMAGE_FILE_MACHINE_ARMTHUMB_MIXED) || (MachineType == IMAGE_FILE_MACHINE_ARM64)) { > VerboseMsg("Located ARM/AArch64 SEC/PEI core in child FV"); > mArm = TRUE; > } > > // Machine type is LOONGARCH64, set a flag so LoongArch64 reset vector processed. > - if (MachineType == EFI_IMAGE_MACHINE_LOONGARCH64) { > + if (MachineType == IMAGE_FILE_MACHINE_LOONGARCH64) { > VerboseMsg("Located LoongArch64 SEC core in child FV"); > mLoongArch = TRUE; > } > @@ -3706,16 +3706,16 @@ Routine Description: > return Status; > } > > - if ( (ImageContext.Machine == EFI_IMAGE_MACHINE_ARMT) || > - (ImageContext.Machine == EFI_IMAGE_MACHINE_AARCH64) ) { > + if ( (ImageContext.Machine == IMAGE_FILE_MACHINE_ARMTHUMB_MIXED) || > + (ImageContext.Machine == IMAGE_FILE_MACHINE_ARM64) ) { > mArm = TRUE; > } > > - if (ImageContext.Machine == EFI_IMAGE_MACHINE_RISCV64) { > + if (ImageContext.Machine == IMAGE_FILE_MACHINE_RISCV64) { > mRiscV = TRUE; > } > > - if (ImageContext.Machine == EFI_IMAGE_MACHINE_LOONGARCH64) { > + if (ImageContext.Machine == IMAGE_FILE_MACHINE_LOONGARCH64) { > mLoongArch = TRUE; > } > > @@ -3991,12 +3991,12 @@ Routine Description: > return Status; > } > > - if ( (ImageContext.Machine == EFI_IMAGE_MACHINE_ARMT) || > - (ImageContext.Machine == EFI_IMAGE_MACHINE_AARCH64) ) { > + if ( (ImageContext.Machine == IMAGE_FILE_MACHINE_ARMTHUMB_MIXED) || > + (ImageContext.Machine == IMAGE_FILE_MACHINE_ARM64) ) { > mArm = TRUE; > } > > - if (ImageContext.Machine == EFI_IMAGE_MACHINE_LOONGARCH64) { > + if (ImageContext.Machine == IMAGE_FILE_MACHINE_LOONGARCH64) { > mLoongArch = TRUE; > } > > diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c > index e9fb3593a91b..de198e58db07 100644 > --- a/BaseTools/Source/C/GenFw/Elf32Convert.c > +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c > @@ -553,16 +553,16 @@ ScanSections32 ( > > switch (mEhdr->e_machine) { > case EM_386: > - NtHdr->Pe32.FileHeader.Machine = EFI_IMAGE_MACHINE_IA32; > + NtHdr->Pe32.FileHeader.Machine = IMAGE_FILE_MACHINE_I386; > NtHdr->Pe32.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC; > break; > case EM_ARM: > - NtHdr->Pe32.FileHeader.Machine = EFI_IMAGE_MACHINE_ARMT; > + NtHdr->Pe32.FileHeader.Machine = IMAGE_FILE_MACHINE_ARMTHUMB_MIXED; > NtHdr->Pe32.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC; > break; > default: > VerboseMsg ("%s unknown e_machine type %hu. Assume IA-32", mInImageName, mEhdr->e_machine); > - NtHdr->Pe32.FileHeader.Machine = EFI_IMAGE_MACHINE_IA32; > + NtHdr->Pe32.FileHeader.Machine = IMAGE_FILE_MACHINE_I386; > NtHdr->Pe32.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC; > } > > diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c > index 2078ff42002f..585c3266afde 100644 > --- a/BaseTools/Source/C/GenFw/Elf64Convert.c > +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c > @@ -1077,25 +1077,25 @@ ScanSections64 ( > > switch (mEhdr->e_machine) { > case EM_X86_64: > - NtHdr->Pe32Plus.FileHeader.Machine = EFI_IMAGE_MACHINE_X64; > + NtHdr->Pe32Plus.FileHeader.Machine = IMAGE_FILE_MACHINE_X64; > NtHdr->Pe32Plus.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; > break; > case EM_AARCH64: > - NtHdr->Pe32Plus.FileHeader.Machine = EFI_IMAGE_MACHINE_AARCH64; > + NtHdr->Pe32Plus.FileHeader.Machine = IMAGE_FILE_MACHINE_ARM64; > NtHdr->Pe32Plus.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; > break; > case EM_RISCV64: > - NtHdr->Pe32Plus.FileHeader.Machine = EFI_IMAGE_MACHINE_RISCV64; > + NtHdr->Pe32Plus.FileHeader.Machine = IMAGE_FILE_MACHINE_RISCV64; > NtHdr->Pe32Plus.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; > break; > case EM_LOONGARCH: > - NtHdr->Pe32Plus.FileHeader.Machine = EFI_IMAGE_MACHINE_LOONGARCH64; > + NtHdr->Pe32Plus.FileHeader.Machine = IMAGE_FILE_MACHINE_LOONGARCH64; > NtHdr->Pe32Plus.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; > break; > > default: > VerboseMsg ("%u unknown e_machine type. Assume X64", (UINTN)mEhdr->e_machine); > - NtHdr->Pe32Plus.FileHeader.Machine = EFI_IMAGE_MACHINE_X64; > + NtHdr->Pe32Plus.FileHeader.Machine = IMAGE_FILE_MACHINE_X64; > NtHdr->Pe32Plus.OptionalHeader.Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; > } > > diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/GenFw.c > index 2717f896a161..06db6badf807 100644 > --- a/BaseTools/Source/C/GenFw/GenFw.c > +++ b/BaseTools/Source/C/GenFw/GenFw.c > @@ -2197,12 +2197,6 @@ Routine Description: > } > } > > - if (PeHdr->Pe32.FileHeader.Machine == IMAGE_FILE_MACHINE_ARM) { > - // Some tools kick out IMAGE_FILE_MACHINE_ARM (0x1c0) vs IMAGE_FILE_MACHINE_ARMT (0x1c2) > - // so patch back to the official UEFI value. > - PeHdr->Pe32.FileHeader.Machine = IMAGE_FILE_MACHINE_ARMT; > - } > - > // > // Set new base address into image > // > @@ -3116,7 +3110,7 @@ Routine Description: > // Get Debug, Export and Resource EntryTable RVA address. > // Resource Directory entry need to review. > // > - if (FileHdr->Machine == EFI_IMAGE_MACHINE_IA32) { > + if (FileHdr->Machine == IMAGE_FILE_MACHINE_I386) { > Optional32Hdr = (EFI_IMAGE_OPTIONAL_HEADER32 *) ((UINT8*) FileHdr + sizeof (EFI_IMAGE_FILE_HEADER)); > SectionHeader = (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) Optional32Hdr + FileHdr->SizeOfOptionalHeader); > if (Optional32Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_EXPORT && \