blob: 348277ebaca8f321dd528c50f01989faa600c719 [file] [log] [blame]
Kristofer Jonsson3a353a32022-04-13 15:00:36 +02001#!/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
21set -o errexit
22set -o pipefail
23set -o errtrace
24
25DEST=$1
26GCDA_DIR=/sys/kernel/debug/gcov
27TMP_DIR=
28
29usage() {
30 echo "Usage: $0 <output.tar.gz>" >&2
31 exit 1
32}
33
34cleanup() {
35 if [ -d "${TMP_DIR}" ]
36 then
37 rm -rf "${TMP_DIR}"
38 fi
39}
40
41trap cleanup EXIT
42
43if [ -z "${DEST}" ]
44then
45 usage
46fi
47
48# Find kernel directory
49readarray -t DRIVER_GCDA < <(find ${GCDA_DIR} -path '*/kernel/ethosu_driver.gcda')
50if [ ${#DRIVER_GCDA[*]} -le 0 ]
51then
52 echo "Error: Could not find Ethos-U kernel directory"
53 exit 1
54fi
55
56LDS_DIR=$(dirname "$(dirname "${DRIVER_GCDA[0]}")")
57DEST=$(realpath "${DEST}")
58TMP_DIR=$(mktemp -d)
59
60# Copy gcda objects to temporary directory
61cd "${LDS_DIR}"
62find . -name "*.gcda" -exec cp --parent {} "${TMP_DIR}" \;
63
64# Create tar.gz archive
65cd "${TMP_DIR}"
66find . -type f -print0 | xargs -0 tar -zcvf "${DEST}"