-
-
Save dcava/176ba2f7ba41fdd8b4739bc0efb85ede to your computer and use it in GitHub Desktop.
Download and build the wireguard kernel module and tools for EdgeOS. see https://github.com/Lochnair/vyatta-wireguard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
WIREGUARD_TAG=0.0.20181218 | |
THISDIR=$(readlink -f $(dirname $0)) | |
SYSROOT=$THISDIR/sysroot | |
TARGET=mips64-octeon-linux-gnu | |
MUSL_CC=$SYSROOT/bin/musl-gcc | |
export PATH=$THISDIR/toolchain/bin:$PATH | |
export CROSS_COMPILE=${TARGET}- | |
export CC=${CROSS_COMPILE}gcc | |
export CFLAGS="-O2 -mabi=64" | |
export ARCH=mips | |
export PKG_CONFIG_PATH=$SYSROOT/lib/pkgconfig | |
msg() { | |
echo -e "\033[1;36m+ $*\033[0m" >&2 | |
} | |
run() { | |
msg "$*" | |
"$@" | |
} | |
download_sdk() { | |
if [[ ! -d OCTEON-SDK ]]; then | |
export GIT_LFS_SKIP_SMUDGE=1 | |
run git clone https://github.com/Cavium-Open-Source-Distributions/OCTEON-SDK/ | |
unset GIT_LFS_SKIP_SMUDGE | |
else | |
msg "OCTEON-SDK already cloned" | |
fi | |
if [[ ! -f OCTEON-SDK/OCTEON-SDK/tools/bin/$CC ]]; then | |
pushd OCTEON-SDK | |
run git lfs pull -I OCTEON-SDK-5.1.tbz | |
run tar xf OCTEON-SDK-5.1.tbz | |
popd | |
else | |
msg "Toolchain already extracted" | |
fi | |
if [[ ! -d toolchain ]]; then | |
run ln -s OCTEON-SDK/OCTEON-SDK/tools toolchain | |
fi | |
} | |
build_sdk() { | |
: | |
} | |
download_kernel() { | |
local gpl_url="https://dl.ubnt.com/firmwares/edgemax/v1.10.x/GPL.ER-e300.v1.10.8.5142457.tar.bz2" | |
local gpl_archive="$(basename "$gpl_url")" | |
local kernel_archive="kernel_5142457-g796b1bf.tgz" | |
if [[ ! -f $gpl_archive ]]; then | |
run wget "$gpl_url" | |
else | |
msg "GPL archive already downloaded" | |
fi | |
if [[ ! -f $kernel_archive ]]; then | |
run tar xf $gpl_archive -O source/$kernel_archive >$kernel_archive | |
else | |
msg "kernel archive already extracted" | |
fi | |
run rm -rf kernel | |
run tar xf $kernel_archive | |
} | |
build_kernel() { | |
run make -C kernel scripts prepare | |
run make -C kernel INSTALL_HDR_PATH=$SYSROOT headers_install | |
} | |
download_musl() { | |
if [[ ! -d musl ]]; then | |
run git clone git://git.musl-libc.org/musl | |
else | |
msg "musl was already cloned" | |
run git -C musl fetch | |
fi | |
pushd musl | |
run git reset --hard | |
run git clean -dxfq | |
run git checkout v1.1.20 | |
popd | |
} | |
build_musl() { | |
pushd musl | |
./configure --host=x86_64 --target=$TARGET --prefix=$SYSROOT --enable-static --disable-shared | |
run make | |
run make install | |
popd | |
} | |
download_libmnl() { | |
if [[ ! -d libmnl ]]; then | |
git clone git://git.netfilter.org/libmnl | |
else | |
msg "libmnl already cloned" | |
run git -C libmnl fetch | |
fi | |
pushd libmnl | |
run git reset --hard | |
run git clean -dxfq | |
run git checkout libmnl-1.0.4 | |
popd | |
} | |
build_libmnl() { | |
pushd libmnl | |
run ./autogen.sh | |
run ./configure CC=$MUSL_CC --prefix=$SYSROOT --host=$TARGET --enable-static --disable-shared | |
run make | |
run make install | |
popd | |
} | |
download_wireguard() { | |
if [[ ! -d WireGuard ]]; then | |
run git clone git://git.zx2c4.com/WireGuard | |
else | |
msg "WireGuard already cloned" | |
run git -C WireGuard fetch | |
fi | |
pushd WireGuard | |
run git reset --hard | |
run git clean -dxfq | |
run git checkout $WIREGUARD_TAG | |
run sed -i 's/prandom_u32_max/\0_exclude_for_e300/' src/compat/compat.h | |
popd | |
} | |
build_wireguard() { | |
run make -C kernel M=$THISDIR/WireGuard/src modules | |
run cp -f WireGuard/src/wireguard.ko . | |
run make CC=$MUSL_CC -C WireGuard/src/tools | |
run cp -f WireGuard/src/tools/wg . | |
run ${CROSS_COMPILE}strip wg | |
} | |
set -e | |
if (( $# == 0 )); then | |
set -- sdk kernel musl libmnl wireguard | |
fi | |
for x in "$@"; do | |
case $x in | |
build_*|download_*) | |
eval $x | |
;; | |
*) | |
eval download_$x | |
eval build_$x | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment