diff options
| author | William D. Jones <thor0505@comcast.net> | 2020-10-15 14:47:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-15 18:47:02 +0000 |
| commit | bcc14672994a3cdd04b7c0e1620d6f5e05145d94 (patch) | |
| tree | 14911f5954cfddc53be9a930eccc2affbb879333 /nmigen_boards/arty_s7.py | |
| parent | 0e95118062b86e8e57f064957088ddb84cfb31ed (diff) | |
arty_s7: add openocd and flashing support.
Diffstat (limited to 'nmigen_boards/arty_s7.py')
| -rw-r--r-- | nmigen_boards/arty_s7.py | 76 |
1 files changed, 63 insertions, 13 deletions
diff --git a/nmigen_boards/arty_s7.py b/nmigen_boards/arty_s7.py index b617566..2871dae 100644 --- a/nmigen_boards/arty_s7.py +++ b/nmigen_boards/arty_s7.py @@ -1,3 +1,4 @@ +import os import textwrap import subprocess @@ -6,7 +7,7 @@ from nmigen.vendor.xilinx_7series import * from .resources import * -__all__ = ["ArtysS7_25Platform", "ArtyS7_50Platform"] +__all__ = ["ArtyS7_25Platform", "ArtyS7_50Platform"] class _ArtyS7Platform(Xilinx7SeriesPlatform): @@ -159,18 +160,67 @@ class _ArtyS7Platform(Xilinx7SeriesPlatform): } return super().toolchain_prepare(fragment, name, **overrides, **kwargs) - def toolchain_program(self, product, name): - with product.extract("{}.bit".format(name)) as bitstream_filename: - cmd = textwrap.dedent(""" - open_hw_manager - connect_hw_server - open_hw_target - current_hw_device [lindex [get_hw_devices] 0] - set_property PROGRAM.FILE {{{}}} [current_hw_device] - program_hw_devices - close_hw_manager - """).format(bitstream_filename).encode("utf-8") - subprocess.run(["vivado", "-nolog", "-nojournal", "-mode", "tcl"], input=cmd, check=True) + def toolchain_program(self, product, name, *, programmer="vivado", flash=True): + assert programmer in ("vivado", "openocd") + + if programmer == "vivado": + if flash: + # It does not appear possible to reset the FPGA via TCL after + # flash programming. + with product.extract("{}.bin".format(name)) as bitstream_filename: + cmd = textwrap.dedent(""" + open_hw_manager + connect_hw_server + open_hw_target + current_hw_device [lindex [get_hw_devices] 0] + create_hw_cfgmem -hw_device [current_hw_device] s25fl128sxxxxxx0-spi-x1_x2_x4 + set_property PROGRAM.FILES {{{}}} [current_hw_cfgmem] + set_property PROGRAM.ADDRESS_RANGE {{use_file}} [current_hw_cfgmem] + set_property PROGRAM.BLANK_CHECK 1 [current_hw_cfgmem] + set_property PROGRAM.ERASE 1 [current_hw_cfgmem] + set_property PROGRAM.CFG_PROGRAM 1 [current_hw_cfgmem] + set_property PROGRAM.VERIFY 1 [current_hw_cfgmem] + create_hw_bitstream -hw_device [current_hw_device] [get_property PROGRAM.HW_CFGMEM_BITFILE [current_hw_device]] + program_hw_devices + program_hw_cfgmem + close_hw_manager + puts "Vivado TCL cannot reset boards. Reset or power-cycle your board now." + """).format(bitstream_filename).encode("utf-8") + subprocess.run(["vivado", "-nolog", "-nojournal", "-mode", "tcl"], input=cmd, check=True) + else: + with product.extract("{}.bit".format(name)) as bitstream_filename: + cmd = textwrap.dedent(""" + open_hw_manager + connect_hw_server + open_hw_target + current_hw_device [lindex [get_hw_devices] 0] + set_property PROGRAM.FILE {{{}}} [current_hw_device] + program_hw_devices + close_hw_manager + """).format(bitstream_filename).encode("utf-8") + subprocess.run(["vivado", "-nolog", "-nojournal", "-mode", "tcl"], input=cmd, check=True) + else: + openocd = os.environ.get("OPENOCD", "openocd") + # In order, OpenOCD searches these directories for files: + # * $HOME/.openocd if $HOME exists (*nix) + # * Path pointed to by $OPENOCD_SCRIPTS if $OPENOCD_SCRIPTS exists + # * $APPDATA/OpenOCD on Windows + # Place the bscan_spi_xc7s50.bit proxy bitstream under a directory + # named "proxy" in one of the above directories so OpenOCD finds it. + if flash: + with product.extract("{}.bin".format(name)) as fn: + subprocess.check_call([openocd, "-f", "board/arty_s7.cfg", + "-c", """init; + jtagspi_init 0 [find proxy/bscan_spi_xc7s50.bit]; + jtagspi_program {} 0; + xc7_program xc7.tap; + shutdown""".format(fn)]) + else: + with product.extract("{}.bit".format(name)) as fn: + subprocess.check_call(["openocd", "-f", "board/arty_s7.cfg", + "-c", """init; + pld load 0 {}; + shutdown""".format(fn)]) class ArtyS7_50Platform(_ArtyS7Platform): |
