diff --git a/backends/arm/scripts/build_executor_runner.sh b/backends/arm/scripts/build_executor_runner.sh index 9e2f3954c53..6e01f0ad320 100755 --- a/backends/arm/scripts/build_executor_runner.sh +++ b/backends/arm/scripts/build_executor_runner.sh @@ -9,7 +9,7 @@ set -eu script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) et_root_dir=$(cd ${script_dir}/../../.. && pwd) et_root_dir=$(realpath ${et_root_dir}) -toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake +toolchain=arm-none-eabi-gcc setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh _setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools." @@ -46,6 +46,7 @@ help() { echo " --output= Output folder Default: /_.pte" echo " --et_build_root= Build output root folder to use, defaults to ${et_build_root}" echo " --ethosu_tools_dir= Path to your Ethos-U tools dir if you not using default: ${ethosu_tools_dir}" + echo " --toolchain= Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc" exit 0 } @@ -63,11 +64,23 @@ for arg in "$@"; do --output=*) output_folder="${arg#*=}" ; output_folder_set=true ;; --et_build_root=*) et_build_root="${arg#*=}";; --ethosu_tools_dir=*) ethosu_tools_dir="${arg#*=}";; + --toolchain=*) toolchain="${arg#*=}";; *) ;; esac done +if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then + toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake +elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then + toolchain_cmake=${et_root_dir}/examples/zephyr/arm-x86-64-gcc.cmake +else + echo "Error: Invalid toolchain selection, provided: ${tolchain}" + echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc}" + exit 1; +fi +toolchain_cmake=$(realpath ${toolchain_cmake}) + # Source the tools # This should be prepared by the setup.sh [[ -f ${setup_path_script} ]] \ @@ -116,7 +129,7 @@ else target_cpu=cortex-m85 fi echo "--------------------------------------------------------------------------------" -echo "Build Arm Baremetal executor_runner for ${target} with ${pte_file} using ${system_config} ${memory_mode} ${extra_build_flags} to '${output_folder}/cmake-out'" +echo "Build Arm ${toolchain/-gcc/} executor_runner for ${target} with ${pte_file} using ${system_config} ${memory_mode} ${extra_build_flags} to '${output_folder}/cmake-out'" echo "--------------------------------------------------------------------------------" cd ${et_root_dir}/examples/arm/executor_runner @@ -130,7 +143,6 @@ if [ "$build_with_etdump" = true ] ; then fi echo "Building with BundleIO/etdump/extra flags: ${build_bundleio_flags} ${build_with_etdump_flags} ${extra_build_flags}" - cmake \ -DCMAKE_BUILD_TYPE=${build_type} \ -DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \ @@ -152,8 +164,8 @@ echo "[${BASH_SOURCE[0]}] Configured CMAKE" cmake --build ${output_folder}/cmake-out -j$(nproc) -- arm_executor_runner -echo "[${BASH_SOURCE[0]}] Generated baremetal elf file:" +echo "[${BASH_SOURCE[0]}] Generated ${toolchain} elf file:" find ${output_folder}/cmake-out -name "arm_executor_runner" -echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $1}') bytes" -echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $2}') bytes" -echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $3}') bytes" +echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $1}') bytes" +echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $2}') bytes" +echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $3}') bytes" diff --git a/backends/arm/scripts/build_executorch.sh b/backends/arm/scripts/build_executorch.sh index cb2b48a644d..a25bbb1e994 100755 --- a/backends/arm/scripts/build_executorch.sh +++ b/backends/arm/scripts/build_executorch.sh @@ -13,8 +13,7 @@ set -eu script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) et_root_dir=$(cd ${script_dir}/../../.. && pwd) et_root_dir=$(realpath ${et_root_dir}) -toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake -toolchain_cmake=$(realpath ${toolchain_cmake}) +toolchain=arm-none-eabi-gcc setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh _setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools." @@ -30,6 +29,7 @@ help() { echo " --build_type= Build with Release, Debug or RelWithDebInfo, default is ${build_type}" echo " --devtools Build Devtools libs" echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log" + echo " --toolchain= Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc" exit 0 } @@ -40,11 +40,23 @@ for arg in "$@"; do --build_type=*) build_type="${arg#*=}";; --devtools) build_devtools=true ;; --etdump) build_with_etdump=true ;; + --toolchain=*) toolchain="${arg#*=}";; *) ;; esac done +if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then + toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake +elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then + toolchain_cmake=${et_root_dir}/examples/zephyr/arm-x86-64-gcc.cmake +else + echo "Error: Invalid toolchain selection, provided: ${tolchain}" + echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc}" + exit 1; +fi +toolchain_cmake=$(realpath ${toolchain_cmake}) + # Source the tools # This should be prepared by the setup.sh [[ -f ${setup_path_script} ]] \ diff --git a/backends/arm/scripts/build_portable_kernels.sh b/backends/arm/scripts/build_portable_kernels.sh index 2719fbb603e..100b75578e0 100755 --- a/backends/arm/scripts/build_portable_kernels.sh +++ b/backends/arm/scripts/build_portable_kernels.sh @@ -13,8 +13,7 @@ set -eu script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) et_root_dir=$(cd ${script_dir}/../../.. && pwd) et_root_dir=$(realpath ${et_root_dir}) -toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake -toolchain_cmake=$(realpath ${toolchain_cmake}) +toolchain=arm-none-eabi-gcc setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh _setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools." @@ -29,6 +28,7 @@ help() { echo " --et_build_root= Build output root folder to use, defaults to ${et_build_root}" echo " --build_type= Build with Release, Debug or RelWithDebInfo, default is ${build_type}" echo " --portable_kernels= Comma separated list of portable (non delagated) kernels to include Default: ${portable_kernels}" + echo " --toolchain= Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc" exit 0 } @@ -38,11 +38,23 @@ for arg in "$@"; do --et_build_root=*) et_build_root="${arg#*=}";; --build_type=*) build_type="${arg#*=}";; --portable_kernels=*) portable_kernels="${arg#*=}";; + --toolchain=*) toolchain="${arg#*=}";; *) ;; esac done +if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then + toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake +elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then + toolchain_cmake=${et_root_dir}/examples/zephyr/arm-x86-64-gcc.cmake +else + echo "Error: Invalid toolchain selection, provided: ${tolchain}" + echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc}" + exit 1; +fi +toolchain_cmake=$(realpath ${toolchain_cmake}) + # Source the tools # This should be prepared by the setup.sh [[ -f ${setup_path_script} ]] \ diff --git a/examples/arm/run.sh b/examples/arm/run.sh index 797739e3cd2..315c71d4381 100755 --- a/examples/arm/run.sh +++ b/examples/arm/run.sh @@ -38,6 +38,7 @@ memory_mode="" et_build_root="${et_root_dir}/arm_test" ethos_u_scratch_dir=${script_dir}/ethos-u-scratch scratch_dir_set=false +toolchain=arm-none-eabi-gcc function help() { echo "Usage: $(basename $0) [options]" @@ -75,6 +76,7 @@ for arg in "$@"; do --no_quantize) aot_arm_compiler_flag_quantize="" ;; --portable_kernels=*) portable_kernels="${arg#*=}";; --target=*) target="${arg#*=}";; + --toolchain=*) toolchain="${arg#*=}";; --output=*) output_folder="${arg#*=}" ; output_folder_set=true ;; --bundleio) bundleio=true ;; --etdump) build_with_etdump=true ;; @@ -94,7 +96,16 @@ done # Default Ethos-u tool folder override with --scratch-dir= ethos_u_scratch_dir=$(realpath ${ethos_u_scratch_dir}) setup_path_script=${ethos_u_scratch_dir}/setup_path.sh -toolchain_cmake=${script_dir}/ethos-u-setup/arm-none-eabi-gcc.cmake +if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then + toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake +elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then + toolchain_cmake=${et_root_dir}/examples/zephyr/arm-x86-64-gcc.cmake +else + echo "Error: Invalid toolchain selection, provided: ${tolchain}" + echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc}" + exit 1; +fi +toolchain_cmake=$(realpath ${toolchain_cmake}) _setup_msg="please refer to ${script_dir}/setup.sh to properly install necessary tools." @@ -134,8 +145,8 @@ function check_setup () { fi # If setup_path_script was correct all these checks should now pass - hash arm-none-eabi-gcc \ - || { echo "Could not find arm baremetal toolchain on PATH, ${_setup_msg}"; return 1; } + hash ${toolchain} \ + || { echo "Could not find ${toolchain} toolchain on PATH, ${_setup_msg}"; return 1; } [[ -f ${toolchain_cmake} ]] \ || { echo "Could not find ${toolchain_cmake} file, ${_setup_msg}"; return 1; } @@ -180,8 +191,8 @@ if [ "$bundleio" = true ] ; then et_dump_flag="--etdump" fi -backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag -backends/arm/scripts/build_portable_kernels.sh --et_build_root="${et_build_root}" --build_type=$build_type --portable_kernels=$portable_kernels +backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag --toolchain="${toolchain}" +backends/arm/scripts/build_portable_kernels.sh --et_build_root="${et_build_root}" --build_type=$build_type --portable_kernels=$portable_kernels --toolchain="${toolchain}" if [[ -z "$model_name" ]]; then # the test models run, and whether to delegate @@ -265,7 +276,7 @@ for i in "${!test_model[@]}"; do else set -x # Rebuild the application as the pte is imported as a header/c array - backends/arm/scripts/build_executor_runner.sh --et_build_root="${et_build_root}" --pte="${pte_file}" --build_type=${build_type} --target=${target} --system_config=${system_config} --memory_mode=${memory_mode} ${bundleio_flag} ${et_dump_flag} --extra_build_flags="${extra_build_flags}" --ethosu_tools_dir="${ethos_u_scratch_dir}" + backends/arm/scripts/build_executor_runner.sh --et_build_root="${et_build_root}" --pte="${pte_file}" --build_type=${build_type} --target=${target} --system_config=${system_config} --memory_mode=${memory_mode} ${bundleio_flag} ${et_dump_flag} --extra_build_flags="${extra_build_flags}" --ethosu_tools_dir="${ethos_u_scratch_dir}" --toolchain="${toolchain}" if [ "$build_only" = false ] ; then # Execute the executor_runner on FVP Simulator elf_file="${output_folder}/${elf_folder}/cmake-out/arm_executor_runner" diff --git a/examples/zephyr/arm-x86-64-gcc.cmake b/examples/zephyr/arm-x86-64-gcc.cmake new file mode 100644 index 00000000000..8e1a478a6cb --- /dev/null +++ b/examples/zephyr/arm-x86-64-gcc.cmake @@ -0,0 +1,106 @@ +# +# Copyright (c) 2020-2022 Arm Limited. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the License); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an AS IS BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Copied this file from core_platform/cmake/toolchain/arm-non-eabi-gcc.cmake And +# modified to align better with cs300 platform + +set(TARGET_CPU + "cortex-m55" + CACHE STRING "Target CPU" +) +string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR) + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_C_COMPILER "arm-zephyr-eabi-gcc") +set(CMAKE_CXX_COMPILER "arm-zephyr-eabi-g++") +set(CMAKE_ASM_COMPILER "arm-zephyr-eabi-gcc") +set(CMAKE_LINKER "arm-zephyr-eabi-ld") + +set(CMAKE_EXECUTABLE_SUFFIX ".elf") +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# Select C/C++ version +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) + +set(GCC_CPU ${CMAKE_SYSTEM_PROCESSOR}) +string(REPLACE "cortex-m85" "cortex-m55" GCC_CPU ${GCC_CPU}) + +# Compile options +add_compile_options( + -mcpu=${GCC_CPU} -mthumb "$<$:-gdwarf-3>" + "$<$:-fno-unwind-tables;-fno-rtti;-fno-exceptions>" + -fdata-sections -ffunction-sections +) + +# Compile defines +add_compile_definitions("$<$>:NDEBUG>") + +# Link options +add_link_options(-mcpu=${GCC_CPU} -mthumb) + +if(SEMIHOSTING) + add_link_options(--specs=rdimon.specs) +else() + add_link_options(--specs=nosys.specs) +endif() + +# Set floating point unit +if(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+fp") + set(FLOAT hard) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+nofp") + set(FLOAT soft) +elseif( + CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)" + OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55(\\+|$)" + OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85(\\+|$)" +) + set(FLOAT hard) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)" + OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)" +) + set(FLOAT hard) + set(FPU_CONFIG "fpv4-sp-d16") + add_compile_options(-mfpu=${FPU_CONFIG}) + add_link_options(-mfpu=${FPU_CONFIG}) +else() + set(FLOAT soft) +endif() + +if(FLOAT) + add_compile_options(-mfloat-abi=${FLOAT}) + add_link_options(-mfloat-abi=${FLOAT}) +endif() + +add_link_options(LINKER:--nmagic,--gc-sections) + +# Compilation warnings +add_compile_options( + # -Wall -Wextra -Wcast-align -Wdouble-promotion -Wformat + # -Wmissing-field-initializers -Wnull-dereference -Wredundant-decls -Wshadow + # -Wswitch -Wswitch-default -Wunused -Wno-redundant-decls + -Wno-stringop-overread + -Wno-error=format= + -Wno-error=maybe-uninitialized + -Wno-error=deprecated-declarations + -Wno-error=shift-count-overflow + -Wno-psabi +)