summaryrefslogtreecommitdiff
path: root/tests/apply_overlay.sh
blob: 55f863c3e5e3b7e2bbd12e7441da3ef28bf2daed (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

PROG_NAME=`basename $0`

function usage() {
  echo "Usage:"
  echo "  $PROG_NAME (--fdt|--ufdt) (--remote) <Base DTS> <Overlay DTS> <Output DTS>"
}

function on_exit() {
  rm -rf "$TEMP_DIR"
}

#
# Start
#

# Setup OVERLAY
if [ "$1" == "--fdt" ]; then
  shift
  OVERLAY="fdt_apply_overlay"
elif [ "$1" == "--ufdt" ]; then
  shift
  OVERLAY="ufdt_apply_overlay"
else
  usage
  exit 1
fi

# --remote: run overlay on the device with adb
if [ "$1" == "--remote" ]; then
  shift
  EXE_PATH="${ANDROID_PRODUCT_OUT}/obj/EXECUTABLES"
  REMOTE_PATH="/data/local/tmp"
  adb push "${EXE_PATH}/${OVERLAY}_intermediates/${OVERLAY}" \
    "$REMOTE_PATH" > /dev/null
fi

if [[ $# -lt 3 ]]; then
  usage
  exit 1
fi

BASE_DTS=$1
OVERLAY_DTS=$2
OUT_DTS=$3

TEMP_DIR=`mktemp -d`
# The script will exit directly if any command fails.
set -e
trap on_exit EXIT

# Compile the *-base.dts to make *-base.dtb
BASE_DTS_NAME=`basename "$BASE_DTS"`
BASE_DTB_NAME="${BASE_DTS_NAME}-base.dtb"
BASE_DTB="${TEMP_DIR}/${BASE_DTB_NAME}"
dtc -@ -qq -O dtb -o "$BASE_DTB" "$BASE_DTS"

# Compile the *-overlay.dts to make *-overlay.dtb
OVERLAY_DTS_NAME=`basename "$OVERLAY_DTS"`
OVERLAY_DTB_NAME="${OVERLAY_DTS_NAME}-overlay.dtb"
OVERLAY_DTB="${TEMP_DIR}/${OVERLAY_DTB_NAME}"
dtc -@ -qq -O dtb -o "$OVERLAY_DTB" "$OVERLAY_DTS"

# Run ufdt_apply_overlay to combine *-base.dtb and *-overlay.dtb
# into *-merged.dtb
MERGED_DTB_NAME="${BASE_DTS_NAME}-merged.dtb"
MERGED_DTB="${TEMP_DIR}/${MERGED_DTB_NAME}"
if [ -z "$REMOTE_PATH" ]; then
  "$OVERLAY" "$BASE_DTB" "$OVERLAY_DTB" "$MERGED_DTB"
else
  adb push "$BASE_DTB" "$REMOTE_PATH" > /dev/null
  adb push "$OVERLAY_DTB" "$REMOTE_PATH" > /dev/null
  adb shell "
    cd "$REMOTE_PATH" &&
    "./${OVERLAY}" "$BASE_DTB_NAME" "$OVERLAY_DTB_NAME" "$MERGED_DTB_NAME"
  "
  adb pull "${REMOTE_PATH}/${MERGED_DTB_NAME}" "$MERGED_DTB" > /dev/null
fi

if [ ! -z "$REMOTE_PATH" ]; then
  # clean up
  adb shell "
    cd "$REMOTE_PATH" &&
    rm -f "$OVERLAY" &&
    rm -f "$BASE_DTB_NAME" &&
    rm -f "$OVERLAY_DTB_NAME" &&
    rm -f "$MERGED_DTB_NAME"
  " > /dev/null
fi

# Dump
dtc -s -O dts -o "$OUT_DTS" "$MERGED_DTB"