forked from litex-hub/linux-on-litex-vexriscv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackup_make.py
348 lines (275 loc) · 13 KB
/
backup_make.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/usr/bin/env python3
import argparse
import os
from litex.soc.integration.builder import Builder
from soc_linux import SoCLinux, video_resolutions
kB = 1024
# Board definition----------------------------------------------------------------------------------
class Board:
def __init__(self, soc_cls, soc_capabilities):
self.soc_cls = soc_cls
self.soc_capabilities = soc_capabilities
def load(self):
raise NotImplementedError
def flash(self):
raise NotImplementedError
# Daphne support --------------------------------------------------------------------------------
class Daphne(Board):
def __init__(self):
from litex_boards.targets import daphne
Board.__init__(self, daphne.BaseSoC, "serial")
def load(self):
from litex.build.xilinx import VivadoProgrammer
prog = VivadoProgrammer()
prog.load_bitstream("build/daphne/gateware/top.bit")
# Arty support -------------------------------------------------------------------------------------
class Arty(Board):
SPIFLASH_PAGE_SIZE = 256
SPIFLASH_SECTOR_SIZE = 64*kB
def __init__(self):
from litex_boards.targets import arty
Board.__init__(self, arty.EthernetSoC, {"serial", "ethernet", "spiflash", "leds", "rgb_led", "switches", "spi", "i2c", "xadc", "icap_bit"})
def load(self):
from litex.build.openocd import OpenOCD
prog = OpenOCD("prog/openocd_xilinx.cfg")
prog.load_bitstream("build/arty/gateware/top.bit")
def flash(self):
flash_regions = {
"build/arty/gateware/top.bin": "0x00000000", # FPGA image: loaded at startup
"buildroot/Image": "0x00400000", # Linux Image: copied to 0xc0000000 by bios
"buildroot/rootfs.cpio": "0x00800000", # File System: copied to 0xc0800000 by bios
"buildroot/rv32.dtb": "0x00f00000", # Device tree: copied to 0xc1000000 by bios
"emulator/emulator.bin": "0x00f80000", # MM Emulator: copied to 0x20000000 by bios
}
from litex.build.openocd import OpenOCD
prog = OpenOCD("prog/openocd_xilinx.cfg",
flash_proxy_basename="prog/bscan_spi_xc7a35t.bit")
prog.set_flash_proxy_dir(".")
for filename, base in flash_regions.items():
base = int(base, 16)
print("Flashing {} at 0x{:08x}".format(filename, base))
prog.flash(base, filename)
# NeTV2 support ------------------------------------------------------------------------------------
class NeTV2(Board):
SPIFLASH_PAGE_SIZE = 256
SPIFLASH_SECTOR_SIZE = 64*kB
def __init__(self):
from litex_boards.targets import netv2
Board.__init__(self, netv2.EthernetSoC, {"serial", "ethernet", "framebuffer", "spiflash", "leds", "xadc"})
def load(self):
from litex.build.openocd import OpenOCD
prog = OpenOCD("prog/openocd_netv2_rpi.cfg")
prog.load_bitstream("build/netv2/gateware/top.bit")
# Genesys2 support ---------------------------------------------------------------------------------
class Genesys2(Board):
def __init__(self):
from litex_boards.targets import genesys2
Board.__init__(self, genesys2.EthernetSoC, {"serial", "ethernet"})
def load(self):
from litex.build.xilinx import VivadoProgrammer
prog = VivadoProgrammer()
prog.load_bitstream("build/genesys2/gateware/top.bit")
# KC705 support ---------------------------------------------------------------------------------
class KC705(Board):
def __init__(self):
from litex_boards.targets import kc705
Board.__init__(self, kc705.BaseSoC, {"serial", "ethernet", "leds", "xadc"})
def load(self):
from litex.build.xilinx import VivadoProgrammer
prog = VivadoProgrammer()
prog.load_bitstream("build/kc705/gateware/top.bit")
# KCU105 support -----------------------------------------------------------------------------------
class KCU105(Board):
def __init__(self):
from litex_boards.targets import kcu105
Board.__init__(self, kcu105.EthernetSoC, {"serial", "ethernet"})
def load(self):
from litex.build.xilinx import VivadoProgrammer
prog = VivadoProgrammer()
prog.load_bitstream("build/kcu105/gateware/top.bit")
# Nexys4DDR support --------------------------------------------------------------------------------
class Nexys4DDR(Board):
def __init__(self):
from litex_boards.targets import nexys4ddr
Board.__init__(self, nexys4ddr.EthernetSoC, {"serial", "ethernet"})
def load(self):
from litex.build.xilinx import VivadoProgrammer
prog = VivadoProgrammer()
prog.load_bitstream("build/nexys4ddr/gateware/top.bit")
# NexysVideo support -------------------------------------------------------------------------------
class NexysVideo(Board):
def __init__(self):
from litex_boards.targets import nexys_video
Board.__init__(self, nexys_video.EthernetSoC, {"serial", "framebuffer"})
def load(self):
from litex.build.xilinx import VivadoProgrammer
prog = VivadoProgrammer()
prog.load_bitstream("build/nexys_video/gateware/top.bit")
# MiniSpartan6 support -----------------------------------------------------------------------------
class MiniSpartan6(Board):
def __init__(self):
from litex_boards.targets import minispartan6
Board.__init__(self, minispartan6.BaseSoC, {"serial"})
def load(self):
os.system("xc3sprog -c ftdi build/minispartan6/gateware/top.bit")
# Pipistrello support ------------------------------------------------------------------------------
class Pipistrello(Board):
def __init__(self):
from litex_boards.targets import pipistrello
Board.__init__(self, pipistrello.BaseSoC, {"serial"})
def load(self):
os.system("fpgaprog -f build/pipistrello/gateware/top.bit")
# Versa ECP5 support -------------------------------------------------------------------------------
class VersaECP5(Board):
SPIFLASH_PAGE_SIZE = 256
SPIFLASH_SECTOR_SIZE = 64*kB
def __init__(self):
from litex_boards.targets import versa_ecp5
Board.__init__(self, versa_ecp5.EthernetSoC, {"serial", "ethernet", "spiflash"})
def load(self):
os.system("openocd -f prog/ecp5-versa5g.cfg -c \"transport select jtag; init; svf build/versa_ecp5/gateware/top.svf; exit\"")
# ULX3S support ------------------------------------------------------------------------------------
class ULX3S(Board):
def __init__(self):
from litex_boards.targets import ulx3s
Board.__init__(self, ulx3s.BaseSoC, {"serial"})
def load(self):
os.system("ujprog build/ulx3s/gateware/top.svf")
# HADBadge support ---------------------------------------------------------------------------------
class HADBadge(Board):
def __init__(self):
from litex_boards.targets import hadbadge
Board.__init__(self, hadbadge.BaseSoC, {"serial"})
def load(self):
os.system("dfu-util --alt 2 --download build/hadbadge/gateware/top.bit --reset")
# OrangeCrab support -------------------------------------------------------------------------------
class OrangeCrab(Board):
def __init__(self):
from litex_boards.targets import orangecrab
Board.__init__(self, orangecrab.BaseSoC, {"serial"})
def load(self):
os.system("openocd -f openocd/ecp5-versa5g.cfg -c \"transport select jtag; init; svf build/gateware/top.svf; exit\"")
# Cam Link 4K support ------------------------------------------------------------------------------
class CamLink4K(Board):
def __init__(self):
from litex_boards.targets import camlink_4k
Board.__init__(self, camlink_4k.BaseSoC, {"serial"})
def load(self):
os.system("camlink configure build/gateware/top.bit")
# De10Lite support ---------------------------------------------------------------------------------
class De10Lite(Board):
def __init__(self):
from litex_boards.targets import de10lite
Board.__init__(self, de10lite.BaseSoC, {"serial"})
def load(self):
from litex.build.altera import USBBlaster
prog = USBBlaster()
prog.load_bitstream("build/de10lite/gateware/top.sof")
# De0Nano support ----------------------------------------------------------------------------------
class De0Nano(Board):
def __init__(self):
from litex_boards.targets import de0nano
Board.__init__(self, de0nano.BaseSoC, {"serial"})
def load(self):
from litex.build.altera import USBBlaster
prog = USBBlaster()
prog.load_bitstream("build/de0nano/gateware/top.sof")
# Main ---------------------------------------------------------------------------------------------
supported_boards = {
# Xilinx
"arty": Arty,
"netv2": NeTV2,
"genesys2": Genesys2,
"kc705": KC705,
"kcu105": KCU105,
"nexys4ddr": Nexys4DDR,
"nexys_video": NexysVideo,
"minispartan6": MiniSpartan6,
"pipistrello": Pipistrello,
"daphne": Daphne,
# Lattice
"versa_ecp5": VersaECP5,
"ulx3s": ULX3S,
"hadbadge": HADBadge,
"orangecrab": OrangeCrab,
"camlink_4k": CamLink4K,
# Altera/Intel
"de0nano": De0Nano,
"de10lite": De10Lite,
}
def main():
description = "Linux on LiteX-VexRiscv\n\n"
description += "Available boards:\n"
for name in supported_boards.keys():
description += "- " + name + "\n"
parser = argparse.ArgumentParser(description=description, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("--board", required=True, help="FPGA board")
parser.add_argument("--build", action="store_true", help="build bitstream")
parser.add_argument("--load", action="store_true", help="load bitstream (to SRAM)")
parser.add_argument("--flash", action="store_true", help="flash bitstream/images (to SPI Flash)")
parser.add_argument("--local-ip", default="192.168.1.50", help="local IP address")
parser.add_argument("--remote-ip", default="192.168.1.100", help="remote IP address of TFTP server")
parser.add_argument("--spi-bpw", type=int, default=8, help="Bits per word for SPI controller")
parser.add_argument("--spi-sck-freq", type=int, default=1e6, help="SPI clock frequency")
parser.add_argument("--video", default="1920x1080_60Hz", help="video configuration")
args = parser.parse_args()
if args.board == "all":
board_names = list(supported_boards.keys())
else:
args.board = args.board.lower()
args.board = args.board.replace(" ", "_")
board_names = [args.board]
for board_name in board_names:
board = supported_boards[board_name]()
soc_kwargs = {"integrated_rom_size": 0x8000}
if board_name in ["versa_ecp5", "ulx3s", "hadbadge", "orangecrab"]:
soc_kwargs["toolchain"] = "trellis"
if board_name in ["de0nano"]:
soc_kwargs["l2_size"] = 2048 # Not enough blockrams for default l2_size of 8192
soc = SoCLinux(board.soc_cls, **soc_kwargs)
if "spiflash" in board.soc_capabilities:
soc.add_spi_flash()
soc.add_constant("SPIFLASH_PAGE_SIZE", board.SPIFLASH_PAGE_SIZE)
soc.add_constant("SPIFLASH_SECTOR_SIZE", board.SPIFLASH_SECTOR_SIZE)
if "ethernet" in board.soc_capabilities:
soc.configure_ethernet(local_ip=args.local_ip, remote_ip=args.remote_ip)
if "leds" in board.soc_capabilities:
soc.add_leds()
if "rgb_led" in board.soc_capabilities:
soc.add_rgb_led()
if "switches" in board.soc_capabilities:
soc.add_switches()
if "spi" in board.soc_capabilities:
soc.add_spi(args.spi_bpw, args.spi_sck_freq)
if "i2c" in board.soc_capabilities:
soc.add_i2c()
if "xadc" in board.soc_capabilities:
soc.add_xadc()
if "framebuffer" in board.soc_capabilities:
assert args.video in video_resolutions.keys(), "Unsupported video resolution"
video_settings = video_resolutions[args.video]
soc.add_framebuffer(video_settings)
if "icap_bit" in board.soc_capabilities:
soc.add_icap_bitstream()
soc.configure_boot()
build_dir = os.path.join("build", board_name)
if args.build:
builder = Builder(soc, output_dir=build_dir,
csr_json=os.path.join(build_dir, "csr.json"))
else:
builder = Builder(soc, output_dir="build/" + board_name,
compile_software=True, compile_gateware=False,
csr_json=os.path.join(build_dir, "csr.json"))
if board_name == "camlink_4k": # FIXME
builder.build("/usr/local/diamond/3.10_x64/bin/lin64")
else:
builder.build()
soc.generate_dts(board_name)
soc.compile_dts(board_name)
soc.compile_emulator(board_name)
if args.load:
board.load()
if args.flash:
board.flash()
if __name__ == "__main__":
main()