From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=jiewen.yao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 6EE27203B99B2 for ; Fri, 22 Jun 2018 09:04:07 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jun 2018 09:04:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,257,1526367600"; d="scan'208";a="51443568" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga008.jf.intel.com with ESMTP; 22 Jun 2018 09:04:06 -0700 Received: from fmsmsx122.amr.corp.intel.com (10.18.125.37) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 22 Jun 2018 09:04:06 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx122.amr.corp.intel.com (10.18.125.37) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 22 Jun 2018 09:04:06 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.223]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.82]) with mapi id 14.03.0319.002; Sat, 23 Jun 2018 00:04:04 +0800 From: "Yao, Jiewen" To: "Chiu, Chasel" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] IntelFsp2Pkg: SplitFspBin.py to support x64 drivers Thread-Index: AQHUChQyXcwZUDKc5Uu6EtIIlO5hFKRscKaA Date: Fri, 22 Jun 2018 16:04:04 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503AC603CC@shsmsx102.ccr.corp.intel.com> References: <20180622103111.15076-1-chasel.chiu@intel.com> In-Reply-To: <20180622103111.15076-1-chasel.chiu@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMTg5NGFmZGQtMWY1NS00OTJlLTg0YWQtMDYwNmI2ODM0NDZmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiT0VZdW5mTmd4RzdcL0xLclJVUnNWWlNrTTBRM09qUVc2Rzd5bVwvZW52T2NYYjROTVIxOGFNSWNHS0xaMkdGbnhkIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Fri, 22 Jun 2018 16:04:07 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jiewen.yao@intel.com > -----Original Message----- > From: Chiu, Chasel > Sent: Friday, June 22, 2018 3:31 AM > To: edk2-devel@lists.01.org > Cc: Yao, Jiewen ; Chiu, Chasel > Subject: [PATCH] IntelFsp2Pkg: SplitFspBin.py to support x64 drivers >=20 > FSP binary potentially can include X64 drivers to > simplify implementation or support new features so > update SplitFspBin.py to support x64 image headers. >=20 > Cc: Jiewen Yao > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Chasel Chiu > --- > IntelFsp2Pkg/Tools/SplitFspBin.py | 82 > +++++++++++++++++++++++++++++++++------ > 1 file changed, 70 insertions(+), 12 deletions(-) >=20 > diff --git a/IntelFsp2Pkg/Tools/SplitFspBin.py > b/IntelFsp2Pkg/Tools/SplitFspBin.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 > available under > # the terms and conditions of the BSD License that accompanies this > distribution. > # 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, > self.DosHdr.e_lfanew) > if self.PeHdr.Signature !=3D 0x4550: > raise Exception("ERROR: Invalid PE32 header !") > - if self.PeHdr.FileHeader.SizeOfOptionalHeader < > EFI_IMAGE_OPTIONAL_HEADER32.DataDirectory.offset: > - raise Exception("ERROR: Unsupported PE32 image !") > - if self.PeHdr.OptionalHeader.NumberOfRvaAndSizes <=3D > EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC: > - raise Exception("ERROR: No relocation information > available !") > + if self.PeHdr.OptionalHeader.PeOptHdr.Magic =3D=3D 0x10b: # = PE32 > 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 > available !") > + 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.NumberOfRvaAndSizes <=3D > EFI_IMAGE_DIRECTORY_ENTRY.BASERELOC: > + raise Exception("ERROR: No relocation information > available !") > + 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 + > self.TeHdr.DataDirectoryBaseReloc.VirtualAddress > else: > - rsize =3D > self.PeHdr.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASER > ELOC].Size > - roffset =3D > self.PeHdr.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY.BASER > ELOC].VirtualAddress > + if self.PeHdr.OptionalHeader.PeOptHdr.Magic =3D=3D 0x10b: # = PE32 > image > + rsize =3D > self.PeHdr.OptionalHeader.PeOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_EN > TRY.BASERELOC].Size > + roffset =3D > self.PeHdr.OptionalHeader.PeOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY_EN > TRY.BASERELOC].VirtualAddress > + if self.PeHdr.OptionalHeader.PeOptHdr.Magic =3D=3D 0x20b: # = PE32+ > image > + rsize =3D > self.PeHdr.OptionalHeader.PePlusOptHdr.DataDirectory[EFI_IMAGE_DIRECTORY > _ENTRY.BASERELOC].Size > + roffset =3D > self.PeHdr.OptionalHeader.PePlusOptHdr.DataDirectory[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(valu= e, > 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(valu= e, > sizeof(c_uint64)) > + count +=3D 1 > else: > raise Exception('ERROR: Unknown relocation type %d !' % > rtype) >=20 > -- > 2.13.3.windows.1