summaryrefslogtreecommitdiff
path: root/automated/linux/device-tree/device-tree.sh
blob: f2deea25bb622965134678a9f24af6e971e071b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
#
# Device Tree test cases
#
# Copyright (C) 2016, Linaro Limited.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Author: Ricardo Salveti <rsalveti@linaro.org>
# Maintainer: Naresh Kamboju <naresh.kamboju@linaro.org>

# shellcheck disable=SC1091
. ../../lib/sh-test-lib

OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
export RESULT_FILE

SYSFS_DEVICE_TREE="/sys/firmware/devicetree/base/"
DEVICE_TREE="/proc/device-tree"
MODEL="model"
COMPATIBLE="compatible"
DT_SKIP_LIST_1="device-tree-${MODEL} device-tree-${COMPATIBLE}"
DT_SKIP_LIST_2="device_tree ${DT_SKIP_LIST_1}"

# Check if /proc/device-tree is available
device_tree() {
    [ -d "${DEVICE_TREE}" ]
    exit_on_fail "device-tree" "${DT_SKIP_LIST_1}"
}

# Check device tree property
device_tree_property() {
    [ "$#" -ne 1 ] && error_msg "Usage: device_tree_property test"
    test="$1"

    DATA="$(cat "${DEVICE_TREE}/${test}")"
    [ -n "${DATA}" ]
    check_return "device-tree-${test}"
}

# Test run.
! check_root && error_msg "This script must be run as root"
[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)"
mkdir -p "${OUTPUT}"

if [ -f /proc/config.gz ]
then
    CONFIG_PROC_FS=$(zcat /proc/config.gz | grep "CONFIG_PROC_FS=")
    CONFIG_OF=$(zcat /proc/config.gz | grep "CONFIG_OF=")
elif [ -f /boot/config-"$(uname -r)" ]
then
    KERNEL_CONFIG_FILE="/boot/config-$(uname -r)"
    CONFIG_PROC_FS=$(grep "CONFIG_PROC_FS=" "${KERNEL_CONFIG_FILE}")
    CONFIG_OF=$(grep "CONFIG_OF=" "${KERNEL_CONFIG_FILE}")
else
    exit_on_skip "device-tree-pre-requirements" "Kernel config file not available"
fi

[ "${CONFIG_PROC_FS}" = "CONFIG_PROC_FS=y" ] && [ "${CONFIG_OF}" = "CONFIG_OF=y" ] && [ -d "${SYSFS_DEVICE_TREE}" ]
exit_on_fail "device-tree-Kconfig" "${DT_SKIP_LIST_2}"
device_tree
device_tree_property "${MODEL}"
device_tree_property "${COMPATIBLE}"