1#!/bin/bash 2 3if [ $# -ne 3 ]; then 4 echo "Usage: $0 <vbmeta.img> <system.img> <VbmetaBootParams.textproto>" 5 exit 1 6fi 7 8# Example Output from 'avbtool calculate_vbmeta_digest --image $OUT/vbmeta.img': 9# 3254db8a232946c712b5c6f8c1a80b31f2a200bab98553d86f5915d06bfd5436 10# 11# Example Output from 'avbtool info_image --image $OUT/vbmeta.img': 12# 13# Minimum libavb version: 1.0 14# Header Block: 256 bytes 15# Authentication Block: 576 bytes 16# Auxiliary Block: 1600 bytes 17# Algorithm: SHA256_RSA4096 18# Rollback Index: 0 19# Flags: 0 20# Release String: 'avbtool 1.1.0' 21# Descriptors: 22# ... 23# 24# 25 26set -e 27 28function die { 29 echo $1 >&2 30 exit 1 31} 32 33# Incrementing major version causes emulator binaries that do not support the 34# version to ignore this file. This can be useful if there is a change 35# not supported by older emulator binaries. 36readonly MAJOR_VERSION=2 37 38readonly VBMETAIMG=$1 39readonly SYSIMG=$2 40readonly TARGET=$3 41 42# Extract the digest 43readonly VBMETA_DIGEST=$(${AVBTOOL:-avbtool} calculate_vbmeta_digest --image $VBMETAIMG) 44 45echo "digest is $VBMETA_DIGEST" 46 47readonly INFO_OUTPUT=$(${AVBTOOL:-avbtool} info_image --image $VBMETAIMG | grep "^Algorithm:") 48echo "output is $INFO_OUTPUT" 49 50# Extract the algorithm 51readonly ALG_OUTPUT=$(echo $INFO_OUTPUT | grep "Algorithm:") 52echo \"$ALG_OUTPUT\" 53readonly ALG_SPLIT=($(echo $ALG_OUTPUT | tr ' ' '\n')) 54readonly ORG_ALGORITHM=${ALG_SPLIT[1]} 55 56if [[ $ORG_ALGORITHM == "SHA256_RSA4096" ]]; then 57VBMETA_HASH_ALG=sha256 58else 59die "Don't know anything about $ORG_ALGORITHM" 60fi 61 62echo "hash algorithm is $VBMETA_HASH_ALG" 63 64# extract the size 65 66function get_bytes { 67 MY_OUTPUT=$(${AVBTOOL:-avbtool} info_image --image $1 | grep "$2" ) 68 MY_SPLIT=($(echo $MY_OUTPUT | tr ' ' '\n')) 69 MY_BYTES=${MY_SPLIT[2]} 70 echo $MY_BYTES 71} 72 73HEADER_SIZE=$(get_bytes $VBMETAIMG "Header Block:") 74AUTHEN_SIZE=$(get_bytes $VBMETAIMG "Authentication Block:") 75AUX_SIZE=$(get_bytes $VBMETAIMG "Auxiliary Block:") 76SYSMETA_SIZE=$(get_bytes $SYSIMG "VBMeta size:") 77 78VBMETA_SIZE=$(expr $HEADER_SIZE + $AUTHEN_SIZE + $AUX_SIZE + $SYSMETA_SIZE) 79 80echo "vbmeta size $VBMETA_SIZE" 81 82HEADER_COMMENT="# androidboot.vbmeta.size=$VBMETA_SIZE androidboot.vbmeta.hash_alg=$VBMETA_HASH_ALG androidboot.vbmeta.digest=$VBMETA_DIGEST" 83 84echo $HEADER_COMMENT > $TARGET 85echo "major_version: $MAJOR_VERSION" >> $TARGET 86#echo "param: \"androidboot.slot_suffix=_a\"" >> $TARGET 87echo "param: \"androidboot.vbmeta.size=$VBMETA_SIZE\"" >> $TARGET 88echo "param: \"androidboot.vbmeta.hash_alg=$VBMETA_HASH_ALG\"" >> $TARGET 89echo "param: \"androidboot.vbmeta.digest=$VBMETA_DIGEST\"" >> $TARGET 90