]> sigrok.org Git - sigrok-util.git/commitdiff
sigrok-fwextract-kingst-la2016: fix fpga bitstream extraction, add device support
authorKevin Grant <redacted>
Mon, 5 Apr 2021 13:07:07 +0000 (14:07 +0100)
committerSoeren Apel <redacted>
Fri, 10 Sep 2021 21:12:45 +0000 (23:12 +0200)
Firmware extraction is trivially broken, probably due to a change of stream name
in the vendor resource file. Fixed that issue and also extracted more files to
support different hardware variations; the two existing hardware revisions of
LA2016 & LA1016 each require different bitstreams. The crc32 of extracted
files is now shown to help track any vendor changes.

firmware/kingst-la/sigrok-fwextract-kingst-la2016

index a5832184577a9f661a559925cb122f19b72cd919..4357994207762fadb837fbcf5d9d92ff8dc5f9cb 100755 (executable)
@@ -24,6 +24,7 @@ import re
 import struct
 import codecs
 import importlib.util
 import struct
 import codecs
 import importlib.util
+import zlib
 
 # reuse parseelf.py module from saleae-logic16:
 fwdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
 # reuse parseelf.py module from saleae-logic16:
 fwdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -132,7 +133,8 @@ class res_writer(object):
             data += b"\0" * (zero_pad_to - len(data))
         with open(fn, "wb") as fp:
             fp.write(data)
             data += b"\0" * (zero_pad_to - len(data))
         with open(fn, "wb") as fp:
             fp.write(data)
-        print("saved %d bytes to %s" % (len(data), fn))
+        data_crc32 = zlib.crc32(data) & 0xffffffff
+        print("saved %d bytes to %s (crc32=%08x)" % (len(data), fn, data_crc32))
 
     def extract(self, res_fn, out_fn, decoder=None, zero_pad_to=None):
         self._write_file(out_fn, self.res.get_resource(res_fn), decoder=decoder, zero_pad_to=zero_pad_to)
 
     def extract(self, res_fn, out_fn, decoder=None, zero_pad_to=None):
         self._write_file(out_fn, self.res.get_resource(res_fn), decoder=decoder, zero_pad_to=zero_pad_to)
@@ -192,5 +194,31 @@ if __name__ == "__main__":
     res = qt_resources(sys.argv[1])
 
     writer = res_writer(res)
     res = qt_resources(sys.argv[1])
 
     writer = res_writer(res)
-    writer.extract("fwfpga/LA2016A", "kingst-la2016a-fpga.bitstream")
-    writer.extract_re(r"fwusb/fw(.*)", r"kingst-la-\1.fw", decoder=maybe_intel_hex_as_blob)
+
+    '''
+    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")