Skip to content

Commit 150c4c6

Browse files
authored
Arm backend: Refactor setup.sh to break out fvp installation (#13865)
Broken out the fvp installation into a separate script handling only that part. No functional change. Signed-off-by: [email protected]
1 parent 26b4e96 commit 150c4c6

File tree

2 files changed

+137
-102
lines changed

2 files changed

+137
-102
lines changed

backends/arm/scripts/fvp_utils.sh

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# Copyright 2025 Arm Limited and/or its affiliates.
6+
#
7+
# This source code is licensed under the BSD-style license found in the
8+
# LICENSE file in the root directory of this source tree.
9+
10+
# The purpose of this file is to isolate all the functions to download
11+
# and setup FVP. The reasons for behind this are multiple.
12+
# The FVP needs a EULA acceptance and since the software download
13+
# differs for arch and os it becomes quite messy to try and handle
14+
# inside setup.sh.
15+
16+
# Important to check for unset variables since this script is always sourced from setup.sh
17+
set -u
18+
19+
# Check if the script is being sourced
20+
(return 0 2>/dev/null)
21+
if [[ $? -ne 0 ]]; then
22+
echo "Error: This script must be sourced."
23+
exit 1
24+
fi
25+
26+
if [[ "${ARCH}" == "x86_64" ]]; then
27+
# FVPs
28+
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"
29+
corstone300_model_dir="Linux64_GCC-9.3"
30+
corstone300_md5_checksum="98e93b949d0fbac977292d8668d34523"
31+
32+
corstone320_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-320/FVP_Corstone_SSE-320_11.27_25_Linux64.tgz?rev=a507bffc219a4d5792f1192ab7002d89&hash=D9A824AA8227D2E679C9B9787FF4E8B6FBE3D7C6"
33+
corstone320_model_dir="Linux64_GCC-9.3"
34+
corstone320_md5_checksum="3deb3c68f9b2d145833f15374203514d"
35+
elif [[ "${ARCH}" == "aarch64" ]] || [[ "${ARCH}" == "arm64" ]]; then
36+
# FVPs
37+
corstone300_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-300/FVP_Corstone_SSE-300_11.22_20_Linux64_armv8l.tgz?rev=9cc6e9a32bb947ca9b21fa162144cb01&hash=7657A4CF27D42E892E3F08D452AAB073"
38+
corstone300_model_dir="Linux64_armv8l_GCC-9.3"
39+
corstone300_md5_checksum="cbbabbe39b07939cff7a3738e1492ef1"
40+
41+
corstone320_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-320/FVP_Corstone_SSE-320_11.27_25_Linux64_armv8l.tgz?rev=b6ebe0923cb84f739e017385fd3c333c&hash=8965C4B98E2FF7F792A099B08831FE3CB6120493"
42+
corstone320_model_dir="Linux64_armv8l_GCC-9.3"
43+
corstone320_md5_checksum="3889f1d80a6d9861ea4aa6f1c88dd0ae"
44+
else
45+
echo "[main] Error: only x86-64 & aarch64/arm64 architecture is supported for now!"; exit 1;
46+
fi
47+
48+
function install_fvp() {
49+
# Download and install the Corstone 300 FVP simulator platform
50+
fvps=("corstone300" "corstone320")
51+
52+
for fvp in "${fvps[@]}"; do
53+
cd "${root_dir}"
54+
if [[ ! -e "FVP_${fvp}.tgz" ]]; then
55+
echo "[${FUNCNAME[0]}] Downloading FVP ${fvp}..."
56+
url_variable=${fvp}_url
57+
fvp_url=${!url_variable}
58+
curl --output "FVP_${fvp}.tgz" "${fvp_url}"
59+
md5_variable=${fvp}_md5_checksum
60+
fvp_md5_checksum=${!md5_variable}
61+
verify_md5 ${fvp_md5_checksum} FVP_${fvp}.tgz || exit 1
62+
fi
63+
64+
echo "[${FUNCNAME[0]}] Installing FVP ${fvp}..."
65+
rm -rf FVP-${fvp}
66+
mkdir -p FVP-${fvp}
67+
cd FVP-${fvp}
68+
tar xf ../FVP_${fvp}.tgz
69+
70+
# Install the FVP
71+
case ${fvp} in
72+
corstone300)
73+
./FVP_Corstone_SSE-300.sh --i-agree-to-the-contained-eula --force --destination ./ --quiet --no-interactive
74+
;;
75+
corstone320)
76+
./FVP_Corstone_SSE-320.sh --i-agree-to-the-contained-eula --force --destination ./ --quiet --no-interactive
77+
;;
78+
*)
79+
echo "[${FUNCNAME[0]}] Error: Unknown FVP model ${fvp}. Exiting."
80+
exit 1
81+
;;
82+
esac
83+
done
84+
}
85+
86+
function check_fvp_eula () {
87+
# Mandatory user arg --i-agree-to-the-contained-eula
88+
eula_acceptance_by_variable="${ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA:-False}"
89+
90+
if [[ "${eula_acceptance}" -eq 0 ]]; then
91+
if [[ ${eula_acceptance_by_variable} != "True" ]]; then
92+
echo "Must pass argument '--i-agree-to-the-contained-eula' to agree to EULA associated with downloading the FVP."
93+
echo "Alternativly set environment variable ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True."
94+
echo "Exiting!"
95+
exit 1
96+
else
97+
echo "Arm EULA for FVP agreed to with ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True environment variable"
98+
fi
99+
fi
100+
}
101+
102+
function setup_fvp() {
103+
if [[ "${OS}" != "Linux" ]]; then
104+
# Check if FVP is callable
105+
if command -v FVP_Corstone_SSE-300_Ethos-U55 &> /dev/null; then
106+
echo "[${FUNCNAME[0]}] Info: FVP for MacOS seem to be installed. Continuing..."
107+
return 0 # If true exit gracefully and proceed with setup
108+
else
109+
echo "[${FUNCNAME[0]}] Warning: FVP only supported with Linux OS, skipping FVP setup..."
110+
echo "[${FUNCNAME[0]}] Warning: For MacOS, using https://github.com/Arm-Examples/FVPs-on-Mac is recommended."
111+
echo "[${FUNCNAME[0]}] Warning: Follow the instructions and make sure the path is set correctly."
112+
return 1 # Throw error. User need to install FVP according to ^^^
113+
fi
114+
fi
115+
}
116+
117+
function setup_path_fvp() {
118+
fvps=("corstone300" "corstone320")
119+
for fvp in "${fvps[@]}"; do
120+
model_dir_variable=${fvp}_model_dir
121+
fvp_model_dir=${!model_dir_variable}
122+
fvp_bin_path="${root_dir}/FVP-${fvp}/models/${fvp_model_dir}"
123+
append_env_in_setup_path PATH ${fvp_bin_path}
124+
done
125+
126+
# Fixup for Corstone-320 python dependency
127+
append_env_in_setup_path LD_LIBRARY_PATH "${root_dir}/FVP-corstone320/python/lib/"
128+
129+
echo "hash FVP_Corstone_SSE-300_Ethos-U55" >> ${setup_path_script}.sh
130+
echo "hash FVP_Corstone_SSE-300_Ethos-U65" >> ${setup_path_script}.sh
131+
echo "hash FVP_Corstone_SSE-320" >> ${setup_path_script}.sh
132+
}

examples/arm/setup.sh

Lines changed: 5 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,11 @@ toolchain_dir=""
3939
toolchain_md5_checksum=""
4040

4141
if [[ "${ARCH}" == "x86_64" ]]; then
42-
# FVPs
43-
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"
44-
corstone300_model_dir="Linux64_GCC-9.3"
45-
corstone300_md5_checksum="98e93b949d0fbac977292d8668d34523"
46-
47-
corstone320_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-320/FVP_Corstone_SSE-320_11.27_25_Linux64.tgz?rev=a507bffc219a4d5792f1192ab7002d89&hash=D9A824AA8227D2E679C9B9787FF4E8B6FBE3D7C6"
48-
corstone320_model_dir="Linux64_GCC-9.3"
49-
corstone320_md5_checksum="3deb3c68f9b2d145833f15374203514d"
50-
5142
# Vulkan SDK
5243
vulkan_sdk_url="https://sdk.lunarg.com/sdk/download/${vulkan_sdk_version}/linux/vulkansdk-linux-x86_64-${vulkan_sdk_version}.tar.xz"
5344
vulkan_sdk_sha256="f22a3625bd4d7a32e7a0d926ace16d5278c149e938dac63cecc00537626cbf73"
5445

5546
elif [[ "${ARCH}" == "aarch64" ]] || [[ "${ARCH}" == "arm64" ]]; then
56-
# FVPs
57-
corstone300_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-300/FVP_Corstone_SSE-300_11.22_20_Linux64_armv8l.tgz?rev=9cc6e9a32bb947ca9b21fa162144cb01&hash=7657A4CF27D42E892E3F08D452AAB073"
58-
corstone300_model_dir="Linux64_armv8l_GCC-9.3"
59-
corstone300_md5_checksum="cbbabbe39b07939cff7a3738e1492ef1"
60-
61-
corstone320_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-320/FVP_Corstone_SSE-320_11.27_25_Linux64_armv8l.tgz?rev=b6ebe0923cb84f739e017385fd3c333c&hash=8965C4B98E2FF7F792A099B08831FE3CB6120493"
62-
corstone320_model_dir="Linux64_armv8l_GCC-9.3"
63-
corstone320_md5_checksum="3889f1d80a6d9861ea4aa6f1c88dd0ae"
64-
6547
# Vulkan SDK
6648
vulkan_sdk_url="https://github.com/jakoch/vulkan-sdk-arm/releases/download/1.4.321.1/vulkansdk-ubuntu-22.04-arm-1.4.321.1.tar.xz"
6749
vulkan_sdk_sha256="c57e318d0940394d3a304034bb7ddabda788b5b0b54638e80e90f7264efe9f84"
@@ -216,76 +198,6 @@ function setup_root_dir() {
216198
setup_path_script="${root_dir}/setup_path"
217199
}
218200

219-
function check_fvp_eula () {
220-
# Mandatory user arg --i-agree-to-the-contained-eula
221-
eula_acceptance_by_variable="${ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA:-False}"
222-
223-
if [[ "${eula_acceptance}" -eq 0 ]]; then
224-
if [[ ${eula_acceptance_by_variable} != "True" ]]; then
225-
echo "Must pass argument '--i-agree-to-the-contained-eula' to agree to EULA associated with downloading the FVP."
226-
echo "Alternativly set environment variable ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True."
227-
echo "Exiting!"
228-
exit 1
229-
else
230-
echo "Arm EULA for FVP agreed to with ARM_FVP_INSTALL_I_AGREE_TO_THE_CONTAINED_EULA=True environment variable"
231-
fi
232-
fi
233-
}
234-
235-
function setup_fvp() {
236-
# check EULA, forward argument
237-
check_fvp_eula
238-
239-
if [[ "${OS}" != "Linux" ]]; then
240-
# Check if FVP is callable
241-
if command -v FVP_Corstone_SSE-300_Ethos-U55 &> /dev/null; then
242-
echo "[${FUNCNAME[0]}] Info: FVP for MacOS seem to be installed. Continuing..."
243-
return 0 # If true exit gracefully and proceed with setup
244-
else
245-
echo "[${FUNCNAME[0]}] Warning: FVP only supported with Linux OS, skipping FVP setup..."
246-
echo "[${FUNCNAME[0]}] Warning: For MacOS, using https://github.com/Arm-Examples/FVPs-on-Mac is recommended."
247-
echo "[${FUNCNAME[0]}] Warning: Follow the instructions and make sure the path is set correctly."
248-
return 1 # Throw error. User need to install FVP according to ^^^
249-
fi
250-
fi
251-
252-
# Download and install the Corstone 300 FVP simulator platform
253-
fvps=("corstone300" "corstone320")
254-
255-
for fvp in "${fvps[@]}"; do
256-
cd "${root_dir}"
257-
if [[ ! -e "FVP_${fvp}.tgz" ]]; then
258-
echo "[${FUNCNAME[0]}] Downloading FVP ${fvp}..."
259-
url_variable=${fvp}_url
260-
fvp_url=${!url_variable}
261-
curl --output "FVP_${fvp}.tgz" "${fvp_url}"
262-
md5_variable=${fvp}_md5_checksum
263-
fvp_md5_checksum=${!md5_variable}
264-
verify_md5 ${fvp_md5_checksum} FVP_${fvp}.tgz || exit 1
265-
fi
266-
267-
echo "[${FUNCNAME[0]}] Installing FVP ${fvp}..."
268-
rm -rf FVP-${fvp}
269-
mkdir -p FVP-${fvp}
270-
cd FVP-${fvp}
271-
tar xf ../FVP_${fvp}.tgz
272-
273-
# Install the FVP
274-
case ${fvp} in
275-
corstone300)
276-
./FVP_Corstone_SSE-300.sh --i-agree-to-the-contained-eula --force --destination ./ --quiet --no-interactive
277-
;;
278-
corstone320)
279-
./FVP_Corstone_SSE-320.sh --i-agree-to-the-contained-eula --force --destination ./ --quiet --no-interactive
280-
;;
281-
*)
282-
echo "[${FUNCNAME[0]}] Error: Unknown FVP model ${fvp}. Exiting."
283-
exit 1
284-
;;
285-
esac
286-
done
287-
}
288-
289201
function setup_vulkan_sdk() {
290202

291203
if command -v vulkaninfo > /dev/null 2>&1; then
@@ -395,20 +307,7 @@ function create_setup_path(){
395307
echo "" > "${setup_path_script}.fish"
396308

397309
if [[ "${enable_fvps}" -eq 1 ]]; then
398-
fvps=("corstone300" "corstone320")
399-
for fvp in "${fvps[@]}"; do
400-
model_dir_variable=${fvp}_model_dir
401-
fvp_model_dir=${!model_dir_variable}
402-
fvp_bin_path="${root_dir}/FVP-${fvp}/models/${fvp_model_dir}"
403-
append_env_in_setup_path PATH ${fvp_bin_path}
404-
done
405-
406-
# Fixup for Corstone-320 python dependency
407-
append_env_in_setup_path LD_LIBRARY_PATH "${root_dir}/FVP-corstone320/python/lib/"
408-
409-
echo "hash FVP_Corstone_SSE-300_Ethos-U55" >> ${setup_path_script}.sh
410-
echo "hash FVP_Corstone_SSE-300_Ethos-U65" >> ${setup_path_script}.sh
411-
echo "hash FVP_Corstone_SSE-320" >> ${setup_path_script}.sh
310+
setup_path_fvp
412311
fi
413312

414313
if [[ "${enable_baremetal_toolchain}" -eq 1 ]]; then
@@ -468,6 +367,8 @@ if [[ $is_script_sourced -eq 0 ]]; then
468367

469368
check_options "$@"
470369

370+
source $et_dir/backends/arm/scripts/fvp_utils.sh
371+
471372
check_platform_support
472373

473374
cd "${script_dir}"
@@ -499,7 +400,9 @@ if [[ $is_script_sourced -eq 0 ]]; then
499400

500401
# Setup FVP
501402
if [[ "${enable_fvps}" -eq 1 ]]; then
403+
check_fvp_eula
502404
setup_fvp
405+
install_fvp
503406
fi
504407

505408
# Setup Vulkan SDK

0 commit comments

Comments
 (0)