Skip to content

Commit

Permalink
Merge pull request #3 from SPRESENSE/update-openocd-0.11.0
Browse files Browse the repository at this point in the history
Update openocd to 0.11.0
  • Loading branch information
Shunichi-K authored Apr 4, 2023
2 parents 5924029 + 387586e commit daa699c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 39 deletions.
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,31 @@ You can use Homebrew package manager (https://brew.sh) to install tools other th
brew install automake autoconf pkg-config libtool
```

### Build packages for all architectures by Docker on MacOSX (recommend)
### Build packages for target host

Install docker and above developer tools, and just run `build-all-packages.sh`. This script is just a batch script to perform build process as below section.
Run following instruction with OPENOCDDIR as spresense-openocd directory in abs path.

This script takes a long time because always perform a clean build.

After script successfully, output all of the package files (`*.tar.bz2`) into `dist` directory.
```bash
OPENOCDDIR=$(pwd)/spresense-openocd ./build.sh
```

### Build packages individually by Docker

It can be built for linux and windows binaries.
You can use docker image using Dockerfile in current directory.
Type following command to build docker container.

```bash
docker build -t buildenv .
docker build -t build-openocd .
```

After container built successfully, you can use `build.sh` from docker.
Created docker image must be run in the root directory of this repository.
After container built successfully, you can use `build-wrapper.sh`.

```bash
docker run -it --rm --mount "type=bind,source=$(pwd),destination=/work" -u $(id -u):$(id -g) buildenv ./build.sh [win32|win64|linux32]
build-wrapper.sh [linux64|win64]
```

If no options to build.sh, create Linux 64 bit package. Available options are `win32`, `win64` and `linux32`.

## Building OpenOCD in Linux

As doing in above docker container image, you can run `build.sh` on Ubuntu 18.04 (bionic).
Please refer `Dockerfile` to necessary build tools for creating linux and windows packages.
If no options to build-wrapper.sh, create Linux 64 bit package. Available options are `win32`, `win64` and `linux32`.

In this way, MacOSX package can not built.
The OpenOCD source directory is $(pwd)/spresense-openocd used in default.
If you want to change it, set OPENOCDDIR variable in abs path.
7 changes: 3 additions & 4 deletions build-all-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ fi

# Make sure want to be build container exists

docker build -t buildenv .
docker build -t build-openocd .

# Linux 64 bit and other supported architectures

docker run -it --rm --mount "type=bind,source=$(pwd),destination=/work" --name build buildenv ./build.sh
docker run -it --rm --mount "type=bind,source=$(pwd),destination=/work" --name build buildenv ./build.sh win32
docker run -it --rm --mount "type=bind,source=$(pwd),destination=/work" --name build buildenv ./build.sh win64
./build-wrapper.sh
TARGET=win64 ./build-wrapper.sh
12 changes: 12 additions & 0 deletions build-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

OPENOCDDIR=$(realpath ${OPENOCDDIR:-spresense-openocd})

# This script uses docker container named as 'build-openocd'.
# Please run 'docker build -t build-openocd .' in this directory
# if you have no build-openocd image.

docker run -it --rm -u $(id -u):$(id -g) \
-v $(pwd):/work \
-v ${OPENOCDDIR}:/tmp/openocd build-openocd \
./build.sh $1
51 changes: 32 additions & 19 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
set -x

LIBUSB_REPOS=https://github.com/libusb/libusb
LIBUSB_VERSION=1.0.21
LIBUSB_VERSION=1.0.23
LIBUSB_ARCHIVE=libusb-${LIBUSB_VERSION}.tar.bz2

HIDAPI_REPOS=https://github.com/libusb/hidapi
HIDAPI_VERSION=0.9.0
HIDAPI_ARCHIVE=hidapi-${HIDAPI_VERSION}.tar.gz

OPENOCD_VERSION=0.12.0
# OpenOCD version would be replaced with actual version
OPENOCD_VERSION=0.11.0
OPENOCD_MODVERSION=spr1

OPENOCDDIR=spresense-openocd
OPENOCDDIR=${OPENOCDDIR:-/tmp/openocd}

DISTDIR=/tmp/dist

Expand All @@ -29,13 +30,16 @@ OPENOCD_CONFIGOPTS="--disable-ftdi \
--disable-opendous \
--disable-aice \
--disable-usbprog \
--disable-esp-usb-jtag \
--disable-nulink \
--disable-rlink \
--disable-armjtagew \
--enable-cmsis-dap \
--disable-kitprog \
--disable-usb-blaster \
--disable-presto \
--disable-openjtag \
--disable-buspirate \
--disable-jlink"

if [ ! -d $OPENOCDDIR ]; then
Expand Down Expand Up @@ -106,11 +110,12 @@ preinstall_lib()

install_libusb()
{
rm -rf libusb
mkdir libusb
tar jxf archives/${LIBUSB_ARCHIVE} --strip-components=1 -C libusb
SRCDIR=/tmp/libusb
rm -rf ${SRCDIR}
mkdir ${SRCDIR}
tar jxf archives/${LIBUSB_ARCHIVE} --strip-components=1 -C ${SRCDIR}

cd libusb
cd ${SRCDIR}
./configure --prefix=${DISTDIR} ${CROSS_COMPILE} || exit 1
make || exit 1

Expand All @@ -124,13 +129,17 @@ install_libusb()

install_hidapi()
{
rm -rf hidapi
mkdir hidapi
tar zxf archives/${HIDAPI_ARCHIVE} --strip-components=1 -C hidapi

cd hidapi
SRCDIR=/tmp/hidapi
rm -rf ${SRCDIR}
mkdir ${SRCDIR}
tar zxf archives/${HIDAPI_ARCHIVE} --strip-components=1 -C ${SRCDIR}

# Do not use realpath, it can not used on macOS.
# This patch file is for macOS only.
PATCHFILE=$(pwd)/hidapi-00-configure.patch
cd ${SRCDIR}
if [ "${PLATFORM}" = "Darwin" ]; then
patch -p1 < ../hidapi-00-configure.patch
patch -p1 < $PATCHFILE
fi
./bootstrap || exit 1
PKG_CONFIG_PATH=${DISTDIR}/lib/pkgconfig \
Expand All @@ -147,15 +156,20 @@ install_hidapi()

install_openocd()
{
cd $OPENOCDDIR
BUILDDIR=/tmp/build-openocd

cd $OPENOCDDIR
git clean -xdf
git -C jimtcl clean -xdf

./bootstrap || exit 1
cd -

mkdir -p $BUILDDIR
cd $BUILDDIR

LDFLAGS='-Wl,-rpath -Wl,"\$\$$ORIGIN/../lib"' \
PKG_CONFIG_PATH=${DISTDIR}/lib/pkgconfig \
./configure --prefix=${DISTDIR} ${CROSS_COMPILE} ${OPENOCD_CONFIGOPTS} || exit 1
$OPENOCDDIR/configure --prefix=${DISTDIR} ${CROSS_COMPILE} ${OPENOCD_CONFIGOPTS} || exit 1

make clean
make || exit 1
Expand All @@ -180,7 +194,6 @@ if [ -e configure ]; then
eval `grep PACKAGE_VERSION= configure`
OPENOCD_VERSION=$PACKAGE_VERSION
fi
echo OpenOCD Version: $OPENOCD_VERSION
cd -

# Create release archive
Expand All @@ -193,10 +206,10 @@ mv ${DISTDIR} ${package}

if [ "$TARGET" = "win32" -o "$TARGET" = "win64" ]; then
distfile=${package}-${TARGET}.zip
zip -r dist/${distfile} ${package}
zip -q -r dist/${distfile} ${package}
else
distfile=${package}-${TARGET}.tar.bz2
tar cvjf dist/${distfile} ${package}
tar cjf dist/${distfile} ${package}
fi

(cd dist; shasum -a 256 ${distfile} > ${distfile}.sha)
Expand Down

0 comments on commit daa699c

Please sign in to comment.