]> sigrok.org Git - sigrok-util.git/blob - firmware/saleae-logic16-extract.py
c3251744e3926bd759e84d43c87d9705ce2c0491
[sigrok-util.git] / firmware / saleae-logic16-extract.py
1 #!/usr/bin/python3
2 ##
3 ## This file is part of the sigrok-util project.
4 ##
5 ## Copyright (C) 2013 Marcus Comstedt <marcus@mc.pp.se>
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
21 import sys
22 import parseelf
23
24 def extract_symbol(elf, symname, filename):
25     blob = elf.load_symbol(elf.dynsym[symname])
26     f = open(filename, 'wb')
27     f.write(blob)
28     f.close()
29     print("saved %d bytes to %s" % (len(blob), filename))
30
31 def extract_bitstream(elf, lv):
32     extract_symbol(elf, 'gLogic16Lv'+lv+'CompressedBitstream',
33                    'saleae-logic16-fpga-'+lv+'.bitstream')
34
35 def usage():
36     print("saleae-logic16-extract.py <programfile>")
37     sys.exit()
38
39
40 #
41 # main
42 #
43
44 if len(sys.argv) != 2:
45     usage()
46
47 try:
48     filename = sys.argv[1]
49     elf = parseelf.elf(filename)
50     extract_bitstream(elf, '18')
51     extract_bitstream(elf, '33')
52 except Exception as e:
53     print("Error: %s" % str(e))
54