From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: eric.jin@intel.com) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by groups.io with SMTP; Mon, 12 Aug 2019 00:45:44 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Aug 2019 00:45:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,376,1559545200"; d="scan'208";a="175809924" Received: from unknown (HELO jjin9-MOBL.ccr.corp.intel.com) ([10.239.192.132]) by fmsmga008.fm.intel.com with ESMTP; 12 Aug 2019 00:45:41 -0700 From: "Eric Jin" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Bob Feng , Liming Gao , Kinney Michael D Subject: [PATCH V2 2/2] BaseTools/Capsule: Tool to generate Windows Firmware Update Driver Date: Mon, 12 Aug 2019 15:45:12 +0800 Message-Id: <20190812074512.50328-1-eric.jin@intel.com> X-Mailer: git-send-email 2.20.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1837 The tool is designed to generate Windows Firmware Update Drivers, the input is one drivername.cap with related parameters, the output Windows Driver package are composed by drivername.cap, drivername.inf and drivername.cat to update the single payload in device. usage: GenerateWindowsDriver [-h] [--output-folder OUTPUTFOLDER] [--product-fmp-guid PRODUCTFMPGUID] [--capsuleversion-dotstring CAPSULEVERSION_DOTSTRING] [--capsuleversion-hexstring CAPSULEVERSION_HEXSTRING] [--product-fw-provider PRODUCTFWPROVIDER] [--product-fw-mfg-name PRODUCTFWMFGNAME] [--product-fw-desc PRODUCTFWDESC] [--capsule-file-name CAPSULEFILENAME] [--pfx-file PFXFILE] [--arch ARCH] [--operating-system-string OPERATINGSYSTEMSTRING] Cc: Sean Brogan Cc: Bret Barkelew Cc: Bob Feng Cc: Liming Gao Cc: Kinney Michael D Signed-off-by: Eric Jin --- .../Python/Capsule/GenerateWindowsDriver.py | 120 ++++++++++++++++++ .../Capsule/WindowsCapsuleSupportHelper.py | 16 ++- 2 files changed, 129 insertions(+), 7 deletions(-) create mode 100644 BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py diff --git a/BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py b/BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py new file mode 100644 index 0000000000..bea7a0df38 --- /dev/null +++ b/BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py @@ -0,0 +1,120 @@ +## @file +# Generate a capsule windows driver. +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' +GenerateWindowsDriver +''' + +import sys +import argparse +import uuid +import struct +import subprocess +import os +import tempfile +import shutil +import platform +import re +import logging +from WindowsCapsuleSupportHelper import WindowsCapsuleSupportHelper +from Common.Uefi.Capsule.FmpCapsuleHeader import FmpCapsuleHeaderClass +from Common.Uefi.Capsule.UefiCapsuleHeader import UefiCapsuleHeaderClass + +# +# Globals for help information +# +__prog__ = 'GenerateWindowsDriver' +__version__ = '0.0' +__copyright__ = 'Copyright (c) 2019, Intel Corporation. All rights reserved.' +__description__ = 'Generate Capsule Windows Driver.\n' + +def GetCapGuid (InputFile): + with open(InputFile, 'rb') as File: + Buffer = File.read() + try: + Result = UefiCapsuleHeader.Decode (Buffer) + if len (Result) > 0: + FmpCapsuleHeader.Decode (Result) + for index in range (0, FmpCapsuleHeader.PayloadItemCount): + Guid = FmpCapsuleHeader.GetFmpCapsuleImageHeader (index).UpdateImageTypeId + return Guid + except: + print ('GenerateCapsule: error: can not decode capsule') + sys.exit (1) + +def ArgCheck(args): + Version = args.CapsuleVersion_DotString.split('.') + + if len(Version) != 4: + logging.critical("Name invalid: '%s'", args.CapsuleVersion_DotString) + raise ValueError("Name invalid.") + for sub in Version: + if int(sub, 16) > 65536: + logging.critical("Name invalid: '%s'", args.CapsuleVersion_DotString) + raise ValueError("Name exceed limit 65536.") + + if not (re.compile(r'[\a-fA-F0-9]*$')).match(args.CapsuleVersion_DotString): + logging.critical("Name invalid: '%s'", args.CapsuleVersion_DotString) + raise ValueError("Name has invalid chars.") + +def CapsuleGuidCheck(InputFile, Guid): + CapGuid = GetCapGuid(InputFile) + if (str(Guid).lower() != str(CapGuid)): + print('GenerateWindowsDriver error: Different Guid from Capsule') + sys.exit(1) + +if __name__ == '__main__': + def convert_arg_line_to_args(arg_line): + for arg in arg_line.split(): + if not arg.strip(): + continue + yield arg + + parser = argparse.ArgumentParser ( + prog = __prog__, + description = __description__ + __copyright__, + conflict_handler = 'resolve', + fromfile_prefix_chars = '@' + ) + parser.convert_arg_line_to_args = convert_arg_line_to_args + parser.add_argument("--output-folder", dest = 'OutputFolder', help = "firmware resource update driver package output folder.") + parser.add_argument("--product-fmp-guid", dest = 'ProductFmpGuid', help = "firmware GUID of resource update driver package") + parser.add_argument("--capsuleversion-dotstring", dest = 'CapsuleVersion_DotString', help = "firmware version with date on which update driver package is authored") + parser.add_argument("--capsuleversion-hexstring", dest = 'CapsuleVersion_HexString', help = "firmware version in Hex of update driver package") + parser.add_argument("--product-fw-provider", dest = 'ProductFwProvider', help = "vendor/provider of entire firmware resource update driver package") + parser.add_argument("--product-fw-mfg-name", dest = 'ProductFwMfgName', help = "manufacturer/vendor of firmware resource update driver package") + parser.add_argument("--product-fw-desc", dest = "ProductFwDesc", help = "description about resource update driver") + parser.add_argument("--capsule-file-name", dest = 'CapsuleFileName', help ="firmware resource image file") + parser.add_argument("--pfx-file", dest = 'PfxFile', help = "pfx file path used to sign resource update driver") + parser.add_argument("--arch", dest = 'Arch', help = "supported architecture:arm/x64/amd64/arm64/aarch64", default = 'amd64') + parser.add_argument("--operating-system-string", dest = 'OperatingSystemString', help = "supported operating system:win10/10/10_au/10_rs2/10_rs3/10_rs4/server10/server2016/serverrs2/serverrs3/serverrs4", default = "win10") + + args = parser.parse_args() + InputFile = os.path.join(args.OutputFolder, '') + args.CapsuleFileName + UefiCapsuleHeader = UefiCapsuleHeaderClass () + FmpCapsuleHeader = FmpCapsuleHeaderClass () + CapsuleGuidCheck(InputFile, args.ProductFmpGuid) + ArgCheck(args) + ProductName = os.path.splitext(args.CapsuleFileName)[0] + WindowsDriver = WindowsCapsuleSupportHelper () + + WindowsDriver.PackageWindowsCapsuleFiles ( + args.OutputFolder, + ProductName, + args.ProductFmpGuid, + args.CapsuleVersion_DotString, + args.CapsuleVersion_HexString, + args.ProductFwProvider, + args.ProductFwMfgName, + args.ProductFwDesc, + args.CapsuleFileName, + args.PfxFile, + None, + None, + args.Arch, + args.OperatingSystemString + ) diff --git a/BaseTools/Source/Python/Capsule/WindowsCapsuleSupportHelper.py b/BaseTools/Source/Python/Capsule/WindowsCapsuleSupportHelper.py index 166af58d81..a29ac21ae8 100644 --- a/BaseTools/Source/Python/Capsule/WindowsCapsuleSupportHelper.py +++ b/BaseTools/Source/Python/Capsule/WindowsCapsuleSupportHelper.py @@ -3,7 +3,11 @@ # Windows Firmware Update Platform spec. # Creates INF, Cat, and then signs it # +# To install run pip install --upgrade edk2-pytool-library +# edk2-pytool-library-0.9.1 is required. +# # Copyright (c) Microsoft Corporation. All rights reserved. +# Copyright (c) 2019, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent ## @@ -12,14 +16,12 @@ import re import datetime import os import logging -from MuEnvironment import PluginManager -from MuPythonLibrary.Uefi.Capsule.CatGenerator import * -from MuPythonLibrary.Uefi.Capsule.InfGenerator import * -from MuPythonLibrary.UtilityFunctions import CatalogSignWithSignTool -from MuPythonLibrary.Windows.VsWhereUtilities import FindToolInWinSdk - +from edk2toollib.windows.capsule.cat_generator import CatGenerator +from edk2toollib.windows.capsule.inf_generator import InfGenerator +from edk2toollib.utility_functions import CatalogSignWithSignTool +from edk2toollib.windows.locate_tools import FindToolInWinSdk -class WindowsCapsuleSupportHelper(PluginManager.IUefiHelperPlugin): +class WindowsCapsuleSupportHelper(object): def RegisterHelpers(self, obj): fp = os.path.abspath(__file__) -- 2.20.1.windows.1