SzuWei Lin | b63f3b7 | 2017-01-10 11:54:22 +0800 | [diff] [blame] | 1 | #!/bin/bash |
SzuWei Lin | 6ad4caa | 2017-04-06 17:12:27 +0800 | [diff] [blame] | 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. |
SzuWei Lin | b63f3b7 | 2017-01-10 11:54:22 +0800 | [diff] [blame] | 15 | |
| 16 | PROG_NAME=`basename $0` |
| 17 | |
SzuWei Lin | 79ba2ae | 2017-06-09 16:44:23 +0800 | [diff] [blame] | 18 | # Set to true to get more debug information |
| 19 | DEBUG=false |
| 20 | # Remove the comment to enable valgrind |
| 21 | # Require build with $mmma external/valgrind |
| 22 | #VALGRIND="valgrind --leak-check=yes --show-reachable=yes" |
| 23 | |
SzuWei Lin | b63f3b7 | 2017-01-10 11:54:22 +0800 | [diff] [blame] | 24 | function usage() { |
| 25 | echo "Usage:" |
SzuWei Lin | 2dcb17e | 2017-01-24 16:11:32 +0800 | [diff] [blame] | 26 | echo " $PROG_NAME (--fdt|--ufdt) (--remote) <Base DTS> <Overlay DTS> <Output DTS>" |
SzuWei Lin | b63f3b7 | 2017-01-10 11:54:22 +0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | function on_exit() { |
| 30 | rm -rf "$TEMP_DIR" |
| 31 | } |
| 32 | |
| 33 | # |
| 34 | # Start |
| 35 | # |
| 36 | |
SzuWei Lin | f7403df | 2017-02-18 15:18:30 +0800 | [diff] [blame] | 37 | # Setup OVERLAY |
| 38 | if [ "$1" == "--fdt" ]; then |
| 39 | shift |
| 40 | OVERLAY="fdt_apply_overlay" |
| 41 | elif [ "$1" == "--ufdt" ]; then |
| 42 | shift |
| 43 | OVERLAY="ufdt_apply_overlay" |
| 44 | else |
| 45 | usage |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
SzuWei Lin | 2dcb17e | 2017-01-24 16:11:32 +0800 | [diff] [blame] | 49 | # --remote: run overlay on the device with adb |
| 50 | if [ "$1" == "--remote" ]; then |
| 51 | shift |
| 52 | EXE_PATH="${ANDROID_PRODUCT_OUT}/obj/EXECUTABLES" |
| 53 | REMOTE_PATH="/data/local/tmp" |
| 54 | adb push "${EXE_PATH}/${OVERLAY}_intermediates/${OVERLAY}" \ |
| 55 | "$REMOTE_PATH" > /dev/null |
| 56 | fi |
| 57 | |
SzuWei Lin | b63f3b7 | 2017-01-10 11:54:22 +0800 | [diff] [blame] | 58 | if [[ $# -lt 3 ]]; then |
| 59 | usage |
| 60 | exit 1 |
| 61 | fi |
| 62 | |
| 63 | BASE_DTS=$1 |
| 64 | OVERLAY_DTS=$2 |
| 65 | OUT_DTS=$3 |
| 66 | |
| 67 | TEMP_DIR=`mktemp -d` |
| 68 | # The script will exit directly if any command fails. |
| 69 | set -e |
| 70 | trap on_exit EXIT |
| 71 | |
| 72 | # Compile the *-base.dts to make *-base.dtb |
| 73 | BASE_DTS_NAME=`basename "$BASE_DTS"` |
SzuWei Lin | 2dcb17e | 2017-01-24 16:11:32 +0800 | [diff] [blame] | 74 | BASE_DTB_NAME="${BASE_DTS_NAME}-base.dtb" |
| 75 | BASE_DTB="${TEMP_DIR}/${BASE_DTB_NAME}" |
SzuWei Lin | 08dd727 | 2017-02-20 10:38:20 +0800 | [diff] [blame] | 76 | dtc -@ -qq -O dtb -o "$BASE_DTB" "$BASE_DTS" |
SzuWei Lin | 79ba2ae | 2017-06-09 16:44:23 +0800 | [diff] [blame] | 77 | if $DEBUG; then |
| 78 | echo "[base.dts]" |
| 79 | dtc -O dts "$BASE_DTB" |
| 80 | fi |
SzuWei Lin | b63f3b7 | 2017-01-10 11:54:22 +0800 | [diff] [blame] | 81 | |
| 82 | # Compile the *-overlay.dts to make *-overlay.dtb |
| 83 | OVERLAY_DTS_NAME=`basename "$OVERLAY_DTS"` |
SzuWei Lin | 2dcb17e | 2017-01-24 16:11:32 +0800 | [diff] [blame] | 84 | OVERLAY_DTB_NAME="${OVERLAY_DTS_NAME}-overlay.dtb" |
| 85 | OVERLAY_DTB="${TEMP_DIR}/${OVERLAY_DTB_NAME}" |
SzuWei Lin | 08dd727 | 2017-02-20 10:38:20 +0800 | [diff] [blame] | 86 | dtc -@ -qq -O dtb -o "$OVERLAY_DTB" "$OVERLAY_DTS" |
SzuWei Lin | 79ba2ae | 2017-06-09 16:44:23 +0800 | [diff] [blame] | 87 | if $DEBUG; then |
| 88 | echo "[overlay.dts]" |
| 89 | dtc -O dts "$OVERLAY_DTB" |
| 90 | fi |
SzuWei Lin | b63f3b7 | 2017-01-10 11:54:22 +0800 | [diff] [blame] | 91 | |
| 92 | # Run ufdt_apply_overlay to combine *-base.dtb and *-overlay.dtb |
| 93 | # into *-merged.dtb |
SzuWei Lin | 2dcb17e | 2017-01-24 16:11:32 +0800 | [diff] [blame] | 94 | MERGED_DTB_NAME="${BASE_DTS_NAME}-merged.dtb" |
| 95 | MERGED_DTB="${TEMP_DIR}/${MERGED_DTB_NAME}" |
| 96 | if [ -z "$REMOTE_PATH" ]; then |
SzuWei Lin | 79ba2ae | 2017-06-09 16:44:23 +0800 | [diff] [blame] | 97 | $VALGRIND "$OVERLAY" "$BASE_DTB" "$OVERLAY_DTB" "$MERGED_DTB" |
SzuWei Lin | 2dcb17e | 2017-01-24 16:11:32 +0800 | [diff] [blame] | 98 | else |
| 99 | adb push "$BASE_DTB" "$REMOTE_PATH" > /dev/null |
| 100 | adb push "$OVERLAY_DTB" "$REMOTE_PATH" > /dev/null |
| 101 | adb shell " |
| 102 | cd "$REMOTE_PATH" && |
| 103 | "./${OVERLAY}" "$BASE_DTB_NAME" "$OVERLAY_DTB_NAME" "$MERGED_DTB_NAME" |
| 104 | " |
| 105 | adb pull "${REMOTE_PATH}/${MERGED_DTB_NAME}" "$MERGED_DTB" > /dev/null |
| 106 | fi |
| 107 | |
| 108 | if [ ! -z "$REMOTE_PATH" ]; then |
| 109 | # clean up |
| 110 | adb shell " |
| 111 | cd "$REMOTE_PATH" && |
| 112 | rm -f "$OVERLAY" && |
| 113 | rm -f "$BASE_DTB_NAME" && |
| 114 | rm -f "$OVERLAY_DTB_NAME" && |
| 115 | rm -f "$MERGED_DTB_NAME" |
| 116 | " > /dev/null |
| 117 | fi |
SzuWei Lin | b63f3b7 | 2017-01-10 11:54:22 +0800 | [diff] [blame] | 118 | |
| 119 | # Dump |
| 120 | dtc -s -O dts -o "$OUT_DTS" "$MERGED_DTB" |
SzuWei Lin | 79ba2ae | 2017-06-09 16:44:23 +0800 | [diff] [blame] | 121 | if $DEBUG; then |
| 122 | echo "[merged.dts]" |
| 123 | cat $OUT_DTS |
| 124 | fi |