forked from f4pga/prjxray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbits2fasm.py
More file actions
executable file
·54 lines (41 loc) · 1.48 KB
/
bits2fasm.py
File metadata and controls
executable file
·54 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
'''
Take raw .bits files and decode them to FASM.
'''
import os
import fasm
from prjxray import db
from prjxray import fasm_disassembler
from prjxray import bitstream
def run(db_root, bits_file, verbose, canonical):
disassembler = fasm_disassembler.FasmDisassembler(db.Database(db_root))
with open(bits_file) as f:
bitdata = bitstream.load_bitdata(f)
print(
fasm.fasm_tuple_to_string(
disassembler.find_features_in_bitstream(bitdata, verbose=verbose),
canonical=canonical))
def main():
import argparse
parser = argparse.ArgumentParser(
description='Convert 7-series bits file to FASM.')
database_dir = os.getenv("XRAY_DATABASE_DIR")
database = os.getenv("XRAY_DATABASE")
db_root_kwargs = {}
if database_dir is None or database is None:
db_root_kwargs['required'] = True
else:
db_root_kwargs['required'] = False
db_root_kwargs['default'] = os.path.join(database_dir, database)
parser.add_argument('--db-root', help="Database root.", **db_root_kwargs)
parser.add_argument('bits_file', help='')
parser.add_argument(
'--verbose',
help='Print lines for unknown tiles and bits',
action='store_true')
parser.add_argument(
'--canonical', help='Output canonical bitstream.', action='store_true')
args = parser.parse_args()
run(args.db_root, args.bits_file, args.verbose, args.canonical)
if __name__ == '__main__':
main()