Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ jobs:
MATRIX_HOSTS+='{
"name": "linux-x86_64",
"runner": "zephyr-runner-v2-linux-x64-4xlarge",
"container": "ghcr.io/zephyrproject-rtos/sdk-build:v1.4.1",
"container": "ghcr.io/zephyrproject-rtos/sdk-build:v1.4.2",
"archive": "tar.xz"
},'
fi
Expand All @@ -278,7 +278,7 @@ jobs:
MATRIX_HOSTS+='{
"name": "linux-aarch64",
"runner": "zephyr-runner-v2-linux-arm64-4xlarge",
"container": "ghcr.io/zephyrproject-rtos/sdk-build:v1.4.1",
"container": "ghcr.io/zephyrproject-rtos/sdk-build:v1.4.2",
"archive": "tar.xz"
},'
fi
Expand All @@ -305,7 +305,7 @@ jobs:
MATRIX_HOSTS+='{
"name": "windows-x86_64",
"runner": "zephyr-runner-v2-linux-x64-4xlarge",
"container": "ghcr.io/zephyrproject-rtos/sdk-build:v1.4.1",
"container": "ghcr.io/zephyrproject-rtos/sdk-build:v1.4.2",
"archive": "7z"
},'
fi
Expand Down Expand Up @@ -1033,6 +1033,7 @@ jobs:
${BREW} install \
ccache \
cmake \
gcc \
meson \
ninja \
pkg-config
Expand Down Expand Up @@ -1076,6 +1077,7 @@ jobs:
git submodule update --depth=1 --recursive qemu
git submodule update --depth=1 --recursive qemu_arc
git submodule update --depth=1 --recursive qemu_xilinx
git submodule update --depth=1 --recursive openocd

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
Expand Down Expand Up @@ -1155,13 +1157,24 @@ jobs:
pushd ${QEMU_BUILD}
${BUILD_PRECMD} ${GITHUB_WORKSPACE}/scripts/build_qemu.sh \
${{ matrix.host.name }} \
${GITHUB_WORKSPACE}/qemu \
${QEMU_SOURCE} \
${BUILD_OUTPUT}
popd

# TODO: Build ARC QEMU
# TODO: Build Xilinx QEMU
# TODO: Build OpenOCD

# Build OpenOCD
OPENOCD_BUILD="${WORKSPACE}/build/openocd"
OPENOCD_SOURCE="${GITHUB_WORKSPACE}/openocd"

mkdir -p ${OPENOCD_BUILD}
pushd ${OPENOCD_BUILD}
${BUILD_PRECMD} ${GITHUB_WORKSPACE}/scripts/build_openocd.sh \
${{ matrix.host.name }} \
${OPENOCD_SOURCE} \
${BUILD_OUTPUT}
popd

# Create archive
ARCHIVE_NAME=hosttools_${{ matrix.host.name }}
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@
[submodule "qemu_xilinx"]
path = qemu_xilinx
url = https://github.com/zephyrproject-rtos/xilinx-qemu.git
[submodule "openocd"]
path = openocd
url = https://github.com/zephyrproject-rtos/openocd.git
5 changes: 3 additions & 2 deletions cmake/zephyr/host-tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Darwin)
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/usr)

set_ifndef(QEMU_BIOS ${HOST_TOOLS_HOME}/opt/qemu/share/qemu)
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/opt/openocd/scripts)
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/opt/openocd/share/openocd/scripts)
elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
# For Windows SDK, each host tool component is placed in its own directory
# under the host tools home directory.
Expand All @@ -35,7 +35,8 @@ elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
# Add host tool component binary directories to the prefix paths for
# discovery by the find_program() function.
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/qemu)
list(APPEND CMAKE_PREFIX_PATH ${HOST_TOOLS_HOME}/openocd)

set_ifndef(QEMU_BIOS ${HOST_TOOLS_HOME}/qemu/share)
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/openocd/scripts)
set_ifndef(OPENOCD_DEFAULT_PATH ${HOST_TOOLS_HOME}/openocd/share/openocd/scripts)
endif()
2 changes: 1 addition & 1 deletion meta-zephyr-sdk/recipes-hosttools/openocd/openocd_git.bb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RDEPENDS_${PN} = "libusb1 hidapi"
SRC_URI = " \
gitsm://github.com/zephyrproject-rtos/openocd.git;protocol=https;nobranch=1 \
"
SRCREV = "662bf274f881afa0aec2c21040eedb91146d8c4a"
SRCREV = "${ZEPHYR_SDK_OPENOCD_SRCREV}"

S = "${WORKDIR}/git"

Expand Down
3 changes: 3 additions & 0 deletions meta-zephyr-sdk/scripts/meta-zephyr-sdk-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS} ZEPHYR_SDK_
export ZEPHYR_SDK_QEMU_XILINX_SRCREV=$(cd qemu_xilinx; git rev-parse HEAD)
export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS} ZEPHYR_SDK_QEMU_XILINX_SRCREV"

export ZEPHYR_SDK_OPENOCD_SRCREV=$(cd openocd; git rev-parse HEAD)
export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS} ZEPHYR_SDK_OPENOCD_SRCREV"

# setconf_var, i.e. "MACHINE","qemuarm",$localconf
setconf_var()
{
Expand Down
1 change: 1 addition & 0 deletions openocd
Submodule openocd added at 662bf2
168 changes: 168 additions & 0 deletions scripts/build_openocd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/usr/bin/env bash

set -e

LIBUSB_VERSION="1.0.29"
HIDAPI_VERSION="0.15.0"
LIBFTDI_VERSION="1.4"

usage()
{
echo "Usage: $(basename $0) host source output"
}

# Validate and parse arguments
if [ "$1" == "" ]; then
usage
echo
echo "host must be specified."
exit 1
elif [ "$2" == "" ]; then
usage
echo
echo "source must be specified."
exit 1
elif [ "$3" == "" ]; then
usage
echo
echo "output must be specified."
exit 1
fi

BUILD_HOST="$1"
BUILD_SOURCE="$2"
BUILD_OUTPUT="$3"
BUILD_SYSROOT="${PWD}/sysroot"

# Set build parameters
OPENOCD_FLAGS=" \
--enable-ftdi \
--enable-cmsis-dap \
--enable-jlink \
--enable-stlink \
--disable-doxygen-html \
--disable-git-update \
--disable-werror \
"

if [ "${BUILD_HOST}" == "windows-x86_64" ]; then
BUILD_PREFIX="${BUILD_OUTPUT}/openocd"

OPENOCD_FLAGS+="--host=x86_64-w64-mingw32"
elif [[ "${BUILD_HOST}" =~ ^macos-.* ]]; then
BUILD_PREFIX="${BUILD_OUTPUT}/opt/openocd"

case ${BUILD_HOST} in
macos-aarch64)
HOMEBREW_PREFIX="/opt/homebrew"
;;
macos-x86_64)
HOMEBREW_PREFIX="/usr/local"
;;
esac

# Ensure that arch-specific Homebrew environment is configured
eval $(${HOMEBREW_PREFIX}/bin/brew shellenv)

# Make pkg-config look for the libraries from the build sysroot
export PKG_CONFIG_PATH="${BUILD_SYSROOT}/lib/pkgconfig"

# Specify statically linked libraries and their dependencies
export LDFLAGS=" \
-framework CoreFoundation \
-framework IOKit \
-framework Security \
"

# Build static libraries required by OpenOCD. These libraries are manually
# built because the corresponding Homebrew packages do not provide usable
# static libraries.

## libusb
wget https://github.com/libusb/libusb/releases/download/v${LIBUSB_VERSION}/libusb-${LIBUSB_VERSION}.tar.bz2
tar xvf libusb-${LIBUSB_VERSION}.tar.bz2
mkdir build-libusb
pushd build-libusb
../libusb-${LIBUSB_VERSION}/configure \
--prefix=${BUILD_SYSROOT} \
--enable-static \
--disable-shared
make -j
make install
popd

## hidapi
wget https://github.com/libusb/hidapi/archive/refs/tags/hidapi-${HIDAPI_VERSION}.tar.gz
tar xvf hidapi-${HIDAPI_VERSION}.tar.gz
mkdir build-hidapi
pushd build-hidapi
cmake \
-DCMAKE_INSTALL_PREFIX=${BUILD_SYSROOT} \
-DBUILD_SHARED_LIBS=OFF \
../hidapi-hidapi-${HIDAPI_VERSION}
cmake --build .
cmake --install .
popd

## libftdi
wget https://www.intra2net.com/en/developer/libftdi/download/libftdi1-${LIBFTDI_VERSION}.tar.bz2
tar xvf libftdi1-${LIBFTDI_VERSION}.tar.bz2
mkdir build-libftdi
pushd build-libftdi
cmake \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_PREFIX_PATH=${BUILD_SYSROOT} \
-DCMAKE_INSTALL_PREFIX=${BUILD_SYSROOT} \
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=ON \
-DSTATICLIBS=ON \
-DBUILD_TESTS=OFF \
-DDOCUMENTATION=OFF \
../libftdi1-${LIBFTDI_VERSION}
cmake --build .
cmake --install .
rm -f ${BUILD_SYSROOT}/lib/libftdi*.dylib
popd
else
echo "ERROR: Invalid build host '${BUILD_HOST}'"
exit 1
fi

# Build OpenOCD
pushd ${BUILD_SOURCE}
./bootstrap
popd

mkdir build-openocd
pushd build-openocd

${BUILD_SOURCE}/configure \
${OPENOCD_FLAGS} \
--prefix="${BUILD_PREFIX}"

make -j
make install

popd

# Copy required dynamic-link libraries for Windows
if [ "${BUILD_HOST}" == "windows-x86_64" ]; then
OPENOCD_WIN_LIBS=" \
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libftdi1.dll \
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libhidapi.dll \
/opt/mingw-w64-win32/x86_64-w64-mingw32/bin/libusb-1.0.dll \
"

for l in ${OPENOCD_WIN_LIBS}; do
cp -f ${l} ${BUILD_PREFIX}/bin
done
fi

# Symlink OpenOCD executable for macOS
if [[ "${BUILD_HOST}" =~ ^macos-.* ]]; then
mkdir -p ${BUILD_OUTPUT}/usr/bin
pushd ${BUILD_OUTPUT}/usr/bin

ln -sf ../../opt/openocd/bin/openocd openocd

popd
fi
2 changes: 1 addition & 1 deletion scripts/build_qemu.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/usr/bin/env bash
#!/usr/bin/env bash

set -e

Expand Down
Loading