Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/migen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 055f7d51fc58
Choose a base ref
...
head repository: m-labs/migen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0df9c16e69bc
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 2, 2015

  1. Adding support for programming with FPGALink

    Steps for getting it set up.
    
     * Get libfpgalink dependencies
       sudo apt-get install \
          build-essential libreadline-dev libusb-1.0-0-dev python-yaml
    
     * Build libfpgalink
       wget -qO- http://tiny.cc/msbil | tar zxf -
       cd makestuff; ./scripts/msget.sh makestuff/common
       cd libs; ../scripts/msget.sh libfpgalink
       cd libfpgalink; make deps
    
     * Convert libfpgalink to python3
       wget -O - http://www.swaton.ukfsn.org/bin/2to3.tar.gz | tar zxf -
       cd examples/python
       cp fpgalink2.py fpgalink3.py
       ../../2to3/2to3 fpgalink3.py | patch fpgalink3.py
    
     * Set your path's correctly.
    
       export LD_LIBRARY_PATH=$(pwd)/libfpgalink/lin.x64/rel:$LD_LIBRARY_PATH
       export PYTHON_PATH=$(pwd)/libfpgalink/examples/python:$PYTHON_PATH
    mithro authored and enjoy-digital committed Jul 2, 2015
    Copy the full SHA
    8daf5e3 View commit details
  2. 1
    Copy the full SHA
    0df9c16 View commit details
Showing with 113 additions and 1 deletion.
  1. +97 −0 mibuild/fpgalink_programmer.py
  2. +16 −1 mibuild/xilinx/programmer.py
97 changes: 97 additions & 0 deletions mibuild/fpgalink_programmer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

import os

from mibuild.generic_programmer import GenericProgrammer
from mibuild.xilinx.programmer import _create_xsvf

import fpgalink3
fpgalink3.flInitialise(0)


class FPGALink(GenericProgrammer):
"""Using the fpgalink library from makestuff
You will need fpgalink library installed from
https://github.com/makestuff/libfpgalink
"""

needs_bitreverse = False

def __init__(self, initial_vidpid=None, pin_cfg="D0D2D3D4",
fpgalink_vidpid="1D50:602B:0002", flash_proxy_basename=None):
"""
Parameters
----------
initial_vidpid : string
The USB vendor and product id of the device before fpgalink
firmware is loaded onto the device.
Format is vid:pid as 4 digit hex numbers.
pin_cfg : string
FPGALink pin configuration string describing how the JTAG interface
is hooked up to the programmer.
fpgalink_vidpid : string
The USB vendor, product and device id of the device after the
fpgalink firmware is loaded onto the device.
Format is vid:pid:did as 4 digit hex numbers.
Defaults to 1D50:602B:0002 which is the makestuff FPGALink device.
"""
GenericProgrammer.__init__(self, flash_proxy_basename)
self.initial_vidpid = initial_vidpid
self.fpgalink_vidpid = fpgalink_vidpid
self.pin_cfg = pin_cfg

def open_device(self):
ivp = self.initial_vidpid
vp = self.fpgalink_vidpid

print("Attempting to open connection to FPGALink device", vp, "...")
try:
handle = fpgalink3.flOpen(self.fpgalink_vidpid)
except fpgalink3.FLException as ex:
if not ivp:
raise FLException(
"Could not open FPGALink device at {0} and"
" no initial VID:PID was supplied".format(vp))

print("Loading firmware into %s..." % ivp)
fpgalink3.flLoadStandardFirmware(ivp, vp)

print("Awaiting renumeration...")
if not fpgalink3.flAwaitDevice(vp, 600):
raise fpgalink3.FLException(
"FPGALink device did not renumerate properly"
" as {0}".format(vp))

print("Attempting to open connection to FPGALink device", vp,
"again...")
handle = fpgalink3.flOpen(vp)

# Only Nero capable hardware support doing programming.
assert fpgalink3.flIsNeroCapable(handle)
return handle

def load_bitstream(self, bitstream_file):
n = 27

xsvf_file = os.path.splitext(bitstream_file)[0]+'.xsvf'
print("\nGenerating xsvf formatted bitstream")
print("="*n)
if os.path.exists(xsvf_file):
os.unlink(xsvf_file)
_create_xsvf(bitstream_file, xsvf_file)
print("\n"+"="*n+"\n")

print("Programming %s to device." % xsvf_file)
print("="*n)
handle = self.open_device()
fpgalink3.flProgram(handle, 'J:'+self.pin_cfg, progFile=xsvf_file)
print("Programming successful!")
print("="*n+"\n")
fpgalink3.flClose(handle)

def flash(self, address, data_file):
raise NotImplementedError("Not supported yet.")
17 changes: 16 additions & 1 deletion mibuild/xilinx/programmer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import subprocess

@@ -70,9 +71,23 @@ def flash(self, address, data_file):


def _run_impact(cmds):
with subprocess.Popen("impact -batch", stdin=subprocess.PIPE) as process:
with subprocess.Popen("impact -batch", stdin=subprocess.PIPE, shell=True) as process:
process.stdin.write(cmds.encode("ASCII"))
process.communicate()
return process.returncode


def _create_xsvf(bitstream_file, xsvf_file):
assert os.path.exists(bitstream_file), bitstream_file
assert not os.path.exists(xsvf_file), xsvf_file
assert 0 == _run_impact("""
setPreference -pref KeepSVF:True
setMode -bs
setCable -port xsvf -file {xsvf}
addDevice -p 1 -file {bitstream}
program -p 1
quit
""".format(bitstream=bitstream_file, xsvf=xsvf_file))


class iMPACT(GenericProgrammer):