Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions backends/arm/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Copyright 2025 Arm Limited and/or its affiliates.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

function verify_md5() {
# Compare the md5 of a file with a provided expected value.

# Arg 1: Expected checksum for file
# Arg 2: Path to file
# Exits with return code 1 if the number of arguments is incorrect.
# Exits with return code 2 if the calculated mf5 does not match the given.

[[ $# -ne 2 ]] \
&& { echo "[${FUNCNAME[0]}] Invalid number of args, expecting 2, but got $#"; exit 1; }
local ref_checksum="${1}"
local file="${2}"

if [[ "${OS}" == "Darwin" ]]; then
local file_checksum="$(md5 -q $file)"
else
local file_checksum="$(md5sum $file | awk '{print $1}')"
fi
if [[ ${ref_checksum} != ${file_checksum} ]]; then
echo "Mismatched MD5 checksum for file: ${file}. Expecting ${ref_checksum} but got ${file_checksum}. Exiting."
exit 2
fi
}

function patch_repo() {
# Patch git repo found in $repo_dir, starting from patch $base_rev and applying patches found in $patch_dir/$name.

# Arg 1: Directory of repo to patch
# Arg 2: Rev to start patching at
# Arg 3: Directory 'setup-dir' containing patches in 'setup-dir/$name'
# Exits with return code 1 if the number of arguments is incorrect.
# Does not do any error handling if the base_rev or patch_dir is not found etc.

[[ $# -ne 3 ]] \
&& { echo "[${FUNCNAME[0]}] Invalid number of args, expecting 3, but got $#"; exit 1; }

local repo_dir="${1}"
local base_rev="${2}"
local name="$(basename $repo_dir)"
local patch_dir="${3}/$name"

echo -e "[${FUNCNAME[0]}] Patching ${name}..."
cd $repo_dir
git fetch
git reset --hard ${base_rev}

[[ -e ${patch_dir} && $(ls -A ${patch_dir}) ]] && \
git am -3 ${patch_dir}/*.patch

echo -e "[${FUNCNAME[0]}] Patched ${name} @ $(git describe --all --long 2> /dev/null) in ${repo_dir} dir.\n"
}
40 changes: 8 additions & 32 deletions examples/arm/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,13 @@ fi
ARCH="$(uname -m)"
OS="$(uname -s)"

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

if [[ "${OS}" == "Darwin" ]]; then
local file_checksum="$(md5 -q $file)"
else
local file_checksum="$(md5sum $file | awk '{print $1}')"
fi
if [[ ${ref_checksum} != ${file_checksum} ]]; then
echo "Mismatched MD5 checksum for file: ${file}. Expecting ${ref_checksum} but got ${file_checksum}. Exiting."
exit 1
fi
}

########
### Hardcoded constants
########
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
et_dir=$(realpath $script_dir/../..)

if [[ "${ARCH}" == "x86_64" ]]; then
# FVPs
Expand Down Expand Up @@ -140,7 +126,7 @@ function setup_fvp() {
curl --output "FVP_${fvp}.tgz" "${fvp_url}"
md5_variable=${fvp}_md5_checksum
fvp_md5_checksum=${!md5_variable}
verify_md5 ${fvp_md5_checksum} FVP_${fvp}.tgz
verify_md5 ${fvp_md5_checksum} FVP_${fvp}.tgz || exit 1
fi

echo "[${FUNCNAME[0]}] Installing FVP ${fvp}..."
Expand Down Expand Up @@ -181,7 +167,7 @@ function setup_toolchain() {
if [[ ! -e "${toolchain_dir}.tar.xz" ]]; then
echo "[${FUNCNAME[0]}] Downloading toolchain ..."
curl --output "${toolchain_dir}.tar.xz" "${toolchain_url}"
verify_md5 ${toolchain_md5_checksum} "${toolchain_dir}.tar.xz"
verify_md5 ${toolchain_md5_checksum} "${toolchain_dir}.tar.xz" || exit 1
fi

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

function patch_repo() {
# This is a temporary hack until it finds a better home in one for the ARM Ml repos
name="$(basename $repo_dir)"
echo -e "[${FUNCNAME[0]}] Preparing ${name}..."
cd $repo_dir
git fetch
git reset --hard ${base_rev}

patch_dir=${script_dir}/ethos-u-setup/${name}/patches/
[[ -e ${patch_dir} && $(ls -A ${patch_dir}) ]] && \
git am -3 ${patch_dir}/*.patch

echo -e "[${FUNCNAME[0]}] Patched ${name} @ $(git describe --all --long 2> /dev/null) in ${repo_dir} dir.\n"
}

function setup_tosa_reference_model() {

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

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

# Setup toolchain
setup_toolchain

Expand All @@ -267,7 +242,8 @@ setup_ethos_u
# Patch the ethos-u dev environment to include executorch application
repo_dir="${root_dir}/ethos-u/core_platform"
base_rev=b728c774158248ba2cad8e78a515809e1eb9b77f
patch_repo
patch_dir=${script_dir}/ethos-u-setup/
patch_repo $repo_dir $base_rev $patch_dir

# Setup the tosa_reference_model
setup_tosa_reference_model
Expand Down
Loading