Kristofer Jonsson | 3a353a3 | 2022-04-13 15:00:36 +0200 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # |
| 4 | # Copyright (c) 2022 Arm Limited. |
| 5 | # |
| 6 | # SPDX-License-Identifier: Apache-2.0 |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 9 | # not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 16 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | # |
| 20 | |
| 21 | set -o errexit |
| 22 | set -o pipefail |
| 23 | set -o errtrace |
| 24 | |
| 25 | DEST=$1 |
| 26 | GCDA_DIR=/sys/kernel/debug/gcov |
| 27 | TMP_DIR= |
| 28 | |
| 29 | usage() { |
| 30 | echo "Usage: $0 <output.tar.gz>" >&2 |
| 31 | exit 1 |
| 32 | } |
| 33 | |
| 34 | cleanup() { |
| 35 | if [ -d "${TMP_DIR}" ] |
| 36 | then |
| 37 | rm -rf "${TMP_DIR}" |
| 38 | fi |
| 39 | } |
| 40 | |
| 41 | trap cleanup EXIT |
| 42 | |
| 43 | if [ -z "${DEST}" ] |
| 44 | then |
| 45 | usage |
| 46 | fi |
| 47 | |
| 48 | # Find kernel directory |
| 49 | readarray -t DRIVER_GCDA < <(find ${GCDA_DIR} -path '*/kernel/ethosu_driver.gcda') |
| 50 | if [ ${#DRIVER_GCDA[*]} -le 0 ] |
| 51 | then |
| 52 | echo "Error: Could not find Ethos-U kernel directory" |
| 53 | exit 1 |
| 54 | fi |
| 55 | |
| 56 | LDS_DIR=$(dirname "$(dirname "${DRIVER_GCDA[0]}")") |
| 57 | DEST=$(realpath "${DEST}") |
| 58 | TMP_DIR=$(mktemp -d) |
| 59 | |
| 60 | # Copy gcda objects to temporary directory |
| 61 | cd "${LDS_DIR}" |
| 62 | find . -name "*.gcda" -exec cp --parent {} "${TMP_DIR}" \; |
| 63 | |
| 64 | # Create tar.gz archive |
| 65 | cd "${TMP_DIR}" |
| 66 | find . -type f -print0 | xargs -0 tar -zcvf "${DEST}" |