From 35dd87499c99c76a594044981bfd1a5fd06f4a98 Mon Sep 17 00:00:00 2001 From: Jiaxun Yang Date: Tue, 5 Mar 2024 21:34:56 +0000 Subject: [PATCH 1/3] build/openocd: Disable polling after init OpenOCD's event polling mechanism may interfere with jtagstream, as we don't expect any command sent by openocd itself. Signed-off-by: Jiaxun Yang --- litex/build/openocd.py | 1 + 1 file changed, 1 insertion(+) diff --git a/litex/build/openocd.py b/litex/build/openocd.py index 2a8f47684..8518a586c 100644 --- a/litex/build/openocd.py +++ b/litex/build/openocd.py @@ -185,6 +185,7 @@ proc jtagstream_serve {tap port} { write_to_file("stream.cfg", cfg) script = "; ".join([ "init", + "poll off", "irscan $_CHIPNAME.tap {:d}".format(ir), "jtagstream_serve $_CHIPNAME.tap {:d}".format(port), "exit", From 18720e29cc4c03207816b79112132f971f43eb19 Mon Sep 17 00:00:00 2001 From: Jiaxun Yang Date: Tue, 5 Mar 2024 21:42:59 +0000 Subject: [PATCH 2/3] build/openocd: Fix tap name for zynq_7000 zynq_7000 have a special tap name fpr PL defined in openocd config file. Just hardcode it here. Signed-off-by: Jiaxun Yang --- litex/build/openocd.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/litex/build/openocd.py b/litex/build/openocd.py index 8518a586c..166fb2e26 100644 --- a/litex/build/openocd.py +++ b/litex/build/openocd.py @@ -40,6 +40,12 @@ class OpenOCD(GenericProgrammer): ]) self.call(["openocd", "-f", config, "-c", script]) + def get_tap_name(self, config): + cfg_str = open(config).read() + if "zynq_7000" in cfg_str: + return "zynq_pl.bs" + return "$_CHIPNAME.tap" + def get_ir(self, chain, config): cfg_str = open(config).read() # Lattice ECP5. @@ -98,6 +104,7 @@ class OpenOCD(GenericProgrammer): - TX valid : bit 9 """ config = self.find_config() + tap_name = self.get_tap_name(config) ir = self.get_ir(chain, config) endstate = self.get_endstate(config) cfg = """ @@ -186,8 +193,8 @@ proc jtagstream_serve {tap port} { script = "; ".join([ "init", "poll off", - "irscan $_CHIPNAME.tap {:d}".format(ir), - "jtagstream_serve $_CHIPNAME.tap {:d}".format(port), + "irscan {} {:d}".format(tap_name, ir), + "jtagstream_serve {} {:d}".format(tap_name, port), "exit", ]) self.call(["openocd", "-f", config, "-f", "stream.cfg", "-c", script]) From a7d441488c784859813579321581c80dc7fc10ba Mon Sep 17 00:00:00 2001 From: Jiaxun Yang Date: Thu, 7 Mar 2024 19:54:04 +0000 Subject: [PATCH 3/3] build/openocd: Allow config file to be searched from local dirs To sort out path for boards using OpenOCD config file shipped with OpenOCD itself. Signed-off-by: Jiaxun Yang --- litex/build/generic_programmer.py | 9 ++++++--- litex/build/openocd.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/litex/build/generic_programmer.py b/litex/build/generic_programmer.py index de968f60d..4c7f602d8 100644 --- a/litex/build/generic_programmer.py +++ b/litex/build/generic_programmer.py @@ -24,6 +24,7 @@ class GenericProgrammer: self.flash_proxy_repos = [ "https://github.com/quartiq/bscan_spi_bitstreams/raw/master/", ] + self.config_dirs = ["prog"] self.config_repos = [ "https://raw.githubusercontent.com/litex-hub/litex-boards/master/litex_boards/prog/", ] @@ -65,9 +66,11 @@ class GenericProgrammer: if os.path.exists(fullname): return self.config # Search in local config directory - fullname = tools.cygpath(os.path.join(self.prog_local, self.config)) - if os.path.exists(fullname): - return fullname + for d in self.config_dirs: + fulldir = os.path.abspath(os.path.expanduser(d)) + fullname = tools.cygpath(os.path.join(fulldir, self.config)) + if os.path.exists(fullname): + return fullname # Search in repositories and download it import requests os.makedirs(self.prog_local, exist_ok=True) diff --git a/litex/build/openocd.py b/litex/build/openocd.py index 166fb2e26..b95d9f1a2 100644 --- a/litex/build/openocd.py +++ b/litex/build/openocd.py @@ -17,6 +17,8 @@ class OpenOCD(GenericProgrammer): def __init__(self, config, flash_proxy_basename=None): GenericProgrammer.__init__(self, flash_proxy_basename) self.config = config + self.config_dirs.append("/usr/share/openocd/scripts") + self.config_dirs.append("/usr/local/share/openocd/scripts") def load_bitstream(self, bitstream): config = self.find_config()