summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py
diff options
context:
space:
mode:
authorJin, Eric <eric.jin@intel.com>2019-08-12 15:45:12 +0800
committerFeng, Bob C <bob.c.feng@intel.com>2019-08-15 20:13:55 +0800
commit48d8d4d80bb299af5422312d92b044cb10a2e790 (patch)
tree82d0c0612a5257501a432dda94bbc6a0b8f6c167 /BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py
parente2aacac58055e699f8ac0beaa31c0aa9f72ef17c (diff)
downloadedk2-48d8d4d80bb299af5422312d92b044cb10a2e790.tar.gz
edk2-48d8d4d80bb299af5422312d92b044cb10a2e790.tar.bz2
edk2-48d8d4d80bb299af5422312d92b044cb10a2e790.zip
BaseTools/Capsule: Tool to generate Windows Firmware Update Driver
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 <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Cc: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Kinney Michael D <michael.d.kinney@intel.com> Signed-off-by: Eric Jin <eric.jin@intel.com> Reviewed-by: Bob Feng <bob.c.feng@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py')
-rw-r--r--BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py120
1 files changed, 120 insertions, 0 deletions
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.<BR>
+# 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
+ )