Skip to content

Instantly share code, notes, and snippets.

@rgov
Created November 6, 2022 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgov/2c61256571df6706529c3d53ab688ddd to your computer and use it in GitHub Desktop.
Save rgov/2c61256571df6706529c3d53ab688ddd to your computer and use it in GitHub Desktop.
Script for building the Linaro compiler toolchain

I wanted to compile software for NVIDIA Jetson release r32.7 using the recommended Linaro gcc 7.3.1 2018.05 aarch64 toolchain. However there is no binary release for native compilation on aarch64 hosts, so I needed to build my own copy of the toolchain. This script does so.

Note that from Jetson release r34, the toolchain has changed to the Bootlin gcc toolchain. This script does not compile this toolchain.

Thanks to Vivin Uthappa for his blog post that introduced the process of building the Linaro toolchain.

#!/bin/bash -eu
ARCH=${ARCH:-$(arch)}
if [[ "$ARCH" = "x86_64" ]]; then
# Just download the prebuilt Linaro toolchain, as documented in the NVIDIA
# Jetson Linux Developer Guide for the L4T release, in the section "Jetson
# Linux Toolchain".
wget -q -O - \
"https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz" \
| tar xJ
ln -s gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu toolchain
fi
# We will try to compile the Linaro toolchain. An alternative would be to use
# qemu-user to emulate the official toolchain release.
# Make a workspace for building the toolchain
mkdir toolchain-build
pushd toolchain-build
# Download the manifest file corresponding to the same Linaro toolchain version
# as referenced in the NVIDIA Jetson Linux Developer Guide for the L4T release.
wget -O manifest.txt \
"https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-linux-manifest.txt"
# Extract the version of ABE used to build this toolchain
ABE_REVISION=(eval "$(sed -n '/abe_revision=/p' toolchain-manifest.txt)"; echo "$abe_revision")
# Clone ABE
git clone "https://git.linaro.org/toolchain/abe.git"
(cd abe && git checkout "$ABE_REVISION")
# Configure and change the host triple so that it doesn't match the target,
# otherwise the compilation will fail.
./abe/configure
sed -i -e '/^build=/ s/unknown/host/' host.conf
# Proceed with the compilation
./abe/abe.sh \
--manifest manifest.txt \
--release 2018.05 \
--build all \
--tarbin
# Install the toolchain
popd
tar xf "toolchain-build/snapshots/gcc-linaro-7.3.1-2018.05-${ARCH}_aarch64-linux-gnu.tar.xz"
ln -s "gcc-linaro-7.3.1-2018.05-${ARCH}_aarch64-linux-gnu" toolchain
echo "Installation complete. You can remove toolchain-build/ if you want."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment