This is a source-able script that downloads the aarch64 toolchain from
developer.arm.com, extracts it, and, when being sourced, adds the path to PATH.
If ccache is installed, it will also add the ccache directory to the front of
PATH.
Add a check in the OSv build script to source the toolchain if arch=aarch64 and
the toolchain has been downloaded to the build directory.
Add "centos" as an option in download_aarch64_packages.py to download the
toolchain. I did not change the logic for Ubuntu here due to the possibility of
ending up with unvetted combinations of this GCC version with various Ubuntu
system libraries that could be built with different versions of GCC. This
toolchain can still be used on Ubuntu by sourcing it directly, but in this case
I recommend building Boost and other dependent libraries from source to ensure
they are built with the same toolchain that is being used to build OSv and your
apps/modules.
This toolchain should work on any distribution that ARM supports, which is
Ubuntu 16.04 LTS or later, or RHEL 7 or later. I've tested this on CentOS 7 and
Ubuntu 18.04.
My primary motivation for this is to support the aarch64 build on CentOS 7.
While the EPEL repository for CentOS 7 does have an aarch64 cross compiler
toolchain available, it is quite an old version (4.8.5). On Ubuntu, the aarch64
cross compiler toolchain conflicts with the gcc-multilib package. Using the ARM
toolchain allows us to avoid these particular issues.
This toolchain does not provide Boost, so Boost will need to be built. Here are
instructions I used for building boost from source. Ensure that the current
working directory is the root of the OSv repository, then run the following
commands:
$ source scripts/download_aarch64_toolchain.sh
$ mkdir -p build/downloaded_packages/aarch64/boost
$ pushd build/downloaded_packages/aarch64/boost
$ wget
https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz
$ tar -xf boost_1_70_0.tar.gz
$ cd boost_1_70_0/
$ BOOST_DIR=$(pwd)
$ ./bootstrap.sh
$ echo "using gcc : arm : aarch64-none-linux-gnu-g++ ;" > user-config.jam
$ ./b2 --user-config=${BOOST_DIR}/user-config.jam toolset=gcc-arm architecture=arm address-model=64 -j$(nproc)
After building boost, we need to set up some symlinks so that OSv can find the
boost headers and libraries. Ensure your current working directory is the boost
source directory BOOST_DIR (it should be already), then run the following
commands:
$ ln -s boost_1_70_0/stage ../install
$ mkdir -p stage/usr/include
$ ln -s ../../../boost stage/usr/include/boost
$ popd
After building boost and setting up the symlinks, we should be ready to build
OSv with the aarch64 toolchain:
$ scripts/build arch=aarch64 fs=ramfs --create-disk image=native-example -j$(nproc)
scripts/build | 5 +++
scripts/download_aarch64_packages.py | 2 +
scripts/download_aarch64_toolchain.sh | 55 +++++++++++++++++++++++++++
3 files changed, 62 insertions(+)
create mode 100644 scripts/download_aarch64_toolchain.sh
diff --git a/scripts/build b/scripts/build
index d859202a..6070ba0f 100755
--- a/scripts/build
+++ b/scripts/build
@@ -90,6 +90,11 @@ done
arch=${arch:-x64}
+if [[ "$arch" == "aarch64" && -d "build/downloaded_packages/aarch64/toolchain/" ]]; then
+ . scripts/download_aarch64_toolchain.sh
+ export CROSS_PREFIX=aarch64-none-linux-gnu-
+fi
+
make "${args[@]}" ${stage1_args} | tee build.out
# check exit status of make
status=${PIPESTATUS[0]}
diff --git a/scripts/download_aarch64_packages.py b/scripts/download_aarch64_packages.py
index 58a3cf7d..931decf9 100755
--- a/scripts/download_aarch64_packages.py
+++ b/scripts/download_aarch64_packages.py
@@ -78,6 +78,8 @@ elif name.lower() == 'ubuntu':
print("Cound not find boost version from neither main nor universe ports index!")
sys.exit(1)
commands_to_download = ubuntu_download_commands(boost_version)
+elif name.lower() == "centos":
+ commands_to_download = [ 'bash -eu %s/scripts/download_aarch64_toolchain.sh' % osv_root ]
else:
print("The distribution %s is not supported for cross-compiling aarch64 version of OSv" % name)
sys.exit(1)
diff --git a/scripts/download_aarch64_toolchain.sh b/scripts/download_aarch64_toolchain.sh
new file mode 100644
index 00000000..0403712c
--- /dev/null
+++ b/scripts/download_aarch64_toolchain.sh
@@ -0,0 +1,55 @@
+#!/bin/bash -eu
+
+# Copyright (c) 2021, DornerWorks, Ltd.
+# Author: Stewart Hildebrand
+# SPDX-License-Identifier: BSD-3-Clause OR MIT
+
+# Usage:
+# $ source download_aarch64_toolchain.sh
+# or
+# $ . download_aarch64_toolchain.sh
+
+#
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads
+
+ARM64_TOOLCHAIN_SCRIPTDIR="$(cd $(dirname ${BASH_SOURCE}) && pwd)/"
+ARM64_TOOLCHAIN_DESTINATION="${ARM64_TOOLCHAIN_SCRIPTDIR}../build/downloaded_packages/aarch64/toolchain/"
+ARM64_TOOLCHAIN_VERSION=9.2-2019.12
+ARM64_TOOLCHAIN_FILENAME=gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu
+
+if [ ! -d ${ARM64_TOOLCHAIN_DESTINATION}${ARM64_TOOLCHAIN_FILENAME} ]; then
+ mkdir -p "${ARM64_TOOLCHAIN_DESTINATION}"
+ pushd "${ARM64_TOOLCHAIN_DESTINATION}" >/dev/null
+ if [ ! -s ${ARM64_TOOLCHAIN_FILENAME}.tar.xz ]; then
+ wget
https://developer.arm.com/-/media/Files/downloads/gnu-a/${ARM64_TOOLCHAIN_VERSION}/binrel/${ARM64_TOOLCHAIN_FILENAME}.tar.xz
+ fi
+ tar -xf ${ARM64_TOOLCHAIN_FILENAME}.tar.xz
+ popd >/dev/null
+fi
+
+if [ -d /usr/lib64/ccache ]; then
+ CCACHE_SYMLINK_DIR=/usr/lib64/ccache
+fi
+if [ -d /usr/lib/ccache ]; then
+ CCACHE_SYMLINK_DIR=/usr/lib/ccache
+fi
+
+PATH=${ARM64_TOOLCHAIN_DESTINATION}${ARM64_TOOLCHAIN_FILENAME}/bin:${PATH}
+if [ ! -z "${CCACHE_SYMLINK_DIR-}" ]; then
+ PATH=${CCACHE_SYMLINK_DIR}:$(echo ${PATH} | sed "s|${CCACHE_SYMLINK_DIR}:||g")
+fi
+
+if [ -z "${CCACHE_SYMLINK_DIR-}" ]; then
+ echo "It is recommended to install ccache and create symlinks for the"
+ echo "aarch64 toolchain in order to significantly speed up the build."
+else
+ if [ ! -h "${CCACHE_SYMLINK_DIR}/aarch64-none-linux-gnu-g++" ] || [ ! -h "${CCACHE_SYMLINK_DIR}/aarch64-none-linux-gnu-gcc" ]; then
+ echo "It is recommended to create ccache symlinks for the aarch64"
+ echo "toolchain in order to significantly speed up the build. Run the"
+ echo "following commands to create the appropriate symlinks:"
+ echo ""
+ echo " sudo ln -s ../../bin/ccache \"${CCACHE_SYMLINK_DIR}/aarch64-none-linux-gnu-gcc\""
+ echo " sudo ln -s ../../bin/ccache \"${CCACHE_SYMLINK_DIR}/aarch64-none-linux-gnu-g++\""
+ echo ""
+ echo "After this, please re-source the toolchain script to enable ccache."
+ fi
+fi
--
2.30.0