From 5847e04be846be02482fca57c1e29a54ed9faa8d Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Sat, 16 Nov 2024 22:13:20 +0100 Subject: [PATCH] west: runner: add support for ecpprog The ecpprog command is an utility written by Greg Davill for flashing FPGAs such as ECP5 or CrossLink-NX series. Devkits typically have an FTDI interface chip to access the external flash. FPGA image is typically at flash offset 0x00000000 flash offset, and the Zephyr image offset can be set via CONFIG_FLASH_LOAD_OFFSET. Signed-off-by: Josuah Demangeon --- boards/common/ecpprog.board.cmake | 5 +++ scripts/west_commands/runners/__init__.py | 1 + scripts/west_commands/runners/ecpprog.py | 41 +++++++++++++++++++++ scripts/west_commands/tests/test_imports.py | 1 + 4 files changed, 48 insertions(+) create mode 100644 boards/common/ecpprog.board.cmake create mode 100644 scripts/west_commands/runners/ecpprog.py diff --git a/boards/common/ecpprog.board.cmake b/boards/common/ecpprog.board.cmake new file mode 100644 index 00000000000..25aa5914f08 --- /dev/null +++ b/boards/common/ecpprog.board.cmake @@ -0,0 +1,5 @@ +# Copyright (c) 2024 tinyVision.ai Inc. +# SPDX-License-Identifier: Apache-2.0 + +board_set_flasher_ifnset(ecpprog) +board_finalize_runner_args(ecpprog) diff --git a/scripts/west_commands/runners/__init__.py b/scripts/west_commands/runners/__init__.py index 5fd582fc952..3ed333c24c2 100644 --- a/scripts/west_commands/runners/__init__.py +++ b/scripts/west_commands/runners/__init__.py @@ -31,6 +31,7 @@ _names = [ 'canopen_program', 'dediprog', 'dfu', + 'ecpprog', 'esp32', 'ezflashcli', 'gd32isp', diff --git a/scripts/west_commands/runners/ecpprog.py b/scripts/west_commands/runners/ecpprog.py new file mode 100644 index 00000000000..48454c2c8a5 --- /dev/null +++ b/scripts/west_commands/runners/ecpprog.py @@ -0,0 +1,41 @@ +# Copyright (c) 2024 tinyVision.ai Inc. +# +# SPDX-License-Identifier: Apache-2.0 + +"""Runner for the ecpprog programming tool for Lattice FPGAs.""" +# https://github.com/gregdavill/ecpprog + +from runners.core import BuildConfiguration, RunnerCaps, ZephyrBinaryRunner + + +class EcpprogBinaryRunner(ZephyrBinaryRunner): + """Runner front-end for programming the FPGA flash at some offset.""" + + def __init__(self, cfg, device=None): + super().__init__(cfg) + self.device = device + + @classmethod + def name(cls): + return "ecpprog" + + @classmethod + def capabilities(cls): + return RunnerCaps(commands={"flash"}) + + @classmethod + def do_add_parser(cls, parser): + parser.add_argument( + "--device", dest="device", help="Device identifier such as i::" + ) + + @classmethod + def do_create(cls, cfg, args): + return EcpprogBinaryRunner(cfg, device=args.device) + + def do_run(self, command, **kwargs): + build_conf = BuildConfiguration(self.cfg.build_dir) + load_offset = build_conf.get("CONFIG_FLASH_LOAD_OFFSET", 0) + command = ("ecpprog", "-o", hex(load_offset), self.cfg.bin_file) + self.logger.debug(" ".join(command)) + self.check_call(command) diff --git a/scripts/west_commands/tests/test_imports.py b/scripts/west_commands/tests/test_imports.py index d47470c5a66..3fb08b68a9e 100644 --- a/scripts/west_commands/tests/test_imports.py +++ b/scripts/west_commands/tests/test_imports.py @@ -22,6 +22,7 @@ def test_runner_imports(): 'canopen', 'dediprog', 'dfu-util', + 'ecpprog', 'esp32', 'ezflashcli', 'gd32isp',