Skip to content

Commit 8206826

Browse files
enjoy-digitalsbourdeauducq
authored andcommittedAug 1, 2014
mibuild: move programmer to mibuild and create programmer directly in platforms
1 parent 244ee52 commit 8206826

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed
 

‎mibuild/platforms/de0nano.py

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from mibuild.generic_platform import *
55
from mibuild.crg import SimpleCRG
66
from mibuild.altera_quartus import AlteraQuartusPlatform
7+
from mibuild.programmer import USBBlaster
78

89
_io = [
910
("clk50", 0, Pins("R8"), IOStandard("3.3-V LVTTL")),
@@ -95,6 +96,9 @@ def __init__(self):
9596
AlteraQuartusPlatform.__init__(self, "EP4CE22F17C6", _io,
9697
lambda p: SimpleCRG(p, "clk50", None))
9798

99+
def create_programmer(self):
100+
return USBBlaster()
101+
98102
def do_finalize(self, fragment):
99103
try:
100104
self.add_period_constraint(self.lookup_request("clk50"), 20)

‎mibuild/platforms/m1.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from mibuild.generic_platform import *
22
from mibuild.crg import SimpleCRG
33
from mibuild.xilinx_ise import XilinxISEPlatform
4+
from mibuild.programmer import UrJTAG
45

56
_io = [
67
("user_led", 0, Pins("B16"), IOStandard("LVCMOS33"), Drive(24), Misc("SLEW=QUIETIO")),
@@ -122,6 +123,9 @@ def __init__(self):
122123
XilinxISEPlatform.__init__(self, "xc6slx45-fgg484-2", _io,
123124
lambda p: SimpleCRG(p, "clk50", None))
124125

126+
def create_programmer(self):
127+
return UrJTAG("fjmem-m1.bit")
128+
125129
def do_finalize(self, fragment):
126130
try:
127131
self.add_period_constraint(self.lookup_request("clk50"), 20)

‎mibuild/platforms/mixxeo.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from mibuild.generic_platform import *
22
from mibuild.crg import SimpleCRG
33
from mibuild.xilinx_ise import XilinxISEPlatform
4+
from mibuild.programmer import UrJTAG
45

56
_io = [
67
("user_led", 0, Pins("V5"), IOStandard("LVCMOS33"), Drive(24), Misc("SLEW=QUIETIO")),
@@ -159,6 +160,9 @@ def __init__(self):
159160
lambda p: SimpleCRG(p, "clk50", None))
160161
self.add_platform_command("CONFIG VCCAUX=\"3.3\";\n")
161162

163+
def create_programmer(self):
164+
return UrJTAG("fjmem-mixxeo.bit")
165+
162166
def do_finalize(self, fragment):
163167
try:
164168
self.add_period_constraint(self.lookup_request("clk50"), 20)

‎mibuild/platforms/papilio_pro.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from mibuild.generic_platform import *
22
from mibuild.crg import SimpleCRG
33
from mibuild.xilinx_ise import XilinxISEPlatform
4+
from mibuild.programmer import XC3SProg
45

56
_io = [
67
("user_led", 0, Pins("P112"), IOStandard("LVCMOS33"), Drive(24), Misc("SLEW=QUIETIO")),
@@ -53,6 +54,9 @@ def __init__(self):
5354
XilinxISEPlatform.__init__(self, "xc6slx9-tqg144-2", _io,
5455
lambda p: SimpleCRG(p, "clk32", None), _connectors)
5556

57+
def create_programmer(self):
58+
return XC3SProg("papilio", "bscan_spi_lx9_papilio.bit")
59+
5660
def do_finalize(self, fragment):
5761
try:
5862
self.add_period_constraint(self.lookup_request("clk32"), 31.25)

‎mibuild/programmer.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import subprocess
2+
import os
3+
4+
class Programmer:
5+
def __init__(self, flash_proxy_basename=None):
6+
self.flash_proxy_basename = flash_proxy_basename
7+
self.flash_proxy_dirs = ["~/.mlabs", "/usr/local/share/mlabs", "/usr/share/mlabs"]
8+
9+
def set_flash_proxy_dir(self, flash_proxy_dir):
10+
if flash_proxy_dir is not None:
11+
self.flash_proxy_dirs = [flash_proxy_dir]
12+
13+
def find_flash_proxy(self):
14+
for d in self.flash_proxy_dirs:
15+
fulldir = os.path.abspath(os.path.expanduser(d))
16+
fullname = os.path.join(fulldir, self.flash_proxy_basename)
17+
if os.path.exists(fullname):
18+
return fullname
19+
raise OSError("Failed to find flash proxy bitstream")
20+
21+
def _run_urjtag(cmds):
22+
with subprocess.Popen("jtag", stdin=subprocess.PIPE) as process:
23+
process.stdin.write(cmds.encode("ASCII"))
24+
process.communicate()
25+
26+
class UrJTAG(Programmer):
27+
needs_bitreverse = True
28+
needs_flash_proxy = True
29+
30+
def load_bitstream(self, bitstream_file):
31+
cmds = """cable milkymist
32+
detect
33+
pld load {bitstream}
34+
quit
35+
""".format(bitstream=bitstream_file)
36+
_run_urjtag(cmds)
37+
38+
def flash(self, address, data_file):
39+
flash_proxy = self.find_flash_proxy()
40+
cmds = """cable milkymist
41+
detect
42+
pld load "{flash_proxy}"
43+
initbus fjmem opcode=000010
44+
frequency 6000000
45+
detectflash 0
46+
endian big
47+
flashmem "{address}" "{data_file}" noverify
48+
""".format(flash_proxy=flash_proxy, address=address, data_file=data_file)
49+
_run_urjtag(cmds)
50+
51+
class XC3SProg(Programmer):
52+
needs_bitreverse = False
53+
needs_flash_proxy = True
54+
55+
def __init__(self, cable, flash_proxy_basename=None):
56+
Programmer.__init__(flash_proxy_basename)
57+
self.cable = cable
58+
59+
def load_bitstream(self, bitstream_file):
60+
subprocess.call(["xc3sprog", "-v", "-c", self.cable, bitstream_file])
61+
62+
def flash(self, address, data_file):
63+
flash_proxy = self.find_flash_proxy()
64+
subprocess.call(["xc3sprog", "-v", "-c", self.cable, "-I"+flash_proxy, "{}:w:0x{:x}:BIN".format(data_file, address)])
65+
66+
class USBBlaster(Programmer):
67+
needs_bitreverse = False
68+
needs_flash_proxy = False
69+
70+
def load_bitstream(self, bitstream_file, port=0):
71+
usb_port = "[USB-"+str(port)+"]"
72+
subprocess.call(["quartus_pgm", "-m", "jtag", "-c", "USB-Blaster"+usb_port, "-o", "p;"+bitstream_file])
73+
74+
def flash(self, address, data_file):
75+
raise NotImplementedError

0 commit comments

Comments
 (0)
Please sign in to comment.