1#!/bin/bash 2 3if [ $# -ne 3 ]; then 4 echo "Usage: $0 <vbmeta.img> <system.img> <VbmetaBootParams.textproto>" 5 exit 0 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 45 46readonly INFO_OUTPUT=$(${AVBTOOL:-avbtool} info_image --image $VBMETAIMG | grep "^Algorithm:") 47 48# Extract the algorithm 49readonly ALG_OUTPUT=$(echo $INFO_OUTPUT | grep "Algorithm:") 50readonly ALG_SPLIT=($(echo $ALG_OUTPUT | tr ' ' '\n')) 51readonly ORG_ALGORITHM=${ALG_SPLIT[1]} 52 53if [[ $ORG_ALGORITHM == "SHA256_RSA4096" ]]; then 54VBMETA_HASH_ALG=sha256 55else 56die "Don't know anything about $ORG_ALGORITHM" 57fi 58 59 60# extract the size 61 62function get_bytes { 63 MY_OUTPUT=$(${AVBTOOL:-avbtool} info_image --image $1 | grep "$2" ) 64 MY_SPLIT=($(echo $MY_OUTPUT | tr ' ' '\n')) 65 MY_BYTES=${MY_SPLIT[2]} 66 echo $MY_BYTES 67} 68 69HEADER_SIZE=$(get_bytes $VBMETAIMG "Header Block:") 70AUTHEN_SIZE=$(get_bytes $VBMETAIMG "Authentication Block:") 71AUX_SIZE=$(get_bytes $VBMETAIMG "Auxiliary Block:") 72SYSMETA_SIZE=$(get_bytes $SYSIMG "VBMeta size:") 73 74VBMETA_SIZE=$(expr $HEADER_SIZE + $AUTHEN_SIZE + $AUX_SIZE + $SYSMETA_SIZE) 75 76 77HEADER_COMMENT="# androidboot.vbmeta.size=$VBMETA_SIZE androidboot.vbmeta.hash_alg=$VBMETA_HASH_ALG androidboot.vbmeta.digest=$VBMETA_DIGEST" 78 79echo $HEADER_COMMENT > $TARGET 80echo "major_version: $MAJOR_VERSION" >> $TARGET 81#echo "param: \"androidboot.slot_suffix=_a\"" >> $TARGET 82echo "param: \"androidboot.vbmeta.size=$VBMETA_SIZE\"" >> $TARGET 83echo "param: \"androidboot.vbmeta.hash_alg=$VBMETA_HASH_ALG\"" >> $TARGET 84echo "param: \"androidboot.vbmeta.digest=$VBMETA_DIGEST\"" >> $TARGET 85