Skip to content

Instantly share code, notes, and snippets.

@SubaruArai
Last active July 13, 2022 04:32
Show Gist options
  • Save SubaruArai/a7e7ff8465dad123d764c42f3f3707ba to your computer and use it in GitHub Desktop.
Save SubaruArai/a7e7ff8465dad123d764c42f3f3707ba to your computer and use it in GitHub Desktop.
cross compiling openocd for rp2040 from linux to windows
sudo apt install automake autoconf build-essential texinfo libtool pkg-config mingw-w64 autopoint flex cmake git
BUILD_DIR="$(pwd)/openocd_build"
LIBUSB1_BUILD_DIR=${BUILD_DIR}/libusb
LIBUSB0_BUILD_DIR=${BUILD_DIR}/libusb-compat
LIBCONFUSE_BUILD_DIR=${BUILD_DIR}/libconfuse
HIDAPI_BUILD_DIR=${BUILD_DIR}/hidapi
LIBFTDI_BUILD_DIR=${BUILD_DIR}/libftdi
mkdir -p ${BUILD_DIR}
pushd ${BUILD_DIR}
git clone --depth 1 --branch tags/v1.0.26 https://github.com/libusb/libusb.git libusb
pushd libusb
./bootstrap.sh
./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared
make
popd
git clone --depth 1 --branch tags/v0.1.7 https://github.com/libusb/libusb-compat-0.1.git libusb-compat
pushd libusb-compat
./autogen.sh
LIBUSB_1_0_CFLAGS="-I${LIBUSB1_BUILD_DIR}/libusb" \
LIBUSB_1_0_LIBS="-L${LIBUSB1_BUILD_DIR}/libusb/.libs -lusb-1.0" \
PKG_CONFIG_PATH=${LIBUSB1_BUILD_DIR} \
./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared
make
popd
git clone --depth 1 --branch tags/v3.3 https://github.com/martinh/libconfuse.git libconfuse
pushd libconfuse
./autogen.sh
# --disable-examples is needed for building with mingw
./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared --disable-examples
make
popd
git clone --depth 1 --branch tags/v1.5 git://developer.intra2net.com/libftdi libftdi
pushd libftdi
mkdir build
pushd build
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-x86_64-w64-mingw32.cmake \
-DLIBUSB_LIBRARIES=${LIBUSB1_BUILD_DIR}/libusb/.libs/ \
-DLIBUSB_INCLUDE_DIR=${LIBUSB1_BUILD_DIR}/libusb \
-DCONFUSE_LIBRARY=${LIBCONFUSE_BUILD_DIR}/src/.libs/ \
-DCONFUSE_INCLUDE_DIR=${LIBCONFUSE_BUILD_DIR}/src/ ../
make ftdi1-static
popd
popd
git clone --depth 1 --branch tags/hidapi-0.12.0 https://github.com/libusb/hidapi.git hidapi
pushd hidapi
./bootstrap
./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared
make
popd
git clone https://github.com/raspberrypi/openocd.git --branch rp2040
pushd openocd
# this is the tested version of openocd, change as needed
git checkout 228ede43db3665e470d2e518730de013a8c74411
./bootstrap
HIDAPI_CFLAGS="-I${HIDAPI_BUILD_DIR}/hidapi" \
HIDAPI_LIBS="-L${HIDAPI_BUILD_DIR}/windows/.libs -lhidapi" \
LIBUSB0_CFLAGS="-I${LIBUSB0_BUILD_DIR}/libusb" \
LIBUSB0_LIBS="-L${LIBUSB0_BUILD_DIR}/libusb/.libs -lusb" \
LIBUSB1_CFLAGS="-I${LIBUSB1_BUILD_DIR}/libusb" \
LIBUSB1_LIBS="-L${LIBUSB1_BUILD_DIR}/libusb/.libs -lusb-1.0" \
LIBFTDI_CFLAGS="-I${LIBFTDI_BUILD_DIR}/src " \
LIBFTDI_LIBS="-L${LIBFTDI_BUILD_DIR}/build/src -lftdi1" \
PKG_CONFIG_PATH=${HIDAPI_BUILD_DIR}/pc:${LIBUSB1_BUILD_DIR}:${LIBUSB0_BUILD_DIR}:${LIBFTDI_BUILD_DIR}/build \
libusb_CFLAGS="-I${LIBUSB1_BUILD_DIR}/libusb" \
libusb_LIBS="-L${LIBUSB1_BUILD_DIR}/libusb/.libs/ -lusb-1.0" \
./configure --host=x86_64-w64-mingw32 --enable-static --disable-shared --enable-picoprobe
make
popd
# now copy the built files to your windows system with the following structure:
# openocd
# |-openocd.exe (copy from openocd/src/openocd.exe)
# |-tcl (copy from openocd/tcl)
# | |- (everything under tcl must be here)
# `.\openocd.exe -f interface/picoprobe.cfg -f target/rp2040.cfg -s tcl` to run in windows
@SubaruArai
Copy link
Author

SubaruArai commented Jul 13, 2022

Credit goes to this blog post and the official cross-compile guide.

Tested under Ubuntu 22.04 LTS in a container(podman) -> Windows 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment