Skip to content

Commit 3a626a9

Browse files
committed
scripts: Add OpenOCD build script
Add a script to build OpenOCD for macOS and Windows, and update the CI workflow to use it. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 398641d commit 3a626a9

File tree

2 files changed

+181
-1
lines changed

2 files changed

+181
-1
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ jobs:
10331033
${BREW} install \
10341034
ccache \
10351035
cmake \
1036+
gcc \
10361037
meson \
10371038
ninja \
10381039
pkg-config
@@ -1162,7 +1163,18 @@ jobs:
11621163
11631164
# TODO: Build ARC QEMU
11641165
# TODO: Build Xilinx QEMU
1165-
# TODO: Build OpenOCD
1166+
1167+
# Build OpenOCD
1168+
OPENOCD_BUILD="${WORKSPACE}/build/openocd"
1169+
OPENOCD_SOURCE="${GITHUB_WORKSPACE}/openocd"
1170+
1171+
mkdir -p ${OPENOCD_BUILD}
1172+
pushd ${OPENOCD_BUILD}
1173+
${BUILD_PRECMD} ${GITHUB_WORKSPACE}/scripts/build_openocd.sh \
1174+
${{ matrix.host.name }} \
1175+
${OPENOCD_SOURCE} \
1176+
${BUILD_OUTPUT}
1177+
popd
11661178
11671179
# Create archive
11681180
ARCHIVE_NAME=hosttools_${{ matrix.host.name }}

scripts/build_openocd.sh

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
LIBUSB_VERSION="1.0.29"
6+
HIDAPI_VERSION="0.15.0"
7+
LIBFTDI_VERSION="1.4"
8+
9+
usage()
10+
{
11+
echo "Usage: $(basename $0) host source output"
12+
}
13+
14+
# Validate and parse arguments
15+
if [ "$1" == "" ]; then
16+
usage
17+
echo
18+
echo "host must be specified."
19+
exit 1
20+
elif [ "$2" == "" ]; then
21+
usage
22+
echo
23+
echo "source must be specified."
24+
exit 1
25+
elif [ "$3" == "" ]; then
26+
usage
27+
echo
28+
echo "output must be specified."
29+
exit 1
30+
fi
31+
32+
BUILD_HOST="$1"
33+
BUILD_SOURCE="$2"
34+
BUILD_OUTPUT="$3"
35+
BUILD_SYSROOT="${PWD}/sysroot"
36+
37+
# Set build parameters
38+
OPENOCD_FLAGS=" \
39+
--enable-ftdi \
40+
--enable-cmsis-dap \
41+
--enable-jlink \
42+
--enable-stlink \
43+
--disable-doxygen-html \
44+
--disable-git-update \
45+
--disable-werror \
46+
"
47+
48+
if [ "${BUILD_HOST}" == "windows-x86_64" ]; then
49+
BUILD_PREFIX="${BUILD_OUTPUT}/openocd"
50+
51+
OPENOCD_FLAGS+="--host=x86_64-w64-mingw32"
52+
elif [[ "${BUILD_HOST}" =~ ^macos-.* ]]; then
53+
BUILD_PREFIX="${BUILD_OUTPUT}/opt/openocd"
54+
55+
case ${BUILD_HOST} in
56+
macos-aarch64)
57+
HOMEBREW_PREFIX="/opt/homebrew"
58+
;;
59+
macos-x86_64)
60+
HOMEBREW_PREFIX="/usr/local"
61+
;;
62+
esac
63+
64+
# Ensure that arch-specific Homebrew environment is configured
65+
eval $(${HOMEBREW_PREFIX}/bin/brew shellenv)
66+
67+
# Make pkg-config look for the libraries from the build sysroot
68+
export PKG_CONFIG_PATH="${BUILD_SYSROOT}/lib/pkgconfig"
69+
70+
# Specify statically linked libraries and their dependencies
71+
export LDFLAGS=" \
72+
-framework CoreFoundation \
73+
-framework IOKit \
74+
-framework Security \
75+
"
76+
77+
# Build static libraries required by OpenOCD. These libraries are manually
78+
# built because the corresponding Homebrew packages do not provide usable
79+
# static libraries.
80+
81+
## libusb
82+
wget https://github.com/libusb/libusb/releases/download/v${LIBUSB_VERSION}/libusb-${LIBUSB_VERSION}.tar.bz2
83+
tar xvf libusb-${LIBUSB_VERSION}.tar.bz2
84+
mkdir build-libusb
85+
pushd build-libusb
86+
../libusb-${LIBUSB_VERSION}/configure \
87+
--prefix=${BUILD_SYSROOT} \
88+
--enable-static \
89+
--disable-shared
90+
make -j
91+
make install
92+
popd
93+
94+
## hidapi
95+
wget https://github.com/libusb/hidapi/archive/refs/tags/hidapi-${HIDAPI_VERSION}.tar.gz
96+
tar xvf hidapi-${HIDAPI_VERSION}.tar.gz
97+
mkdir build-hidapi
98+
pushd build-hidapi
99+
cmake \
100+
-DCMAKE_INSTALL_PREFIX=${BUILD_SYSROOT} \
101+
-DBUILD_SHARED_LIBS=OFF \
102+
../hidapi-hidapi-${HIDAPI_VERSION}
103+
cmake --build .
104+
cmake --install .
105+
popd
106+
107+
## libftdi
108+
wget https://www.intra2net.com/en/developer/libftdi/download/libftdi1-${LIBFTDI_VERSION}.tar.bz2
109+
tar xvf libftdi1-${LIBFTDI_VERSION}.tar.bz2
110+
mkdir build-libftdi
111+
pushd build-libftdi
112+
cmake \
113+
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
114+
-DCMAKE_PREFIX_PATH=${BUILD_SYSROOT} \
115+
-DCMAKE_INSTALL_PREFIX=${BUILD_SYSROOT} \
116+
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=ON \
117+
-DSTATICLIBS=ON \
118+
-DBUILD_TESTS=OFF \
119+
-DDOCUMENTATION=OFF \
120+
../libftdi1-${LIBFTDI_VERSION}
121+
cmake --build .
122+
cmake --install .
123+
rm -f ${BUILD_SYSROOT}/lib/libftdi*.dylib
124+
popd
125+
else
126+
echo "ERROR: Invalid build host '${BUILD_HOST}'"
127+
exit 1
128+
fi
129+
130+
# Build OpenOCD
131+
pushd ${BUILD_SOURCE}
132+
./bootstrap
133+
popd
134+
135+
mkdir build-openocd
136+
pushd build-openocd
137+
138+
${BUILD_SOURCE}/configure \
139+
${OPENOCD_FLAGS} \
140+
--prefix="${BUILD_PREFIX}"
141+
142+
make -j
143+
make install
144+
145+
popd
146+
147+
# Copy required dynamic-link libraries for Windows
148+
if [ "${BUILD_HOST}" == "windows-x86_64" ]; then
149+
OPENOCD_WIN_LIBS=" \
150+
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libftdi1.dll \
151+
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libhidapi.dll \
152+
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libusb-1.0.dll \
153+
"
154+
155+
for l in ${OPENOCD_WIN_LIBS}; do
156+
cp -f ${l} ${BUILD_PREFIX}/bin
157+
done
158+
fi
159+
160+
# Symlink OpenOCD executable for macOS
161+
if [[ "${BUILD_HOST}" =~ ^macos-.* ]]; then
162+
mkdir -p ${BUILD_OUTPUT}/usr/bin
163+
pushd ${BUILD_OUTPUT}/usr/bin
164+
165+
ln -sf ../../opt/openocd/bin/openocd openocd
166+
167+
popd
168+
fi

0 commit comments

Comments
 (0)