diff --git a/examples/arm/setup.sh b/examples/arm/setup.sh index 49729fdbf61..0dd4c68cfd7 100755 --- a/examples/arm/setup.sh +++ b/examples/arm/setup.sh @@ -7,28 +7,15 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -set -eu - -if [[ "${1:-'.'}" == "-h" || "${#}" -gt 2 ]]; then - echo "Usage: $(basename $0) <--i-agree-to-the-contained-eula> [path-to-a-scratch-dir]" - echo "Supplied args: $*" - exit 1 -fi - - -######## -### Helper functions -######## -ARCH="$(uname -m)" -OS="$(uname -s)" - - +set -u ######## ### Hardcoded constants ######## script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) et_dir=$(realpath $script_dir/../..) +ARCH="$(uname -m)" +OS="$(uname -s)" if [[ "${ARCH}" == "x86_64" ]]; then # FVPs @@ -80,37 +67,38 @@ tosa_reference_model_rev="v0.80.1" vela_repo_url="https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-vela" vela_rev="fc970e3da72e5f6930b840b357684126602b3126" -######## -### Mandatory user args -######## -eula_acceptance="${1:-'.'}" -if [[ "${eula_acceptance}" != "--i-agree-to-the-contained-eula" ]]; then - if [[ ${ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA} != "True" ]]; then - echo "Must pass first positional argument '--i-agree-to-the-contained-eula' to agree to EULA associated with downloading the FVP. Exiting!" - exit 1 - else - echo "Arm EULA for FVP agreed to with ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True environment variable" - fi -else - shift; # drop this arg -fi ######## ### Optional user args ######## -root_dir=${1:-"${script_dir}/ethos-u-scratch"} +root_dir=${2:-"${script_dir}/ethos-u-scratch"} mkdir -p ${root_dir} root_dir=$(realpath ${root_dir}) +setup_path_script="${root_dir}/setup_path.sh" + ######## ### Functions ######## function setup_fvp() { + + # Mandatory user arg --i-agree-to-the-contained-eula + eula_acceptance="${1:-'.'}" + if [[ "${eula_acceptance}" != "--i-agree-to-the-contained-eula" ]]; then + if [[ ${ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA} != "True" ]]; then + echo "Must pass first positional argument '--i-agree-to-the-contained-eula' to agree to EULA associated with downloading the FVP. Exiting!" + exit 1 + else + echo "Arm EULA for FVP agreed to with ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True environment variable" + fi + else + shift; # drop this arg + fi if [[ "${OS}" != "Linux" ]]; then echo "[${FUNCNAME[0]}] Warning: FVP only supported with Linux OS, skipping FVP setup..." echo "[${FUNCNAME[0]}] Warning: For MacOS, using https://github.com/Arm-Examples/FVPs-on-Mac is recommended." - echo "[${FUNCNAME[0]}] Warning: Follow the instructions and make sure the path is set correctly." + echo "[${FUNCNAME[0]}] Warning: Follow the instructions and make sure the path is set correctly." return 1 fi @@ -148,17 +136,7 @@ function setup_fvp() { exit 1 ;; esac - - model_dir_variable=${fvp}_model_dir - fvp_model_dir=${!model_dir_variable} - fvp_bin_path="$(cd models/${fvp_model_dir} && pwd)" - export PATH=${PATH}:${fvp_bin_path} - - echo "export PATH=\${PATH}:${fvp_bin_path}" >> ${setup_path_script} done - - # Fixup for Corstone-320 python dependency - echo "export LD_LIBRARY_PATH=${root_dir}/FVP-corstone320/python/lib/" >> ${setup_path_script} } function setup_toolchain() { @@ -173,10 +151,6 @@ function setup_toolchain() { echo "[${FUNCNAME[0]}] Installing toolchain ..." rm -rf "${toolchain_dir}" tar xf "${toolchain_dir}.tar.xz" - toolchain_bin_path="$(cd ${toolchain_dir}/bin && pwd)" - export PATH=${PATH}:${toolchain_bin_path} - hash arm-none-eabi-gcc - echo "export PATH=\${PATH}:${toolchain_bin_path}" >> ${setup_path_script} } function setup_tosa_reference_model() { @@ -188,48 +162,81 @@ function setup_tosa_reference_model() { } function setup_vela() { - # - # Prepare the Vela compiler for AoT to Ethos-U compilation - # pip install ethos-u-vela@git+${vela_repo_url}@${vela_rev} } +function setup_path() { + echo $setup_path_script +} + +function create_setup_path(){ + echo "" > "${setup_path_script}" + fvps=("corstone300" "corstone320") + for fvp in "${fvps[@]}"; do + model_dir_variable=${fvp}_model_dir + fvp_model_dir=${!model_dir_variable} + fvp_bin_path="${root_dir}/FVP-${fvp}/models/${fvp_model_dir}" + echo "export PATH=\${PATH}:${fvp_bin_path}" >> ${setup_path_script} + done + + # Fixup for Corstone-320 python dependency + echo "export LD_LIBRARY_PATH=${root_dir}/FVP-corstone320/python/lib/" >> ${setup_path_script} + + toolchain_bin_path="$(cd ${toolchain_dir}/bin && pwd)" + echo "export PATH=\${PATH}:${toolchain_bin_path}" >> ${setup_path_script} + + echo "hash FVP_Corstone_SSE-300_Ethos-U55" >> ${setup_path_script} + echo "hash FVP_Corstone_SSE-300_Ethos-U65" >> ${setup_path_script} + echo "hash FVP_Corstone_SSE-320" >> ${setup_path_script} +} + ######## ### main ######## -# do basic checks -# Make sure we are on a supported platform -if [[ "${ARCH}" != "x86_64" ]] && [[ "${ARCH}" != "aarch64" ]] \ - && [[ "${ARCH}" != "arm64" ]]; then - echo "[main] Error: only x86-64 & aarch64 architecture is supported for now!" - exit 1 -fi +# Only run this if script is executed, not if it is sourced +(return 0 2>/dev/null) && is_script_sourced=1 || is_script_sourced=0 +if [[ $is_script_sourced -eq 0 ]] + then + set -e + if [[ "${ARCH}" != "x86_64" ]] && [[ "${ARCH}" != "aarch64" ]] \ + && [[ "${ARCH}" != "arm64" ]]; then + echo "[main] Error: only x86-64 & aarch64 architecture is supported for now!" + exit 1 + fi -cd "${script_dir}" + # Make sure we are on a supported platform + if [[ "${1:-'.'}" == "-h" || "${#}" -gt 2 ]]; then + echo "Usage: $(basename $0) <--i-agree-to-the-contained-eula> [path-to-a-scratch-dir]" + echo "Supplied args: $*" + exit 1 + fi -# Setup the root dir -cd "${root_dir}" -echo "[main] Using root dir ${root_dir}" + cd "${script_dir}" -setup_path_script="${root_dir}/setup_path.sh" -echo "" > "${setup_path_script}" + # Setup the root dir + cd "${root_dir}" + echo "[main] Using root dir ${root_dir}" + + # Import utils + source $et_dir/backends/arm/scripts/utils.sh -# Import utils -source $et_dir/backends/arm/scripts/utils.sh + # Setup FVP + setup_fvp ${1:-'.'} -# Setup toolchain -setup_toolchain + # Setup toolchain + setup_toolchain -# Setup the tosa_reference_model -setup_tosa_reference_model + # Create new setup_path script only if fvp and toolchain setup went well. + create_setup_path -# Setup vela and patch in codegen fixes -setup_vela + # Setup the tosa_reference_model + setup_tosa_reference_model -# Setup FVP -setup_fvp + # Setup vela and patch in codegen fixes + setup_vela -echo "[main] update path by doing 'source ${setup_path_script}'" + echo "[main] update path by doing 'source ${setup_path_script}'" -echo "[main] success!" -exit 0 + echo "[main] success!" + exit 0 +fi