From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.3022.1688021888365497852 for ; Wed, 28 Jun 2023 23:58:08 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=bRLpNJtE; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: bob.c.feng@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688021888; x=1719557888; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Fg6idKLnwFuFcmRxGQX2dB3t99KOV2g7I7F30XX6vBs=; b=bRLpNJtEUkBmCND0VKWCJUn6Vixw/JRDvHNViaHJQyXVZ2WqkC/6uPR0 eECaUmvF348iYKAVmT6d4HK8zqqnAaRF31541oxpN5OEAxDL6+vvRdN3n K1Qac0kZIHxhiOW1qRwAcIOD0ipJfiBtQNo094RZmiIIl5RhQ6Sw++Y6x Clp6q23Mqxa7nXbTy/dypLRGjn2TtzK72KNNyPaG0faHhz3PtsLgh5Rjb 2DNT1uW4rF+kOtmsIgR+134R2PlQsSe/O7/xhI8aytDDK3qaq3mgZF/dX Z1KrHZVs02obyhpZFIyElWR5llLOa1/BGzFaYBFA6qYkBqa04epUTmJ+l g==; X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="425708957" X-IronPort-AV: E=Sophos;i="6.01,167,1684825200"; d="scan'208";a="425708957" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 23:57:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10755"; a="787279674" X-IronPort-AV: E=Sophos;i="6.01,167,1684825200"; d="scan'208";a="787279674" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga004.fm.intel.com with ESMTP; 28 Jun 2023 23:57:44 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 28 Jun 2023 23:57:44 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Wed, 28 Jun 2023 23:57:44 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.42) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Wed, 28 Jun 2023 23:57:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NVLZvnXMox0sKPWURj7MlXxNBAWH6UAc1VXfy0vn6wXi6ETgfZMoizJAhXspHFj1U0f8vjJCwfRVxNEVHVLlVLr7qHDn86pjCZG/mAZpsb6IeCR9noKOmltvuU6MLPA4nYJFRl4+tCeZLIUHwSGX2RQc1YLJ5zkM2jWGEep+FTy1QVYSZp4ajA0xkHPOkQWI8H+cO/H/9PpIWKY/VQ0TH8Sx6R0MUhHBga59V7W2NcrYc++LunFe4N6XnwgNDnoaiTkA7YxrYr9CsDq4nmxY5LD0EDyoxWEPEBkdqSPo6Ynccpx8yGjg1PVzRsBr5JeyTvpMtYlWQf1nLWPhqNJcrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jZsJmC2ubJbU1jT9N3TIPWlOGFZVGJbYVsSC/iW4nJY=; b=i7f0gdlqwsISTgbfiRSzaRZPP7C5dz1llqKhdokgEJXl/a+wNxv7xlBdcXkqAv8VddyZ8dM+M1HEJzbW/dYOsX7hUwKO9e4TKNI/vk2cI9rN19zLOq/ibRpYeaTciiCIR8vP23Q02QKF/9IUcZhVa/Aej51DKxAZq6FiSRNtZ160W1dY2LRhdp/tWvc+mLY2mlQ2M1yEN/9QsDQH9WdvhJH6qB3RhlI2ZMiyKSkKbWbNCOTnIueTNdc4Y5fsyY2PEAHpbJbmPTo62UYOkWv8bX3iX6f72fFn/yGfPjw9jPbyBc8UMk5lwVfh9/BkwD3XCaVMrlY8nndCSnGSNWYAcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from PH7PR11MB5863.namprd11.prod.outlook.com (2603:10b6:510:135::11) by CH0PR11MB5299.namprd11.prod.outlook.com (2603:10b6:610:be::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Thu, 29 Jun 2023 06:57:41 +0000 Received: from PH7PR11MB5863.namprd11.prod.outlook.com ([fe80::c14c:19b2:4d95:30f9]) by PH7PR11MB5863.namprd11.prod.outlook.com ([fe80::c14c:19b2:4d95:30f9%4]) with mapi id 15.20.6521.023; Thu, 29 Jun 2023 06:57:41 +0000 From: "Bob Feng" To: "Chen, Christine" , "devel@edk2.groups.io" CC: Rebecca Cran , "Gao, Liming" Subject: Re: [Patch V2 3/4] BaseTools: FMMT support ELF UPLD parser Thread-Topic: [Patch V2 3/4] BaseTools: FMMT support ELF UPLD parser Thread-Index: AQHZqjq0Pv/pWJJ8UEK/PK24PHPyZK+hWXJQ Date: Thu, 29 Jun 2023 06:57:41 +0000 Message-ID: References: <20230629033501.457-1-yuwei.chen@intel.com> In-Reply-To: <20230629033501.457-1-yuwei.chen@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH7PR11MB5863:EE_|CH0PR11MB5299:EE_ x-ms-office365-filtering-correlation-id: 794c9489-57b2-420d-7afe-08db786e220f x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: cVxI2qvsyREk0+SU4jwAcoAJnBB/6gEb5DJQmPNaH/fSuGddP6UZl0LgIjuQhi2C1joGvGWuyKXTRKdklV95+rL53sBh1iWggkDdZlKgRCAk0PFK0OnOmb0ufOLm8xqcnjeR4VyM2tw7etaAm7eIcxAkfJvoYwBrzj/fKfrZXS8GKqWxvrDPBMhMv+BljSd7oO+8IRSpUih1vGQuC+UKQz08HngSGaClh6mDjPjPnbXRwtpXn3AKZfzdKo0LeWyBmE2FFBN2CCv6E6+nqKp+sWOs/Iqha9jKzDQzzMmhoEGIyMvhHQVxgrdIpKPFOgvtZagqoL/F7JqZB4CMPkYxY3MBPSVmdRfQCXlklQYHzyGVHekfRz5pd29YuBpH/SI6dsD0cRxwMYU/erQZKtgFYREe0yHtvHRrqxPfbIsAOOVUnmnFYJZ97Ju/na7f2cAUVdC9wE5U9hI+cKNTajseOzrV9g6b/GHEkZFYIB+yxlhirjTx/gCeTqzzc2ZVRRAp2lac8r+hj6XnDpMNmiCGm+RiXSPMU82KIdMtOnmJM/XGsCtS9qKk2VJHvmf0irZ2Zr1V8fwwebKvds1BHawqmeUyKRatInuJGu123nUCNVq6+xGN7iwxKKVXhJrBGbBc x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR11MB5863.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(136003)(376002)(366004)(39860400002)(396003)(451199021)(66556008)(66446008)(4326008)(66476007)(316002)(76116006)(38070700005)(64756008)(478600001)(33656002)(66946007)(8936002)(8676002)(52536014)(5660300002)(30864003)(2906002)(26005)(110136005)(54906003)(86362001)(55016003)(41300700001)(7696005)(53546011)(6506007)(71200400001)(9686003)(122000001)(82960400001)(186003)(38100700002)(83380400001)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?qwOaICK30GMEsIsufcVS42NzfCIbD48YV2CHoc0FOnQyYupGPNJK6ghEu6Z9?= =?us-ascii?Q?W3fHmaTOwin9Ihk8tWvyxM8YtsNzjDcBcU+3aqcw1ecVXsn4b/0eaxOrihk3?= =?us-ascii?Q?LSnqhFX5e6cAb/pbQGLbXAneJVxXEPrSeFZkEk+/UNsglnVcSDqv99+o5bAa?= =?us-ascii?Q?FQq1fsah82R7DoZcsQeyKVMEyEZroEMh0ZjmKEwWXJpgxYgzfqrkM0qa7l7d?= =?us-ascii?Q?LY1CmI15gpRWRAfwB7bnDZaTdFzh0TsM8a9Yo+1OEmXTukVSJ+IQtPgQEcqI?= =?us-ascii?Q?NrtmgZzJB+6pemRthSwlJTRx+K5fvGKrEdSGWExD3KzdLUDcNWsAQtqDcmSj?= =?us-ascii?Q?iCIG41oefHPzsKMfVH0f+nF6vv0b+5ytxVMu7sA3HmqillUZFhBwM/cLn9Hn?= =?us-ascii?Q?3mItpVQvnWajky7ccoy1fhoxlSncHT1E0hSb8AsViNXX6y6apsQ4d9TvlDCE?= =?us-ascii?Q?1cb5jVnIG0G8Xc1NVuHbulwvCGyAO1QRrLWCsSqWsUK2155ymsaoJpxQfeQI?= =?us-ascii?Q?EmMj0hSJqM7WNbQk6FQldeTxIPtBX5M8bur3FGJMUP/pWScdqFY71wmjuDdH?= =?us-ascii?Q?ztRfzv6NPDqrKAEAUvMid1dnD6oHJWrhar9Altw1sJ9CkUKY4JI5g96vcvtf?= =?us-ascii?Q?HHhgIuTuWrR0pZZRqvaoQyorIxp27/rYorXak++a5ogB1Kz1RAJ+2xMfz4z4?= =?us-ascii?Q?NPOL8//JV0knLIHrxkPShpDK5EUOPcWg40rQGIYQCMh5e9Rw1ILpgww/arEb?= =?us-ascii?Q?N7JWl9I+sN/bCFRRuCRKng0nf6AOs3M2XQRYDHOWosBO7JM1bxQ1fLMS/iwZ?= =?us-ascii?Q?Dk3+sLh7LBJZDDxFjb8ozYE4TqHOgsBuaAn0xH1QXgB1JuaBx47CFL4FKcWo?= =?us-ascii?Q?zB/fbyG3WuzJF5HPQs1p3mU0JS98Vmco8J7upnY342pSLUrlzlkx9n8tFZ6x?= =?us-ascii?Q?eAyypStrqOQsUQibBHMODpPxLkMsuHODnhxofOAupMyIuWfL1VQpU6AZltTX?= =?us-ascii?Q?64RaCpIY8GdKjVMJDqw2TOTysoQNT8tOhW6GgV+QumdYv7FVXslIQFzVHy+E?= =?us-ascii?Q?N2bIdnKhLIadj4ICCet5mlYRSzIQhyZEw3+yHfz1aGb7wxnAzG0YiKV72TQS?= =?us-ascii?Q?329UrFGeQAp6PYKDdTT9N/Rs8mklCG9gXzJZc7lOoikOM7Dky/PNrYnmYFpR?= =?us-ascii?Q?UVCpEggBAJH1AnplBfGPmErGr4t3uClTeaWtUgh+asOnbIiZjvDEBsLI3egB?= =?us-ascii?Q?/gn+qKBtQGP/9IUklgQLuf65CWpaMdSpJSJjOUSBJuidTgg+lrYbTeAyhXWK?= =?us-ascii?Q?xKb4Fj0ogLJ2E3er4OtfczV8IpSEAXbQcbH7bj7O0A92/LAa4G4MpKvP/zUI?= =?us-ascii?Q?5FIP6WUcg1qlS0zUjXHybBUQJrjz9u6RGG2rmWakbmzZQHrzvO6kh4DfSG+y?= =?us-ascii?Q?mXTi9WJgQkKScnQbqe8ETqW1GEXycfX9ZggmTVkcaKsta038r2c3awboMQa8?= =?us-ascii?Q?QTPjswZllxilm+Uj5bMGhk0bIzfUJWuCTwtyIM9JkKC3FaqNx4a3mWWbck19?= =?us-ascii?Q?/kyst+krfXGWmcGaqWAiMF2NQ1jOK0qeh9+0cfYP?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH7PR11MB5863.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 794c9489-57b2-420d-7afe-08db786e220f X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Jun 2023 06:57:41.6014 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 1E36U+nhB1DeK4XxpM4fJMdfDlQTYoIUX1BKHQPFKdiUeUaXfbepkpxsat0sQjObzDbruHxwCa0cz1KrhmQ8Tw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5299 Return-Path: bob.c.feng@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng -----Original Message----- From: Chen, Christine =20 Sent: Thursday, June 29, 2023 11:35 AM To: devel@edk2.groups.io Cc: Rebecca Cran ; Feng, Bob C ; G= ao, Liming Subject: [Patch V2 3/4] BaseTools: FMMT support ELF UPLD parser FMMT add new function to support the .elf file parsing. Using '-v' option, the UPLD info will be printed out. ''' - UNIVERSAL_PAYLOAD_INFO - 4 bytes align (BOOLEAN) - Identifier - SpecRevision - Attribute - Revision - Capability - ProducerId - ImageId UPLD Buffer ''' Cc: Rebecca Cran Cc: Bob Feng Cc: Liming Gao Signed-off-by: Yuwei Chen --- BaseTools/Source/Python/FMMT/FMMT.py | 2 ++ BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py | 36 +++++++++= ++++++++++++++++++++++++++- BaseTools/Source/Python/FMMT/core/BiosTree.py | 48 +++++++++= +++++++++++++++++++++++++++++++++++++-- BaseTools/Source/Python/FMMT/core/BiosTreeNode.py | 56 +++++++++= ++++++++++++++++++++++++++++++++++++++++++++++- BaseTools/Source/Python/FMMT/core/FMMTParser.py | 2 +- BaseTools/Source/Python/FirmwareStorageFormat/UPLHeader.py | 244 +++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++ 6 files changed, 383 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/FMMT/FMMT.py b/BaseTools/Source/Python= /FMMT/FMMT.py index bf580b3843a8..26fc4c5792c4 100644 --- a/BaseTools/Source/Python/FMMT/FMMT.py +++ b/BaseTools/Source/Python/FMMT/FMMT.py @@ -84,6 +84,8 @@ class FMMT(): ROOT_TYPE =3D ROOT_FFS_TREE elif filetype =3D=3D '.sec': ROOT_TYPE =3D ROOT_SECTION_TREE + elif filetype =3D=3D '.elf': + ROOT_TYPE =3D ROOT_ELF_TREE else: ROOT_TYPE =3D ROOT_TREE ViewFile(inputfile, ROOT_TYPE, layoutfilename, outputfile) diff --= git a/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py b/BaseTools= /Source/Python/FMMT/core/BinaryFactoryProduct.py index 2d4e6d9276d7..de174f26ab23 100644 --- a/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py +++ b/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py @@ -15,10 +15,13 @@ from core.GuidTools import GUIDTools from utils.FmmtLo= gger import FmmtLogger as logger =20 ROOT_TREE =3D 'ROOT' +ROOT_ELF_TREE =3D 'ROOT_ELF_TREE' ROOT_FV_TREE =3D 'ROOT_FV_TREE' ROOT_FFS_TREE =3D 'ROOT_FFS_TREE' ROOT_SECTION_TREE =3D 'ROOT_SECTION_TREE' =20 +ELF_TREE =3D 'ELF' +ELF_SECTION_TREE =3D 'ELF_SECTION_TREE' FV_TREE =3D 'FV' DATA_FV_TREE =3D 'DATA_FV' FFS_TREE =3D 'FFS' @@ -49,6 +52,12 @@ class BinaryProduct(): def ParserData(): pass =20 +class ElfFactory(BinaryFactory): + type =3D [ROOT_ELF_TREE, ELF_TREE] + + def Create_Product(): + return ElfProduct() + class SectionFactory(BinaryFactory): type =3D [SECTION_TREE] =20 @@ -354,6 +363,30 @@ class FdProduct(BinaryProduct): tmp_index +=3D 1 return Fd_Struct =20 +class ElfSectionProduct(BinaryProduct): + ## Decompress the compressed section. + def ParserData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset= : int=3D0) -> None: + pass + def ParserSectionData(self, Section_Tree, whole_Data: bytes, Rel_Whole= _Offset: int=3D0) -> None: + pass + def ParserProgramData(self, Section_Tree, whole_Data: bytes, Rel_Whole= _Offset: int=3D0) -> None: + pass + +class ElfProduct(BinaryProduct): + + def ParserData(self, ParTree, Whole_Data: bytes, Rel_Whole_Offset: int= =3D0) -> None: + Elf_Info =3D ElfNode(Whole_Data) + if Elf_Info.Header.ELF_PHOff !=3D 0: + Elf_Info.GetProgramList(Whole_Data[Elf_Info.Header.ELF_PHOff:]= ) + if Elf_Info.Header.ELF_SHOff !=3D 0: + Elf_Info.GetSectionList(Whole_Data[Elf_Info.Header.ELF_SHOff:]= ) + Elf_Info.FindUPLDSection(Whole_Data) + Elf_Tree =3D BIOSTREE(Elf_Info.Name) + Elf_Tree.type =3D ELF_TREE + Elf_Info.Data =3D Whole_Data[Elf_Info.HeaderLength:] + Elf_Tree.Data =3D Elf_Info + ParTree.insertChild(Elf_Tree) + class ParserEntry(): FactoryTable:dict =3D { SECTION_TREE: SectionFactory, @@ -364,6 +397,7 @@ class ParserEntry(): SEC_FV_TREE: FvFactory, ROOT_FV_TREE: FdFactory, ROOT_TREE: FdFactory, + ROOT_ELF_TREE: ElfFactory, } =20 def GetTargetFactory(self, Tree_type: str) -> BinaryFactory: @@ -377,4 +411,4 @@ class ParserEntry(): def DataParser(self, Tree, Data: bytes, Offset: int) -> None: TargetFactory =3D self.GetTargetFactory(Tree.type) if TargetFactory: - self.Generate_Product(TargetFactory, Tree, Data, Offset) \ No newline at end of file + self.Generate_Product(TargetFactory, Tree, Data, Offset) diff --git a/BaseTools/Source/Python/FMMT/core/BiosTree.py b/BaseTools/Sour= ce/Python/FMMT/core/BiosTree.py index 137f49748b09..c5a7b017f4b1 100644 --- a/BaseTools/Source/Python/FMMT/core/BiosTree.py +++ b/BaseTools/Source/Python/FMMT/core/BiosTree.py @@ -12,6 +12,7 @@ ROOT_TREE =3D 'ROOT' ROOT_FV_TREE =3D 'ROOT_FV_TREE' ROOT_FFS_TREE =3D 'ROOT_FFS_TREE' ROOT_SECTION_TREE =3D 'ROOT_SECTION_TREE' +ROOT_ELF_TREE =3D 'ROOT_ELF_TREE' =20 FV_TREE =3D 'FV' DATA_FV_TREE =3D 'DATA_FV' @@ -21,11 +22,13 @@ FFS_FREE_SPACE =3D 'FFS_FREE_SPACE' SECTION_TREE =3D 'SECTION' SEC_FV_TREE =3D 'SEC_FV_IMAGE' BINARY_DATA =3D 'BINARY' +ELF_TREE =3D 'ELF' =20 RootType =3D [ROOT_TREE, ROOT_FV_TREE, ROOT_FFS_TREE, ROOT_SECTION_TREE] = FvType =3D [FV_TREE, SEC_FV_TREE] FfsType =3D FFS_TREE SecType =3D SECTIO= N_TREE +ElfType =3D [ROOT_ELF_TREE, ELF_TREE] =20 class BIOSTREE: def __init__(self, NodeName: str) -> None: @@ -118,6 +121,31 @@ class BIOSTREE: Info.append("Image File: {}".format(Key)) Info.append("FilesNum: {}".format(TargetDict.get(Key).get('Fil= esNum'))) Info.append("\n") + elif TargetDict[Key]["Type"] =3D=3D ROOT_ELF_TREE: + Info.append("ELF File: {}\n".format(Key)) + elif TargetDict[Key]["Type"] =3D=3D ELF_TREE: + ProducerId =3D "" + ImageId =3D "" + if TargetDict.get(Key).get('IfExist'): + Identifier =3D TargetDict.get(Key).get('Identifier') + for item in TargetDict.get(Key).get('ProducerId'): + ProducerId +=3D chr(item) + for item in TargetDict.get(Key).get('ImageId'): + ImageId +=3D chr(item) + Info.append("- UNIVERSAL_PAYLOAD_INFO") + Info.append(" - 4 bytes align: {}".format(TargetDict.get(= Key).get('Upld_Info_Align'))) + Info.append(" - Identifier: {} # 0x48444c50--PLDH / 0x= 444c5055--UPLD".format(hex(Identifier))) + Info.append(" - SpecRevision: {}".format(hex(TargetDict= .get(Key).get('SpecRevision')))) + Info.append(" - Attribute: {}".format(hex(TargetDict.ge= t(Key).get('Attribute')))) + Info.append(" - Revision: {}".format(hex(TargetDict.get= (Key).get('Revision')))) + Info.append(" - Capability: {}".format(hex(TargetDict.g= et(Key).get('Capability')))) + Info.append(" - ProducerId: {}".format(ProducerId)) + Info.append(" - ImageId: {}".format(ImageId)) + Info.append("\n") + Info.append("- UPLD buffer") + Info.append(" Buffer: {}".format(TargetDict.get(Key).get(= 'Upld_Buffer'))) + else: + print("Do not find the Upld Info section!!!\n") elif TargetDict[Key]["Type"] in FvType: space +=3D 2 if TargetDict[Key]["Type"] =3D=3D SEC_FV_TREE: @@ -146,13 +174,29 @@ class BIOSTREE: if TreeInfo is None: TreeInfo =3Dcollections.OrderedDict() =20 - if self.type =3D=3D ROOT_TREE or self.type =3D=3D ROOT_FV_TREE or = self.type =3D=3D ROOT_FFS_TREE or self.type =3D=3D ROOT_SECTION_TREE: + if self.type =3D=3D ROOT_TREE or self.type =3D=3D ROOT_FV_TREE or = self.type =3D=3D ROOT_FFS_TREE or self.type =3D=3D ROOT_SECTION_TREE or sel= f.type =3D=3D ROOT_ELF_TREE: key =3D str(self.key) TreeInfo[self.key] =3D collections.OrderedDict() TreeInfo[self.key]["Name"] =3D key TreeInfo[self.key]["Type"] =3D self.type TreeInfo[self.key]["FilesNum"] =3D len(self.Child) - elif self.type =3D=3D FV_TREE or self.type =3D=3D SEC_FV_TREE: + elif self.type =3D=3D ELF_TREE: + key =3D str(self.Data.Name) + TreeInfo[key] =3D collections.OrderedDict() + TreeInfo[key]["Name"] =3D key + TreeInfo[key]["Type"] =3D self.type + TreeInfo[key]["IfExist"] =3D self.Data.UpldInfo + if self.Data.UpldInfo: + TreeInfo[key]["Identifier"] =3D self.Data.UpldInfo.Identif= ier + TreeInfo[key]["SpecRevision"] =3D self.Data.UpldInfo.SpecR= evision + TreeInfo[key]["Attribute"] =3D self.Data.UpldInfo.Attribut= e + TreeInfo[key]["Revision"] =3D self.Data.UpldInfo.Revision + TreeInfo[key]["Capability"] =3D self.Data.UpldInfo.Capabil= ity + TreeInfo[key]["ProducerId"] =3D self.Data.UpldInfo.Produce= rId + TreeInfo[key]["ImageId"] =3D self.Data.UpldInfo.ImageId + TreeInfo[key]["Upld_Info_Align"] =3D self.Data.Upld_Info_A= lign + TreeInfo[key]["Upld_Buffer"] =3D self.Data.UpldBuffer + elif self.type =3D=3D FV_TREE or self.type =3D=3D SEC_FV_TREE: key =3D str(self.Data.FvId) TreeInfo[key] =3D collections.OrderedDict() TreeInfo[key]["Name"] =3D key diff --git a/BaseTools/Source/Py= thon/FMMT/core/BiosTreeNode.py b/BaseTools/Source/Python/FMMT/core/BiosTree= Node.py index 20447766c821..5ca4c20dc67a 100644 --- a/BaseTools/Source/Python/FMMT/core/BiosTreeNode.py +++ b/BaseTools/Source/Python/FMMT/core/BiosTreeNode.py @@ -4,6 +4,7 @@ # Copyright (c) 2021-, Intel Corporation. All rights reserved.
# SPDX= -License-Identifier: BSD-2-Clause-Patent ## +from FirmwareStorageFormat.UPLHeader import * from FirmwareStorageFormat.FvHeader import * from FirmwareStorageFormat.F= fsFileHeader import * from FirmwareStorageFormat.SectionHeader import * @@= -37,6 +38,59 @@ class BinaryNode: self.HOffset =3D 0 self.Data =3D b'' =20 +class ElfNode: + def __init__(self, buffer: bytes) -> None: + self.Header =3D ELF_HEADER32.from_buffer_copy(buffer) + if self.Header.ELF_Identification[0:4] !=3D b'\x7fELF': + logger.error('Invalid Elf Header! Elf Identification {} is not= ".ELF".'.format(self.Header.ELF_Identification)) + raise Exception("Process Failed: Invalid ELF Header Identifica= tion!") + self.Class =3D self.Header.ELF_Identification[4] + if self.Class =3D=3D 0x02: + self.Header =3D ELF_HEADER64.from_buffer_copy(buffer) + elif self.Class !=3D 0x01: + logger.error('Invalid Elf Class! Elf Class {} is not 0x01 or 0= x02.'.format(self.Class)) + raise Exception("Process Failed: Invalid ELF Class!") + + self.ProList =3D [] + self.SecList =3D [] + self.UpldInfoSection =3D None + self.UpldInfo =3D None + self.UpldBuffer =3D b'' + self.Name =3D "ELF" + self.HeaderLength =3D len(struct2stream(self.Header)) + self.HOffset =3D 0 + self.DOffset =3D 0 + self.ROffset =3D 0 + self.Data =3D b'' + self.PadData =3D b'' + self.Upld_Info_Align =3D False + + def GetProgramList(self, buffer: bytes) -> None: + for i in range(self.Header.ELF_PHNum): + if self.Class =3D=3D 0x01: + ElfProgramHeader =3D ELF_PROGRAM_HEADER32.from_buffer_copy= (buffer[i*self.Header.ELF_PHEntSize:]) + elif self.Class =3D=3D 0x02: + ElfProgramHeader =3D ELF_PROGRAM_HEADER64.from_buffer_copy= (buffer[i*self.Header.ELF_PHEntSize:]) + self.ProList.append(ElfProgramHeader) + + def GetSectionList(self, buffer: bytes) -> None: + for i in range(self.Header.ELF_SHNum): + if self.Class =3D=3D 0x01: + ElfSectionHeader =3D ELF_SECTION_HEADER32.from_buffer_copy= (buffer[i*self.Header.ELF_SHEntSize:]) + elif self.Class =3D=3D 0x02: + ElfSectionHeader =3D ELF_SECTION_HEADER64.from_buffer_copy= (buffer[i*self.Header.ELF_SHEntSize:]) + self.SecList.append(ElfSectionHeader) + + def FindUPLDSection(self, buffer: bytes) -> None: + for item in self.SecList: + if buffer[item.SH_Offset:item.SH_Offset+4] =3D=3D b'PLDH' or b= uffer[item.SH_Offset:item.SH_Offset+4] =3D=3D b'UPLD': + self.UpldInfoSection =3D item + self.UpldInfo =3D UNIVERSAL_PAYLOAD_INFO.from_buffer_copy(= buffer[item.SH_Offset:item.SH_Offset+item.SH_Size]) + self.UpldBuffer =3D struct2stream(self.UpldInfo) + if (self.UpldInfoSection.SH_Offset) % 4 =3D=3D 0: + # if (self.UpldInfoSection.SH_Offset - self.Header.ELF_Ent= ry) % 4 =3D=3D 0: + self.Upld_Info_Align =3D True + class FvNode: def __init__(self, name, buffer: bytes) -> None: self.Header =3D EFI_FIRMWARE_VOLUME_HEADER.from_buffer_copy(buffer= ) @@ -191,4 +245,4 @@ class FreeSpaceNode: self.HOffset =3D 0 self.DOffset =3D 0 self.ROffset =3D 0 - self.PadData =3D b'' \ No newline at end of file + self.PadData =3D b'' diff --git a/BaseTools/Source/Python/FMMT/core/FMMTParser.py b/BaseTools/So= urce/Python/FMMT/core/FMMTParser.py index e76ac5118509..25a2bde79961 100644 --- a/BaseTools/Source/Python/FMMT/core/FMMTParser.py +++ b/BaseTools/Source/Python/FMMT/core/FMMTParser.py @@ -20,7 +20,7 @@ class FMMTParser: =20 ## Parser the nodes in WholeTree. def ParserFromRoot(self, WholeFvTree=3DNone, whole_data: bytes=3Db'', = Reloffset: int=3D0) -> None: - if WholeFvTree.type =3D=3D ROOT_TREE or WholeFvTree.type =3D=3D RO= OT_FV_TREE: + if WholeFvTree.type =3D=3D ROOT_TREE or WholeFvTree.type =3D=3D RO= OT_FV_TREE or WholeFvTree.type =3D=3D ROOT_ELF_TREE: ParserEntry().DataParser(self.WholeFvTree, whole_data, Reloffs= et) else: ParserEntry().DataParser(WholeFvTree, whole_data, Reloffset) d= iff --git a/BaseTools/Source/Python/FirmwareStorageFormat/UPLHeader.py b/Ba= seTools/Source/Python/FirmwareStorageFormat/UPLHeader.py new file mode 100644 index 000000000000..fd4da939f912 --- /dev/null +++ b/BaseTools/Source/Python/FirmwareStorageFormat/UPLHeader.py @@ -0,0 +1,244 @@ +## @file +# This file is used to define the UPL Header C Struct. +# +# Copyright (c) 2023-, Intel Corporation. All rights reserved.
#=20 +SPDX-License-Identifier: BSD-2-Clause-Patent ## from struct import *=20 +from ctypes import * from FirmwareStorageFormat.Common import * + +EFI_COMMON_SECTION_HEADER_LEN =3D 4 +EFI_COMMON_SECTION_HEADER2_LEN =3D 8 + +# ELF header. +class ELF_HEADER32(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_Identification', ARRAY(c_char, 16)), # /* File ident= ification. */ + ('ELF_Type', c_uint16), # Elf32_Half = /* File type. */ + ('ELF_Machine', c_uint16), # Elf32_Half = /* Machine architecture. */ + ('ELF_Version', c_uint32), # Elf32_Word = /* ELF format version. */ + ('ELF_Entry', c_uint32), # Elf32_Addr = /* Entry point. */ + ('ELF_PHOff', c_uint32), # Elf32_Off = /* Program header file offset. */ + ('ELF_SHOff', c_uint32), # Elf32_Off = /* Section header file offset. */ + ('ELF_Flags', c_uint32), # Elf32_Word = /* Architecture-specific flags. */ + ('ELF_EFSize', c_uint16), # Elf32_Half = /* Size of ELF header in bytes. */ + ('ELF_PHEntSize', c_uint16), # Elf32_Half = /* Size of program header entry. */ + ('ELF_PHNum', c_uint16), # Elf32_Half = /* Number of program header entries. */ + ('ELF_SHEntSize', c_uint16), # Elf32_Half = /* Size of section header entry. */ + ('ELF_SHNum', c_uint16), # Elf32_Half = /* Number of section header entries. */ + ('ELF_SNStr', c_uint16), # Elf32_Half = /* Section name strings section. */ + ] + +class ELF_HEADER64(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_Identification', ARRAY(c_char, 16)), # /* File ident= ification. */ + ('ELF_Type', c_uint16), # Elf64_Half = /* File type. */ + ('ELF_Machine', c_uint16), # Elf64_Half = /* Machine architecture. */ + ('ELF_Version', c_uint32), # Elf64_Word = /* ELF format version. */ + ('ELF_Entry', c_uint64), # Elf64_Addr = /* Entry point. */ + ('ELF_PHOff', c_uint64), # Elf64_Off = /* Program header file offset. */ + ('ELF_SHOff', c_uint64), # Elf64_Off = /* Section header file offset. */ + ('ELF_Flags', c_uint32), # Elf64_Word = /* Architecture-specific flags. */ + ('ELF_EFSize', c_uint16), # Elf64_Half = /* Size of ELF header in bytes. */ + ('ELF_PHEntSize', c_uint16), # Elf64_Half = /* Size of program header entry. */ + ('ELF_PHNum', c_uint16), # Elf64_Half = /* Number of program header entries. */ + ('ELF_SHEntSize', c_uint16), # Elf64_Half = /* Size of section header entry. */ + ('ELF_SHNum', c_uint16), # Elf64_Half = /* Number of section header entries. */ + ('ELF_SNStr', c_uint16), # Elf64_Half = /* Section name strings section. */ + ] + +# Section header. +class ELF_SECTION_HEADER32(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('SH_Name', c_uint32), # Elf32_Word = /* Section name (index into the section header string table). */ + ('SH_Type', c_uint32), # Elf32_Word = /* Section type. */ + ('SH_Flags', c_uint32), # Elf32_Word = /* Section flags. */ + ('SH_ADDR', c_uint32), # Elf32_Addr = /* Address in memory image. */ + ('SH_Offset', c_uint32), # Elf32_Off = /* Offset in file. */ + ('SH_Size', c_uint32), # Elf32_Word = /* Size in bytes. */ + ('SH_Link', c_uint32), # Elf32_Word = /* Index of a related section. */ + ('SH_Info', c_uint32), # Elf32_Word = /* Depends on section type. */ + ('SH_AddrAlign', c_uint32), # Elf32_Word = /* Alignment in bytes. */ + ('SH_EntSize', c_uint32), # Elf32_Word = /* Size of each entry in section. */ + ] + +class ELF_SECTION_HEADER64(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('SH_Name', c_uint32), # Elf32_Word = /* Section name (index into the section header string table). */ + ('SH_Type', c_uint32), # Elf32_Word = /* Section type. */ + ('SH_Flags', c_uint64), # Elf32_XWord = /* Section flags. */ + ('SH_ADDR', c_uint64), # Elf32_Addr = /* Address in memory image. */ + ('SH_Offset', c_uint64), # Elf32_Off = /* Offset in file. */ + ('SH_Size', c_uint64), # Elf32_XWord = /* Size in bytes. */ + ('SH_Link', c_uint32), # Elf32_Word = /* Index of a related section. */ + ('SH_Info', c_uint32), # Elf32_Word = /* Depends on section type. */ + ('SH_AddrAlign', c_uint64), # Elf32_XWord = /* Alignment in bytes. */ + ('SH_EntSize', c_uint64), # Elf32_XWord = /* Size of each entry in section. */ + ] + +# Program header. +class ELF_PROGRAM_HEADER32(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('PH_Type', c_uint32), # Elf32_Word = /* Entry type. */ + ('PH_Offset', c_uint32), # Elf32_Off = /* File offset of contents. */ + ('PH_VirAddr', c_uint32), # Elf32_Addr = /* Virtual address in memory image. */ + ('PH_PhyAddr', c_uint32), # Elf32_Addr = /* Physical address (not used). */ + ('PH_FileSize', c_uint32), # Elf32_Word = /* Size of contents in file. */ + ('PH_MemorySize', c_uint32), # Elf32_Word = /* Size of contents in memory. */ + ('PH_Flags', c_uint32), # Elf32_Word = /* Access permission flags. */ + ('PH_Align', c_uint32), # Elf32_Word = /* Alignment in memory and file. */ + ] + +class ELF_PROGRAM_HEADER64(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('PH_Type', c_uint32), # Elf32_Word = /* Entry type. */ + ('PH_Flags', c_uint32), # Elf32_Word = /* Access permission flags. */ + ('PH_Offset', c_uint64), # Elf32_Off = /* File offset of contents. */ + ('PH_VirAddr', c_uint64), # Elf32_Addr = /* Virtual address in memory image. */ + ('PH_PhyAddr', c_uint64), # Elf32_Addr = /* Physical address (not used). */ + ('PH_FileSize', c_uint64), # Elf32_XWord = /* Size of contents in file. */ + ('PH_MemorySize', c_uint64), # Elf32_XWord = /* Size of contents in memory. */ + ('PH_Align', c_uint64), # Elf32_XWord = /* Alignment in memory and file. */ + ] + +# Dynamic union. +class ELF_DYNAMIC_UNION(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_Dynamic_Val', c_uint32), # Elf32_Word = /* Integer value. */ + ('ELF_Dynamic_Ptr', c_uint32), # Elf32_Addr = /* Address value. */ + ] + + +# Dynamic structure. The ".dynamic" section contains an array of them. +class ELF_DYNAMIC_STRUCTURE(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_Dynamic_Tag', c_int32), # Elf32_Sword = /* Entry type. */ + ('ELF_Dynamic_Union', ELF_DYNAMIC_UNION), # Elf32_Off = /* Section type. */ + ] + +## Relocation entries. + +# /* Relocations that don't need an addend field. */ class=20 +ELF_RELOCATION(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_ReOffset', c_uint32), # Elf32_Addr = /* Location to be relocated. */ + ('ELF_ReInfo', c_uint32), # Elf32_Word = /* Relocation type and symbol index. */ + ] + +# /* Relocations that need an addend field. */ class=20 +ELF_RELOCATION(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_ReOffset', c_uint32), # Elf32_Addr = /* Location to be relocated. */ + ('ELF_ReInfo', c_uint32), # Elf32_Word = /* Relocation type and symbol index. */ + ('ELF_ReAddend', c_int32), # Elf32_SWord = /* Addend. */ + ] + +# Move Entry +class ELF_MOVE(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_MValue', c_uint64), # Elf32_Lword = /* symbol value */ + ('ELF_MInfo', c_uint32), # Elf32_Word = /* size + index */ + ('ELF_MPOffset', c_int32), # Elf32_Word = /* symbol offset */ + ('ELF_MRepeat', c_uint16), # Elf32_Half = /* repeat count */ + ('ELF_MStride', c_uint16), # Elf32_Half = /* stride info */ + ] + +## Hardware/Software capabilities entry class=20 +ELF_CAPA_UNION(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_Capa_Val', c_uint32), # Elf32_Word = /* Integer value. */ + ('ELF_Capa_Ptr', c_uint32), # Elf32_Addr = /* Address value. */ + ] + +class ELF_CAPABILITY(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_Capa_Tag', c_uint32), # Elf32_Word = /* how to interpret value */ + ('ELF_Capa_Union', ELF_CAPA_UNION), # ELF_CAPA_UNIO= N + ] + +# Symbol table entries. +class ELF_SYMBOL(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_ST_Name', c_uint32), # Elf32_Word = /* String table index of name. */ + ('ELF_ST_Value', c_uint32), # Elf32_Addr = /* Symbol value. */ + ('ELF_ST_Size', c_uint32), # Elf32_Word = /* Size of associated object. */ + ('ELF_ST_Info', c_char), # /* Type and b= inding information. */ + ('ELF_ST_Other', c_char), # /* Reserved (= not used). */ + ('ELF_ST_Shndx', c_uint16), # Elf32_Half = /* Section index of symbol. */ + ] + +# Structures used by Sun & GNU symbol versioning. +class ELF_VERDEF(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_VD_Version', c_uint16), # Elf32_Half + ('ELF_VD_Flags', c_uint16), # Elf32_Half + ('ELF_VD_Ndx', c_uint16), # Elf32_Half + ('ELF_VD_Cnt', c_uint16), # Elf32_Half + ('ELF_VD_Hash', c_uint32), # Elf32_Word + ('ELF_VD_Aux', c_uint32), # Elf32_Word + ('ELF_VD_Next', c_uint32), # Elf32_Word + ] + +class ELF_VERDAUX(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_VDA_Name', c_uint32), # Elf32_Word + ('ELF_VDA_Next', c_uint32), # Elf32_Word + ] + +class ELF_VERNEED(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_VN_Version', c_uint16), # Elf32_Half + ('ELF_VN_Cnt', c_uint16), # Elf32_Half + ('ELF_VN_File', c_uint32), # Elf32_Word + ('ELF_VN_Aux', c_uint32), # Elf32_Word + ('ELF_VN_Next', c_uint32), # Elf32_Word + ] + +class ELF_VERNAUX(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_VNA_Hash', c_uint32), # Elf32_Word + ('ELF_VNA_Flags', c_uint16), # Elf32_Half + ('ELF_VNA_Other', c_uint16), # Elf32_Half + ('ELF_VNA_Name', c_uint32), # Elf32_Word + ('ELF_VNA_Next', c_uint32), # Elf32_Word + ] + +class ELF_SYMINFO(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('ELF_SI_BoundTo', c_uint16), # Elf32_Half = /* direct bindings - symbol bound to */ + ('ELF_SI_Flags', c_uint16), # Elf32_Half = /* per symbol flags */ + ] + +class UNIVERSAL_PAYLOAD_INFO(Structure): + _pack_ =3D 1 + _fields_ =3D [ + ('Identifier', c_uint32), # ?PLDH? Identi= fier for the unverial payload info. 0x504c4448 + ('HeaderLength', c_uint32), # Length of the= structure in bytes. + ('SpecRevision', c_uint16), # Indicates com= pliance with a revision of this specification in the BCD format. 7 : 0 - Mi= nor Version / 15 : 8 - Major Version For revision v0.75 the value will be 0= x0075. + ('Reserved', c_uint16), # Reserved for = future use. + ('Revision', c_uint32), # Revision of t= he Payload binary. Major.Minor .Revision.Build . The ImageRevision can be d= ecoded as follows: 7 : 0 - Build Number / 15 :8 - Revision / 23 :16 - Min= or Version / 31 :24 - Major Version + ('Attribute', c_uint32), # Length of the= structure in bytes. + ('Capability', c_uint32), # Length of the= structure in bytes. + ('ProducerId', ARRAY(c_uint8, 16)), # Length of the= structure in bytes. + ('ImageId', ARRAY(c_uint8, 16)), # Length of the= structure in bytes. + ] -- 2.27.0.windows.1