Skip to content

Commit

Permalink
Add XSA generation to write_bitstream
Browse files Browse the repository at this point in the history
  • Loading branch information
stridge-cruxml authored and QuantamHD committed Sep 7, 2023
1 parent 7fd311e commit 7fcbce7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
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
21 changes: 18 additions & 3 deletions vivado/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ vivado_placement = rule(
],
)

def _vivado_place_optimize_impl(ctx):
def _vivado_place_optimi outputs = [bitstream]ze_impl(ctx):
placement_checkpoint = ctx.actions.declare_file("{}.dcp".format(ctx.label.name))
timing_summary_report = ctx.actions.declare_file("{}_timing.rpt".format(ctx.label.name))
util_report = ctx.actions.declare_file("{}_util.rpt".format(ctx.label.name))
Expand Down Expand Up @@ -591,14 +591,25 @@ def _vivado_write_bitstream_impl(ctx):

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

outputs = [bitstream]

if ctx.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 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"
}

0 comments on commit 7fcbce7

Please sign in to comment.