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
16if ! hash iasl; then
17    echo "Please install 'acpica-tools' first"
18    exit 1
19fi
20
21SRCDIR="data"
22ASL_LIST="
23  ssdt1.asl
24  ssdt2.asl
25  ssdt3.asl
26"
27PYCONFIG="${SRCDIR}/mkdtboimg_acpi.cfg"
28
29OUTDIR="out"
30MKDTIMG_OUT="${OUTDIR}/mkdtimg_acpi_out"
31MKDTIMG_DUMP="${MKDTIMG_OUT}"/dump.aml
32
33MKDTBOIMG_OUT="${OUTDIR}/mkdtboimg_acpi_out"
34MKDTBOIMG_OUTCREATE="${MKDTBOIMG_OUT}/create"
35MKDTBOIMG_OUTCFG="${MKDTBOIMG_OUT}/cfg_create"
36MKDTBOIMG_CREATEDUMP="${MKDTBOIMG_OUTCREATE}"/dump.aml
37MKDTBOIMG_CFGDUMP="${MKDTBOIMG_OUTCFG}"/dump.aml
38
39mkdir -p "$MKDTIMG_OUT"
40mkdir -p "$MKDTBOIMG_OUTCREATE"
41mkdir -p "$MKDTBOIMG_OUTCFG"
42
43for asl in ${ASL_LIST}; do
44  echo "Building $asl..."
45  src_asl="${SRCDIR}/${asl}"
46  out_aml_pfx="${OUTDIR}/${asl%.asl}"
47  iasl -p "${out_aml_pfx}" "$src_asl"
48done
49
50echo "Creating acpi image with mkdtbimg"
51mkdtimg create ${MKDTIMG_OUT}/create_acpi.img --dt_type=acpi --page_size=2048 --id=0x100 --rev=0x100 --version=1 \
52    "${OUTDIR}/ssdt1.aml" "${OUTDIR}/ssdt2.aml" "${OUTDIR}/ssdt3.aml" > /dev/null
53
54echo "Creating acpi image with mkdtboimg"
55../src/mkdtboimg.py create  ${MKDTBOIMG_OUTCREATE}/create_acpi.img --dt_type=acpi --page_size=2048 --id=0x200 --rev=0x200 --version=2 \
56    "${OUTDIR}/ssdt1.aml" "${OUTDIR}/ssdt2.aml" "${OUTDIR}/ssdt3.aml" > /dev/null
57
58echo "Creating acpi image with ${PYCONFIG} config file"
59../src/mkdtboimg.py cfg_create ${MKDTBOIMG_OUTCFG}/create_acpi.img ${PYCONFIG} -d "${OUTDIR}"
60
61echo "Dumping fragments from mkdtimg tool image"
62mkdtimg dump ${MKDTIMG_OUT}/create_acpi.img -b "${MKDTIMG_DUMP}"| grep -v 'FDT' > ${MKDTIMG_OUT}/create.dump
63
64echo "Dumping fragments from mkdtboimg.py tool for image generated with 'create'"
65../src/mkdtboimg.py dump ${MKDTBOIMG_OUTCREATE}/create_acpi.img --output ${MKDTBOIMG_OUTCREATE}/create.dump -b "${MKDTBOIMG_CREATEDUMP}" --decompress
66
67echo "Dumping fragments from mkdtboimg.py tool for image generated with 'cfg_create'"
68../src/mkdtboimg.py dump ${MKDTBOIMG_OUTCFG}/create_acpi.img --output ${MKDTBOIMG_OUTCFG}/create.dump -b "${MKDTBOIMG_CFGDUMP}" --decompress
69
70echo "======================================================================================"
71echo "Testing differences between image created by 'create' for 'mkdtimg' and 'mkdtboimg.py'"
72echo "======================================================================================"
73for x in ${MKDTIMG_DUMP}.*
74do
75    file=$(basename $x)
76    if [ ! -e ${MKDTBOIMG_OUTCREATE}/$file ]
77    then
78        continue
79    fi
80    echo "diff $x vs ${MKDTBOIMG_OUTCREATE}/$file"
81    diff $x ${MKDTBOIMG_OUTCREATE}/$file
82done
83echo "=========================================================================================="
84echo "Testing differences between image created by 'cfg_create' for 'mkdtimg' and 'mkdtboimg.py'"
85echo "=========================================================================================="
86for x in ${MKDTIMG_DUMP}.*
87do
88    file=$(basename $x)
89    if [ ! -e ${MKDTBOIMG_OUTCFG}/$file ]
90    then
91        continue
92    fi
93    echo "diff $x vs ${MKDTBOIMG_OUTCFG}/$file"
94    diff $x ${MKDTBOIMG_OUTCFG}/$file
95done
96