xref: /aosp_15_r20/system/libufdt/tests/verifyDTBO.sh (revision 13e8728f0cffde9369df671f7b293a048a99c7ed)
1#!/bin/bash
2
3if [ -z "${ANDROID_HOST_OUT}" ]; then
4  echo 'ANDROID_HOST_OUT not set. Please run lunch'
5  exit 1
6fi
7
8ANDROID_HOST_BIN_LOCATION=${ANDROID_HOST_OUT}/bin
9
10adb root
11
12tmpdir=$(mktemp -d)
13trap 'rm -rf ${tmpdir};' EXIT
14
15cd $tmpdir
16
17#find out the location to read the DTBO image from
18boot_suffix=$(adb wait-for-device shell getprop ro.boot.slot_suffix)
19dtbo_partition="/dev/block/by-name/dtbo"
20dtbo_path=$dtbo_partition$boot_suffix
21
22#read the dtbo image and the final device tree from device
23adb pull $dtbo_path dtbo.img > /dev/null
24adb pull /sys/firmware/fdt final_dt > /dev/null
25
26#decompile the DTBO image
27mkdtimg_path="${ANDROID_HOST_BIN_LOCATION}/mkdtboimg"
28$mkdtimg_path dump dtbo.img -b dumped_dtbo > /dev/null
29
30#Get the index of the overlay applied. Try bootconfig first, then cmdline.
31overlay_idx=$(adb shell cat /proc/bootconfig \
32    | grep 'androidboot.dtbo_idx = .*$' | cut -d "=" -f 2 | sed 's/[ \\\"]//g')
33if [[ ! $overlay_idx =~ [0-9]+ ]]; then
34  overlay_idx=$(adb shell cat /proc/cmdline | grep -o "androidboot.dtbo_idx=[^ ]*" | cut -d "=" -f 2)
35fi
36arg=""
37for idx in ${overlay_idx//,/ }
38do
39  arg="${arg}dumped_dtbo.${idx} "
40done
41
42#verify that the overlay was correctly applied
43verify_bin_path="${ANDROID_HOST_BIN_LOCATION}/ufdt_verify_overlay_host"
44$verify_bin_path final_dt $arg
45result=$?
46
47if [[ "$result" -eq "0" ]]; then
48  echo "Overlay was verified successfully"
49else
50  echo "Incorrect overlay application"
51fi
52
53exit $result
54
55