]> sigrok.org Git - sigrok-util.git/blame - firmware/lecroy-logicstudio/sigrok-fwextract-lecroy-logicstudio
sigrok-fwextract-dreamsourcelab-dslogic: Download v0.98 firmware
[sigrok-util.git] / firmware / lecroy-logicstudio / sigrok-fwextract-lecroy-logicstudio
CommitLineData
43c4c002
TS
1#!/usr/bin/python3
2##
3## This file is part of the sigrok-util project.
4##
5## Copyright (C) 2015 Tilman Sauerbeck <tilman@code-monkey.de>
6##
7## This program is free software; you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation; either version 3 of the License, or
10## (at your option) any later version.
11##
12## This program is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with this program; if not, see <http://www.gnu.org/licenses/>.
19##
20
21import sys
22
23def reverse_bits8(x):
24 '''
25 Reverses the bits in the given byte.
26 '''
27 x = (x & 0x55) << 1 | (x & 0xaa) >> 1
28 x = (x & 0x33) << 2 | (x & 0xcc) >> 2
29 x = (x & 0x0f) << 4 | (x & 0xf0) >> 4
30
31 return x
32
33def main():
34 with open(sys.argv[1], 'rb') as f:
35 data = f.read()
36
37 ident = 'FPGA_BINS'
38
39 firmware_offset = data.index(ident.encode(encoding = 'UTF-16-LE'))
40 firmware_offset += len(ident) * 2
41
42 bitstream_size = 464196
43
44 blobs = [
45 ('lecroy-logicstudio16-16.bitstream', 0),
46 ('lecroy-logicstudio16-8.bitstream', bitstream_size)
47 ]
48
49 for (blob_name, blob_offset) in blobs:
50 out_bytes = bytearray()
51
52 for u in range(blob_offset, blob_offset + bitstream_size):
53 inb = data[firmware_offset + u]
54 outb = reverse_bits8(inb)
55 out_bytes.append(outb)
56
57 with open(blob_name, 'wb') as f:
58 f.write(out_bytes)
59
60 print('Wrote {}'.format(blob_name))
61main()