Skip to content

Commit 6fe6870

Browse files
authored
Break out utils of setup.sh
The two bash function verify_md5 and patch_repo are put in a separate util.sh for when they need to be called from other setup flows. Change-Id: Ifce8e138e1cb74f71cff5bf40e8ec9afac500e95
1 parent 307c7b2 commit 6fe6870

File tree

3 files changed

+65
-32
lines changed

3 files changed

+65
-32
lines changed

backends/arm/scripts/utils.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
function verify_md5() {
8+
# Compare the md5 of a file with a provided expected value.
9+
10+
# Arg 1: Expected checksum for file
11+
# Arg 2: Path to file
12+
# Exits with return code 1 if the number of arguments is incorrect.
13+
# Exits with return code 2 if the calculated mf5 does not match the given.
14+
15+
[[ $# -ne 2 ]] \
16+
&& { echo "[${FUNCNAME[0]}] Invalid number of args, expecting 2, but got $#"; exit 1; }
17+
local ref_checksum="${1}"
18+
local file="${2}"
19+
20+
if [[ "${OS}" == "Darwin" ]]; then
21+
local file_checksum="$(md5 -q $file)"
22+
else
23+
local file_checksum="$(md5sum $file | awk '{print $1}')"
24+
fi
25+
if [[ ${ref_checksum} != ${file_checksum} ]]; then
26+
echo "Mismatched MD5 checksum for file: ${file}. Expecting ${ref_checksum} but got ${file_checksum}. Exiting."
27+
exit 2
28+
fi
29+
}
30+
31+
function patch_repo() {
32+
# Patch git repo found in $repo_dir, starting from patch $base_rev and applying patches found in $patch_dir/$name.
33+
34+
# Arg 1: Directory of repo to patch
35+
# Arg 2: Rev to start patching at
36+
# Arg 3: Directory 'setup-dir' containing patches in 'setup-dir/$name'
37+
# Exits with return code 1 if the number of arguments is incorrect.
38+
# Does not do any error handling if the base_rev or patch_dir is not found etc.
39+
40+
[[ $# -ne 3 ]] \
41+
&& { echo "[${FUNCNAME[0]}] Invalid number of args, expecting 3, but got $#"; exit 1; }
42+
43+
local repo_dir="${1}"
44+
local base_rev="${2}"
45+
local name="$(basename $repo_dir)"
46+
local patch_dir="${3}/$name"
47+
48+
echo -e "[${FUNCNAME[0]}] Patching ${name}..."
49+
cd $repo_dir
50+
git fetch
51+
git reset --hard ${base_rev}
52+
53+
[[ -e ${patch_dir} && $(ls -A ${patch_dir}) ]] && \
54+
git am -3 ${patch_dir}/*.patch
55+
56+
echo -e "[${FUNCNAME[0]}] Patched ${name} @ $(git describe --all --long 2> /dev/null) in ${repo_dir} dir.\n"
57+
}

examples/arm/setup.sh

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,13 @@ fi
2222
ARCH="$(uname -m)"
2323
OS="$(uname -s)"
2424

25-
function verify_md5() {
26-
[[ $# -ne 2 ]] \
27-
&& { echo "[${FUNCNAME[0]}] Invalid number of args, expecting 2, but got $#"; exit 1; }
28-
local ref_checksum="${1}"
29-
local file="${2}"
3025

31-
if [[ "${OS}" == "Darwin" ]]; then
32-
local file_checksum="$(md5 -q $file)"
33-
else
34-
local file_checksum="$(md5sum $file | awk '{print $1}')"
35-
fi
36-
if [[ ${ref_checksum} != ${file_checksum} ]]; then
37-
echo "Mismatched MD5 checksum for file: ${file}. Expecting ${ref_checksum} but got ${file_checksum}. Exiting."
38-
exit 1
39-
fi
40-
}
4126

4227
########
4328
### Hardcoded constants
4429
########
4530
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
31+
et_dir=$(realpath $script_dir/../..)
4632

4733
if [[ "${ARCH}" == "x86_64" ]]; then
4834
# FVPs
@@ -140,7 +126,7 @@ function setup_fvp() {
140126
curl --output "FVP_${fvp}.tgz" "${fvp_url}"
141127
md5_variable=${fvp}_md5_checksum
142128
fvp_md5_checksum=${!md5_variable}
143-
verify_md5 ${fvp_md5_checksum} FVP_${fvp}.tgz
129+
verify_md5 ${fvp_md5_checksum} FVP_${fvp}.tgz || exit 1
144130
fi
145131

146132
echo "[${FUNCNAME[0]}] Installing FVP ${fvp}..."
@@ -181,7 +167,7 @@ function setup_toolchain() {
181167
if [[ ! -e "${toolchain_dir}.tar.xz" ]]; then
182168
echo "[${FUNCNAME[0]}] Downloading toolchain ..."
183169
curl --output "${toolchain_dir}.tar.xz" "${toolchain_url}"
184-
verify_md5 ${toolchain_md5_checksum} "${toolchain_dir}.tar.xz"
170+
verify_md5 ${toolchain_md5_checksum} "${toolchain_dir}.tar.xz" || exit 1
185171
fi
186172

187173
echo "[${FUNCNAME[0]}] Installing toolchain ..."
@@ -207,20 +193,6 @@ function setup_ethos_u() {
207193
echo "[${FUNCNAME[0]}] Done @ $(git describe --all --long 3> /dev/null) in ${root_dir}/ethos-u dir."
208194
}
209195

210-
function patch_repo() {
211-
# This is a temporary hack until it finds a better home in one for the ARM Ml repos
212-
name="$(basename $repo_dir)"
213-
echo -e "[${FUNCNAME[0]}] Preparing ${name}..."
214-
cd $repo_dir
215-
git fetch
216-
git reset --hard ${base_rev}
217-
218-
patch_dir=${script_dir}/ethos-u-setup/${name}/patches/
219-
[[ -e ${patch_dir} && $(ls -A ${patch_dir}) ]] && \
220-
git am -3 ${patch_dir}/*.patch
221-
222-
echo -e "[${FUNCNAME[0]}] Patched ${name} @ $(git describe --all --long 2> /dev/null) in ${repo_dir} dir.\n"
223-
}
224196

225197
function setup_tosa_reference_model() {
226198

@@ -258,6 +230,9 @@ echo "[main] Using root dir ${root_dir}"
258230
setup_path_script="${root_dir}/setup_path.sh"
259231
echo "" > "${setup_path_script}"
260232

233+
# Import utils
234+
source $et_dir/backends/arm/scripts/utils.sh
235+
261236
# Setup toolchain
262237
setup_toolchain
263238

@@ -267,7 +242,8 @@ setup_ethos_u
267242
# Patch the ethos-u dev environment to include executorch application
268243
repo_dir="${root_dir}/ethos-u/core_platform"
269244
base_rev=b728c774158248ba2cad8e78a515809e1eb9b77f
270-
patch_repo
245+
patch_dir=${script_dir}/ethos-u-setup/
246+
patch_repo $repo_dir $base_rev $patch_dir
271247

272248
# Setup the tosa_reference_model
273249
setup_tosa_reference_model

0 commit comments

Comments
 (0)