libavb: Support vbmeta blobs in beginning of partition.

If we don't find a AvbFooter when resolving a chain descriptor, also
check if there's a vbmeta struct in the beginning. If there is, use
it.

This is to support the use-case where a single vbmeta_<orgname>
partition can hold metadata for several other partitions which may not
be easily readable by the bootloader (e.g. they are "logical"
partitions using a proprietary partitioning format). For example, this
supports the following setup

vbmeta         # chain desc for vbmeta_google
vbmeta_google  # hash desc for boot, dtbo and hashtree desc for system, vendor
boot
dtbo
super          # container for system and vendor logical partitions
system         # logical partition (not readable by bootloader)
vendor         # logical partition (not readable by bootloader)

where vbmeta_google has the vbmeta struct in the beginning just as if
it were the main vbmeta partition.

Additional change: Previously it was optional to support the
get_size_of_partition() operation. Starting with this commit, this
operation is mandatory and must be implemented such that
AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION is returned for partitions that
don't exist.

Also introduce a new 'extract_vbmeta_image' sub-command to avbtool
that can be used to extract the vbmeta blob from a footer.

Change-Id: I157537f36f77c768283c0745794cf9be93089c35
2 files changed