]> sigrok.org Git - sigrok-util.git/blobdiff - firmware/kingst-la/sigrok-fwextract-kingst-la2016
sigrok-fwextract-kingst-la2016: extract more blobs (all of them)
[sigrok-util.git] / firmware / kingst-la / sigrok-fwextract-kingst-la2016
index 4357994207762fadb837fbcf5d9d92ff8dc5f9cb..712bb01f9399c5479a96b2249318a746293bb291 100755 (executable)
 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
 ##
 
+# This utility extracts FX2 MCU firmware and FPGA bitstream images from
+# the "KingstVIS" vendor software. The blobs are kept in Qt resources
+# sections. The script was tested with several v3.5 software versions.
+
+import argparse
 import os
 import sys
 import re
@@ -26,7 +31,7 @@ import codecs
 import importlib.util
 import zlib
 
-# reuse parseelf.py module from saleae-logic16:
+# Reuse the parseelf.py module from saleae-logic16.
 fwdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 parseelf_py = os.path.join(fwdir, "saleae-logic16", "parseelf.py")
 spec = importlib.util.spec_from_file_location("parseelf", parseelf_py)
@@ -57,7 +62,7 @@ class qt_resources(object):
                 sname, sym["st_size"], len(value)))
         return value
 
-    # qt resource stuff:
+    # Qt resource stuff.
     def _get_resource_name(self, offset):
         length, i = struct.unpack(">HI", self._res_names[offset:offset + 2 + 4])
         offset += 2 + 4
@@ -148,7 +153,7 @@ def decode_intel_hex(hexdata):
     """ return list of (address, data)
     """
     datas = []
-    # assume \n or \r\n*
+    # Assume LF-only or CR-LF style end-of-line.
     for line in hexdata.split(b"\n"):
         line = line.strip()
         if chr(line[0]) != ":": raise Exception("invalid line: %r" % line)
@@ -184,41 +189,23 @@ def intel_hex_as_blob(hexdata):
 def maybe_intel_hex_as_blob(data):
     if data[0] == ord(":") and max(data) < 127:
           return intel_hex_as_blob(data)
-    return data # keep binary data
+    return data # Keep binary data.
 
 if __name__ == "__main__":
-    if len(sys.argv) != 2:
-        print("sigrok-fwextract-kingst-la2016 <programfile>")
-        sys.exit()
-
-    res = qt_resources(sys.argv[1])
+    parser = argparse.ArgumentParser(description = "KingstVIS firmware extraction")
+    parser.add_argument('executable', help = "KingstVIS executable file")
+    options = parser.parse_args()
+    exe_fn = options.executable
 
+    res = qt_resources(exe_fn)
     writer = res_writer(res)
 
-    '''
-    05-APR-2021
-    This extraction script has been tested with the
-    vendor software versions v3.5.0 and v3.5.1
-    These files were extracted and tested successfully:
-    saved 5430 bytes to kingst-la-01a2.fw (crc32=720551a9)
-    saved 178362 bytes to kingst-la2016a1-fpga.bitstream (crc32=7cc894fa)
-    saved 178542 bytes to kingst-la2016-fpga.bitstream (crc32=20694ff1)
-    saved 178379 bytes to kingst-la1016a1-fpga.bitstream (crc32=166866be)
-    saved 178151 bytes to kingst-la1016-fpga.bitstream (crc32=7db70001)
-    '''
-
-    # extract all firmware and fpga bitstreams
-    # writer.extract_re(r"fwfpga/(.*)", r"kingst-\1-fpga.bitstream")
-    # writer.extract_re(r"fwusb/fw(.*)", r"kingst-la-\1.fw", decoder=maybe_intel_hex_as_blob)
-
-    # extract fx2 mcu firmware for both the la2016 and la1016
-    # note that 0x01a2 is the usb pid for both of these devices
-    writer.extract_re("fwusb/fw01A2", "kingst-la-01a2.fw", decoder=maybe_intel_hex_as_blob)
-
-    # extract fpga bitstreams for la2016
-    # there are two bitstreams, newer hardware uses the 'a1' bitstream
-    writer.extract_re("fwfpga/LA2016(.*)", r"kingst-la2016\1-fpga.bitstream")
-
-    # extract fpga bitstreams for la1016
-    # there are two bitstreams, newer hardware uses the 'a1' bitstream
-    writer.extract_re("fwfpga/LA1016(.*)", r"kingst-la1016\1-fpga.bitstream")
+    # Extract all MCU firmware and FPGA bitstream images. The sigrok
+    # project may not cover all KingstVIS supported devices. Users can
+    # either just copy those files which are strictly required for their
+    # specific device (diagnostics will identify those). Or just copy a
+    # few more files while some of them remain unused later (their size
+    # is small). Seeing which files would be contained is considered
+    # valuable, to identify device variants or candidate models.
+    writer.extract_re(r"fwusb/fw(.*)", r"kingst-la-\1.fw", decoder=maybe_intel_hex_as_blob)
+    writer.extract_re(r"fwfpga/(.*)", r"kingst-\1-fpga.bitstream")