Skip to content

Driver for openFPGALoader #1402

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ Arguments:

Used by:
- `OpenOCDDriver`_
- `OpenFPGALoaderDriver`_
- `QuartusHPSDriver`_

USBDebugger
Expand All @@ -863,6 +864,7 @@ Arguments:

Used by:
- `OpenOCDDriver`_
- `OpenFPGALoaderDriver`_

SNMPEthernetPort
~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -1950,6 +1952,40 @@ Arguments:
- board_config (str): optional, board config in the ``openocd/scripts/board/`` directory
- load_commands (list of str): optional, load commands to use instead of ``init``, ``bootstrap {filename}``, ``shutdown``

OpenFPGALoaderDriver
~~~~~~~~~~~~~~~~~~~~

An :any:`OpenFPGALoaderDriver` controls the openFPGALoader tool to bootstrap an FPGA chip with a
bitstream.

A list of supported FPGA chips, boards and programming cables can be found on the project's page:
- https://trabucayre.github.io/openFPGALoader/compatibility/fpga.html
- https://trabucayre.github.io/openFPGALoader/compatibility/board.html
- https://trabucayre.github.io/openFPGALoader/compatibility/cable.html

Binds to:
interface:
- `AlteraUSBBlaster`_
- NetworkAlteraUSBBlaster
Comment on lines +1968 to +1969
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also add this driver to AlteraUSBBlaster's "Used by" section.

- `USBDebugger`_
- NetworkUSBDebugger

Implements:
- :any:`BootstrapProtocol`

.. code-block:: yaml

OpenFPGALoaderDriver:
board: 'vcu118'
image: 'bitstreamkey'
frequency: 20000000

Arguments:
- image (str): optional, key in :ref:`images <labgrid-device-config-images>` containing the path
of the bitstream, if not specified when calling `load()`
- board (str): optional, the FPGA board identifier
- frequency (int): optional, force a non-default programmer frequency in Hz

QuartusHPSDriver
~~~~~~~~~~~~~~~~
A :any:`QuartusHPSDriver` controls the "Quartus Prime Programmer and Tools" to
Expand Down
1 change: 1 addition & 0 deletions labgrid/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .fastbootdriver import AndroidFastbootDriver
from .dfudriver import DFUDriver
from .openocddriver import OpenOCDDriver
from .openfpgaloaderdriver import OpenFPGALoaderDriver
from .quartushpsdriver import QuartusHPSDriver
from .flashromdriver import FlashromDriver
from .onewiredriver import OneWirePIODriver
Expand Down
71 changes: 71 additions & 0 deletions labgrid/driver/openfpgaloaderdriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import attr

from ..factory import target_factory
from ..protocol import BootstrapProtocol
from ..step import step
from ..util.managedfile import ManagedFile
from ..util.helper import processwrapper
from .common import Driver


@target_factory.reg_driver
@attr.s(eq=False)
class OpenFPGALoaderDriver(Driver, BootstrapProtocol):
"""OpenFPGALoaderDriver - Driver to bootstrap FPGA boards with a bitstream file

Arguments:
image (str): optional, the default bitstream image file if not specified when calling load()
board (str): optional, the FPGA board identifier
frequency (int): optional, force a non-default programmer frequency in Hz
"""
bindings = {
"interface": {
"AlteraUSBBlaster", "NetworkAlteraUSBBlaster",
"USBDebugger", "NetworkUSBDebugger",
},
}

image = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str))
)
board = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str))
)
frequency = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(int))
)

def __attrs_post_init__(self):
super().__attrs_post_init__()

if self.target.env:
self.tool = self.target.env.config.get_tool('openfpgaloader')
else:
self.tool = 'openFPGALoader'

@Driver.check_active
@step(args=['filename'])
def load(self, filename=None):
cmd = [self.tool]

if filename is None and self.image is not None:
filename = self.target.env.config.get_image_path(self.image)
mf = ManagedFile(filename, self.interface)
mf.sync_to_resource()
cmd += ["--bitstream", mf.get_remote_path()]

cmd += ["--busdev-num", f"{self.interface.busnum}:{self.interface.devnum}"]

if self.board:
cmd += ["--board", self.board]

if self.frequency:
cmd += ["--freq", str(self.frequency)]

processwrapper.check_output(
self.interface.wrap_command(cmd),
print_on_silent_log=True
)
4 changes: 4 additions & 0 deletions man/labgrid-device-config.5
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ See: \fI\%https://git.pengutronix.de/cgit/barebox/tree/scripts/mxs\-usb\-loader.
Path to the openocd binary, used by the OpenOCDDriver.
See: \fI\%https://openocd.org/\fP
.TP
.B \fBopenfpgaloader\fP
Path to the openFPGALoader binary, used by the OpenFPGALoaderDriver.
See: \fI\%https://github.com/trabucayre/openFPGALoader\fP
.TP
.B \fBquartus_hps\fP
Path to the quartus_hps binary, used by the QuartusHPSDriver.
See: \fI\%https://www.intel.com/content/www/us/en/docs/programmable/683039/22\-3/hps\-flash\-programmer.html\fP
Expand Down
4 changes: 4 additions & 0 deletions man/labgrid-device-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ TOOLS KEYS
Path to the openocd binary, used by the OpenOCDDriver.
See: https://openocd.org/

``openfpgaloader``
Path to the openFPGALoader binary, used by the OpenFPGALoaderDriver.
See: https://github.com/trabucayre/openFPGALoader

``quartus_hps``
Path to the quartus_hps binary, used by the QuartusHPSDriver.
See: https://www.intel.com/content/www/us/en/docs/programmable/683039/22-3/hps-flash-programmer.html
Expand Down
Loading