Re: [edk2-devel] [PATCH v3 1/1] BaseTools/Capsule: Tool to Generate Windows Firmware Update Driver

2019-06-12 Thread Liming Gao
Eric:
  Can you help post link for Windows Firmware Update Drivers?

Thanks
Liming
>-Original Message-
>From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Eric
>Jin
>Sent: Tuesday, June 11, 2019 2:23 PM
>To: devel@edk2.groups.io
>Cc: Feng, Bob C ; Gao, Liming
>; Kinney, Michael D 
>Subject: [edk2-devel] [PATCH v3 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| 159
>+++
>+++
>+
> BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py   | 114
>+++
>+++
> BaseTools/Source/Python/Capsule/InfGenerator.py| 210
>+++
>+++
>+++
>+
> BaseTools/Source/Python/Capsule/WindowsCapsuleSupportHelper.py | 102
>+++
>+++
> 4 files changed, 585 insertions(+)
>
>diff --git a/BaseTools/Source/Python/Capsule/CatGenerator.py
>b/BaseTools/Source/Python/Capsule/CatGenerator.py
>new file mode 100644
>index 00..5f7fefa788
>--- /dev/null
>+++ b/BaseTools/Source/Python/Capsule/CatGenerator.py
>@@ -0,0 +1,159 @@
>+## @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.rst

[edk2-devel] [PATCH v3 1/1] BaseTools/Capsule: Tool to Generate Windows Firmware Update Driver

2019-06-11 Thread Eric Jin
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| 159 
+++
 BaseTools/Source/Python/Capsule/GenerateWindowsDriver.py   | 114 
++
 BaseTools/Source/Python/Capsule/InfGenerator.py| 210 
++
 BaseTools/Source/Python/Capsule/WindowsCapsuleSupportHelper.py | 102 
++
 4 files changed, 585 insertions(+)

diff --git a/BaseTools/Source/Python/Capsule/CatGenerator.py 
b/BaseTools/Source/Python/Capsule/CatGenerator.py
new file mode 100644
index 00..5f7fefa788
--- /dev/null
+++ b/BaseTools/Source/Python/Capsule/CatGenerator.py
@@ -0,0 +1,159 @@
+## @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()
+
+endtime = datetime.datetime.now()
+delta = endtime - starttime
+