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.web09.5904.1611022132716678634 for ; Mon, 18 Jan 2021 18:08:53 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=U9q52re4; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: yuwei.chen@intel.com) IronPort-SDR: WM2sShxJ0T8M0+fUbIj6dQthv5WxnWfXFmhKLIoFFmp3xYihRGaiTNU1WtZlorM1IWSUvLcEEL K+FXlSsGnD5w== X-IronPort-AV: E=McAfee;i="6000,8403,9868"; a="240407542" X-IronPort-AV: E=Sophos;i="5.79,357,1602572400"; d="scan'208";a="240407542" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2021 18:08:49 -0800 IronPort-SDR: pqoiH8jNuyQ7/iLCVSYpDz+zfjw/Vr29dfFOyNkYxpSaqRLBMqcic5DPUi6xbHAcOcAGYyowvi Xagiv0SAzTMg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,357,1602572400"; d="scan'208";a="399261222" Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga004.fm.intel.com with ESMTP; 18 Jan 2021 18:08:49 -0800 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 18 Jan 2021 18:08:48 -0800 Received: from fmsmsx606.amr.corp.intel.com (10.18.126.86) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 18 Jan 2021 18:08:48 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 18 Jan 2021 18:08:48 -0800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.107) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Mon, 18 Jan 2021 18:08:47 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MdZN/UaEizusYse+GwCs2l3jkR5NnuHGXw1aYaZMOjSpfHruaotS1w1A8denllMji9U0qx7TacG/LphNNz0dqarztLbam3LTDrE260gScIxlGcBgyz1nzLJ9EoHjgOVAgPsBv0dJA5FMty57wLM1kXKMInIjFQdpL2/vDlo8LFMzeHrd7AuN/sp3kNKT9vDjUEzUENtJkMWOoUlft7P01vcrdKV2X+z3CpVjg0k1MbVZYrsflT05r0kmZrCalZlEEfNTxVtpQQFTNrMLRUtgkFK6b4QW7FYQgOc+Zv05K6q5GFQmxkI+9VJ4qusoNy2nGBkJvzV4k7LAJBSs3RNrpA== 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-SenderADCheck; bh=hUDEFfdmUGxLWpqyuk9tc26CWQPyNPC1xOkOFE/yySY=; b=KO5rDeyqF7lq+2TmHYV43WkjAOc5cfHrpuLDXdqzyR3PWBlbpBmos39Ful7OACvbrNJffjN8aFAKbhFV5DhKW1fjREVHwSIvfoPlR8bSi02oyNkhni0qygNBmocUHFMn3VZslpjsI/k+onEwzYatVIoYPOm3zOJgBGirscFEOiOf/s8nxnPQfpQ8dVv2jzn6aRUJw0qSWIg8HIUdvHrp2yrAN6X+wks0LWIOjTV+h4boIbz9sHmMv10MPRf2zrzvSvgDej3lDnfaiJGs0YAV9wUn983oMZ+Jprz25n/NykOVGXtxQvhW3Rp1Qgk7E8AMUBU7Ih8sRitreDM5fzgrOw== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hUDEFfdmUGxLWpqyuk9tc26CWQPyNPC1xOkOFE/yySY=; b=U9q52re4fdRHoehhKctc5HCGET5vZ5+JOvHhgS5YhcvhT9b9N6exQmA2S5Xe2jdTXAfp4ZTkG2uep7gTAlG4kAOT29G/flladotqoDZ+qQIHns9Lh6ueqjywiYgkQr7gKFNC7WuJLXQAQgaANiUGmiC7ysxz5sSv1VMfCMWEgqo= Received: from DM5PR11MB1594.namprd11.prod.outlook.com (2603:10b6:4:5::16) by DM6PR11MB4025.namprd11.prod.outlook.com (2603:10b6:5:197::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 02:08:46 +0000 Received: from DM5PR11MB1594.namprd11.prod.outlook.com ([fe80::59f7:5329:fc62:a3be]) by DM5PR11MB1594.namprd11.prod.outlook.com ([fe80::59f7:5329:fc62:a3be%9]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 02:08:46 +0000 From: "Yuwei Chen" To: "Feng, Bob C" , "devel@edk2.groups.io" CC: Liming Gao Subject: Re: [Patch 1/2 V4] BaseTools: Convert Split tool to python Thread-Topic: [Patch 1/2 V4] BaseTools: Convert Split tool to python Thread-Index: AQHW7gJc9X2rnR4jwUiIOoSoDXJa46ouM/fg Date: Tue, 19 Jan 2021 02:08:45 +0000 Message-ID: References: <20210119012747.1343-1-bob.c.feng@intel.com> In-Reply-To: <20210119012747.1343-1-bob.c.feng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-reaction: no-action dlp-product: dlpe-windows authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.55.46.39] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2fa447b8-2b20-4133-ea28-08d8bc1f2743 x-ms-traffictypediagnostic: DM6PR11MB4025: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:41; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wOaJRw72kZNKONPp26s3jEmWoVQNUfmTVGpLcpn9PaMdbJxQBxxZyaBB4Va7MyjhBCdWLhBndGgG0NO18BdxUEm220N3bsQLqhGQGYwZx3Hp1DiW47LCHcN3gWm1wOdE6sV7vqTolFgOYWi+doLJ+HjdJSu9EeB57dvthRoukN54Qd49pT2TyN9XAqPzZxQZQZSgmqzT0Zq6S/phIeJsxT/cEW/RUAgsw0eCsjfvUvkLgQ6UHWX3XkV4p4yDwLuhkQbtfVBteSLIuUTUOYDXQ51O3IOAreuqLolsML3PVXqeV0cXtDKISMjqpJwibWCy6MXky8LxqrfVEdc1WAPk0zOq5CQjkjR9gk34l6eKs0k5mOp1xT6peyekyNuOda51LZgwVfPFNoqz7jQGK+oGuGBKZW5+1+XzI8eRg7j2xrhrlpEmUwXz5YLnq4viX09A1sgpnK+WS7OeF4g4ksmvKQsoyWfqRhpmbiLbCOB6U7+rpQxxEgDRFdwcILTOIb3ExDAXENX9P8/F9/JSOkGpSw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR11MB1594.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(366004)(136003)(346002)(376002)(26005)(30864003)(33656002)(478600001)(5660300002)(186003)(7696005)(66476007)(4326008)(19627235002)(316002)(71200400001)(2906002)(110136005)(66556008)(55016002)(83380400001)(9686003)(86362001)(8676002)(53546011)(76116006)(66446008)(64756008)(6506007)(8936002)(66946007)(52536014)(966005)(559001)(579004)(14943795004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?MNWPOUwlDtLGdqbi6yPSjxRHklzn9Dyz8LXGdceVOskbbZJfy2l2ueOrAXVb?= =?us-ascii?Q?cbQDy4mWoFbddc4eGMZMuQKy8y7gONqqptGnC6q6k7x3btC8T4SvL6gpaMdM?= =?us-ascii?Q?NsPXMnjJ4pysBchAkEe+XHaypNSvyCRJRDDAAdhQfcOHx9b2MN8l5CvG2ChI?= =?us-ascii?Q?8c5V2zTrYiLdK0RLOL0FcComrhGODrwD/8VNQQmCF7Gn/2D6ghWyV8lVSGcg?= =?us-ascii?Q?6wnkoU3hscE/nvLI8wUSR1P5XTbDHVq8jel96YDmPgMP6a1HrkF7UuAFjjso?= =?us-ascii?Q?diEkrWydyNYQ6xbYJKFiVW2VSIO73WIAnOtVP+4e9I5vzysnvespKUt3Gk1m?= =?us-ascii?Q?LThQYP/1wbW1x/HTNVzRMTgOleJqMl77BweR9OQ5kMEFZA6hLWR9nAIewBIi?= =?us-ascii?Q?DN9nAdN9wC6qkt98KASIWHXE6DSSr7GKTBtZoO3aXa+H5xJLRhUCX0KF4QcV?= =?us-ascii?Q?IuXMm94qIoqznYfWklNI7x3JSNIcqbj9Qyx06AA4uQ63Dpt8hJ0zZzv2qLTW?= =?us-ascii?Q?KWA/PjCEBhheoXxEr+pVRBfz710MkI3cLEnPXiO0jH56NYQVTZryIFUHNoPT?= =?us-ascii?Q?lttdLfLoQTnPx8TpQ5mQyquEosm4qggSfQRfJUyxIVFzvqR+Epz+XdbAD3R2?= =?us-ascii?Q?QIuxxa52sgph6oCoV4ARzfipWItEOFIwqHOKCz1HZxh+3o2lplD+OjAZRTMT?= =?us-ascii?Q?uyL0+qEXUZd3TqRKak+awsadnyykcRnBu5KS+xpuOBql9UpuvBDzNziAsUJv?= =?us-ascii?Q?UlTen7eoMf6OPmcg+utoT/nSgDf0O3zNSmgpMVEc9gshiSk6o1+TcdxD+gCh?= =?us-ascii?Q?R2Zrd4P9YUhEkaA3NEYO1+gpQQC9e9qbtY/8mA0Nltho4gybzhZ4HrcdBkKi?= =?us-ascii?Q?pamBO7RdGvMJ9hLbbN2c01gacRmVmyLP39QsO3VOYPlcB+1rPszNQJ8/M+tv?= =?us-ascii?Q?VzN2wN0Ysu0Caew/OFBDjVQ4fI+b9T1/priikHM/qj0=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM5PR11MB1594.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fa447b8-2b20-4133-ea28-08d8bc1f2743 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jan 2021 02:08:45.9616 (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: U2O7FMsB00AXQDLIcIVXBoWZ+CJ4yoiMmvVTH3FXh1H9uc7RoXV3tR6wpYoejk56PlcJSxs4254n5nLGerVC6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4025 Return-Path: yuwei.chen@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yuwei Chen > -----Original Message----- > From: Feng, Bob C > Sent: Tuesday, January 19, 2021 9:28 AM > To: devel@edk2.groups.io > Cc: Liming Gao ; Chen, Christine > > Subject: [Patch 1/2 V4] BaseTools: Convert Split tool to python >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3165 >=20 > There are 2 reasons to convert Split tool from C to Python. > 1. We are in the process of moving the Basetools Python code to a separat= e > repository. But there still are many C tools under edk2/BaseTools. To mak= e all > Basetools be in the separate repo, we can convert the C tools to Python t= ools. > 2. The original Split tool is very slow. This python tool can reduce 90% = time. >=20 > Signed-off-by: Bob Feng > Cc: Liming Gao > Cc: Yuwei Chen > --- > V3: No change for this patch. > V4: Update the version to 2.0 > BaseTools/Source/C/Split/Split.c | 466 -------------------- > BaseTools/BinWrappers/PosixLike/Split | 31 +- > BaseTools/BinWrappers/WindowsLike/Split.bat | 3 + > BaseTools/Source/C/GNUmakefile | 1 - > BaseTools/Source/C/Makefile | 1 - > BaseTools/Source/C/Split/GNUmakefile | 17 - > BaseTools/Source/C/Split/Makefile | 16 - > BaseTools/Source/Python/Split/Split.py | 202 +++++++++ > BaseTools/Source/Python/Split/__init__.py | 10 + > 9 files changed, 223 insertions(+), 524 deletions(-) delete mode 100644 > BaseTools/Source/C/Split/Split.c create mode 100644 > BaseTools/BinWrappers/WindowsLike/Split.bat > delete mode 100644 BaseTools/Source/C/Split/GNUmakefile > delete mode 100644 BaseTools/Source/C/Split/Makefile create mode > 100644 BaseTools/Source/Python/Split/Split.py > create mode 100644 BaseTools/Source/Python/Split/__init__.py >=20 > diff --git a/BaseTools/Source/C/Split/Split.c > b/BaseTools/Source/C/Split/Split.c > deleted file mode 100644 > index be0ee124bfe0..000000000000 > --- a/BaseTools/Source/C/Split/Split.c > +++ /dev/null > @@ -1,466 +0,0 @@ > -/** @file > - > - Split a file into two pieces at the request offset. > - > -Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.
> -SPDX-License-Identifier: BSD-2-Clause-Patent > - > -**/ > - > -// GC_TODO: fix comment to start with /*++ -#include -#include > -#include -#ifdef __GNUC__ -#include - > #else -#include -#endif -#include -#include "ParseIn= f.h" > -#include "CommonLib.h" > -#include "EfiUtilityMsgs.h" > -// > -// Utility Name > -// > -#define UTILITY_NAME "Split" > - > -// > -// Utility version information > -// > -#define UTILITY_MAJOR_VERSION 1 > -#define UTILITY_MINOR_VERSION 0 > - > -void > -Version ( > - void > - ) > -/*++ > - > -Routine Description: > - > - Displays the standard utility information to SDTOUT > - > -Arguments: > - > - None > - > -Returns: > - > - None > - > ---*/ > -{ > - printf ("%s Version %d.%d Build %s\n", UTILITY_NAME, > UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION); -} > - > -void > -Usage ( > - void > - ) > -/*++ > - > -Routine Description: > - > - GC_TODO: Add function description > - > -Arguments: > - > - > -Returns: > - > - GC_TODO: add return values > - > ---*/ > -{ > - Version(); > - printf ("Copyright (c) 1999-2017 Intel Corporation. All rights reserve= d.\n"); > - printf ("\n SplitFile creates two Binary files either in the same dir= ectory as > the current working\n"); > - printf (" directory or in the specified directory.\n"); > - printf ("\nUsage: \n\ > - Split\n\ > - -f, --filename inputFile to split\n\ > - -s, --split VALUE the number of bytes in the first file\n\ > - [-p, --prefix OutputDir]\n\ > - [-o, --firstfile Filename1]\n\ > - [-t, --secondfile Filename2]\n\ > - [-v, --verbose]\n\ > - [--version]\n\ > - [-q, --quiet disable all messages except fatal errors]\n\ > - [-d, --debug[#]\n\ > - [-h, --help]\n"); > -} > - > -EFI_STATUS > -GetSplitValue ( > - IN CONST CHAR8* SplitValueString, > - OUT UINT64 *ReturnValue > -) > -{ > - UINT64 len =3D 0; > - UINT64 base =3D 1; > - UINT64 index =3D 0; > - UINT64 number =3D 0; > - CHAR8 lastCHAR =3D 0; > - EFI_STATUS Status =3D EFI_SUCCESS; > - > - if (SplitValueString !=3D NULL){ > - len =3D strlen(SplitValueString); > - } > - > - if (len =3D=3D 0) { > - return EFI_ABORTED; > - } > - > - Status =3D AsciiStringToUint64 (SplitValueString, FALSE, ReturnValue); > - if (!EFI_ERROR (Status)) { > - return Status; > - } > - > - if (SplitValueString[0] =3D=3D '0' && (SplitValueString[1] =3D=3D 'x' = || > SplitValueString[1] =3D=3D 'X')) { > - Status =3D AsciiStringToUint64 (SplitValueString, TRUE, ReturnValue)= ; > - if (!EFI_ERROR (Status)) { > - return Status; > - } > - } > - > - lastCHAR =3D (CHAR8)toupper((int)SplitValueString[len - 1]); > - > - if (lastCHAR !=3D 'K' && lastCHAR !=3D 'M' && lastCHAR !=3D 'G') { > - return STATUS_ERROR; > - } > - > - for (;index < len - 1; ++index) { > - if (!isdigit((int)SplitValueString[index])) { > - return EFI_ABORTED; > - } > - } > - > - number =3D atol (SplitValueString); > - if (lastCHAR =3D=3D 'K') > - base =3D 1024; > - else if (lastCHAR =3D=3D 'M') > - base =3D 1024*1024; > - else > - base =3D 1024*1024*1024; > - > - *ReturnValue =3D number*base; > - > - return EFI_SUCCESS; > -} > - > -EFI_STATUS > -CountVerboseLevel ( > - IN CONST CHAR8* VerboseLevelString, > - IN CONST UINT64 Length, > - OUT UINT64 *ReturnValue > -) > -{ > - UINT64 i =3D 0; > - for (;i < Length; ++i) { > - if (VerboseLevelString[i] !=3D 'v' && VerboseLevelString[i] !=3D 'V'= ) { > - return EFI_ABORTED; > - } > - ++(*ReturnValue); > - } > - > - return EFI_SUCCESS; > -} > - > -EFI_STATUS > -CreateDir ( > - IN OUT CHAR8** FullFileName > -) > -{ > - CHAR8* temp =3D *FullFileName; > - CHAR8* start =3D temp; > - CHAR8 tempchar; > - UINT64 index =3D 0; > - > - for (;index < strlen(temp); ++index) { > - if (temp[index] =3D=3D '\\' || temp[index] =3D=3D '/') { > - if (temp[index + 1] !=3D '\0') { > - tempchar =3D temp[index + 1]; > - temp[index + 1] =3D 0; > - if (chdir(start)) { > - if (mkdir(start, S_IRWXU | S_IRWXG | S_IRWXO) !=3D 0) { > - return EFI_ABORTED; > - } > - chdir(start); > - } > - start =3D temp + index + 1; > - temp[index] =3D '/'; > - temp[index + 1] =3D tempchar; > - } > - } > - } > - > - return EFI_SUCCESS; > -} > - > -int > -main ( > - int argc, > - char*argv[] > - ) > -/*++ > - > -Routine Description: > - > - GC_TODO: Add function description > - > -Arguments: > - > - argc - GC_TODO: add argument description > - ] - GC_TODO: add argument description > - > -Returns: > - > - GC_TODO: add return values > - > ---*/ > -{ > - EFI_STATUS Status =3D EFI_SUCCESS; > - INTN ReturnStatus =3D STATUS_SUCCESS; > - FILE *In; > - CHAR8 *InputFileName =3D NULL; > - CHAR8 *OutputDir =3D NULL; > - CHAR8 *OutFileName1 =3D NULL; > - CHAR8 *OutFileName2 =3D NULL; > - UINT64 SplitValue =3D (UINT64) -1; > - FILE *Out1 =3D NULL; > - FILE *Out2 =3D NULL; > - CHAR8 *OutName1 =3D NULL; > - CHAR8 *OutName2 =3D NULL; > - CHAR8 *CurrentDir =3D NULL; > - UINT64 Index; > - CHAR8 CharC; > - UINT64 DebugLevel =3D 0; > - UINT64 VerboseLevel =3D 0; > - > - SetUtilityName(UTILITY_NAME); > - if (argc =3D=3D 1) { > - Usage(); > - return STATUS_ERROR; > - } > - > - argc --; > - argv ++; > - > - if ((stricmp (argv[0], "-h") =3D=3D 0) || (stricmp (argv[0], "--help")= =3D=3D 0)) { > - Usage(); > - return STATUS_SUCCESS; > - } > - > - if (stricmp (argv[0], "--version") =3D=3D 0) { > - Version(); > - return STATUS_SUCCESS; > - } > - > - while (argc > 0) { > - if ((stricmp (argv[0], "-p") =3D=3D 0) || (stricmp (argv[0], "--pref= ix") =3D=3D 0)) { > - OutputDir =3D argv[1]; > - if (OutputDir =3D=3D NULL) { > - Warning (NULL, 0, 0, "NO output directory specified.", NULL); > - return STATUS_ERROR; > - } > - argc -=3D 2; > - argv +=3D 2; > - continue; > - } > - > - if ((stricmp (argv[0], "-f") =3D=3D 0) || (stricmp (argv[0], "--file= name") =3D=3D 0)) { > - InputFileName =3D argv[1]; > - if (InputFileName =3D=3D NULL) { > - Error (NULL, 0, 0x1001, "NO Input file specified.", NULL); > - return STATUS_ERROR; > - } > - argc -=3D 2; > - argv +=3D 2; > - continue; > - } > - > - if ((stricmp (argv[0], "-s") =3D=3D 0) || (stricmp (argv[0], "--spli= t") =3D=3D 0)) { > - Status =3D GetSplitValue(argv[1], &SplitValue); > - if (EFI_ERROR (Status)) { > - Error (NULL, 0, 0x1003, "Input split value is not one valid inte= ger.", NULL); > - return STATUS_ERROR; > - } > - argc -=3D 2; > - argv +=3D 2; > - continue; > - } > - > - if ((stricmp (argv[0], "-o") =3D=3D 0) || (stricmp (argv[0], "--firs= tfile") =3D=3D 0)) { > - OutFileName1 =3D argv[1]; > - if (OutFileName1 =3D=3D NULL) { > - Warning (NULL, 0, 0, NULL, "No output file1 specified."); > - } > - argc -=3D 2; > - argv +=3D 2; > - continue; > - } > - > - if ((stricmp (argv[0], "-t") =3D=3D 0) || (stricmp (argv[0], "--seco= ndfile") =3D=3D 0)) { > - OutFileName2 =3D argv[1]; > - if (OutFileName2 =3D=3D NULL) { > - Warning (NULL, 0, 0, NULL, "No output file2 specified."); > - } > - argc -=3D 2; > - argv +=3D 2; > - continue; > - } > - > - if ((stricmp (argv[0], "-q") =3D=3D 0) || (stricmp (argv[0], "--quie= t") =3D=3D 0)) { > - argc --; > - argv ++; > - continue; > - } > - > - if ((strlen(argv[0]) >=3D 2 && argv[0][0] =3D=3D '-' && (argv[0][1] = =3D=3D 'v' || > argv[0][1] =3D=3D 'V')) || (stricmp (argv[0], "--verbose") =3D=3D 0)) { > - VerboseLevel =3D 1; > - if (strlen(argv[0]) > 2) { > - Status =3D CountVerboseLevel (&argv[0][2], strlen(argv[0]) - 2, > &VerboseLevel); > - if (EFI_ERROR (Status)) { > - Error (NULL, 0, 0x1003, NULL, "%s is invalid parameter!", argv= [0]); > - return STATUS_ERROR; > - } > - } > - > - argc --; > - argv ++; > - continue; > - } > - > - if ((stricmp (argv[0], "-d") =3D=3D 0) || (stricmp (argv[0], "--debu= g") =3D=3D 0)) { > - Status =3D AsciiStringToUint64 (argv[1], FALSE, &DebugLevel); > - if (EFI_ERROR (Status)) { > - Error (NULL, 0, 0x1003, "Input debug level is not one valid inte= grator.", > NULL); > - return STATUS_ERROR; > - } > - argc -=3D 2; > - argv +=3D 2; > - continue; > - } > - // > - // Don't recognize the parameter. > - // > - Error (NULL, 0, 0x1003, NULL, "%s is invalid parameter!", argv[0]); > - return STATUS_ERROR; > - } > - > - if (InputFileName =3D=3D NULL) { > - Error (NULL, 0, 0x1001, "NO Input file specified.", NULL); > - return STATUS_ERROR; > - } > - > - In =3D fopen (LongFilePath (InputFileName), "rb"); > - if (In =3D=3D NULL) { > - // ("Unable to open file \"%s\"\n", InputFileName); > - Error (InputFileName, 0, 1, "File open failure", NULL); > - return STATUS_ERROR; > - } > - > - if (OutFileName1 =3D=3D NULL) { > - OutName1 =3D (CHAR8*)malloc(strlen(InputFileName) + 16); > - if (OutName1 =3D=3D NULL) { > - Warning (NULL, 0, 0, NULL, "Memory Allocation Fail."); > - ReturnStatus =3D STATUS_ERROR; > - goto Finish; > - } > - strcpy (OutName1, InputFileName); > - strcat (OutName1, "1"); > - OutFileName1 =3D OutName1; > - > - } > - if (OutFileName2 =3D=3D NULL) { > - OutName2 =3D (CHAR8*)malloc(strlen(InputFileName) + 16); > - if (OutName2 =3D=3D NULL) { > - Warning (NULL, 0, 0, NULL, "Memory Allocation Fail."); > - ReturnStatus =3D STATUS_ERROR; > - goto Finish; > - } > - strcpy (OutName2, InputFileName); > - strcat (OutName2, "2"); > - OutFileName2 =3D OutName2; > - > - } > - > - if (OutputDir !=3D NULL) { > - //OutputDirSpecified =3D TRUE; > - if (chdir(OutputDir) !=3D 0) { > - Warning (NULL, 0, 0, NULL, "Change dir to OutputDir Fail."); > - ReturnStatus =3D STATUS_ERROR; > - goto Finish; > - } > - } > - > - CurrentDir =3D (CHAR8*)getcwd((CHAR8*)0, 0); > - if (EFI_ERROR(CreateDir(&OutFileName1))) { > - Error (OutFileName1, 0, 5, "Create Dir for File1 Fail.", NULL); > - ReturnStatus =3D STATUS_ERROR; > - goto Finish; > - } > - chdir(CurrentDir); > - > - if (EFI_ERROR(CreateDir(&OutFileName2))) { > - Error (OutFileName2, 0, 5, "Create Dir for File2 Fail.", NULL); > - ReturnStatus =3D STATUS_ERROR; > - goto Finish; > - } > - chdir(CurrentDir); > - free(CurrentDir); > - > - Out1 =3D fopen (LongFilePath (OutFileName1), "wb"); > - if (Out1 =3D=3D NULL) { > - // ("Unable to open file \"%s\"\n", OutFileName1); > - Error (OutFileName1, 0, 1, "File open failure", NULL); > - ReturnStatus =3D STATUS_ERROR; > - goto Finish; > - } > - > - Out2 =3D fopen (LongFilePath (OutFileName2), "wb"); > - if (Out2 =3D=3D NULL) { > - // ("Unable to open file \"%s\"\n", OutFileName2); > - Error (OutFileName2, 0, 1, "File open failure", NULL); > - ReturnStatus =3D STATUS_ERROR; > - goto Finish; > - } > - > - for (Index =3D 0; Index < SplitValue; Index++) { > - CharC =3D (CHAR8) fgetc (In); > - if (feof (In)) { > - break; > - } > - > - fputc (CharC, Out1); > - } > - > - for (;;) { > - CharC =3D (CHAR8) fgetc (In); > - if (feof (In)) { > - break; > - } > - > - fputc (CharC, Out2); > - } > - > -Finish: > - if (OutName1 !=3D NULL) { > - free(OutName1); > - } > - if (OutName2 !=3D NULL) { > - free(OutName2); > - } > - if (In !=3D NULL) { > - fclose (In); > - } > - if (Out1 !=3D NULL) { > - fclose (Out1); > - } > - if (Out2 !=3D NULL) { > - fclose (Out2); > - } > - > - return ReturnStatus; > -} > diff --git a/BaseTools/BinWrappers/PosixLike/Split > b/BaseTools/BinWrappers/PosixLike/Split > index 0945d86d9209..f3770eed42b4 100755 > --- a/BaseTools/BinWrappers/PosixLike/Split > +++ b/BaseTools/BinWrappers/PosixLike/Split > @@ -1,29 +1,14 @@ > #!/usr/bin/env bash > +#python `dirname $0`/RunToolFromSource.py `basename $0` $* > + > +# If a ${PYTHON_COMMAND} command is available, use it in preference to > +python if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then > + python_exe=3D${PYTHON_COMMAND} > +fi >=20 > full_cmd=3D${BASH_SOURCE:-$0} # see > http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not = a > good choice here dir=3D$(dirname "$full_cmd") cmd=3D${full_cmd##*/} >=20 > -if [ -n "$WORKSPACE" ] && [ -e "$WORKSPACE/Conf/BaseToolsCBinaries" ] - > then > - exec "$WORKSPACE/Conf/BaseToolsCBinaries/$cmd" > -elif [ -n "$WORKSPACE" ] && [ -e "$EDK_TOOLS_PATH/Source/C" ] -then > - if [ ! -e "$EDK_TOOLS_PATH/Source/C/bin/$cmd" ] > - then > - echo "BaseTools C Tool binary was not found ($cmd)" > - echo "You may need to run:" > - echo " make -C $EDK_TOOLS_PATH/Source/C" > - else > - exec "$EDK_TOOLS_PATH/Source/C/bin/$cmd" "$@" > - fi > -elif [ -e "$dir/../../Source/C/bin/$cmd" ] -then > - exec "$dir/../../Source/C/bin/$cmd" "$@" > -else > - echo "Unable to find the real '$cmd' to run" > - echo "This message was printed by" > - echo " $0" > - exit 127 > -fi > - > +export > PYTHONPATH=3D"$dir/../../Source/Python${PYTHONPATH:+:"$PYTHONPATH"} > " > +exec "${python_exe:-python}" "$dir/../../Source/Python/$cmd/$cmd.py" > "$@" > diff --git a/BaseTools/BinWrappers/WindowsLike/Split.bat > b/BaseTools/BinWrappers/WindowsLike/Split.bat > new file mode 100644 > index 000000000000..9616cd893bec > --- /dev/null > +++ b/BaseTools/BinWrappers/WindowsLike/Split.bat > @@ -0,0 +1,3 @@ > +@setlocal > +@set ToolName=3D%~n0% > +@%PYTHON_COMMAND% > +%BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py % > * > diff --git a/BaseTools/Source/C/GNUmakefile > b/BaseTools/Source/C/GNUmakefile index 464f43277455..8c191e0c3817 > 100644 > --- a/BaseTools/Source/C/GNUmakefile > +++ b/BaseTools/Source/C/GNUmakefile > @@ -55,11 +55,10 @@ APPLICATIONS =3D \ > GenFv \ > GenFw \ > GenSec \ > GenCrc32 \ > LzmaCompress \ > - Split \ > TianoCompress \ > VolInfo \ > DevicePath >=20 > SUBDIRS :=3D $(LIBRARIES) $(APPLICATIONS) diff --git > a/BaseTools/Source/C/Makefile b/BaseTools/Source/C/Makefile index > e8f8abe59a79..a376d32e220e 100644 > --- a/BaseTools/Source/C/Makefile > +++ b/BaseTools/Source/C/Makefile > @@ -17,11 +17,10 @@ APPLICATIONS =3D \ > GenFfs \ > GenFv \ > GenFw \ > GenSec \ > LzmaCompress \ > - Split \ > TianoCompress \ > VolInfo \ > DevicePath >=20 > all: libs apps install > diff --git a/BaseTools/Source/C/Split/GNUmakefile > b/BaseTools/Source/C/Split/GNUmakefile > deleted file mode 100644 > index b3d4dff51ac1..000000000000 > --- a/BaseTools/Source/C/Split/GNUmakefile > +++ /dev/null > @@ -1,17 +0,0 @@ > -## @file > -# GNU/Linux makefile for 'Split' module build. > -# > -# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
= -# > SPDX-License-Identifier: BSD-2-Clause-Patent -# -MAKEROOT ?=3D .. > - > -APPNAME =3D Split > - > -OBJECTS =3D Split.o > - > -include $(MAKEROOT)/Makefiles/app.makefile > - > -LIBS =3D -lCommon > - > - > diff --git a/BaseTools/Source/C/Split/Makefile > b/BaseTools/Source/C/Split/Makefile > deleted file mode 100644 > index 19d3e31a7624..000000000000 > --- a/BaseTools/Source/C/Split/Makefile > +++ /dev/null > @@ -1,16 +0,0 @@ > -## @file > -# Windows makefile for 'Split' module build. > -# > -# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
= -# > SPDX-License-Identifier: BSD-2-Clause-Patent -# - > !INCLUDE ..\Makefiles\ms.common > - > -APPNAME =3D Split > - > -LIBS =3D $(LIB_PATH)\Common.lib > - > -OBJECTS =3D Split.obj > - > -!INCLUDE ..\Makefiles\ms.app > - > diff --git a/BaseTools/Source/Python/Split/Split.py > b/BaseTools/Source/Python/Split/Split.py > new file mode 100644 > index 000000000000..c39f8a7adc61 > --- /dev/null > +++ b/BaseTools/Source/Python/Split/Split.py > @@ -0,0 +1,202 @@ > +# @file > +# Split a file into two pieces at the request offset. > +# > +# Copyright (c) 2021, Intel Corporation. All rights reserved.
# # > +SPDX-License-Identifier: BSD-2-Clause-Patent # ## > + > +# Import Modules > +# > +import argparse > +import os > +import io > +import shutil > +import logging > +import sys > +import tempfile > + > +parser =3D argparse.ArgumentParser(description=3D''' > +SplitFile creates two Binary files either in the same directory as the c= urrent > working directory or in the specified directory. > +''') > +parser.add_argument("-f", "--filename", dest=3D"inputfile", > + required=3DTrue, help=3D"The input file to split > +tool.") parser.add_argument("-s", "--split", dest=3D"position", > + required=3DTrue, help=3D"The number of bytes in the > +first file. The valid format are HEX, Decimal and Decimal[KMG].") > parser.add_argument("-p", "--prefix", dest=3D"output", > + help=3D"The output folder.") > +parser.add_argument("-o", "--firstfile", help=3D"The first file name") > +parser.add_argument("-t", "--secondfile", help=3D"The second file name"= ) > +parser.add_argument("--version", action=3D"version", version=3D'%(prog)s > Version 2.0', > + help=3D"Print debug information.") > + > +group =3D parser.add_mutually_exclusive_group() > +group.add_argument("-v", "--verbose", action=3D"store_true", > + help=3D"Print debug information.") > +group.add_argument("-q", "--quiet", action=3D"store_true", > + help=3D"Disable all messages except fatal errors") > + > +SizeDict =3D { > + "K": 1024, > + "M": 1024*1024, > + "G": 1024*1024*1024 > +} > + > + > +def GetPositionValue(position): > + ''' > + Parse the string of the argument position and return a decimal numbe= r. > + The valid position formats are > + 1. HEX > + e.g. 0x1000 or 0X1000 > + 2. Decimal > + e.g. 100 > + 3. Decimal[KMG] > + e.g. 100K or 100M or 100G or 100k or 100m or 100g > + ''' > + logger =3D logging.getLogger('Split') > + PosVal =3D 0 > + header =3D position[:2].upper() > + tailer =3D position[-1].upper() > + > + try: > + if tailer in SizeDict: > + PosVal =3D int(position[:-1]) * SizeDict[tailer] > + else: > + if header =3D=3D "0X": > + PosVal =3D int(position, 16) > + else: > + PosVal =3D int(position) > + except Exception as e: > + logger.error( > + "The parameter %s format is incorrect. The valid format is H= EX, > Decimal and Decimal[KMG]." % position) > + raise(e) > + > + return PosVal > + > + > +def getFileSize(filename): > + ''' > + Read the input file and return the file size. > + ''' > + logger =3D logging.getLogger('Split') > + length =3D 0 > + try: > + with open(filename, "rb") as fin: > + fin.seek(0, io.SEEK_END) > + length =3D fin.tell() > + except Exception as e: > + logger.error("Access file failed: %s", filename) > + raise(e) > + > + return length > + > + > +def splitFile(inputfile, position, outputdir=3DNone, outputfile1=3DNone, > outputfile2=3DNone): > + ''' > + Split the inputfile into outputfile1 and outputfile2 from the positi= on. > + ''' > + logger =3D logging.getLogger('Split') > + > + inputfile =3D os.path.abspath(inputfile) > + workspace =3D os.path.dirname(inputfile) > + if not os.path.exists(inputfile): > + logger.error("File Not Found: %s" % inputfile) > + raise(Exception) > + > + if outputfile1 and outputfile2 and outputfile1 =3D=3D outputfile2: > + logger.error( > + "The firstfile and the secondfile can't be the same: %s" % o= utputfile1) > + raise(Exception) > + > + if not outputdir: > + outputdir =3D workspace > + elif not os.path.isabs(outputdir): > + outputdir =3D os.path.join(workspace, outputdir) > + > + # Create dir for the output files > + try: > + if not outputfile1: > + outputfile1 =3D os.path.abspath(os.path.join( > + outputdir, "{}1".format(os.path.basename(inputfile)))) > + else: > + outputfile1 =3D os.path.abspath(os.path.join(outputdir, outp= utfile1)) > + outputdir =3D os.path.dirname(outputfile1) > + if not os.path.exists(outputdir): > + os.makedirs(outputdir) > + > + if not outputfile2: > + outputfile2 =3D os.path.abspath(os.path.join( > + outputdir, "{}2".format(os.path.basename(inputfile)))) > + else: > + outputfile2 =3D os.path.abspath(os.path.join(outputdir, outp= utfile2)) > + outputdir =3D os.path.dirname(outputfile2) > + if not os.path.exists(outputdir): > + os.makedirs(outputdir) > + except Exception as e: > + logger.error("Can't make dir: %s" % outputdir) > + raise(e) > + > + if position <=3D 0: > + if outputfile2 !=3D inputfile: > + shutil.copy2(inputfile, outputfile2) > + with open(outputfile1, "wb") as fout: > + fout.write(b'') > + else: > + inputfilesize =3D getFileSize(inputfile) > + if position >=3D inputfilesize: > + if outputfile1 !=3D inputfile: > + shutil.copy2(inputfile, outputfile1) > + with open(outputfile2, "wb") as fout: > + fout.write(b'') > + else: > + try: > + tempdir =3D tempfile.mkdtemp() > + tempfile1 =3D os.path.join(tempdir, "file1.bin") > + tempfile2 =3D os.path.join(tempdir, "file2.bin") > + with open(inputfile, "rb") as fin: > + content1 =3D fin.read(position) > + with open(tempfile1, "wb") as fout1: > + fout1.write(content1) > + > + content2 =3D fin.read(inputfilesize - position) > + with open(tempfile2, "wb") as fout2: > + fout2.write(content2) > + shutil.copy2(tempfile1, outputfile1) > + shutil.copy2(tempfile2, outputfile2) > + except Exception as e: > + logger.error("Split file failed") > + raise(e) > + finally: > + if os.path.exists(tempdir): > + shutil.rmtree(tempdir) > + > + > +def main(): > + args =3D parser.parse_args() > + status =3D 0 > + > + logger =3D logging.getLogger('Split') > + if args.quiet: > + logger.setLevel(logging.CRITICAL) > + if args.verbose: > + logger.setLevel(logging.DEBUG) > + > + lh =3D logging.StreamHandler(sys.stdout) > + lf =3D logging.Formatter("%(levelname)-8s: %(message)s") > + lh.setFormatter(lf) > + logger.addHandler(lh) > + > + try: > + position =3D GetPositionValue(args.position) > + splitFile(args.inputfile, position, args.output, > + args.firstfile, args.secondfile) > + except Exception as e: > + status =3D 1 > + > + return status > + > + > +if __name__ =3D=3D "__main__": > + exit(main()) > diff --git a/BaseTools/Source/Python/Split/__init__.py > b/BaseTools/Source/Python/Split/__init__.py > new file mode 100644 > index 000000000000..8f4daf86e84a > --- /dev/null > +++ b/BaseTools/Source/Python/Split/__init__.py > @@ -0,0 +1,10 @@ > +# @file > +# Split a file into two pieces at the request offset. > +# > +# Copyright (c) 2021, Intel Corporation. All rights reserved.
# # > +SPDX-License-Identifier: BSD-2-Clause-Patent # ## > + > +# Import Modules > -- > 2.29.1.windows.1