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 PROG_NAME=`basename $0` 17 18 function usage() { 19 echo "Usage:" 20 echo " $PROG_NAME <Base DTS> <Overlay DTS> <Output DTS>" 21 } 22 23 function on_exit() { 24 rm -rf "$TEMP_DIR" 25 } 26 27 # 28 # Start 29 # 30 31 if [[ $# -lt 3 ]]; then 32 usage 33 exit 1 34 fi 35 36 BASE_DTS=$1 37 OVERLAY_DTS=$2 38 OUT_DTS=$3 39 40 TEMP_DIR=`mktemp -d` 41 # The script will exit directly if any command fails. 42 set -e 43 trap on_exit EXIT 44 45 # Finds '/dts-v1/; and /plugin/;' then replace them with '/* REMOVED */' 46 OVERLAY_DTS_DIR=`dirname "$OVERLAY_DTS"` 47 OVERLAY_DTS_NAME=`basename "$OVERLAY_DTS"` 48 OVERLAY_DT_WO_HEADER_DTS="$TEMP_DIR/$OVERLAY_DTS_NAME" 49 sed "s/\\(\\/dts-v1\\/\\s*;\\|\\/plugin\\/\\s*;\\)/\\/\\* REMOVED \\*\\//g" \ 50 "$OVERLAY_DTS" > "$OVERLAY_DT_WO_HEADER_DTS" 51 52 # Appends /include/ ...; 53 BASE_DTS_DIR=`dirname "$BASE_DTS"` 54 BASE_DTS_NAME=`basename "$BASE_DTS"` 55 BASE_DT_WITH_INC_DTS="$TEMP_DIR/$BASE_DTS_NAME" 56 cp "$BASE_DTS" "$BASE_DT_WITH_INC_DTS" 57 echo "/include/ \"$OVERLAY_DT_WO_HEADER_DTS\"" >> "$BASE_DT_WITH_INC_DTS" 58 59 # Simulate device tree overlay 60 MERGED_DTB="$BASE_DT_WITH_INC_DTS.dtb" 61 dtc -@ -i "$BASE_DTS_DIR" -i "$OVERLAY_DTS_DIR" -O dtb -o "$MERGED_DTB" "$BASE_DT_WITH_INC_DTS" 62 63 # Dump 64 dtc -s -O dts -o "$OUT_DTS" "$MERGED_DTB" 65