Skip to content

Commit 0fa0003

Browse files
authored
Arm backend: Make run.sh run without setup.sh (#10515)
This commit lets the user run run.sh without running setup.sh manually. As long as the FVP eula has been accepted. Setup.sh can still be run manually and with another scratchdir set by the user. But if setup.sh is sourced the scratchdir cannot be set. Setup.sh has been give some cleanup to handle scratchdir being set by user and code has been moved into functions.
1 parent 4236e5b commit 0fa0003

File tree

2 files changed

+80
-38
lines changed

2 files changed

+80
-38
lines changed

examples/arm/run.sh

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ system_config=""
3636
memory_mode=""
3737
et_build_root="${et_root_dir}/arm_test"
3838
ethos_u_scratch_dir=${script_dir}/ethos-u-scratch
39+
scratch_dir_set=false
3940

4041
function help() {
4142
echo "Usage: $(basename $0) [options]"
@@ -81,7 +82,7 @@ for arg in "$@"; do
8182
--system_config=*) system_config="${arg#*=}";;
8283
--memory_mode=*) memory_mode="${arg#*=}";;
8384
--et_build_root=*) et_build_root="${arg#*=}";;
84-
--scratch-dir=*) ethos_u_scratch_dir="${arg#*=}";;
85+
--scratch-dir=*) ethos_u_scratch_dir="${arg#*=}" ; scratch_dir_set=true ;;
8586
*)
8687
;;
8788
esac
@@ -113,25 +114,47 @@ then
113114
fi
114115
fi
115116

116-
#######
117-
### Main
118-
#######
119-
# Source the tools
120-
# This should be prepared by the setup.sh
121-
[[ -f ${setup_path_script} ]] \
122-
|| { echo "Missing ${setup_path_script}. ${_setup_msg}"; exit 1; }
117+
function check_setup () {
118+
# basic checks that setup.sh did everything needed before we get started
123119

124-
source ${setup_path_script}
120+
# check if setup_path_script was created, if so source it
121+
if [[ -f ${setup_path_script} ]]; then
122+
source $setup_path_script
123+
else
124+
echo "Could not find ${setup_path_script} file, ${_setup_msg}"
125+
return 1
126+
fi
127+
128+
# If setup_path_script was correct all these checks should now pass
129+
hash arm-none-eabi-gcc \
130+
|| { echo "Could not find arm baremetal toolchain on PATH, ${_setup_msg}"; return 1; }
125131

126-
# basic checks before we get started
127-
hash arm-none-eabi-gcc \
128-
|| { echo "Could not find arm baremetal toolchain on PATH, ${_setup_msg}"; exit 1; }
132+
[[ -f ${toolchain_cmake} ]] \
133+
|| { echo "Could not find ${toolchain_cmake} file, ${_setup_msg}"; return 1; }
129134

130-
[[ -f ${toolchain_cmake} ]] \
131-
|| { echo "Could not find ${toolchain_cmake} file, ${_setup_msg}"; exit 1; }
135+
[[ -f ${et_root_dir}/CMakeLists.txt ]] \
136+
|| { echo "Executorch repo doesn't contain CMakeLists.txt file at root level"; return 1; }
132137

133-
[[ -f ${et_root_dir}/CMakeLists.txt ]] \
134-
|| { echo "Executorch repo doesn't contain CMakeLists.txt file at root level"; exit 1; }
138+
return 0
139+
}
140+
141+
#######
142+
### Main
143+
#######
144+
if ! check_setup; then
145+
if [ "$scratch_dir_set" = false ] ; then
146+
# check setup failed, no scratchdir given as parameter. trying to run setup.sh
147+
if ${script_dir}/setup.sh; then
148+
# and recheck setup. If this fails exit.
149+
if ! check_setup; then
150+
exit 1
151+
fi
152+
else
153+
# setup.sh failed, it should print why
154+
exit 1
155+
fi
156+
fi
157+
fi
135158

136159
# Build executorch libraries
137160
cd $et_root_dir

examples/arm/setup.sh

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ et_dir=$(realpath $script_dir/../..)
1717
ARCH="$(uname -m)"
1818
OS="$(uname -s)"
1919

20+
# Figure out if setup.sh was called or sourced and save it into "is_script_sourced"
21+
(return 0 2>/dev/null) && is_script_sourced=1 || is_script_sourced=0
22+
2023
if [[ "${ARCH}" == "x86_64" ]]; then
2124
# FVPs
2225
corstone300_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-300/FVP_Corstone_SSE-300_11.22_20_Linux64.tgz?rev=018659bd574f4e7b95fa647e7836ccf4&hash=22A79103C6FA5FFA7AFF3BE0447F3FF9"
@@ -59,35 +62,45 @@ fi
5962
vela_repo_url="https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-vela"
6063
vela_rev="425541302c7e4b6fbeca7c0061286b131ee507c3"
6164

62-
########
63-
### Optional user args
64-
########
65-
root_dir=${2:-"${script_dir}/ethos-u-scratch"}
66-
mkdir -p ${root_dir}
67-
root_dir=$(realpath ${root_dir})
68-
setup_path_script="${root_dir}/setup_path.sh"
69-
70-
7165
########
7266
### Functions
7367
########
68+
function setup_root_dir() {
69+
# Handle a different root_dir set by the user as argument to the
70+
# script. This can only happen if the script is being executed and
71+
# not sourced.
72+
root_dir="${script_dir}/ethos-u-scratch"
73+
if [[ $is_script_sourced -eq 0 ]]; then
74+
root_dir=${2:-"${script_dir}/ethos-u-scratch"}
75+
fi
76+
mkdir -p ${root_dir}
77+
root_dir=$(realpath ${root_dir})
78+
setup_path_script="${root_dir}/setup_path.sh"
79+
}
7480

75-
function setup_fvp() {
76-
81+
function check_fvp_eula () {
7782
# Mandatory user arg --i-agree-to-the-contained-eula
7883
eula_acceptance="${1:-'.'}"
7984
eula_acceptance_by_variable="${ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA:-False}"
8085

8186
if [[ "${eula_acceptance}" != "--i-agree-to-the-contained-eula" ]]; then
8287
if [[ ${eula_acceptance_by_variable} != "True" ]]; then
83-
echo "Must pass first positional argument '--i-agree-to-the-contained-eula' to agree to EULA associated with downloading the FVP. Exiting!"
84-
exit 1
88+
echo "Must pass first positional argument '--i-agree-to-the-contained-eula' to agree to EULA associated with downloading the FVP."
89+
echo "Alternativly set environment variable ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True."
90+
echo "Exiting!"
91+
exit 1
8592
else
86-
echo "Arm EULA for FVP agreed to with ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True environment variable"
93+
echo "Arm EULA for FVP agreed to with ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True environment variable"
8794
fi
8895
else
8996
shift; # drop this arg
9097
fi
98+
}
99+
100+
function setup_fvp() {
101+
# check EULA, forward argument
102+
check_fvp_eula ${1:-'.'}
103+
91104
if [[ "${OS}" != "Linux" ]]; then
92105
# Check if FVP is callable
93106
if command -v FVP_Corstone_SSE-300_Ethos-U55 &> /dev/null; then
@@ -181,14 +194,7 @@ function create_setup_path(){
181194
echo "hash FVP_Corstone_SSE-320" >> ${setup_path_script}
182195
}
183196

184-
########
185-
### main
186-
########
187-
# Only run this if script is executed, not if it is sourced
188-
(return 0 2>/dev/null) && is_script_sourced=1 || is_script_sourced=0
189-
if [[ $is_script_sourced -eq 0 ]]
190-
then
191-
set -e
197+
function check_platform_support() {
192198
if [[ "${ARCH}" != "x86_64" ]] && [[ "${ARCH}" != "aarch64" ]] \
193199
&& [[ "${ARCH}" != "arm64" ]]; then
194200
echo "[main] Error: only x86-64 & aarch64 architecture is supported for now!"
@@ -201,10 +207,23 @@ if [[ $is_script_sourced -eq 0 ]]
201207
echo "Supplied args: $*"
202208
exit 1
203209
fi
210+
}
211+
212+
########
213+
### main
214+
########
215+
216+
# script is not sourced! Lets run "main"
217+
if [[ $is_script_sourced -eq 0 ]]
218+
then
219+
set -e
220+
221+
check_platform_support
204222

205223
cd "${script_dir}"
206224

207225
# Setup the root dir
226+
setup_root_dir
208227
cd "${root_dir}"
209228
echo "[main] Using root dir ${root_dir}"
210229

0 commit comments

Comments
 (0)