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>
This commit is contained in:
Jin, Eric 2019-08-12 15:45:12 +08:00 committed by Feng, Bob C
parent e2aacac580
commit 48d8d4d80b
2 changed files with 129 additions and 7 deletions

View File

@ -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
)

View File

@ -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__)