Skip to content

Commit 53bbe72

Browse files
committed
Plumbing to allow arm example runnner to use command line parameter zephyr toolchain when possible
1 parent adb5318 commit 53bbe72

File tree

5 files changed

+137
-17
lines changed

5 files changed

+137
-17
lines changed

backends/arm/scripts/build_executor_runner.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -eu
99
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
1010
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
1111
et_root_dir=$(realpath ${et_root_dir})
12-
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
12+
toolchain=arm-none-eabi-gcc
1313
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
1414
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."
1515

@@ -46,6 +46,7 @@ help() {
4646
echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte"
4747
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
4848
echo " --ethosu_tools_dir=<FOLDER> Path to your Ethos-U tools dir if you not using default: ${ethosu_tools_dir}"
49+
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc"
4950
exit 0
5051
}
5152

@@ -63,11 +64,15 @@ for arg in "$@"; do
6364
--output=*) output_folder="${arg#*=}" ; output_folder_set=true ;;
6465
--et_build_root=*) et_build_root="${arg#*=}";;
6566
--ethosu_tools_dir=*) ethosu_tools_dir="${arg#*=}";;
67+
--toolchain=*) toolchain="${arg#*=}";;
6668
*)
6769
;;
6870
esac
6971
done
7072

73+
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
74+
toolchain_cmake=$(realpath ${toolchain_cmake})
75+
7176
# Source the tools
7277
# This should be prepared by the setup.sh
7378
[[ -f ${setup_path_script} ]] \
@@ -116,7 +121,7 @@ else
116121
target_cpu=cortex-m85
117122
fi
118123
echo "--------------------------------------------------------------------------------"
119-
echo "Build Arm Baremetal executor_runner for ${target} with ${pte_file} using ${system_config} ${memory_mode} ${extra_build_flags} to '${output_folder}/cmake-out'"
124+
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'"
120125
echo "--------------------------------------------------------------------------------"
121126

122127
cd ${et_root_dir}/examples/arm/executor_runner
@@ -130,7 +135,6 @@ if [ "$build_with_etdump" = true ] ; then
130135
fi
131136

132137
echo "Building with BundleIO/etdump/extra flags: ${build_bundleio_flags} ${build_with_etdump_flags} ${extra_build_flags}"
133-
134138
cmake \
135139
-DCMAKE_BUILD_TYPE=${build_type} \
136140
-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \
@@ -152,8 +156,8 @@ echo "[${BASH_SOURCE[0]}] Configured CMAKE"
152156

153157
cmake --build ${output_folder}/cmake-out -j$(nproc) -- arm_executor_runner
154158

155-
echo "[${BASH_SOURCE[0]}] Generated baremetal elf file:"
159+
echo "[${BASH_SOURCE[0]}] Generated ${toolchain} elf file:"
156160
find ${output_folder}/cmake-out -name "arm_executor_runner"
157-
echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $1}') bytes"
158-
echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $2}') bytes"
159-
echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $3}') bytes"
161+
echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $1}') bytes"
162+
echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $2}') bytes"
163+
echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $3}') bytes"

backends/arm/scripts/build_executorch.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ set -eu
1313
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
1414
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
1515
et_root_dir=$(realpath ${et_root_dir})
16-
toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
17-
toolchain_cmake=$(realpath ${toolchain_cmake})
16+
toolchain=arm-none-eabi-gcc
1817
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
1918
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."
2019

@@ -30,6 +29,7 @@ help() {
3029
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
3130
echo " --devtools Build Devtools libs"
3231
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
32+
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc"
3333
exit 0
3434
}
3535

@@ -40,11 +40,15 @@ for arg in "$@"; do
4040
--build_type=*) build_type="${arg#*=}";;
4141
--devtools) build_devtools=true ;;
4242
--etdump) build_with_etdump=true ;;
43+
--toolchain=*) toolchain="${arg#*=}";;
4344
*)
4445
;;
4546
esac
4647
done
4748

49+
toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/${toolchain}.cmake
50+
toolchain_cmake=$(realpath ${toolchain_cmake})
51+
4852
# Source the tools
4953
# This should be prepared by the setup.sh
5054
[[ -f ${setup_path_script} ]] \

backends/arm/scripts/build_portable_kernels.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ set -eu
1313
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
1414
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
1515
et_root_dir=$(realpath ${et_root_dir})
16-
toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
17-
toolchain_cmake=$(realpath ${toolchain_cmake})
16+
toolchain=arm-none-eabi-gcc
1817
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
1918
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."
2019

@@ -29,6 +28,7 @@ help() {
2928
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
3029
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
3130
echo " --portable_kernels=<OPS> Comma separated list of portable (non delagated) kernels to include Default: ${portable_kernels}"
31+
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc"
3232
exit 0
3333
}
3434

@@ -38,11 +38,15 @@ for arg in "$@"; do
3838
--et_build_root=*) et_build_root="${arg#*=}";;
3939
--build_type=*) build_type="${arg#*=}";;
4040
--portable_kernels=*) portable_kernels="${arg#*=}";;
41+
--toolchain=*) toolchain="${arg#*=}";;
4142
*)
4243
;;
4344
esac
4445
done
4546

47+
toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/${toolchain}.cmake
48+
toolchain_cmake=$(realpath ${toolchain_cmake})
49+
4650
# Source the tools
4751
# This should be prepared by the setup.sh
4852
[[ -f ${setup_path_script} ]] \
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#
2+
# Copyright (c) 2020-2022 Arm Limited. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the License); you may
7+
# not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
# Copied this file from core_platform/cmake/toolchain/arm-non-eabi-gcc.cmake And
20+
# modified to align better with cs300 platform
21+
22+
set(TARGET_CPU
23+
"cortex-m55"
24+
CACHE STRING "Target CPU"
25+
)
26+
string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR)
27+
28+
set(CMAKE_SYSTEM_NAME Generic)
29+
set(CMAKE_C_COMPILER "arm-zephyr-eabi-gcc")
30+
set(CMAKE_CXX_COMPILER "arm-zephyr-eabi-g++")
31+
set(CMAKE_ASM_COMPILER "arm-zephyr-eabi-gcc")
32+
set(CMAKE_LINKER "arm-zephyr-eabi-ld")
33+
34+
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
35+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
36+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
37+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
38+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
39+
40+
# Select C/C++ version
41+
set(CMAKE_C_STANDARD 11)
42+
set(CMAKE_CXX_STANDARD 17)
43+
44+
set(GCC_CPU ${CMAKE_SYSTEM_PROCESSOR})
45+
string(REPLACE "cortex-m85" "cortex-m55" GCC_CPU ${GCC_CPU})
46+
47+
# Compile options
48+
add_compile_options(
49+
-mcpu=${GCC_CPU} -mthumb "$<$<CONFIG:DEBUG>:-gdwarf-3>"
50+
"$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>"
51+
-fdata-sections -ffunction-sections
52+
)
53+
54+
# Compile defines
55+
add_compile_definitions("$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")
56+
57+
# Link options
58+
add_link_options(-mcpu=${GCC_CPU} -mthumb)
59+
60+
if(SEMIHOSTING)
61+
add_link_options(--specs=rdimon.specs)
62+
else()
63+
add_link_options(--specs=nosys.specs)
64+
endif()
65+
66+
# Set floating point unit
67+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+fp")
68+
set(FLOAT hard)
69+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+nofp")
70+
set(FLOAT soft)
71+
elseif(
72+
CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)"
73+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55(\\+|$)"
74+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85(\\+|$)"
75+
)
76+
set(FLOAT hard)
77+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)"
78+
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)"
79+
)
80+
set(FLOAT hard)
81+
set(FPU_CONFIG "fpv4-sp-d16")
82+
add_compile_options(-mfpu=${FPU_CONFIG})
83+
add_link_options(-mfpu=${FPU_CONFIG})
84+
else()
85+
set(FLOAT soft)
86+
endif()
87+
88+
if(FLOAT)
89+
add_compile_options(-mfloat-abi=${FLOAT})
90+
add_link_options(-mfloat-abi=${FLOAT})
91+
endif()
92+
93+
add_link_options(LINKER:--nmagic,--gc-sections)
94+
95+
# Compilation warnings
96+
add_compile_options(
97+
# -Wall -Wextra -Wcast-align -Wdouble-promotion -Wformat
98+
# -Wmissing-field-initializers -Wnull-dereference -Wredundant-decls -Wshadow
99+
# -Wswitch -Wswitch-default -Wunused -Wno-redundant-decls
100+
-Wno-stringop-overread
101+
-Wno-error=format=
102+
-Wno-error=maybe-uninitialized
103+
-Wno-error=deprecated-declarations
104+
-Wno-error=shift-count-overflow
105+
-Wno-psabi
106+
)

examples/arm/run.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ memory_mode=""
3838
et_build_root="${et_root_dir}/arm_test"
3939
ethos_u_scratch_dir=${script_dir}/ethos-u-scratch
4040
scratch_dir_set=false
41+
toolchain=arm-none-eabi-gcc
4142

4243
function help() {
4344
echo "Usage: $(basename $0) [options]"
@@ -75,6 +76,7 @@ for arg in "$@"; do
7576
--no_quantize) aot_arm_compiler_flag_quantize="" ;;
7677
--portable_kernels=*) portable_kernels="${arg#*=}";;
7778
--target=*) target="${arg#*=}";;
79+
--toolchain=*) toolchain="${arg#*=}";;
7880
--output=*) output_folder="${arg#*=}" ; output_folder_set=true ;;
7981
--bundleio) bundleio=true ;;
8082
--etdump) build_with_etdump=true ;;
@@ -94,7 +96,7 @@ done
9496
# Default Ethos-u tool folder override with --scratch-dir=<FOLDER>
9597
ethos_u_scratch_dir=$(realpath ${ethos_u_scratch_dir})
9698
setup_path_script=${ethos_u_scratch_dir}/setup_path.sh
97-
toolchain_cmake=${script_dir}/ethos-u-setup/arm-none-eabi-gcc.cmake
99+
toolchain_cmake=${script_dir}/ethos-u-setup/${toolchain}.cmake
98100
_setup_msg="please refer to ${script_dir}/setup.sh to properly install necessary tools."
99101

100102

@@ -134,8 +136,8 @@ function check_setup () {
134136
fi
135137

136138
# If setup_path_script was correct all these checks should now pass
137-
hash arm-none-eabi-gcc \
138-
|| { echo "Could not find arm baremetal toolchain on PATH, ${_setup_msg}"; return 1; }
139+
hash ${toolchain} \
140+
|| { echo "Could not find ${toolchain} toolchain on PATH, ${_setup_msg}"; return 1; }
139141

140142
[[ -f ${toolchain_cmake} ]] \
141143
|| { echo "Could not find ${toolchain_cmake} file, ${_setup_msg}"; return 1; }
@@ -180,8 +182,8 @@ if [ "$bundleio" = true ] ; then
180182
et_dump_flag="--etdump"
181183
fi
182184

183-
backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag
184-
backends/arm/scripts/build_portable_kernels.sh --et_build_root="${et_build_root}" --build_type=$build_type --portable_kernels=$portable_kernels
185+
backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag --toolchain="${toolchain}"
186+
backends/arm/scripts/build_portable_kernels.sh --et_build_root="${et_build_root}" --build_type=$build_type --portable_kernels=$portable_kernels --toolchain="${toolchain}"
185187

186188
if [[ -z "$model_name" ]]; then
187189
# the test models run, and whether to delegate
@@ -265,7 +267,7 @@ for i in "${!test_model[@]}"; do
265267
else
266268
set -x
267269
# Rebuild the application as the pte is imported as a header/c array
268-
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}"
270+
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}"
269271
if [ "$build_only" = false ] ; then
270272
# Execute the executor_runner on FVP Simulator
271273
elf_file="${output_folder}/${elf_folder}/cmake-out/arm_executor_runner"

0 commit comments

Comments
 (0)