blob: 23c3bbb16b1c10ddee2251d0395308f6dab0f73b [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001#!/bin/bash
Andrew Geissler517393d2023-01-13 08:55:19 -06002set -u -e
Brad Bishopbec4ebc2022-08-03 09:55:16 -04003
Andrew Geissler517393d2023-01-13 08:55:19 -06004BASENAME=arm-gnu-toolchain
Andrew Geisslerea144b02023-01-27 16:03:57 -06005VER=${VER:-12.2.rel1}
Andrew Geissler517393d2023-01-13 08:55:19 -06006HOST_ARCH=${HOST_ARCH:-$(uname -m)}
Brad Bishopbec4ebc2022-08-03 09:55:16 -04007
8DOWNLOAD_DIR=$1
9TOOLCHAIN_DIR=$2
10TOOLCHAIN_LINK_DIR=$3
11
12# These should be already created by .gitlab-ci.yml, but do here if run outside of that env
13mkdir -p $DOWNLOAD_DIR $TOOLCHAIN_DIR $TOOLCHAIN_LINK_DIR
14
Andrew Geissler517393d2023-01-13 08:55:19 -060015download() {
16 TRIPLE=$1
17 URL=https://developer.arm.com/-/media/Files/downloads/gnu/$VER/binrel/$BASENAME-$VER-$HOST_ARCH-$TRIPLE.tar.xz
18 wget -P $DOWNLOAD_DIR -nc $URL
19}
20
Brad Bishopbec4ebc2022-08-03 09:55:16 -040021if [ $HOST_ARCH = "aarch64" ]; then
Andrew Geissler517393d2023-01-13 08:55:19 -060022 # AArch64 Linux hosted cross compilers
Brad Bishopbec4ebc2022-08-03 09:55:16 -040023
Andrew Geissler517393d2023-01-13 08:55:19 -060024 # AArch32 target with hard float
25 download arm-none-linux-gnueabihf
Brad Bishopbec4ebc2022-08-03 09:55:16 -040026elif [ $HOST_ARCH = "x86_64" ]; then
Andrew Geissler517393d2023-01-13 08:55:19 -060027 # x86_64 Linux hosted cross compilers
Brad Bishopbec4ebc2022-08-03 09:55:16 -040028
Andrew Geissler517393d2023-01-13 08:55:19 -060029 # AArch32 target with hard float
30 download arm-none-linux-gnueabihf
Brad Bishopbec4ebc2022-08-03 09:55:16 -040031
Andrew Geissler517393d2023-01-13 08:55:19 -060032 # AArch64 GNU/Linux target
33 download aarch64-none-linux-gnu
Brad Bishopbec4ebc2022-08-03 09:55:16 -040034else
35 echo "ERROR - Unknown build arch of $HOST_ARCH"
36 exit 1
37fi
38
Andrew Geissler517393d2023-01-13 08:55:19 -060039for i in arm aarch64; do
40 if [ ! -d $TOOLCHAIN_DIR/$BASENAME-$VER-$HOST_ARCH-$i-none-linux-gnu*/ ]; then
41 if [ ! -f $DOWNLOAD_DIR/$BASENAME-$VER-$HOST_ARCH-$i-none-linux-gnu*.tar.xz ]; then
Brad Bishopbec4ebc2022-08-03 09:55:16 -040042 continue
43 fi
44
Andrew Geissler517393d2023-01-13 08:55:19 -060045 tar -C $TOOLCHAIN_DIR -axvf $DOWNLOAD_DIR/$BASENAME-$VER-$HOST_ARCH-$i-none-linux-gnu*.tar.xz
Brad Bishopbec4ebc2022-08-03 09:55:16 -040046 fi
47
48 # Setup a link for the toolchain to use local to the building machine (e.g., not in a shared location)
Andrew Geissler517393d2023-01-13 08:55:19 -060049 ln -s $TOOLCHAIN_DIR/$BASENAME-$VER-$HOST_ARCH-$i-none-linux-gnu* $TOOLCHAIN_LINK_DIR/$i
Brad Bishopbec4ebc2022-08-03 09:55:16 -040050done