build/openfpgaloader: Add kwargs support to flash method and some comments.

This commit is contained in:
Florent Kermarrec 2024-01-02 13:43:48 +01:00
parent acf07a21c9
commit 3909b1d611
1 changed files with 32 additions and 1 deletions

View File

@ -13,31 +13,62 @@ class OpenFPGALoader(GenericProgrammer):
needs_bitreverse = False needs_bitreverse = False
def __init__(self, board="", cable="", freq=0, fpga_part="", index_chain=None): def __init__(self, board="", cable="", freq=0, fpga_part="", index_chain=None):
# openFPGALoader base command.
self.cmd = ["openFPGALoader"] self.cmd = ["openFPGALoader"]
# Specify FPGA board.
if board: if board:
self.cmd += ["--board", board] self.cmd += ["--board", board]
# Specify FPGA part/device.
if fpga_part: if fpga_part:
self.cmd += ["--fpga-part", fpga_part] self.cmd += ["--fpga-part", fpga_part]
# Specify programmation cable.
if cable: if cable:
self.cmd += ["--cable", cable] self.cmd += ["--cable", cable]
# Specify programmation frequency.
if freq: if freq:
self.cmd += ["--freq", str(int(float(freq)))] self.cmd += ["--freq", str(int(float(freq)))]
# Specify index in the JTAG chain.
if index_chain is not None: if index_chain is not None:
self.cmd += ["--index-chain", str(int(index_chain))] self.cmd += ["--index-chain", str(int(index_chain))]
def load_bitstream(self, bitstream_file): def load_bitstream(self, bitstream_file):
# Load base command.
cmd = self.cmd + ["--bitstream", bitstream_file] cmd = self.cmd + ["--bitstream", bitstream_file]
# Execute command.
self.call(cmd) self.call(cmd)
def flash(self, address, data_file, external=False, unprotect_flash=False, verify=False): def flash(self, address, data_file, external=False, unprotect_flash=False, verify=False, **kwargs):
# Flash base command.
cmd = self.cmd + ["--write-flash", "--bitstream", data_file] cmd = self.cmd + ["--write-flash", "--bitstream", data_file]
# Flash Internal/External selection.
if external: if external:
cmd += ["--external-flash"] cmd += ["--external-flash"]
# Flash Offset.
if address: if address:
cmd += ["--offset"] cmd += ["--offset"]
cmd += [str(address)] cmd += [str(address)]
# Flash Unprotect.
if unprotect_flash: if unprotect_flash:
cmd += ["--unprotect-flash"] cmd += ["--unprotect-flash"]
# Flash Verify.
if verify: if verify:
cmd += ["--verify"] cmd += ["--verify"]
# Handle kwargs for specific, less common cases.
for key, value in kwargs.items():
cmd.append(f"--{key}")
if value is not None:
cmd.append(str(value))
# Execute Command.
self.call(cmd) self.call(cmd)