Re: [edk2-devel] [PATCH v2 1/1] BaseTools/Capsule: Tool to Generate Windows Firmware Update Driver
Bob, Thank for the comments. Will be updated in v2. Best Regards Eric -Original Message- From: Feng, Bob C Sent: Tuesday, June 11, 2019 9:37 AM To: Jin, Eric ; devel@edk2.groups.io Cc: Gao, Liming ; Kinney, Michael D Subject: RE: [PATCH v2 1/1] BaseTools/Capsule: Tool to Generate Windows Firmware Update Driver Hi Eric, There are 2 comments on the code. +if(capture): +outr = PropagatingThread(target=reader, args=(outfile, outstream, c.stdout,)) +outr.start() +outr.join() +c.wait() +else: +c.wait() c.wait() in both "if" and "else" block, I think it should be just called once out of the if...else block. +def CapsuleGuidCheck(InputFile, Guid): +TempCapDecode = 'TempCapDecode.txt' +Command = 'python GenerateCapsule.py "' + InputFile + '" --dump-info >' + TempCapDecode +os.system (Command) +with open(TempCapDecode, 'rb') as f: +for line in f: +if re.search(b'UpdateImageTypeId', line, re.M|re.I): +CapGuid = str(line).split('= ')[1][:-5] +break +f.close() +os.remove(TempCapDecode) +if (Guid != CapGuid): +print('GenerateWindowsDriver error: Different Guid from Capsule') +sys.exit(1) f.close() is not necessary and I think the statements after f.close() should be out of the "with" block. Thanks, Bob -Original Message- From: Jin, Eric Sent: Monday, June 3, 2019 11:39 AM To: devel@edk2.groups.io Cc: Feng, Bob C ; Gao, Liming ; Kinney, Michael D Subject: [PATCH v2 1/1] BaseTools/Capsule: Tool to Generate Windows Firmware Update Driver 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: Bob Feng Cc: Liming Gao Cc: Kinney Michael D Signed-off-by: Eric Jin --- BaseTools/Source/Python/Capsule/CatGenerator.py| 161 + BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py | 115 +++ BaseTools/Source/Python/Capsule/InfGenerator.py| 210 ++ BaseTools/Source/Python/Capsule/WindowsCapsuleSupportHelper.py | 102 ++ 4 files changed, 588 insertions(+) diff --git a/BaseTools/Source/Python/Capsule/CatGenerator.py b/BaseTools/Source/Python/Capsule/CatGenerator.py new file mode 100644 index 00..77956d331d --- /dev/null +++ b/BaseTools/Source/Python/Capsule/CatGenerator.py @@ -0,0 +1,161 @@ +## @file + # Script to generate Cat files for capsule update based on supplied +inf file # # Copyright (c) 2019, Microsoft Corporation # Copyright +(c) 2019, Intel Corporation. All rights reserved. # +SPDX-License-Identifier: BSD-2-Clause-Patent # ## + +import os +import logging +import datetime +import subprocess +import threading + +class PropagatingThread(threading.Thread): +def run(self): +self.exc = None +try: +if hasattr(self, '_Thread__target'): +# Thread uses name mangling prior to Python 3. +self.ret = self._Thread__target(*self._Thread__args, **self._Thread__kwargs) +else: +self.ret = self._target(*self._args, **self._kwargs) +except BaseException as e: +self.exc = e +def join(self, timeout=None): +super(PropagatingThread, self).join() +if self.exc: + raise self.exc +return self.ret +def reader(filepath, outstream, stream): +if filepath: +try: +with open(filepath, "w") as
Re: [edk2-devel] [PATCH v2 1/1] BaseTools/Capsule: Tool to Generate Windows Firmware Update Driver
Hi Eric, There are 2 comments on the code. +if(capture): +outr = PropagatingThread(target=reader, args=(outfile, outstream, c.stdout,)) +outr.start() +outr.join() +c.wait() +else: +c.wait() c.wait() in both "if" and "else" block, I think it should be just called once out of the if...else block. +def CapsuleGuidCheck(InputFile, Guid): +TempCapDecode = 'TempCapDecode.txt' +Command = 'python GenerateCapsule.py "' + InputFile + '" --dump-info >' + TempCapDecode +os.system (Command) +with open(TempCapDecode, 'rb') as f: +for line in f: +if re.search(b'UpdateImageTypeId', line, re.M|re.I): +CapGuid = str(line).split('= ')[1][:-5] +break +f.close() +os.remove(TempCapDecode) +if (Guid != CapGuid): +print('GenerateWindowsDriver error: Different Guid from Capsule') +sys.exit(1) f.close() is not necessary and I think the statements after f.close() should be out of the "with" block. Thanks, Bob -Original Message- From: Jin, Eric Sent: Monday, June 3, 2019 11:39 AM To: devel@edk2.groups.io Cc: Feng, Bob C ; Gao, Liming ; Kinney, Michael D Subject: [PATCH v2 1/1] BaseTools/Capsule: Tool to Generate Windows Firmware Update Driver 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: Bob Feng Cc: Liming Gao Cc: Kinney Michael D Signed-off-by: Eric Jin --- BaseTools/Source/Python/Capsule/CatGenerator.py| 161 + BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py | 115 +++ BaseTools/Source/Python/Capsule/InfGenerator.py| 210 ++ BaseTools/Source/Python/Capsule/WindowsCapsuleSupportHelper.py | 102 ++ 4 files changed, 588 insertions(+) diff --git a/BaseTools/Source/Python/Capsule/CatGenerator.py b/BaseTools/Source/Python/Capsule/CatGenerator.py new file mode 100644 index 00..77956d331d --- /dev/null +++ b/BaseTools/Source/Python/Capsule/CatGenerator.py @@ -0,0 +1,161 @@ +## @file + # Script to generate Cat files for capsule update based on supplied +inf file # # Copyright (c) 2019, Microsoft Corporation # Copyright +(c) 2019, Intel Corporation. All rights reserved. # +SPDX-License-Identifier: BSD-2-Clause-Patent # ## + +import os +import logging +import datetime +import subprocess +import threading + +class PropagatingThread(threading.Thread): +def run(self): +self.exc = None +try: +if hasattr(self, '_Thread__target'): +# Thread uses name mangling prior to Python 3. +self.ret = self._Thread__target(*self._Thread__args, **self._Thread__kwargs) +else: +self.ret = self._target(*self._args, **self._kwargs) +except BaseException as e: +self.exc = e +def join(self, timeout=None): +super(PropagatingThread, self).join() +if self.exc: + raise self.exc +return self.ret +def reader(filepath, outstream, stream): +if filepath: +try: +with open(filepath, "w") as f: +print("The file is" + filepath) +except FileNotFoundError: +print("Sorry, the file" + filepath + "does not exist.") + +while True: +s = stream.readline().decode() +if not s: +stream.close() +break +# write to file if caller provideds
[edk2-devel] [PATCH v2 1/1] BaseTools/Capsule: Tool to Generate Windows Firmware Update Driver
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: Bob Feng Cc: Liming Gao Cc: Kinney Michael D Signed-off-by: Eric Jin --- BaseTools/Source/Python/Capsule/CatGenerator.py| 161 + BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py | 115 +++ BaseTools/Source/Python/Capsule/InfGenerator.py| 210 ++ BaseTools/Source/Python/Capsule/WindowsCapsuleSupportHelper.py | 102 ++ 4 files changed, 588 insertions(+) diff --git a/BaseTools/Source/Python/Capsule/CatGenerator.py b/BaseTools/Source/Python/Capsule/CatGenerator.py new file mode 100644 index 00..77956d331d --- /dev/null +++ b/BaseTools/Source/Python/Capsule/CatGenerator.py @@ -0,0 +1,161 @@ +## @file + # Script to generate Cat files for capsule update based on supplied inf file + # + # Copyright (c) 2019, Microsoft Corporation + # Copyright (c) 2019, Intel Corporation. All rights reserved. + # SPDX-License-Identifier: BSD-2-Clause-Patent + # + ## + +import os +import logging +import datetime +import subprocess +import threading + +class PropagatingThread(threading.Thread): +def run(self): +self.exc = None +try: +if hasattr(self, '_Thread__target'): +# Thread uses name mangling prior to Python 3. +self.ret = self._Thread__target(*self._Thread__args, **self._Thread__kwargs) +else: +self.ret = self._target(*self._args, **self._kwargs) +except BaseException as e: +self.exc = e +def join(self, timeout=None): +super(PropagatingThread, self).join() +if self.exc: + raise self.exc +return self.ret +def reader(filepath, outstream, stream): +if filepath: +try: +with open(filepath, "w") as f: +print("The file is" + filepath) +except FileNotFoundError: +print("Sorry, the file" + filepath + "does not exist.") + +while True: +s = stream.readline().decode() +if not s: +stream.close() +break +# write to file if caller provideds file +if filepath: +try: +with open(filepath, "a") as f: +f.write(s) +except FileNotFoundError: +print("Sorry, the file" + filepath + "does not exist.") +if(outstream is not None): +# write to stream object if caller provided object +outstream.write(s) +logging.info(s.rstrip()) + +def RunCmd(cmd, parameters, capture=True, workingdir=None, outfile=None, outstream=None, environ=None): +cmd = cmd.strip('"\'') +if " " in cmd: +cmd = '"' + cmd + '"' +if parameters is not None: +parameters = parameters.strip() +cmd += " " + parameters +starttime = datetime.datetime.now() +logging.info("Cmd to run is: " + cmd) +logging.info("") +logging.info("--Cmd Output Starting---") +logging.info("") +c = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=workingdir, shell=True, env=environ) +if(capture): +outr = PropagatingThread(target=reader, args=(outfile, outstream, c.stdout,)) +outr.start() +outr.join() +c.wait() +else: +c.wait() + +endtime = datetime.datetime.now() +delta = endtime - starttime