|
11 | 11 | # The 101 variant is eguivalent to the LiteFury and 215 variant equivalent to the NiteFury from |
12 | 12 | # RHSResearchLLC that are documented at: https://github.com/RHSResearchLLC/NiteFury-and-LiteFury. |
13 | 13 |
|
| 14 | +import subprocess |
| 15 | + |
14 | 16 | from litex.build.generic_platform import * |
15 | | -from litex.build.xilinx import Xilinx7SeriesPlatform, VivadoProgrammer |
16 | | -from litex.build.openocd import OpenOCD |
| 17 | +from litex.build.xilinx import Xilinx7SeriesPlatform |
| 18 | +from litex.build.openocd import OpenOCD |
| 19 | +from litex.build.openfpgaloader import OpenFPGALoader |
17 | 20 |
|
18 | 21 | # IOs ---------------------------------------------------------------------------------------------- |
19 | 22 |
|
@@ -197,17 +200,26 @@ def __init__(self, variant="cle-215+", toolchain="vivado"): |
197 | 200 | "write_cfgmem -force -format bin -interface spix4 -size 16 -loadbit \"up 0x0 {build_name}_fallback.bit\" -file {build_name}_fallback.bin" |
198 | 201 | ] |
199 | 202 |
|
200 | | - def create_programmer(self, name='openocd'): |
201 | | - proxy = { |
202 | | - "cle-101": "bscan_spi_xc7a100t.bit", |
203 | | - "cle-215": "bscan_spi_xc7a200t.bit", |
204 | | - "cle-215+": "bscan_spi_xc7a200t.bit" |
205 | | - }[self.variant] |
206 | | - if name == 'openocd': |
207 | | - return OpenOCD("openocd_xc7_ft232.cfg", proxy) |
208 | | - elif name == 'vivado': |
209 | | - # TODO: some board versions may have s25fl128s |
210 | | - return VivadoProgrammer(flash_part='s25fl256sxxxxxx0-spi-x1_x2_x4') |
| 203 | + def detect_ftdi_chip(self): |
| 204 | + lsusb_log = subprocess.run(['lsusb'], capture_output=True, text=True) |
| 205 | + for ftdi_chip in ["ft232", "ft2232", "ft4232"]: |
| 206 | + if f"Future Technology Devices International, Ltd {ftdi_chip.upper()}" in lsusb_log.stdout: |
| 207 | + return ftdi_chip |
| 208 | + return None |
| 209 | + |
| 210 | + def create_programmer(self, name="openfpgaloader"): |
| 211 | + ftdi_chip = self.detect_ftdi_chip() |
| 212 | + if ftdi_chip is None: |
| 213 | + raise RuntimeError("No compatible FTDI device found.") |
| 214 | + device = { |
| 215 | + "cle-101": "xc7a100t", |
| 216 | + "cle-215": "xc7a200t", |
| 217 | + "cle-215+": "xc7a200t" |
| 218 | + }[self.variant] |
| 219 | + if name == "openfpgaloader": |
| 220 | + return OpenFPGALoader(cable=ftdi_chip, fpga_part="{device}fbg484", freq=10e6) |
| 221 | + elif name == "openocd": |
| 222 | + return OpenOCD(f"openocd_xc7_{ftdi_chip}.cfg", f"bscan_spi_{device}.bit") |
211 | 223 |
|
212 | 224 | def do_finalize(self, fragment): |
213 | 225 | Xilinx7SeriesPlatform.do_finalize(self, fragment) |
|
0 commit comments