3 ## This file is part of the sigrok-util project.
5 ## Copyright (C) 2015 Tilman Sauerbeck <tilman@code-monkey.de>
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.
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.
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/>.
25 Reverses the bits in the given byte.
27 x = (x & 0x55) << 1 | (x & 0xaa) >> 1
28 x = (x & 0x33) << 2 | (x & 0xcc) >> 2
29 x = (x & 0x0f) << 4 | (x & 0xf0) >> 4
34 with open(sys.argv[1], 'rb') as f:
39 firmware_offset = data.index(ident.encode(encoding = 'UTF-16-LE'))
40 firmware_offset += len(ident) * 2
42 bitstream_size = 464196
45 ('lecroy-logicstudio16-16.bitstream', 0),
46 ('lecroy-logicstudio16-8.bitstream', bitstream_size)
49 for (blob_name, blob_offset) in blobs:
50 out_bytes = bytearray()
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)
57 with open(blob_name, 'wb') as f:
60 print('Wrote {}'.format(blob_name))