Skip to content

Commit

Permalink
Use two versions of openocd.
Browse files Browse the repository at this point in the history
openocd-vexriscv is required because openocd-riscv does not allow the CPU to be reset while openocd is connected. This is unfortunately required for the current state of swCcTopologyTest and is non-trivial to fix.

We intend to at some point remove this test case and get rid of the custom openocd version in favor of the "official" riscv version.
  • Loading branch information
lmbollen committed Feb 19, 2025
1 parent da607a6 commit ffd3339
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bittide-instances/data/openocd/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ mkdir -p "${stderr_dir}"
OPENOCD_STDERR_LOG="$(realpath ${OPENOCD_STDERR_LOG})"

cd $(dirname $0)
exec openocd-riscv -f ports.tcl -f sipeed.tcl -f vexriscv_init.tcl $@ \
exec ${OPENOCD_BIN} -f ports.tcl -f sipeed.tcl -f vexriscv_init.tcl $@ \
> >(tee "${OPENOCD_STDOUT_LOG}") \
2> >(tee "${OPENOCD_STDERR_LOG}" >&2)
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ driverFunc testName targets = do
putStrLn "Starting OpenOCD..."
(ocd, ocdPh, ocdClean1) <-
startOpenOcdWithEnv
[("OPENOCD_STDOUT_LOG", ocdStdout), ("OPENOCD_STDERR_LOG", ocdStderr)]
[ ("OPENOCD_STDOUT_LOG", ocdStdout)
, ("OPENOCD_STDERR_LOG", ocdStderr)
, ("OPENOCD_BIN", "openocd-vexriscv")
]
d.usbAdapterLocation
gdbPort
tclPort
Expand Down
10 changes: 8 additions & 2 deletions bittide-instances/src/Bittide/Instances/Hitl/Utils/Program.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ startOpenOcdWithEnv ::
-- | Telnet port
Int ->
IO (ProcessStdIoHandles, ProcessHandle, IO ())
startOpenOcdWithEnv extraEnv usbLoc gdbPort tclPort telnetPort = do
startOpenOcdWithEnv extraEnv0 usbLoc gdbPort tclPort telnetPort = do
-- Check if OPENOCD_BIN is set. If not, append ("OPENOCD_BIN", "openocd") to the environment.
-- This is necessary because swCcTopologiesTest relies on the custom OpenOCD binary.
let extraEnv1
| any ((== "OPENOCD_BIN") . fst) extraEnv0 = extraEnv0
| otherwise = ("OPENOCD_BIN", "openocd") : extraEnv0

startOpenOcdPath <- getOpenOcdStartPath
currentEnv <- getEnvironment
let
Expand All @@ -113,7 +119,7 @@ startOpenOcdWithEnv extraEnv usbLoc gdbPort tclPort telnetPort = do
, env =
Just
( currentEnv
<> extraEnv
<> extraEnv1
<> [ ("USB_DEVICE", usbLoc)
, ("GDB_PORT", show gdbPort)
, ("TCL_PORT", show tclPort)
Expand Down
1 change: 1 addition & 0 deletions nix/bin/install-openocd-vexriscv-udev
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ if [ -f "${UDEV_RULES_D}/${UDEV_RULES_BASENAME}" ]; then
echo "'${UDEV_RULES_D}/${UDEV_RULES_BASENAME}' already exists, doing nothing"
else
exec_print sudo cp "$OPENOCD_DIST/share/openocd/contrib/${UDEV_RULES_BASENAME}" "${UDEV_RULES_D}"
exec_print sudo cp "$VEXOPENOCD_DIST/share/openocd/contrib/${UDEV_RULES_BASENAME}" "${UDEV_RULES_D}"
exec_print sudo udevadm control --reload-rules
fi
1 change: 1 addition & 0 deletions nix/nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let

verilog-ethernet = import ./verilog-ethernet.nix { inherit (nixpkgs) pkgs; };
mc = import ./mc.nix { inherit (nixpkgs) pkgs; };
openocd-vexriscv = import ./openocd-vexriscv.nix { inherit (nixpkgs) pkgs; };
openocd-riscv = import ./openocd-riscv.nix { inherit (nixpkgs) pkgs; };

# Haskell overrides
Expand Down
38 changes: 38 additions & 0 deletions nix/openocd-vexriscv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{ pkgs ? import ./nixpkgs.nix {} }:

pkgs.stdenv.mkDerivation rec {
name = "openocd-vexriscv";

buildInputs = [
pkgs.autoconf
pkgs.automake
pkgs.coreutils
pkgs.git
pkgs.libtool
pkgs.libusb1
pkgs.libyaml
pkgs.pkg-config
pkgs.texinfo
pkgs.which
];

src = pkgs.fetchgit {
url = "https://github.com/SpinalHDL/openocd_riscv.git";
rev = "058dfa50d625893bee9fecf8d604141911fac125";
sha256 = "sha256-UuX4Zfr9DiJx60nvBAv+9xCbWXExrk5KNSC5V5e4rsw=";
fetchSubmodules = true;
deepClone = true;
postFetch = ''
# See: https://github.com/NixOS/nixpkgs/issues/8567#issuecomment-1846499599
find "$out/" -type d -name '.git' | xargs rm -rf
'';
};

installPhase = ''
SKIP_SUBMODULE=1 ./bootstrap
./configure --enable-ftdi --enable-dummy --prefix=$out
make -j $(nproc)
make install
mv $out/bin/openocd $out/bin/openocd-vexriscv
'';
}
4 changes: 4 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pkgs.mkShell {
pkgs.pcre

# VexRiscv OpenOCD
pkgs.openocd-vexriscv
pkgs.openocd-riscv
pkgs.gdb

Expand All @@ -78,7 +79,10 @@ pkgs.mkShell {
# Prevents Perl warnings
export LC_ALL="C.UTF-8";
export VERILOG_ETHERNET_SRC="${pkgs.verilog-ethernet}"
# TODO: Get rid of custom OpenOCD build for sWCcTopologyTest
export OPENOCD_DIST="${pkgs.openocd-riscv}"
export VEXOPENOCD_DIST="${pkgs.openocd-vexriscv}"
# We use unstable features (floating point), we don't want to hear about it
# every time we build.
Expand Down

0 comments on commit ffd3339

Please sign in to comment.