1#!/bin/bash
2# Copyright (C) 2016 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# We want to generate two device tree blob (.dtb) files by combining
17# the "base" and "add" device tree source (.dts) files in two
18# different ways.
19#
20# 1) Use /include/ and compile via dtc to make the "gold standard"
21#
22# 2) Compile them separately dtc, and join them with the
23#    ufdt_apply_overlay program
24#
25# Then, compare 1) and 2) with dts_diff (diff merged nodes) and return 0
26# iff they are identical.
27
28SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
29source ${SCRIPT_DIR}/common.sh
30
31on_exit() {
32  rm -rf "$TEMP_DIR"
33}
34
35# Constants
36IN_DATA_DIR="testdata"
37
38TEMP_DIR=`mktemp -d`
39# The script will exit directly if any command fails.
40set -e
41trap on_exit EXIT
42
43# Global variables
44TESTCASE_NAME=$1
45BASE_DTS="$IN_DATA_DIR/${TESTCASE_NAME}-base.dts"
46OVERLAY_DTS="$IN_DATA_DIR/${TESTCASE_NAME}-overlay.dts"
47REF_MERGED_DTS="$TEMP_DIR/${TESTCASE_NAME}-ref-merged.dts"
48OVL_MERGED_DTS="$TEMP_DIR/${TESTCASE_NAME}-ovl-merged.dts"
49
50#
51# Complie and diff
52#
53$SCRIPT_DIR/apply_overlay.sh --fdt "$BASE_DTS" "$OVERLAY_DTS" "$REF_MERGED_DTS"
54$SCRIPT_DIR/apply_overlay.sh --ufdt "$BASE_DTS" "$OVERLAY_DTS" "$OVL_MERGED_DTS"
55dts_diff "$REF_MERGED_DTS" "$OVL_MERGED_DTS"
56