forked from f4pga/prjxray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfasm2frames.py
More file actions
executable file
·96 lines (76 loc) · 2.62 KB
/
fasm2frames.py
File metadata and controls
executable file
·96 lines (76 loc) · 2.62 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
from __future__ import print_function
from prjxray import fasm_assembler
from prjxray import db
import argparse
import os
import os.path
def dump_frames_verbose(frames):
print()
print("Frames: %d" % len(frames))
for addr in sorted(frames.keys()):
words = frames[addr]
print(
'0x%08X ' % addr + ', '.join(['0x%08X' % w for w in words]) +
'...')
def dump_frames_sparse(frames):
print()
print("Frames: %d" % len(frames))
for addr in sorted(frames.keys()):
words = frames[addr]
# Skip frames without filled words
for w in words:
if w:
break
else:
continue
print('Frame @ 0x%08X' % addr)
for i, w in enumerate(words):
if w:
print(' % 3d: 0x%08X' % (i, w))
def dump_frm(f, frames):
'''Write a .frm file given a list of frames, each containing a list of 101 32 bit words'''
for addr in sorted(frames.keys()):
words = frames[addr]
f.write(
'0x%08X ' % addr + ','.join(['0x%08X' % w for w in words]) + '\n')
def run(db_root, filename_in, f_out, sparse=False, debug=False):
assembler = fasm_assembler.FasmAssembler(db.Database(db_root))
assembler.parse_fasm_filename(filename_in)
frames = assembler.get_frames(sparse=sparse)
if debug:
dump_frames_sparse(frames)
dump_frm(f_out, frames)
def main():
parser = argparse.ArgumentParser(
description=
'Convert FPGA configuration description ("FPGA assembly") into binary frame equivalent'
)
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(
'--sparse', action='store_true', help="Don't zero fill all frames")
parser.add_argument(
'--debug', action='store_true', help="Print debug dump")
parser.add_argument('fn_in', help='Input FPGA assembly (.fasm) file')
parser.add_argument(
'fn_out',
default='/dev/stdout',
nargs='?',
help='Output FPGA frame (.frm) file')
args = parser.parse_args()
run(
db_root=args.db_root,
filename_in=args.fn_in,
f_out=open(args.fn_out, 'w'),
sparse=args.sparse,
debug=args.debug)
if __name__ == '__main__':
main()