From nobody Fri May 3 14:54:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1529663488314218.53462319688037; Fri, 22 Jun 2018 03:31:28 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 676F6210D43A2; Fri, 22 Jun 2018 03:31:27 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 931F5210D4388 for ; Fri, 22 Jun 2018 03:31:26 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jun 2018 03:31:25 -0700 Received: from cchiu4-mobl1.gar.corp.intel.com ([10.5.240.39]) by orsmga004.jf.intel.com with ESMTP; 22 Jun 2018 03:31:24 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=chasel.chiu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,256,1526367600"; d="scan'208";a="210248662" From: "Chasel, Chiu" To: edk2-devel@lists.01.org Date: Fri, 22 Jun 2018 18:31:11 +0800 Message-Id: <20180622103111.15076-1-chasel.chiu@intel.com> X-Mailer: git-send-email 2.13.3.windows.1 Subject: [edk2] [PATCH] IntelFsp2Pkg: SplitFspBin.py to support x64 drivers X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiewen Yao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" FSP binary potentially can include X64 drivers to simplify implementation or support new features so update SplitFspBin.py to support x64 image headers. Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Chasel Chiu Reviewed-by: Jiewen.yao@intel.com --- IntelFsp2Pkg/Tools/SplitFspBin.py | 82 +++++++++++++++++++++++++++++++++--= ---- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/IntelFsp2Pkg/Tools/SplitFspBin.py b/IntelFsp2Pkg/Tools/SplitFs= pBin.py index e4c3aa6d0b..9b18720307 100644 --- a/IntelFsp2Pkg/Tools/SplitFspBin.py +++ b/IntelFsp2Pkg/Tools/SplitFspBin.py @@ -1,6 +1,6 @@ ## @ FspTool.py # -# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials are licensed and made availa= ble under # the terms and conditions of the BSD License that accompanies this distri= bution. # The full text of the license may be found at @@ -234,11 +234,51 @@ class EFI_IMAGE_OPTIONAL_HEADER32(Structure): ('DataDirectory', ARRAY(EFI_IMAGE_DATA_DIRECTORY, = 16)) ] =20 +class EFI_IMAGE_OPTIONAL_HEADER32_PLUS(Structure): + _fields_ =3D [ + ('Magic', c_uint16), + ('MajorLinkerVersion', c_uint8), + ('MinorLinkerVersion', c_uint8), + ('SizeOfCode', c_uint32), + ('SizeOfInitializedData', c_uint32), + ('SizeOfUninitializedData', c_uint32), + ('AddressOfEntryPoint', c_uint32), + ('BaseOfCode', c_uint32), + ('ImageBase', c_uint64), + ('SectionAlignment', c_uint32), + ('FileAlignment', c_uint32), + ('MajorOperatingSystemVersion', c_uint16), + ('MinorOperatingSystemVersion', c_uint16), + ('MajorImageVersion', c_uint16), + ('MinorImageVersion', c_uint16), + ('MajorSubsystemVersion', c_uint16), + ('MinorSubsystemVersion', c_uint16), + ('Win32VersionValue', c_uint32), + ('SizeOfImage', c_uint32), + ('SizeOfHeaders', c_uint32), + ('CheckSum' , c_uint32), + ('Subsystem', c_uint16), + ('DllCharacteristics', c_uint16), + ('SizeOfStackReserve', c_uint64), + ('SizeOfStackCommit' , c_uint64), + ('SizeOfHeapReserve', c_uint64), + ('SizeOfHeapCommit' , c_uint64), + ('LoaderFlags' , c_uint32), + ('NumberOfRvaAndSizes', c_uint32), + ('DataDirectory', ARRAY(EFI_IMAGE_DATA_DIRECTORY, = 16)) + ] + +class EFI_IMAGE_OPTIONAL_HEADER(Union): + _fields_ =3D [ + ('PeOptHdr', EFI_IMAGE_OPTIONAL_HEADER32), + ('PePlusOptHdr', EFI_IMAGE_OPTIONAL_HEADER32_PLUS) + ] + class EFI_IMAGE_NT_HEADERS32(Structure): _fields_ =3D [ ('Signature', c_uint32), ('FileHeader', EFI_IMAGE_FILE_HEADER), - ('OptionalHeader', EFI_IMAGE_OPTIONAL_HEADER32) + ('OptionalHeader', EFI_IMAGE_OPTIONAL_HEADER) ] =20 =20 @@ -527,16 +567,24 @@ class PeTeImage: tehdr =3D EFI_TE_IMAGE_HEADER.from_buffer (data, 0) if tehdr.Signature =3D=3D 'VZ': # TE image self.TeHdr =3D tehdr - elif tehdr.Signature =3D=3D 'MZ': # PE32 image + elif tehdr.Signature =3D=3D 'MZ': # PE image self.TeHdr =3D None self.DosHdr =3D EFI_IMAGE_DOS_HEADER.from_buffer (data, 0) self.PeHdr =3D EFI_IMAGE_NT_HEADERS32.from_buffer (data, sel= f.DosHdr.e_lfanew) if self.PeHdr.Signature !=3D 0x4550: raise Exception("ERROR: Invalid PE32 header !") - if self.PeHdr.FileHeader.SizeOfOptionalHeader < EFI_IMAGE_OPTI= ONAL_HEADER32.DataDirectory.offset: - raise Exception("ERROR: Unsupported PE32 image !") - if self.PeHdr.OptionalHeader.NumberOfRvaAndSizes <=3D EFI_IMAG= E_DIRECTORY_ENTRY.BASERELOC: - raise Exception("ERROR: No relocation information availabl= e !") + if self.PeHdr.OptionalHeader.PeOptHdr.Magic =3D=3D 0x10b: # PE= 32 image + if self.PeHdr.FileHeader.SizeOfOptionalHeader < EFI_IMAGE_= OPTIONAL_HEADER32.DataDirectory.offset: + raise Exception("ERROR: Unsupported PE32 image !") + if self.PeHdr.OptionalHeader.PeOptHdr.NumberOfRvaAndSizes = <=3D EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC: + raise Exception("ERROR: No relocation information avai= lable !") + elif self.PeHdr.OptionalHeader.PeOptHdr.Magic =3D=3D 0x20b: # = PE32+ image + if self.PeHdr.FileHeader.SizeOfOptionalHeader < EFI_IMAGE_= OPTIONAL_HEADER32_PLUS.DataDirectory.offset: + raise Exception("ERROR: Unsupported PE32+ image !") + if self.PeHdr.OptionalHeader.PePlusOptHdr.NumberOfRvaAndSi= zes <=3D EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC: + raise Exception("ERROR: No relocation information avai= lable !") + else: + raise Exception("ERROR: Invalid PE32 optional header !") self.Offset =3D offset self.Data =3D data self.RelocList =3D [] @@ -549,8 +597,12 @@ class PeTeImage: rsize =3D self.TeHdr.DataDirectoryBaseReloc.Size roffset =3D sizeof(self.TeHdr) - self.TeHdr.StrippedSize + sel= f.TeHdr.DataDirectoryBaseReloc.VirtualAddress else: - rsize =3D self.PeHdr.OptionalHeader.DataDirectory[EFI_IMAGE_= DIRECTORY_ENTRY.BASERELOC].Size - roffset =3D self.PeHdr.OptionalHeader.DataDirectory[EFI_IMAGE_= DIRECTORY_ENTRY.BASERELOC].VirtualAddress + if self.PeHdr.OptionalHeader.PeOptHdr.Magic =3D=3D 0x10b: # PE= 32 image + rsize =3D self.PeHdr.OptionalHeader.PeOptHdr.DataDirecto= ry[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].Size + roffset =3D self.PeHdr.OptionalHeader.PeOptHdr.DataDirecto= ry[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].VirtualAddress + if self.PeHdr.OptionalHeader.PeOptHdr.Magic =3D=3D 0x20b: # PE= 32+ image + rsize =3D self.PeHdr.OptionalHeader.PePlusOptHdr.DataDir= ectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].Size + roffset =3D self.PeHdr.OptionalHeader.PePlusOptHdr.DataDir= ectory[EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC].VirtualAddress =20 alignment =3D 4 offset =3D roffset @@ -565,9 +617,9 @@ class PeTeImage: for each in rdata: roff =3D each & 0xfff rtype =3D each >> 12 - if rtype =3D=3D 0: # IMAGE_REL_BASED.ABSOLUTE: + if rtype =3D=3D 0: # IMAGE_REL_BASED_ABSOLUTE: continue - if rtype !=3D 3: # IMAGE_REL_BASED_HIGHLOW + if ((rtype !=3D 3) and (rtype !=3D 10)): # IMAGE_REL_BASED= _HIGHLOW and IMAGE_REL_BASED_DIR64 raise Exception("ERROR: Unsupported relocation type %d= !" % rtype) # Calculate the offset of the relocation aoff =3D blkhdr.PageRVA + roff @@ -582,12 +634,18 @@ class PeTeImage: return count =20 for (rtype, roff) in self.RelocList: - if rtype =3D=3D 0x03: # HIGHLOW + if rtype =3D=3D 3: # IMAGE_REL_BASED_HIGHLOW offset =3D roff + self.Offset value =3D Bytes2Val(fdbin[offset:offset+sizeof(c_uint32)]) value +=3D delta fdbin[offset:offset+sizeof(c_uint32)] =3D Val2Bytes(value,= sizeof(c_uint32)) count +=3D 1 + elif rtype =3D=3D 10: # IMAGE_REL_BASED_DIR64 + offset =3D roff + self.Offset + value =3D Bytes2Val(fdbin[offset:offset+sizeof(c_uint64)]) + value +=3D delta + fdbin[offset:offset+sizeof(c_uint64)] =3D Val2Bytes(value,= sizeof(c_uint64)) + count +=3D 1 else: raise Exception('ERROR: Unknown relocation type %d !' % rt= ype) =20 --=20 2.13.3.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel