--- /dev/null
+#!/usr/bin/python3
+##
+## This file is part of the sigrok-util project.
+##
+## Copyright (C) 2015 Tilman Sauerbeck <tilman@code-monkey.de>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, see <http://www.gnu.org/licenses/>.
+##
+
+import sys
+
+def reverse_bits8(x):
+ '''
+ Reverses the bits in the given byte.
+ '''
+ x = (x & 0x55) << 1 | (x & 0xaa) >> 1
+ x = (x & 0x33) << 2 | (x & 0xcc) >> 2
+ x = (x & 0x0f) << 4 | (x & 0xf0) >> 4
+
+ return x
+
+def main():
+ with open(sys.argv[1], 'rb') as f:
+ data = f.read()
+
+ ident = 'FPGA_BINS'
+
+ firmware_offset = data.index(ident.encode(encoding = 'UTF-16-LE'))
+ firmware_offset += len(ident) * 2
+
+ bitstream_size = 464196
+
+ blobs = [
+ ('lecroy-logicstudio16-16.bitstream', 0),
+ ('lecroy-logicstudio16-8.bitstream', bitstream_size)
+ ]
+
+ for (blob_name, blob_offset) in blobs:
+ out_bytes = bytearray()
+
+ for u in range(blob_offset, blob_offset + bitstream_size):
+ inb = data[firmware_offset + u]
+ outb = reverse_bits8(inb)
+ out_bytes.append(outb)
+
+ with open(blob_name, 'wb') as f:
+ f.write(out_bytes)
+
+ print('Wrote {}'.format(blob_name))
+main()
--- /dev/null
+.TH SIGROK\-FWEXTRACT\-LECROY\-LOGICSTUDIO 1 "Oct 25, 2015"
+.SH "NAME"
+sigrok\-fwextract\-lecroy\-logicstudio \- Extract LeCroy LogicStudio firmware
+.SH "SYNOPSIS"
+.B sigrok\-fwextract\-lecroy\-logicstudio [FILE]
+.SH "DESCRIPTION"
+This tool extracts firmware from the Windows software that ships with the LeCroy LogicStudio logic analyzer. It is called with the path to
+.B LS16Lib.dll
+as its only argument, e.g.:
+.PP
+.B " $ sigrok-fwextract-lecroy-logicstudio /path/to/LogicStudio/LS16Lib.dll"
+.PP
+The program will then write two FPGA bitstream files to the current directory.
+Copy these over to the location where libsigrok expects to find its firmware
+files. By default this is
+.BR /usr/local/share/sigrok-firmware .
+.SH OPTIONS
+None.
+.SH "EXIT STATUS"
+Exits with 0 on success, 1 on most failures.
+.SH "SEE ALSO"
+\fBsigrok\-fwextract\-saleae\-logic16\fP(1)
+.SH "BUGS"
+Please report any bugs via Bugzilla
+.RB "(" http://sigrok.org/bugzilla ")"
+or on the sigrok\-devel mailing list
+.RB "(" sigrok\-devel@lists.souceforge.net ")."
+.SH "LICENSE"
+This program is covered by the GNU General Public License (GPL),
+version 3 or later.
+.SH "AUTHORS"
+Please see the individual source code files.