1#!/bin/bash
2# Copyright (C) 2017 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
16SRCDIR="data"
17DTS_LIST="
18  board1v1.dts
19  board1v1_1.dts
20  board2v1.dts
21"
22DTB_LIST=(
23  "board1v1.dts.dtb"
24  "board1v1_1.dts.dtb"
25  "board2v1.dts.dtb"
26  "board1v1.dts.dtb"
27)
28CONFIG="${SRCDIR}/mkdtimg.cfg"
29
30ALIGN=4
31
32OUTDIR="out"
33OUTDTB_CFG="${OUTDIR}/dump_cfg.dtb"
34OUTDTB="${OUTDIR}/dump.dtb"
35
36mkdir -p "$OUTDIR"
37for dts in ${DTS_LIST}; do
38  echo "Building $dts..."
39  src_dts="${SRCDIR}/${dts}"
40  out_dtb="${OUTDIR}/${dts}.dtb"
41  dtc -O dtb -@ -qq -a "$ALIGN" -o "$out_dtb" "$src_dts"
42done
43
44IMG="${OUTDIR}/cfg_create.img"
45mkdtimg cfg_create "$IMG" "${CONFIG}" --dtb-dir="$OUTDIR"
46mkdtimg dump "$IMG" -b "$OUTDTB_CFG" | tee "${OUTDIR}/cfg_create.dump"
47for index in ${!DTB_LIST[@]}; do
48  diff ${OUTDIR}/${DTB_LIST[$index]} ${OUTDTB_CFG}.$index
49done
50
51IMG="${OUTDIR}/create.img"
52mkdtimg create "$IMG" \
53  --page_size=4096 --id=/:board_id --rev=/:board_rev --custom0=0xabc \
54  "${OUTDIR}/board1v1.dts.dtb" \
55  "${OUTDIR}/board1v1_1.dts.dtb" --id=/:another_board_id \
56  "${OUTDIR}/board2v1.dts.dtb" --rev=0x201 \
57  "${OUTDIR}/board1v1.dts.dtb" --custom0=0xdef
58mkdtimg dump "$IMG" -b "$OUTDTB" | tee "${OUTDIR}/create.dump"
59for index in ${!DTB_LIST[@]}; do
60  diff ${OUTDIR}/${DTB_LIST[$index]} ${OUTDTB}.$index
61done
62
63diff "${OUTDIR}/cfg_create.dump" "${OUTDIR}/create.dump"
64