Skip to content

Commit

Permalink
Actually use extracted port names
Browse files Browse the repository at this point in the history
Starting with Alex's XML parsing stuff, we now actually pass this stuff
to our `gen_xo.tcl` script. This also uses the `mode` attribute on the
`port` XML elements to distinguish which ports are relevant.
  • Loading branch information
sampsyo committed Apr 8, 2022
1 parent f1149c1 commit 026a360
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions fud/fud/stages/xilinx/xclbin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
import logging as log
import xml.etree.ElementTree as ET
from pathlib import Path
Expand All @@ -9,6 +8,22 @@
from fud.utils import shell


def get_ports(kernel_xml):
"""Parse an XML file to get the names of AXI ports in a design.
The argument is the filename for a `kernel.xml` file that is also an
input to the Xilinx `.xo` packaging step (which describes the
physical ports in the design and how the logical arguments are
mapped onto these ports). We extract the names of all AXI master
ports.
"""
tree = ET.parse(kernel_xml)
root = tree.getroot()
for port in root.iter('port'):
if port.attrib['mode'] == 'master':
yield port.attrib['name']


class XilinxStage(Stage):
name = "xclbin"

Expand Down Expand Up @@ -54,35 +69,25 @@ def _define_steps(self, input_data, builder, config):
/ "gen_xo.tcl"
)




# Locate generated kernel XML file
xmlfile = 'kernel.xml'
tree = ET.parse(xmlfile)
root = tree.getroot()
axi_str = ""
for port in root.iter('port'):
if re.search("_axi$", port.attrib['name']):
#print(port.attrib['name'])
axi_str += port.attrib['name'] + " "

# Remove any trailing spaces
axi_str.strip()


package_cmd = (
"cd {tmpdir} && "
"mkdir -p xclbin && "
"/scratch/opt/Xilinx/Vivado/2020.2/bin/vivado "
"-mode batch "
"-source gen_xo.tcl "
"-tclargs xclbin/kernel.xo m0_axi"
"-tclargs xclbin/kernel.xo {port_names}"
)

@builder.step(package_cmd)
def package_xo(client: SourceType.UnTyped, tmpdir: SourceType.String):
self._shell(client, package_cmd.format(tmpdir=tmpdir), remote_exec)
# Get the AXI port names.
port_names = list(get_ports(os.path.join(tmpdir, 'kernel.xml')))

# Run the .xo packager Vivado script.
self._shell(client, package_cmd.format(
tmpdir=tmpdir,
port_names=' '.join(port_names),
), remote_exec)

xclbin_cmd = (
"cd {tmpdir} && "
Expand Down

0 comments on commit 026a360

Please sign in to comment.