diff --git a/backends/arm/scripts/utils.sh b/backends/arm/scripts/utils.sh new file mode 100644 index 00000000000..cb606021dba --- /dev/null +++ b/backends/arm/scripts/utils.sh @@ -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" +} diff --git a/examples/arm/ethos-u-setup/core_platform/patches/0001-Move-rodata-to-the-DDR.patch b/examples/arm/ethos-u-setup/core_platform/0001-Move-rodata-to-the-DDR.patch similarity index 100% rename from examples/arm/ethos-u-setup/core_platform/patches/0001-Move-rodata-to-the-DDR.patch rename to examples/arm/ethos-u-setup/core_platform/0001-Move-rodata-to-the-DDR.patch diff --git a/examples/arm/setup.sh b/examples/arm/setup.sh index 5498bd78974..334b0979367 100755 --- a/examples/arm/setup.sh +++ b/examples/arm/setup.sh @@ -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 @@ -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}..." @@ -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 ..." @@ -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() { @@ -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 @@ -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