public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Eric Jin" <eric.jin@intel.com>
To: devel@edk2.groups.io
Cc: Sean Brogan <sean.brogan@microsoft.com>,
	Bret Barkelew <Bret.Barkelew@microsoft.com>,
	Bob Feng <bob.c.feng@intel.com>,
	Liming Gao <liming.gao@intel.com>,
	Kinney Michael D <michael.d.kinney@intel.com>
Subject: [PATCH 2/2] BaseTools/Capsule: Tool to generate Windows Firmware Update Driver
Date: Wed,  7 Aug 2019 17:09:07 +0800	[thread overview]
Message-ID: <20190807090907.19284-1-eric.jin@intel.com> (raw)

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>
---
 .../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.<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
+                                                   )
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.<BR>
 # 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


                 reply	other threads:[~2019-08-07  9:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190807090907.19284-1-eric.jin@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox