Skip to content

Commit 4df40e1

Browse files
authored
Arm backend: Add skip setup options to setup.sh (#11474)
Adds following new options: --skip-fvp-setup --skip-vela-setup --skip-toolchain-setup By default nothing will be skipped. Also adds explicit --root-dir option to support previous usage. cc @digantdesai @freddan80 @per @zingo @oscarandersson8218
1 parent 77f16dc commit 4df40e1

File tree

1 file changed

+107
-51
lines changed

1 file changed

+107
-51
lines changed

examples/arm/setup.sh

Lines changed: 107 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
1616
et_dir=$(realpath $script_dir/../..)
1717
ARCH="$(uname -m)"
1818
OS="$(uname -s)"
19+
root_dir="${script_dir}/ethos-u-scratch"
20+
eula_acceptance=0
21+
skip_toolchain_setup=0
22+
skip_fvp_setup=0
23+
skip_vela_setup=0
24+
1925

2026
# Figure out if setup.sh was called or sourced and save it into "is_script_sourced"
2127
(return 0 2>/dev/null) && is_script_sourced=1 || is_script_sourced=0
@@ -65,41 +71,81 @@ vela_rev="8cac2b9a7204b57125a8718049519b091a98846c"
6571
########
6672
### Functions
6773
########
74+
75+
function print_usage() {
76+
echo "Usage: $(basename $0) <--i-agree-to-the-contained-eula> [--root-dir path-to-a-scratch-dir] [--skip-fvp-setup] [--skip-toolchain-setup] [--skip-vela-setup]"
77+
echo "Supplied args: $*"
78+
}
79+
80+
function check_options() {
81+
while [[ "${#}" -gt 0 ]]; do
82+
case "$1" in
83+
--i-agree-to-the-contained-eula)
84+
eula_acceptance=1
85+
shift
86+
;;
87+
--root-dir)
88+
# Only change default root dir if the script is being executed and not sourced.
89+
if [[ $is_script_sourced -eq 0 ]]; then
90+
root_dir=${2:-"${root_dir}"}
91+
fi
92+
93+
if [[ $# -ge 2 ]]; then
94+
shift 2
95+
else
96+
print_usage "$@"
97+
exit 1
98+
fi
99+
;;
100+
--skip-toolchain-setup)
101+
skip_toolchain_setup=1
102+
shift
103+
;;
104+
--skip-fvp-setup)
105+
skip_fvp_setup=1
106+
shift
107+
;;
108+
--skip-vela-setup)
109+
skip_vela_setup=1
110+
shift
111+
;;
112+
--help)
113+
print_usage "$@"
114+
exit 0
115+
;;
116+
*)
117+
print_usage "$@"
118+
exit 1
119+
;;
120+
esac
121+
done
122+
}
123+
68124
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
76125
mkdir -p ${root_dir}
77126
root_dir=$(realpath ${root_dir})
78127
setup_path_script="${root_dir}/setup_path.sh"
79128
}
80129

81130
function check_fvp_eula () {
82131
# Mandatory user arg --i-agree-to-the-contained-eula
83-
eula_acceptance="${1:-'.'}"
84132
eula_acceptance_by_variable="${ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA:-False}"
85133

86-
if [[ "${eula_acceptance}" != "--i-agree-to-the-contained-eula" ]]; then
134+
if [[ "${eula_acceptance}" -eq 0 ]]; then
87135
if [[ ${eula_acceptance_by_variable} != "True" ]]; then
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!"
136+
echo "Must pass argument '--i-agree-to-the-contained-eula' to agree to EULA associated with downloading the FVP."
137+
echo "Alternativly set environment variable ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True."
138+
echo "Exiting!"
91139
exit 1
92140
else
93141
echo "Arm EULA for FVP agreed to with ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True environment variable"
94142
fi
95-
else
96-
shift; # drop this arg
97143
fi
98144
}
99145

100146
function setup_fvp() {
101147
# check EULA, forward argument
102-
check_fvp_eula ${1:-'.'}
148+
check_fvp_eula
103149

104150
if [[ "${OS}" != "Linux" ]]; then
105151
# Check if FVP is callable
@@ -169,81 +215,91 @@ function setup_vela() {
169215
pip install ethos-u-vela@git+${vela_repo_url}@${vela_rev}
170216
}
171217

172-
function setup_path() {
173-
echo $setup_path_script
174-
}
175-
176218
function create_setup_path(){
177-
echo "" > "${setup_path_script}"
178-
fvps=("corstone300" "corstone320")
179-
for fvp in "${fvps[@]}"; do
180-
model_dir_variable=${fvp}_model_dir
181-
fvp_model_dir=${!model_dir_variable}
182-
fvp_bin_path="${root_dir}/FVP-${fvp}/models/${fvp_model_dir}"
183-
echo "export PATH=\${PATH}:${fvp_bin_path}" >> ${setup_path_script}
184-
done
219+
cd "${root_dir}"
185220

186-
# Fixup for Corstone-320 python dependency
187-
echo "export LD_LIBRARY_PATH=${root_dir}/FVP-corstone320/python/lib/" >> ${setup_path_script}
221+
echo "" > "${setup_path_script}"
188222

189-
toolchain_bin_path="$(cd ${toolchain_dir}/bin && pwd)"
190-
echo "export PATH=\${PATH}:${toolchain_bin_path}" >> ${setup_path_script}
223+
if [[ "${skip_fvp_setup}" -eq 0 ]]; then
224+
fvps=("corstone300" "corstone320")
225+
for fvp in "${fvps[@]}"; do
226+
model_dir_variable=${fvp}_model_dir
227+
fvp_model_dir=${!model_dir_variable}
228+
fvp_bin_path="${root_dir}/FVP-${fvp}/models/${fvp_model_dir}"
229+
echo "export PATH=\${PATH}:${fvp_bin_path}" >> ${setup_path_script}
230+
done
231+
232+
# Fixup for Corstone-320 python dependency
233+
echo "export LD_LIBRARY_PATH=${root_dir}/FVP-corstone320/python/lib/" >> ${setup_path_script}
234+
235+
echo "hash FVP_Corstone_SSE-300_Ethos-U55" >> ${setup_path_script}
236+
echo "hash FVP_Corstone_SSE-300_Ethos-U65" >> ${setup_path_script}
237+
echo "hash FVP_Corstone_SSE-320" >> ${setup_path_script}
238+
fi
191239

192-
echo "hash FVP_Corstone_SSE-300_Ethos-U55" >> ${setup_path_script}
193-
echo "hash FVP_Corstone_SSE-300_Ethos-U65" >> ${setup_path_script}
194-
echo "hash FVP_Corstone_SSE-320" >> ${setup_path_script}
240+
if [[ "${skip_toolchain_setup}" -eq 0 ]]; then
241+
toolchain_bin_path="$(cd ${toolchain_dir}/bin && pwd)"
242+
echo "export PATH=\${PATH}:${toolchain_bin_path}" >> ${setup_path_script}
243+
fi
195244
}
196245

197246
function check_platform_support() {
247+
# Make sure we are on a supported platform
198248
if [[ "${ARCH}" != "x86_64" ]] && [[ "${ARCH}" != "aarch64" ]] \
199249
&& [[ "${ARCH}" != "arm64" ]]; then
200250
echo "[main] Error: only x86-64 & aarch64 architecture is supported for now!"
201251
exit 1
202252
fi
203-
204-
# Make sure we are on a supported platform
205-
if [[ "${1:-'.'}" == "-h" || "${#}" -gt 2 ]]; then
206-
echo "Usage: $(basename $0) <--i-agree-to-the-contained-eula> [path-to-a-scratch-dir]"
207-
echo "Supplied args: $*"
208-
exit 1
209-
fi
210253
}
211254

255+
212256
########
213257
### main
214258
########
215259

216260
# script is not sourced! Lets run "main"
217-
if [[ $is_script_sourced -eq 0 ]]
218-
then
261+
if [[ $is_script_sourced -eq 0 ]]; then
219262
set -e
220263

264+
check_options "$@"
265+
221266
check_platform_support
222267

223268
cd "${script_dir}"
224269

225270
# Setup the root dir
226271
setup_root_dir
227272
cd "${root_dir}"
228-
echo "[main] Using root dir ${root_dir}"
273+
echo "[main] Using root dir ${root_dir} and options:"
274+
echo "skip-fvp-setup=${skip_fvp_setup}"
275+
echo "skip-toolchain-setup=${skip_toolchain_setup}"
276+
echo "skip-vela-setup=${skip_vela_setup}"
229277

230278
# Import utils
231279
source $et_dir/backends/arm/scripts/utils.sh
232280

233-
# Setup FVP
234-
setup_fvp ${1:-'.'}
235-
236281
# Setup toolchain
237-
setup_toolchain
282+
if [[ "${skip_toolchain_setup}" -eq 0 ]]; then
283+
setup_toolchain
284+
fi
238285

239-
# Create new setup_path script only if fvp and toolchain setup went well.
240-
create_setup_path
286+
# Setup FVP
287+
if [[ "${skip_fvp_setup}" -eq 0 ]]; then
288+
setup_fvp
289+
fi
290+
291+
# Create new setup_path script
292+
if [[ "${skip_toolchain_setup}" -eq 0 || "${skip_fvp_setup}" -eq 0 ]]; then
293+
create_setup_path
294+
fi
241295

242296
# Setup the tosa_reference_model
243297
$et_dir/backends/arm/scripts/install_reference_model.sh ${root_dir}
244298

245299
# Setup vela and patch in codegen fixes
246-
setup_vela
300+
if [[ "${skip_vela_setup}" -eq 0 ]]; then
301+
setup_vela
302+
fi
247303

248304
echo "[main] update path by doing 'source ${setup_path_script}'"
249305

0 commit comments

Comments
 (0)