Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable creation of xsa #180

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions vivado/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ vivado_write_bitstream(

It has the optional argument `write_bitstream_tcl_template` which by default loads [write_bitstream.tcl.template](write_bitstream.tcl.template). This can be modified.

Optionally set `with_xsa = True` to generate the `.xsa` file.

## xsim_test

Executes a test bench using the vivado simulator, xsim.
Expand Down
23 changes: 20 additions & 3 deletions vivado/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,25 @@ def _vivado_write_bitstream_impl(ctx):

checkpoint_in = ctx.attr.checkpoint[VivadoRoutingCheckpointInfo].checkpoint

outputs = [bitstream]

if ctx.attr.with_xsa:
with_xsa_str = "1"
xsa_out = ctx.actions.declare_file("{}.xsa".format(ctx.label.name))
xsa_path = xsa_out.path
outputs.append(xsa_out)
else:
with_xsa_str = "0"
xsa_path = "nothing.xsa"

substitutions = {
"{{THREADS}}": "{}".format(ctx.attr.threads),
"{{CHECKPOINT_IN}}": checkpoint_in.path,
"{{BITSTREAM}}": bitstream.path,
"{{WRITE_XSA}}": with_xsa_str,
"{{XSA_PATH}}": xsa_path,
}

outputs = [bitstream]

default_info = run_tcl_template(
ctx,
ctx.file.write_bitstream_template,
Expand Down Expand Up @@ -627,6 +638,10 @@ vivado_write_bitstream = rule(
doc = "Threads to pass to vivado which defines the amount of parallelism.",
default = 8,
),
"with_xsa": attr.bool(
doc = "Generate xsa too",
default = False,
),
"write_bitstream_template": attr.label(
doc = "The write bitstream tcl template",
default = "@rules_hdl//vivado:write_bitstream.tcl.template",
Expand All @@ -638,7 +653,7 @@ vivado_write_bitstream = rule(
],
)

def vivado_flow(name, module, module_top, part_number, xilinx_env, tags = [], ip_blocks = []):
def vivado_flow(name, module, module_top, part_number, xilinx_env, tags = [], ip_blocks = [], with_xsa=False):
"""Runs the entire bitstream flow as a convenience macro.

Args:
Expand All @@ -649,6 +664,7 @@ def vivado_flow(name, module, module_top, part_number, xilinx_env, tags = [], ip
xilinx_env: The shell script to setup the Xilinx/vivado environment.
tags: Optional tags to use for the rules.
ip_blocks: Optional ip blocks to include in a design.
with_xsa: Also generate the xsa file.
"""
vivado_synthesize(
name = "{}_synth".format(name),
Expand Down Expand Up @@ -693,6 +709,7 @@ def vivado_flow(name, module, module_top, part_number, xilinx_env, tags = [], ip
checkpoint = "{}_route".format(name),
xilinx_env = xilinx_env,
tags = tags,
with_xsa = with_xsa,
)

def _xsim_test_impl(ctx):
Expand Down
3 changes: 3 additions & 0 deletions vivado/write_bitstream.tcl.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ puts "Post Route WNS = $WNS"

if {$WNS >= 0} {
write_bitstream -force {{BITSTREAM}}
if {{{WRITE_XSA}}} {
write_hw_platform -fixed -include_bit -force -file {{XSA_PATH}}
}
} else {
puts "Failed to make timing, refusing to make bitstream"
}