From 43c4c0027191514a350ce4d37e8076c33dfbcb4a Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sun, 25 Oct 2015 14:13:37 +0100 Subject: [PATCH] Add a script that extracts FPGA bitstreams for LeCroy LogicStudio. --- .../sigrok-fwextract-lecroy-logicstudio | 61 +++++++++++++++++++ .../sigrok-fwextract-lecroy-logicstudio.1 | 32 ++++++++++ 2 files changed, 93 insertions(+) create mode 100755 firmware/lecroy-logicstudio/sigrok-fwextract-lecroy-logicstudio create mode 100644 firmware/lecroy-logicstudio/sigrok-fwextract-lecroy-logicstudio.1 diff --git a/firmware/lecroy-logicstudio/sigrok-fwextract-lecroy-logicstudio b/firmware/lecroy-logicstudio/sigrok-fwextract-lecroy-logicstudio new file mode 100755 index 0000000..aa6376e --- /dev/null +++ b/firmware/lecroy-logicstudio/sigrok-fwextract-lecroy-logicstudio @@ -0,0 +1,61 @@ +#!/usr/bin/python3 +## +## This file is part of the sigrok-util project. +## +## Copyright (C) 2015 Tilman Sauerbeck +## +## 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 . +## + +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() diff --git a/firmware/lecroy-logicstudio/sigrok-fwextract-lecroy-logicstudio.1 b/firmware/lecroy-logicstudio/sigrok-fwextract-lecroy-logicstudio.1 new file mode 100644 index 0000000..25a0e2b --- /dev/null +++ b/firmware/lecroy-logicstudio/sigrok-fwextract-lecroy-logicstudio.1 @@ -0,0 +1,32 @@ +.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. -- 2.30.2