From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 37A8AD80CA0 for ; Wed, 29 Nov 2023 23:22:22 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=J+biQge6wwWgMkXzKDc/LHukLrzAo79pvkGlrOnQwmc=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1701300140; v=1; b=h6yNiLB4E+OrlL0Ppg92ZGgCyAW+gmg2rYVvZSbOkZEZy0kjOCRPo+3Im58eBSIFkbdzQ6Am oBfH6x2BMaMygEHeOFkoDpiVOr8QKnYu5fNfbh4vdKsxLMu71XLiZOKcDe3yptaMrreozdERwZV rtDGLjAWPbOz6StisrCL3Lmk= X-Received: by 127.0.0.2 with SMTP id kS9rYY7687511x2IwT3kFSmV; Wed, 29 Nov 2023 15:22:20 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.58054.1701300139672554289 for ; Wed, 29 Nov 2023 15:22:20 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="396047997" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="396047997" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 15:22:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="803447246" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="803447246" X-Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga001.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 29 Nov 2023 15:22:17 -0800 X-Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Wed, 29 Nov 2023 15:22:16 -0800 X-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.34 via Frontend Transport; Wed, 29 Nov 2023 15:22:16 -0800 X-Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.41) 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.34; Wed, 29 Nov 2023 15:22:16 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hP1h+aFs6IZBX+GMbR5YmRb79PTiGc230sK4m2k2pi0qP0xY9aowJqk2nR3bG2i+z8N/nUZcLrgtl6jkT+do9qeCe1se0HgeFKnKqz9VB6JM2wr5NwLshLhANULC/5jqnOfNoV3H+Ohg5FmTdNxLEuFXk28qhBSdmeP1dTnhUXeV1QphEwAObOstENarqphwMQuO7jZnalzHM0dySA3w1cXGBTp6OlUq+RiKcyFQTB8R5J0jJn/Xd2ZFAfcj/9FaU4+0+OIRvLiCs1kDejAbrRnNS8+F2VxcFM7sJbvivFqxNEnmojwUcVW6MyrWqWhcGaF/T/E8RpdAelQTdwoq5A== 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=lPutwzM0jO4FkJ/Jx7SjrlwSqhc7WF44UPPtLT88oKQ=; b=VOBuKir6LKxC0mbSbCB5RtSWZmFAZ0rChNLFB8JpoNzUxGacO1hYOxJGyHkISWFxOJ73ChB6NDTTOO+iEwmU4M1/SGdqNZB9VZeDIjhfGy0I7Tt2/MLVs7cfeBIjbkBXExjpJRBz90tCsM5C8ENrEp0oiJGqe6dG9/vVsQA4KwpZt98TGSXS8yqMviT+yzVM6cy+9GwV0hVw56zwBddrJ1JBGBQ4TjmvlOVltF24Lvt97Ow2Fx2h+ePB1NzvgqpmeoACTQgZ2rihOCISywkjLGw16JMtEjl9/q9Ne2LnFb9QNRS1tUuEP/O/XXWqC7YZTU7OIy2D5kNcyeJMEm/B2w== 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 X-Received: from MW4PR11MB5821.namprd11.prod.outlook.com (2603:10b6:303:184::5) by DM6PR11MB4546.namprd11.prod.outlook.com (2603:10b6:5:2a7::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Wed, 29 Nov 2023 23:22:13 +0000 X-Received: from MW4PR11MB5821.namprd11.prod.outlook.com ([fe80::ced7:2db7:4cae:ab0]) by MW4PR11MB5821.namprd11.prod.outlook.com ([fe80::ced7:2db7:4cae:ab0%7]) with mapi id 15.20.7025.022; Wed, 29 Nov 2023 23:22:13 +0000 From: "Nate DeSimone" To: "devel@edk2.groups.io" , "Desimone, Nathaniel L" CC: "Chiu, Chasel" , "Gao, Liming" , "Dong, Eric" Subject: Re: [edk2-devel] [edk2-platforms][PATCH v1] MinPlatformPkg: Update PatchFv Tools for Python 3.x Thread-Topic: [edk2-devel] [edk2-platforms][PATCH v1] MinPlatformPkg: Update PatchFv Tools for Python 3.x Thread-Index: AQHaIZc8aFawUC516kSynMqDopSGxrCR8o9A Date: Wed, 29 Nov 2023 23:22:13 +0000 Message-ID: References: <20231128010339.1954-1-nathaniel.l.desimone@intel.com> <179BA3DA5F43EA7E.19746@groups.io> In-Reply-To: <179BA3DA5F43EA7E.19746@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR11MB5821:EE_|DM6PR11MB4546:EE_ x-ms-office365-filtering-correlation-id: bdc27810-f8e1-4179-ea2c-08dbf1320499 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: ncYWPBXgMmlMDIgtDaINnWKOD7nRhUPrAMbhIp3nfhbFrFkG6eymCg5uYjpGKevLOQD0pgZ14Vnniqst22uKrJ4b+9srmPrrh+k95AxzlCyX28ufrzWZNgIwzD4hksx5k2gCPtzqOCYjwxkYxlj06fcZxoAeo+dBoH8iSNUZ49jRAyagz4TOzE5WLaI8zn0gjNOKDt2IXCM8Wffh96nz9lHvbu9+LT58ybEnim0IHKVkeVTTAKIu6vAgNnrgydQW5pzRQKeqGUkPbPpzwm3779B2tRrZ7sK5mIMhVtIazJMCsXCc8jdQiE3vQ4MSHyDYvOTCl0kjD3YN3ByIwoHC0h2x2OZ+qS73Xyh1Q3/NeUC6FBb3g/r/IINfYHjlDOJRG9IT9PxP6lnuBbguaj9C+GVSpZXASFoHOR7kjjYU32O1/tZV7kicORiuJW9pLi/hXqXo7cbxIL1A/rvtbdJ1AMCRxbO2XiV3dJ92ODu7zDV5Z0NTQaeZrCR6XBLalNGVYRlfLgxD56mp4V6i1eoJOtkt9dpWEb/XLyBsfrU2urXfSe/EYpPc34VviskkbzKB/ieaBjLvIA4AgFHB3HdtutC3vywSv6+pPNRwev+IYucAKAVnrXW5561cZiLWa3ihQ9YBXo/Yihpt8sYCrAQ1D5bIkex9yNai99gAI97jpixbR88EY5OFw3/zD9TyqRNe x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?36mqhDV1LsKHefhhXsaxxIg+7KzKv2keMM2IiIY6dswuNp7KBp4O/VdIv5LL?= =?us-ascii?Q?wSF4DrG49Cmd/tYRxNb0t5tQ0tWxcRB6wwkycnUdUsBfCkaQDhHfROHvPDV+?= =?us-ascii?Q?xDX8V7tJzrktGMAVZW9GzSexonIfpb6L6PWXXe/+4LFl5cEkuJO7HWycHqgg?= =?us-ascii?Q?lzY57g+55ZcWe7GgiDNQXOFwdxJG2+h1iv0fb1jkz2VSbOO0sEDPDEg/i3lf?= =?us-ascii?Q?ciI1BDeJPUedjwXvieiyORlVcOGq+avLyfQwUgJUYTStmbjWOcZP/VFR8Vhq?= =?us-ascii?Q?pt90laRPjTIgPlYH4TFVjwvyrNjFui1USZMRqyKYFQRjXOZbUM6/eXVCxOx/?= =?us-ascii?Q?lZH+shpPGQ011T70c913AEDlqrQrblQfqON5sGxStL9QJY62mVhC+K73X7pM?= =?us-ascii?Q?ZDzE0MNJtQR7KzZKDm1kmpWKcGI1e8Dwo55SHKX4DK60UqRISLbyY7d5uIPL?= =?us-ascii?Q?11aTlZ143Q457URkzyEGb1xGmkx28N38YF3JiuYRgNfaHtVUWhmDCZ/OQEgg?= =?us-ascii?Q?d6fjpCkuW+q+4jI4LgzUzcKJhzESlDUJaLwC0U5VN0kOoWNuLI2F+M8KrxSo?= =?us-ascii?Q?w2eYZPRplWqcOgN8ccvBfA1vEuYnrnXTyd5bha8aoUALWBzflOMM88hw7b1i?= =?us-ascii?Q?zrwWpR/GLyou+ynY25A9zOLLM8MpEvbFYltzm8j+LmHnPObSusyxZCxKT6DR?= =?us-ascii?Q?hR4f7fq3uSH7wzeB4OjynwLyif3e83HhIzUl0QizX+7rYEqfZ3gaL3claTTo?= =?us-ascii?Q?3R67e012FDxMcF1cxY313twuyCWOqSSJX8iOHA1woT2uKe9RU7vo91EQWuBd?= =?us-ascii?Q?dNUHOwIDrhCJrMrmll0qdJzaM22npZc2m2ISusPPEwdk7ynN4ZmjpmC+06TM?= =?us-ascii?Q?mSBf7CVSmFpvdTMw9obcAHHoGu1REz1+wan7Rb83St9a1xae4wsCaFZkVlaz?= =?us-ascii?Q?BDF0Xh3RR9tCwyCX3WmZ61G4SGtgKdquGAtSyE3J8Y0GUDxKkfYnEymvZwwt?= =?us-ascii?Q?RrXIo/PXCK66TGU+9TpYxOAmTABBkTjOaejuwaHSWM4gogEF5nOkLCCGcCS0?= =?us-ascii?Q?NyajvIbP8e1Nh8GQTVO56B5c498vjSM39ek6iBHm16YJfVWSPylFbmmsvseZ?= =?us-ascii?Q?RcHEXqCAhbUk87OaVJcUMqWQyckGraDfwgjZHQAAvlAkQnG1FXWXUi3MhjR1?= =?us-ascii?Q?1FkbfCJH33BZ8DXFzIgST5x5L9ajhraNehQwqQBfwL6smHQwce8ElX8AfXGe?= =?us-ascii?Q?nPKHyqOFcBySdnOPHFG6cJuPbdNpvAKeM6fSBNE3FGf0eocyQQUzqVdhmaFt?= =?us-ascii?Q?uxy/+i5qF61VFgf/IiJ/qOZM+3IoOf4NRx6BpYdosOBZ2vP1VeO1Sy/GhZnX?= =?us-ascii?Q?sjogR4DeyQYXmE8XjvY5h1DNM7fHg4gfqDlWigdsE7/AHEqFeqlqGEpAgZ7b?= =?us-ascii?Q?hhYfhVbr/omb2qpUhcqIEAJY2PcoHXN3DAcQBAS/IDkB4Bd5MpWrB1ymDsKI?= =?us-ascii?Q?UIOAeixq9lFK7RwZuyRKJ8YZC88+8trZsQgebdxk7oHnLIHGP4r7fQbbXAxK?= =?us-ascii?Q?sYCVqKbg1LQ8RiF+Cqxg8wL57e5Bt7BIJrpLENqJK5/SMVPGCKkgiK9qqr/R?= =?us-ascii?Q?Uw=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB5821.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bdc27810-f8e1-4179-ea2c-08dbf1320499 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Nov 2023 23:22:13.0837 (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: GK/Ms8ElwEi7jSBa8XSPR+4clNOjOKDT59h2Mwp5W9QbXS/F7nHpqmEYyR2SG6XAmNOKfNQ5H5xm+RCZCnF/aqY38ZpK6GiYhJysmvOrJ6s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4546 X-OriginatorOrg: intel.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,nathaniel.l.desimone@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: PBsMuOytIhgmvhGXA9X8rnpKx7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=h6yNiLB4; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") Pushed as d02c09d -----Original Message----- From: devel@edk2.groups.io On Behalf Of Nate DeSimon= e Sent: Monday, November 27, 2023 5:04 PM To: devel@edk2.groups.io Cc: Chiu, Chasel ; Gao, Liming ; Dong, Eric Subject: [edk2-devel] [edk2-platforms][PATCH v1] MinPlatformPkg: Update Pat= chFv Tools for Python 3.x PatchFv tools now run on Python 3.x Cc: Chasel Chiu Cc: Liming Gao Cc: Eric Dong Signed-off-by: Nate DeSimone --- .../MinPlatformPkg/Tools/PatchFv/PatchBfv.py | 35 ++++---- .../Tools/PatchFv/PatchBinFv.py | 69 ++++++++-------- .../Tools/PatchFv/RebaseBinFv.py | 82 +++++++++---------- 3 files changed, 92 insertions(+), 94 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py b/Plat= form/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py index 1312bfc328..f05480b91f 100644 --- a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py +++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBfv.py @@ -1,6 +1,6 @@ ## @ PatchBfv.py # -# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights=20 +reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -11,8 +11,7 @@ im= port sys import time import shutil import struct -import binascii -from ctypes import * +from ctypes import * =20 class FileChecker: def __init__(self): @@ -21,17 +20,17 @@ class FileChecker: self.pcd =3D ["", "", ""] =20 def PrintPcd(self): - print "PCD: " + self.pcd[0] + "|" + self.pcd[1] + "(" + self.pcd[2= ] + ")" + print("PCD: {0}|{1}({2})".format(*(self.pcd))) =20 def ProcessReport(self): try : file =3D open(self.reportFile) except Exception: - print "fail to open " + self.reportFile + print("fail to open " + self.reportFile) return try: file.seek(0) - print "checking - " + self.pcd[0] + print("checking - " + self.pcd[0]) ValuePair =3D self.GetPcdFromReport (file, self.pcd[0]) self.pcd[1] =3D ValuePair[0] self.pcd[2] =3D ValuePair[1] @@ -42,12 +41,12 @@ class FileChecker: =20 def PatchFd(self): fileName =3D self.fdName - print "patching BFV - " + fileName + print("patching BFV - " + fileName) =20 try : file =3D open(fileName, "rb") except Exception: - print "fail to open " + fileName + print("fail to open " + fileName) return try: buffer =3D file.read() @@ -57,7 +56,7 @@ class FileChecker: offset =3D -4 =20 l =3D struct.pack("L", int(self.pcd[1],16)) - print " [" + hex(offset) + "] " + binascii.hexlify(data[-4:])= + " <=3D " + binascii.hexlify(l) + print(" [" + hex(offset) + "] " + bytes(data[-4:]).hex() +=20 + " <=3D " + bytes(l).hex()) data[-4:] =3D l =20 file =3D open(fileName, "wb") @@ -77,36 +76,36 @@ class FileCh= ecker: =20 newline =3D line[:-1] =20 - if (cmp (newline, TargetPkg) =3D=3D 0): + if newline =3D=3D TargetPkg: FoundPkg =3D True continue =20 - if (cmp (newline, "") =3D=3D 0) or ((cmp (newline[0], " ") != =3D 0) and (cmp (newline[0], "0") !=3D 0)): + if newline =3D=3D "" or (newline[0] !=3D " " and newline[0] != =3D "0"): FoundPkg =3D False =20 if (FoundPkg =3D=3D True) : newline =3D newline.strip() splitLine =3D newline.split(" ", 2) - if (cmp (splitLine[0], "*F") =3D=3D 0) or (cmp (splitLine[= 0], "*P") =3D=3D 0) : - if (cmp (splitLine[1], TargetPcd) =3D=3D 0): - print "found - " + TargetPkg + "." + TargetPcd + if splitLine[0] =3D=3D "*F" or splitLine[0] =3D=3D "*P": + if splitLine[1] =3D=3D TargetPcd: + print("found - " + TargetPkg + "." + TargetPcd) =20 splitLine =3D splitLine[2].strip()[1:].strip().spl= it(" ", 1) - if (cmp (splitLine[0], "FIXED") =3D=3D 0) or (cmp = (splitLine[0], "PATCH") =3D=3D 0): + if splitLine[0] =3D=3D "FIXED" or splitLine[0] =3D= =3D "PATCH": SplitLine =3D splitLine[1].strip()[1:].split("= )", 1) Type =3D SplitLine[0] Value =3D SplitLine[1].strip()[1:].strip().spl= it()[0] - print " Type - (" + Type + "), Value - (" + V= alue + ")" + print(" Type - (" + Type + "), Value - ("=20 + + Value + ")") return [Value, Type] return ["", ""] - =20 + def main(): global FileChecker =20 fileChecker =3D FileChecker() =20 if (len(sys.argv) !=3D 4) : - print "usage: PatchBfv " + print("usage: PatchBfv ") return 0 =20 fileChecker.fdName =3D sys.argv[1] diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py b/Pl= atform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py index b98c951b45..78576a3029 100644 --- a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py +++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/PatchBinFv.py @@ -1,6 +1,6 @@ ## @ PatchBinFv.py # -# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights=20 +reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -11,7 +11,6 @@ im= port sys import time import shutil import struct -import binascii from ctypes import * =20 class FileChecker: @@ -30,20 +29,20 @@ class FileChecker: def IsSyncSection(self, line): name =3D self.GetSectionName(line) for sectionName in self.SyncSectionList: - if (cmp (sectionName, name) =3D=3D 0) : + if sectionName =3D=3D name: return True return False =20 def PrintPcdList(self, pcdList): for pcd in pcdList: - print "PCD: " + pcd[0] + "|" + pcd[1] + "|" + pcd[2] + " <=3D= =3D " + pcd[3] + "(" + pcd[4] + ")" + print(("PCD: {0} | {1} | {2} <=3D=3D {3}({4})".format(*pcd))) =20 def GetInfFileGuid(self, fileName): guid =3D "" try : file =3D open(fileName) except Exception: - print "fail to open " + fileName + print("fail to open " + fileName) return try: while 1: @@ -53,7 +52,7 @@ class FileChecker: =20 newline =3D line[:-1] =20 - if cmp (line[:11], " FILE_GUID") =3D=3D 0: + if line[:11] =3D=3D " FILE_GUID": splitLine =3D line.split("=3D") templine =3D splitLine[1] guid =3D templine[1:1+36] @@ -66,7 +65,7 @@ class File= Checker: try : file =3D open(fileName) except Exception: - print "fail to open " + fileName + print("fail to open " + fileName) return try: while 1: @@ -76,23 +75,23 @@ class FileChecker: =20 newline =3D line[:-1] =20 - if cmp (line[0], "#") =3D=3D 0: + if line[0] =3D=3D "#": continue =20 =20 - if cmp (line[0], "[") =3D=3D 0: + if line[0] =3D=3D "[": SyncToDest =3D self.IsSyncSection(line) PatchOffset =3D False =20 - if (cmp (self.GetSectionName(line), "PatchPcd") =3D=3D 0) = : + if (self.GetSectionName(line) =3D=3D "PatchPcd"): PatchOffset =3D True continue =20 if SyncToDest =3D=3D True : line =3D line.strip() - if (cmp (line, "") =3D=3D 0) : + if line =3D=3D "": continue - if (cmp (line[0], "#") =3D=3D 0) : + if line[0] =3D=3D "#": continue =20 splitLine =3D line.split(" ") @@ -108,9 +107,9 @@ clas= s FileChecker: =20 def ProcessFvInf(self, fvName): sourceFileName =3D os.path.join(self.sourceRoot,fvName,self.target= ,fvName+".inf") - print "\nprocessing - " + sourceFileName + print("\nprocessing - " + sourceFileName) fileGuid =3D self.GetInfFileGuid (sourceFileName) - print "FV NAME GUID - " + fileGuid + print("FV NAME GUID - " + fileGuid) =20 self.InfPcdList =3D [] self.ParseInfFile(sourceFileName) @@ -122,12 +121,12 @@ class File= Checker: try : file =3D open(self.reportFile) except Exception: - print "fail to open " + self.reportFile + print("fail to open " + self.reportFile) return try: for pcd in self.InfPcdList: file.seek(0) - print "checking - " + pcd[0] + print("checking - " + pcd[0]) ValuePair =3D self.GetPcdFromReport (file, pcd[0]) pcd[3] =3D ValuePair[0] pcd[4] =3D ValuePair[1] @@ -138,12 +137,12 @@ class FileChecker: =20 def PatchFv(self, fvName): sourceFileName =3D os.path.join(self.sourceRoot,fvName,self.target= ,fvName+".Fv") - print "patching - " + sourceFileName + print("patching - " + sourceFileName) =20 try : file =3D open(sourceFileName, "rb") except Exception: - print "fail to open " + sourceFileName + print("fail to open " + sourceFileName) return try: buffer =3D file.read() @@ -152,21 +151,21 @@ class FileChecker: =20 for pcd in self.InfPcdList: offset =3D int(pcd[2], 16) - if (cmp (pcd[4], "BOOLEAN") =3D=3D 0) or (cmp (pcd[4], "UI= NT8") =3D=3D 0): + if (pcd[4] =3D=3D "BOOLEAN") or (pcd[4] =3D=3D "UINT8"): b =3D struct.pack("B", int(pcd[3],16)) - print " [" + hex(offset) + "] " + binascii.hexlify(da= ta[offset:offset+1]) + " <=3D " + binascii.hexlify(b) + print(" [" + hex(offset) + "] " +=20 + bytes(data[offset:offset+1]).hex() + " <=3D " + bytes(b).hex()) data[offset:offset+1] =3D b - elif (cmp (pcd[4], "UINT16") =3D=3D 0): + elif (pcd[4] =3D=3D "UINT16"): h =3D struct.pack("H", int(pcd[3],16)) - print " [" + hex(offset) + "] " + binascii.hexlify(da= ta[offset:offset+2]) + " <=3D " + binascii.hexlify(h) + print(" [" + hex(offset) + "] " +=20 + bytes(data[offset:offset+2]).hex() + " <=3D " + bytes(h).hex()) data[offset:offset+2] =3D h - elif (cmp (pcd[4], "UINT32") =3D=3D 0): + elif (pcd[4] =3D=3D "UINT32"): l =3D struct.pack("I", int(pcd[3],16)) - print " [" + hex(offset) + "] " + binascii.hexlify(da= ta[offset:offset+4]) + " <=3D " + binascii.hexlify(l) + print(" [" + hex(offset) + "] " +=20 + bytes(data[offset:offset+4]).hex() + " <=3D " + bytes(l).hex()) data[offset:offset+4] =3D l - elif (cmp (pcd[4], "UINT64") =3D=3D 0): + elif (pcd[4] =3D=3D "UINT64"): q =3D struct.pack("Q", int(pcd[3],16)) - print " [" + hex(offset) + "] " + binascii.hexlify(da= ta[offset:offset+8]) + " <=3D " + binascii.hexlify(q) + print(" [" + hex(offset) + "] " +=20 + bytes(data[offset:offset+8]).hex() + " <=3D " + bytes(q).hex()) data[offset:offset+8] =3D q file =3D open(sourceFileName, "wb") file.write(data) @@ -185,36 +184,36 @@ class FileChecker: =20 newline =3D line[:-1] =20 - if (cmp (newline, TargetPkg) =3D=3D 0): + if (newline =3D=3D TargetPkg): FoundPkg =3D True continue =20 - if (cmp (newline, "") =3D=3D 0) or ((cmp (newline[0], " ") != =3D 0) and (cmp (newline[0], "0") !=3D 0)): + if (newline =3D=3D "") or ((newline[0] !=3D " ") and (newline[= 0] !=3D "0")): FoundPkg =3D False =20 if (FoundPkg =3D=3D True) : newline =3D newline.strip() splitLine =3D newline.split(" ", 2) - if (cmp (splitLine[0], "*F") =3D=3D 0) or (cmp (splitLine[= 0], "*P") =3D=3D 0): - if (cmp (splitLine[1], TargetPcd) =3D=3D 0): - print "found - " + TargetPkg + "." + TargetPcd + if (splitLine[0] =3D=3D "*F") or (splitLine[0] =3D=3D "*P"= ): + if (splitLine[1] =3D=3D TargetPcd): + print("found - " + TargetPkg + "." + TargetPcd) =20 splitLine =3D splitLine[2].strip()[1:].strip().spl= it(" ", 1) - if (cmp (splitLine[0], "FIXED") =3D=3D 0) or (cmp = (splitLine[0], "PATCH") =3D=3D 0): + if (splitLine[0] =3D=3D "FIXED") or (splitLine[0] = =3D=3D "PATCH"): SplitLine =3D splitLine[1].strip()[1:].split("= )", 1) Type =3D SplitLine[0] Value =3D SplitLine[1].strip()[1:].strip().spl= it()[0] - print " Type - (" + Type + "), Value - (" + V= alue + ")" + print(" Type - (" + Type + "), Value - ("=20 + + Value + ")") return [Value, Type] return ["", ""] - =20 + def main(): global FileChecker =20 fileChecker =3D FileChecker() =20 if (len(sys.argv) !=3D 5) : - print "usage: PatchBinFv " + print("usage: PatchBinFv =20 + ") return 0 =20 fileChecker.target =3D sys.argv[1] diff --git a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py b/P= latform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py index 149630e4ef..2cea491f41 100644 --- a/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py +++ b/Platform/Intel/MinPlatformPkg/Tools/PatchFv/RebaseBinFv.py @@ -1,6 +1,6 @@ ## @ PatchBinFv.py # -# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2023, Intel Corporation. All rights=20 +reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # =20 @@ -10,8 +10,8 @@ import sys import time import shutil import struct -import binascii -from ctypes import * +from ctypes import * +from functools import reduce =20 class GUID(Structure): _fields_ =3D [ @@ -380,9 +380,9 @@ class PeTeImage: def __init__(self, offset, data): self.Offset =3D offset tehdr =3D EFI_TE_IMAGE_HEADER.from_buffer (data, 0) - if tehdr.Signature =3D=3D 'VZ': # TE image + if tehdr.Signature =3D=3D b'VZ': # TE image self.TeHdr =3D tehdr - elif tehdr.Signature =3D=3D 'MZ': # PE32 image + elif tehdr.Signature =3D=3D b'MZ': # PE32 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) @@ -397,7 +397,7 @@ class PeTeImage: self.RelocList =3D [] =20 def IsTeImage(self): - return self.TeHdr is not None + return self.TeHdr is not None =20 def ParseReloc(self): if self.IsTeImage(): @@ -415,7 +415,7 @@ class PeTeImage: offset +=3D sizeof(blkhdr) # Read relocation type,offset pairs rlen =3D blkhdr.BlockSize - sizeof(PE_RELOC_BLOCK_HEADER) - rnum =3D rlen/sizeof(c_uint16) + rnum =3D rlen // sizeof(c_uint16) rdata =3D (c_uint16 * rnum).from_buffer(self.Data, offset) for each in rdata: roff =3D each & 0xfff @@ -532,21 +532,21 @@ class FileChecker: def IsSyncSection(self, line): name =3D self.GetSectionName(line) for sectionName in self.SyncSectionList: - if (cmp (sectionName, name) =3D=3D 0) : + if sectionName =3D=3D name: return True return False =20 def PrintRebasePcd(self, pcd): - print "PCD: " + pcd[0] + "|" + pcd[3] + " <=3D=3D " + pcd[1] + "("= + pcd[2] + ")" + print("PCD: {0} | {3} <=3D=3D {1}({2})".format(*pcd)) =20 def RebaseFv(self, fvName, rebasePcd): sourceFileName =3D os.path.join(self.sourceRoot,fvName,self.target= ,fvName+".Fv") - print "rebasing(FV) - " + sourceFileName + print("rebasing(FV) - " + sourceFileName) =20 try : file =3D open(sourceFileName, "rb") except Exception: - print "fail to open " + sourceFileName + print("fail to open " + sourceFileName) return try: buffer =3D file.read() @@ -554,15 +554,15 @@ class FileChecker: file.close() =20 FvHeader =3D EFI_FIRMWARE_VOLUME_HEADER.from_buffer (data, 0) - print "HeaderLength - " + hex(FvHeader.HeaderLength) - print "ExtHeaderOffset - " + hex(FvHeader.ExtHeaderOffset) + print("HeaderLength - " + hex(FvHeader.HeaderLength)) + print("ExtHeaderOffset - " + hex(FvHeader.ExtHeaderOffset)) =20 if (FvHeader.ExtHeaderOffset =3D=3D 0): Offset =3D FvHeader.HeaderLength else: FvExHeader =3D EFI_FIRMWARE_VOLUME_EXT_HEADER.from_buffer(= data, FvHeader.ExtHeaderOffset) - print " FvName - %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02= x%02x%02x" % (FvExHeader.FvName.Guid1, FvExHeader.FvName.Guid2, FvExHeader.= FvName.Guid3, FvExHeader.FvName.Guid4[0], FvExHeader.FvName.Guid4[1], FvExH= eader.FvName.Guid4[2], FvExHeader.FvName.Guid4[3], FvExHeader.FvName.Guid4[= 4], FvExHeader.FvName.Guid4[5], FvExHeader.FvName.Guid4[6], FvExHeader.FvNa= me.Guid4[7]) - print " ExtHeaderSize - " + hex(FvExHeader.ExtHeaderSize) + print(" FvName - %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02= x%02x%02x" % (FvExHeader.FvName.Guid1, FvExHeader.FvName.Guid2, FvExHeader.= FvName.Guid3, FvExHeader.FvName.Guid4[0], FvExHeader.FvName.Guid4[1], FvExH= eader.FvName.Guid4[2], FvExHeader.FvName.Guid4[3], FvExHeader.FvName.Guid4[= 4], FvExHeader.FvName.Guid4[5], FvExHeader.FvName.Guid4[6], FvExHeader.FvNa= me.Guid4[7])) + print(" ExtHeaderSize - " +=20 + hex(FvExHeader.ExtHeaderSize)) Offset =3D FvHeader.ExtHeaderOffset + FvExHeader.ExtHeader= Size Offset =3D (Offset + 0x7) & ~0x7 =20 @@ -576,20 +576,20 @@ class FileChecker: if (FfsHeader.Type =3D=3D 0xFF) or (FfsHeader.Type =3D=3D = EFI_FV_FILETYPE_FFS_PAD) : Offset =3D (FfsOffset + FfsSize + 7) & ~0x7 continue - print "Ffs - %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%= 02x" % (FfsHeader.Name.Guid1, FfsHeader.Name.Guid2, FfsHeader.Name.Guid3, F= fsHeader.Name.Guid4[0], FfsHeader.Name.Guid4[1], FfsHeader.Name.Guid4[2], F= fsHeader.Name.Guid4[3], FfsHeader.Name.Guid4[4], FfsHeader.Name.Guid4[5], F= fsHeader.Name.Guid4[6], FfsHeader.Name.Guid4[7]) + print("Ffs -=20 + %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" %=20 + (FfsHeader.Name.Guid1, FfsHeader.Name.Guid2, FfsHeader.Name.Guid3,=20 + FfsHeader.Name.Guid4[0], FfsHeader.Name.Guid4[1],=20 + FfsHeader.Name.Guid4[2], FfsHeader.Name.Guid4[3],=20 + FfsHeader.Name.Guid4[4], FfsHeader.Name.Guid4[5],=20 + FfsHeader.Name.Guid4[6], FfsHeader.Name.Guid4[7])) Offset =3D Offset + sizeof(EFI_FFS_FILE_HEADER) while (Offset < FfsOffset + FfsSize) : SectionHeader =3D EFI_COMMON_SECTION_HEADER.from_buffe= r (data, Offset) #print " Section - " + hex(Offset) if (SectionHeader.Type =3D=3D EFI_SECTION_PE32) or (Se= ctionHeader.Type =3D=3D EFI_SECTION_TE) : PeOffset =3D Offset + sizeof(EFI_COMMON_SECTION_HE= ADER) - print " PE - " + hex(PeOffset) + "(" + binascii= .hexlify(data[PeOffset:PeOffset+2]) + ")" + print(" PE - " + hex(PeOffset) + "(" + bytes(da= ta[PeOffset:PeOffset+2]).hex() + ")") =20 newbase =3D int(rebasePcd[1],16) oldbase =3D int(rebasePcd[3],16) =20 delta =3D newbase - oldbase - print " delta - " + hex(delta) + "(" + hex(oldb= ase) + " <=3D=3D " + hex(newbase) + ")" + print(" delta - " + hex(delta) + "(" + hex(oldb= ase) + " <=3D=3D " + hex(newbase) + ")") =20 PeLength =3D FfsSize-sizeof(EFI_FFS_FILE_HEADER); =20 @@ -618,26 +618,26 @@ class FileChecker: =20 newline =3D line[:-1].replace('\r','') =20 - if (cmp (newline, TargetPkg) =3D=3D 0): + if newline =3D=3D TargetPkg: FoundPkg =3D True continue =20 - if (cmp (newline, "") =3D=3D 0) or ((cmp (newline[0], " ") != =3D 0) and (cmp (newline[0], "0") !=3D 0)): + if newline =3D=3D "" or (newline[0] !=3D " " and newline[0] != =3D "0"): FoundPkg =3D False =20 if (FoundPkg =3D=3D True) : newline =3D newline.strip() splitLine =3D newline.split(" ", 2) - if (cmp (splitLine[0], "*F") =3D=3D 0) or (cmp (splitLine[= 0], "*P") =3D=3D 0): - if (cmp (splitLine[1], TargetPcd) =3D=3D 0): - print "found - " + TargetPkg + "." + TargetPcd + if (splitLine[0] =3D=3D "*F") or (splitLine[0] =3D=3D "*P"= ): + if splitLine[1] =3D=3D TargetPcd: + print("found - " + TargetPkg + "." + TargetPcd) =20 splitLine =3D splitLine[2].strip()[1:].strip().spl= it(" ", 1) - if (cmp (splitLine[0], "FIXED") =3D=3D 0) or (cmp = (splitLine[0], "PATCH") =3D=3D 0): + if splitLine[0] =3D=3D "FIXED" or splitLine[0] =3D= =3D "PATCH": SplitLine =3D splitLine[1].strip()[1:].split("= )", 1) Type =3D SplitLine[0] Value =3D SplitLine[1].strip()[1:].strip().spl= it()[0] - print " Type - (" + Type + "), Value - (" + V= alue + ")" + print(" Type - (" + Type + "), Value - ("=20 + + Value + ")") return [Value, Type] return ["", ""] =20 @@ -648,7 +648,7 @@ class FileChecker: try : file =3D open(fileName) except Exception: - print "fail to open " + fileName + print("fail to open " + fileName) return try: while 1: @@ -658,21 +658,21 @@ class FileChecker: =20 newline =3D line[:-1].replace('\r','') =20 - if cmp (newline, "") =3D=3D 0: + if newline =3D=3D "": continue =20 - if cmp (newline, "#![Pcd]") =3D=3D 0: + if newline =3D=3D "#![Pcd]": ParseBase =3D True continue =20 if ParseBase =3D=3D True : - if (cmp (line[0:2], "#!") !=3D 0) : + if line[0:2] !=3D "#!": ParseBase =3D False continue newline =3D newline[2:].strip() =20 splitLine =3D newline.split("|") - if cmp (PcdName, splitLine[0]) =3D=3D 0: + if PcdName =3D=3D splitLine[0]: Value =3D splitLine[1] finally: file.close() @@ -681,11 +681,11 @@ class FileChecker: =20 def SetNewFvBase (self, fvName, PcdName, OldFvBase, NewFvBase): fileName =3D os.path.join(self.sourceRoot,fvName,self.target,fvNam= e+".inf") - print "update - " + fileName + print("update - " + fileName) try : file =3D open(fileName, "r") except Exception: - print "fail to open " + fileName + print("fail to open " + fileName) return try: lines =3D file.readlines() @@ -699,23 +699,23 @@ class FileChecker: =20 newline =3D line[:-1].strip() =20 - if cmp (newline, "") =3D=3D 0: + if newline =3D=3D "": continue =20 - if cmp (newline, "#![Pcd]") =3D=3D 0: + if newline =3D=3D "#![Pcd]": ParseBase =3D True continue =20 if ParseBase =3D=3D True : - if (cmp (line[0:2], "#!") !=3D 0) : + if line[0:2] !=3D "#!": ParseBase =3D False continue newline =3D newline[2:].strip() =20 splitLine =3D newline.split("|") - if cmp (PcdName, splitLine[0]) =3D=3D 0: - if cmp (OldFvBase, splitLine[1]) !=3D 0: - print "ERROR: OldFvBase mismatch!" + if PcdName =3D=3D splitLine[0]: + if OldFvBase !=3D splitLine[1]: + print("ERROR: OldFvBase mismatch!") else: lines[index] =3D "#! " + PcdName + "|" + NewF= vBase + "\n" break @@ -730,11 +730,11 @@ class FileChecker: try : file =3D open(self.reportFile) except Exception: - print "fail to open " + self.reportFile + print("fail to open " + self.reportFile) return try: file.seek(0) - print "checking - " + self.RebasePcd[0] + print("checking - " + self.RebasePcd[0]) ValuePair =3D self.GetPcdFromReport (file, self.RebasePcd[0]) self.RebasePcd[1] =3D ValuePair[0] self.RebasePcd[2] =3D ValuePair[1] @@ -747,7 +747,7 @@ def mai= n(): fileChecker =3D FileChecker() =20 if (len(sys.argv) !=3D 6) : - print "usage: RebaseBinFv " + print("usage: RebaseBinFv =20 + ") return 0 =20 fileChecker.target =3D sys.argv[1] -- 2.39.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111861): https://edk2.groups.io/g/devel/message/111861 Mute This Topic: https://groups.io/mt/102883404/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-