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.69545.1679570270434336002 for ; Thu, 23 Mar 2023 04:17:50 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DsW5kzxb; 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=1679570269; 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=sv7DPjtU+l1dgL1++Buoi4Nl0FL3TQh09GdNfBsdrDo=; b=DsW5kzxbqFZGoS4rcbv5aGYnBV4b3q02AgUEYRe9ycDRfdKWPpEY3FcmXjRXX4TIpIr38q cV/LnNjKnhtsNXqjCmngqZ01c7Tx3cJQU9vM76JPD6h4h6MA73Y33xnXxnbwUtImIhzVAs 39rTA/liw45G77FuL63n1bv6xRAz1rE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-225-thdXf9rXNfSQJGaL7ydegg-1; Thu, 23 Mar 2023 07:17:46 -0400 X-MC-Unique: thdXf9rXNfSQJGaL7ydegg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44A1585A5A3; Thu, 23 Mar 2023 11:17:45 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.241]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D31A940C6E67; Thu, 23 Mar 2023 11:17:44 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id B4C07180062C; Thu, 23 Mar 2023 12:17:33 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Leif Lindholm , Pawel Polawski , Bob Feng , Sunil V L , =?UTF-8?q?Marvin=20H=C3=A4user?= , Chao Li , Dongyan Qian , Michael D Kinney , Zhiguang Liu , Yuwei Chen , Liming Gao , Ard Biesheuvel , Baoqi Zhang , Oliver Steffen , Daniel Schaefer , Gerd Hoffmann Subject: [PATCH 6/8] BaseTools: switch from EFI_IMAGE_MACHINE_* to IMAGE_FILE_MACHINE_* Date: Thu, 23 Mar 2023 12:17:31 +0100 Message-Id: <20230323111733.690211-7-kraxel@redhat.com> In-Reply-To: <20230323111733.690211-1-kraxel@redhat.com> References: <20230323111733.690211-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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 --- 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 && \ -- 2.39.2