Skip to content

Commit

Permalink
Update libusb and hidapi versions
Browse files Browse the repository at this point in the history
- Update libusb 1.0.23, hidapi 0.11.0
- Change source directory to /tmp, for prevent scanning from anti-virus softwares
- Add disable options for openocd
- Downgrade openocd to 0.11.0 because of 0.12.0 is not used from Cortex-Debug extension
  • Loading branch information
SPRESENSE committed Apr 4, 2023
1 parent 5924029 commit 0e7e9b3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 41 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 ${1:-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 $TARGET
49 changes: 28 additions & 21 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_VERSION=0.11.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,14 +129,12 @@ install_libusb()

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

cd hidapi
if [ "${PLATFORM}" = "Darwin" ]; then
patch -p1 < ../hidapi-00-configure.patch
fi
cd ${SRCDIR}
./bootstrap || exit 1
PKG_CONFIG_PATH=${DISTDIR}/lib/pkgconfig \
./configure --prefix=${DISTDIR} ${CROSS_COMPILE} || exit 1
Expand All @@ -147,15 +150,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 +188,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 +200,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 0e7e9b3

Please sign in to comment.