From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.4132.1681459388741108391 for ; Fri, 14 Apr 2023 01:03:08 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JjzOCdy4; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681459387; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8iYJASGVPLDmPao6g4Y4VD/HUKRLSCIY40Iu93Ql7m4=; b=JjzOCdy4OkD7E4piKBK+j52M0ju+u4EauqeV2eYg+WVPjnRcq3By/TMuQ5DKcFK/0xP562 UesaocXI8RbI25gctDHlxRBKFZ3iwLhq4W3c9mNX+o3R1EFANOLDyiZZMOL0ypru3WiQv4 lW6ECMaAEvYfj5yGCIhuADH13QNSqms= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-643-SYAc943HN9CEOgPsKGMWYA-1; Fri, 14 Apr 2023 04:03:04 -0400 X-MC-Unique: SYAc943HN9CEOgPsKGMWYA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEF821C08975; Fri, 14 Apr 2023 08:03:03 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 64B6D492C13; Fri, 14 Apr 2023 08:03:03 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id BF95F18003BF; Fri, 14 Apr 2023 10:02:50 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Pawel Polawski , Dongyan Qian , Sunil V L , Baoqi Zhang , Chao Li , Rebecca Cran , Ard Biesheuvel , Zhiguang Liu , Liming Gao , Yuwei Chen , =?UTF-8?q?Marvin=20H=C3=A4user?= , Leif Lindholm , Michael D Kinney , Daniel Schaefer , Bob Feng , Oliver Steffen , Gerd Hoffmann Subject: [PATCH v4 08/10] BaseTools: switch from EFI_IMAGE_MACHINE_* to IMAGE_FILE_MACHINE_* Date: Fri, 14 Apr 2023 10:02:48 +0200 Message-Id: <20230414080250.1357004-9-kraxel@redhat.com> In-Reply-To: <20230414080250.1357004-1-kraxel@redhat.com> References: <20230414080250.1357004-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Use the newer versions of the machine #defines. Signed-off-by: Gerd Hoffmann Reviewed-by: Chao Li --- 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 22161edf443d..fb867b5660a9 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 0172370174b6..038bb054e57a 100644 --- a/BaseTools/Source/C/Common/BasePeCoff.c +++ b/BaseTools/Source/C/Common/BasePeCoff.c @@ -169,13 +169,13 @@ PeCoffLoaderCheckImageType ( 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 // @@ -759,16 +759,16 @@ PeCoffLoaderRelocateImage ( 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: @@ -1255,14 +1255,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 dfcb100a594f..d53ecb176721 100644 --- a/BaseTools/Source/C/GenFw/Elf64Convert.c +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c @@ -1137,25 +1137,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 0da25fd05541..0289c8ef8a5c 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 // @@ -3117,7 +3111,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 && \ -- 2.39.2