xref: /netbsd-src/external/gpl2/dtc/dist/dtdiff (revision cc7d2833ecf67da5a5ddc470841931eb9f6723e4)
1b8ae3907Smacallan#! /bin/bash
2*cc7d2833Sskrll# SPDX-License-Identifier: GPL-2.0-or-later
3b8ae3907Smacallan
4b8ae3907Smacallan# This script uses the bash <(...) extension.
5b8ae3907Smacallan# If you want to change this to work with a generic /bin/sh, make sure
6b8ae3907Smacallan# you fix that.
7b8ae3907Smacallan
8b8ae3907Smacallan
9b8ae3907SmacallanDTC=dtc
10b8ae3907Smacallan
11b8ae3907Smacallansource_and_sort () {
12b8ae3907Smacallan    DT="$1"
13b8ae3907Smacallan    if [ -d "$DT" ]; then
14b8ae3907Smacallan	IFORMAT=fs
15b8ae3907Smacallan    elif [ -f "$DT" ]; then
16b8ae3907Smacallan	case "$DT" in
17b8ae3907Smacallan	    *.dts)
18b8ae3907Smacallan		IFORMAT=dts
19b8ae3907Smacallan		;;
20b8ae3907Smacallan	    *.dtb)
21b8ae3907Smacallan		IFORMAT=dtb
22b8ae3907Smacallan		;;
23b8ae3907Smacallan	esac
24b8ae3907Smacallan    fi
25b8ae3907Smacallan
26b8ae3907Smacallan    if [ -z "$IFORMAT" ]; then
27b8ae3907Smacallan	echo "Unrecognized format for $DT" >&2
28b8ae3907Smacallan	exit 2
29b8ae3907Smacallan    fi
30b8ae3907Smacallan
31b8ae3907Smacallan    $DTC -I $IFORMAT -O dts -qq -f -s -o - "$DT"
32b8ae3907Smacallan}
33b8ae3907Smacallan
34b8ae3907Smacallanif [ $# != 2 ]; then
35b8ae3907Smacallan    echo "Usage: dtdiff <device tree> <device tree>" >&2
36b8ae3907Smacallan    exit 1
37b8ae3907Smacallanfi
38b8ae3907Smacallan
39b8ae3907Smacallandiff -u <(source_and_sort "$1") <(source_and_sort "$2")
40