1#!/bin/bash 2# Copyright 2021 The TensorFlow Authors. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================== 16 17set -e 18 19SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 20cd "$SCRIPT_DIR/../../../.." 21 22TOOLCHAINS_DIR=$(realpath tensorflow/lite/tools/cmake/toolchains) 23mkdir -p ${TOOLCHAINS_DIR} 24 25case $1 in 26 armhf) 27 if [[ ! -d "${TOOLCHAINS_DIR}/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf" ]]; then 28 curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz >&2 29 tar xvf gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz -C ${TOOLCHAINS_DIR} >&2 30 fi 31 ARMCC_ROOT=${TOOLCHAINS_DIR}/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf 32 echo "ARMCC_FLAGS=\"-march=armv7-a -mfpu=neon-vfpv4 -funsafe-math-optimizations \ 33 -isystem ${ARMCC_ROOT}/lib/gcc/arm-linux-gnueabihf/8.3.0/include \ 34 -isystem ${ARMCC_ROOT}/lib/gcc/arm-linux-gnueabihf/8.3.0/include-fixed \ 35 -isystem ${ARMCC_ROOT}/arm-linux-gnueabihf/include/c++/8.3.0 \ 36 -isystem ${ARMCC_ROOT}/arm-linux-gnueabihf/libc/usr/include \ 37 -isystem \"\${CROSSTOOL_PYTHON_INCLUDE_PATH}\" \ 38 -isystem /usr/include\"" 39 echo "ARMCC_PREFIX=${ARMCC_ROOT}/bin/arm-linux-gnueabihf-" 40 ;; 41 aarch64) 42 if [[ ! -d "${TOOLCHAINS_DIR}/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu" ]]; then 43 curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz >&2 44 tar xvf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz -C ${TOOLCHAINS_DIR} >&2 45 fi 46 ARMCC_ROOT=${TOOLCHAINS_DIR}/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu 47 echo "ARMCC_FLAGS=\"-funsafe-math-optimizations \ 48 -isystem ${ARMCC_ROOT}/lib/gcc/aarch64-linux-gnu/8.3.0/include \ 49 -isystem ${ARMCC_ROOT}/lib/gcc/aaarch64-linux-gnu/8.3.0/include-fixed \ 50 -isystem ${ARMCC_ROOT}/aarch64-linux-gnu/include/c++/8.3.0 \ 51 -isystem ${ARMCC_ROOT}/aarch64-linux-gnu/libc/usr/include \ 52 -isystem \"\${CROSSTOOL_PYTHON_INCLUDE_PATH}\" \ 53 -isystem /usr/include\"" 54 echo "ARMCC_PREFIX=${ARMCC_ROOT}/bin/aarch64-linux-gnu-" 55 ;; 56 rpi0) 57 if [[ ! -d "${TOOLCHAINS_DIR}/arm-rpi-linux-gnueabihf" ]]; then 58 curl -L https://github.com/rvagg/rpi-newer-crosstools/archive/eb68350c5c8ec1663b7fe52c742ac4271e3217c5.tar.gz -o rpi-toolchain.tar.gz >&2 59 tar xzf rpi-toolchain.tar.gz -C ${TOOLCHAINS_DIR} >&2 60 mv ${TOOLCHAINS_DIR}/rpi-newer-crosstools-eb68350c5c8ec1663b7fe52c742ac4271e3217c5 ${TOOLCHAINS_DIR}/arm-rpi-linux-gnueabihf >&2 61 fi 62 ARMCC_ROOT=${TOOLCHAINS_DIR}/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf 63 echo "ARMCC_FLAGS=\"-march=armv6 -mfpu=vfp -funsafe-math-optimizations \ 64 -isystem ${ARMCC_ROOT}/lib/gcc/arm-rpi-gnueabihf/6.5.0/include \ 65 -isystem ${ARMCC_ROOT}/lib/gcc/arm-rpi-gnueabihf/6.5.0/include-fixed \ 66 -isystem ${ARMCC_ROOT}/arm-rpi-linux-gnueabihf/include/c++/6.5.0 \ 67 -isystem ${ARMCC_ROOT}/arm-rpi-linux-gnueabihf/sysroot/usr/include \ 68 -isystem \"\${CROSSTOOL_PYTHON_INCLUDE_PATH}\" \ 69 -isystem /usr/include\"" 70 echo "ARMCC_PREFIX=${ARMCC_ROOT}/bin/arm-rpi-linux-gnueabihf-" 71 ;; 72 *) 73 echo "Usage: download_toolchains.sh [armhf|aarch64|rpi0]" >&2 74 exit 75 ;; 76 esac 77 78echo "download_toolchains.sh completed successfully." >&2 79