This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
litex_patch.py
121 lines (99 loc) · 3.3 KB
/
litex_patch.py
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import os
from migen import *
from migen.fhdl.structure import _Fragment
def _build(
self,
platform,
fragment,
build_dir="build",
build_name="top",
synth_opts="",
run=True,
build_backend="litex",
**kwargs
):
self._build_name = build_name
self._build_dir = build_dir
self._synth_opts += synth_opts
self.platform = platform
self.fragment = fragment
# Create Build Directory.
os.makedirs(self._build_dir, exist_ok=True)
cwd = os.getcwd()
os.chdir(self._build_dir)
# Finalize Design.
if not isinstance(self.fragment, _Fragment):
self.fragment = self.fragment.get_fragment()
platform.finalize(self.fragment)
# Generate Verilog.
v_output = platform.get_verilog(self.fragment, name=build_name, **kwargs)
self._vns = v_output.ns
v_file = build_name + ".v"
v_output.write(v_file)
# Finalize toolchain (after gateware is complete)
self.finalize()
# Get signals and platform constraints
self.named_sc, self.named_pc = platform.resolve_signals(self._vns)
# platform.add_source(v_file)
# Generate Design Timing Constraints File.
tim_cst_file = self.build_timing_constraints(v_output.ns)
# Generate Design IO Constraints File.
io_cst_file = self.build_io_constraints()
# Generate Design Placement Constraints File.
place_cst_file = self.build_placement_constraints()
if build_backend not in self.supported_build_backend:
raise NotImplementedError(
"Build backend {build_backend} is not supported by {toolchain} toolchain".format(
build_backend=build_backend, toolchain=type(self).__name__
)
)
# LiteX backend.
if build_backend == "litex":
# Generate project.
self.build_project()
# Generate build script.
script = self.build_script()
# Run.
if run:
self.run_script(script)
# Edalize backend.
else:
from edalize import get_edatool
# Get tool name and options
(tool, tool_options) = self.get_tool_options()
# Files list
files = []
for filename, language, library, *copy in self.platform.sources:
ext = {
"verilog": "verilogSource",
"systemverilog": "systemVerilogSource",
"vhdl": "vhdlSource",
}[language]
files.append({"name": filename, "file_type": ext})
# IO/timings constraints
files.append(
{"name": os.path.abspath(io_cst_file[0]), "file_type": io_cst_file[1]}
)
if tim_cst_file[0] != "":
files.append(
{"name": os.path.abspath(tim_cst_file[0]), "file_type": tim_cst_file[1]}
)
if place_cst_file[0] != "":
files.append(
{
"name": os.path.abspath(place_cst_file[0]),
"file_type": place_cst_file[1],
}
)
edam = {
"name": self._build_name,
"files": files,
**tool_options,
"toplevel": self._build_name,
}
backend = get_edatool(tool)(edam=edam, work_root=self._build_dir)
backend.configure()
if run:
backend.build()
os.chdir(cwd)
return v_output.ns