From a8bca119c28824ebb5ebc0bc688c3c20886ec10f Mon Sep 17 00:00:00 2001 From: Hridya Valsaraju Date: Fri, 23 Mar 2018 16:01:03 -0700 Subject: Allow recovery-dtbo in recovery.img to be signed Non-A/B devices need to include the DTBO image within the recovery partition to be self-sufficient and prevent OTA failures. The CL includes the size of recovery DTBO in the size of the boot image to be signed to prevent image truncation. Test: Verified that recovery.img was not getting truncated. Bug: 74763691 Change-Id: Id56928129dfea167e2451aa5f4609fef77e00ff4 Merged-In: Id56928129dfea167e2451aa5f4609fef77e00ff4 (cherry picked from commit 9bb9f8f857170c5865944bdc9e4700a73a6e7434) --- verity/BootSignature.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/verity/BootSignature.java b/verity/BootSignature.java index 3cf94990..10171c31 100644 --- a/verity/BootSignature.java +++ b/verity/BootSignature.java @@ -72,6 +72,11 @@ public class BootSignature extends ASN1Object private PublicKey publicKey; private static final int FORMAT_VERSION = 1; + /** + * Offset of recovery DTBO length in a boot image header of version greater than + * or equal to 1. + */ + private static final int BOOT_IMAGE_HEADER_V1_RECOVERY_DTBO_SIZE_OFFSET = 1632; /** * Initializes the object for signing an image file @@ -209,6 +214,22 @@ public class BootSignature extends ASN1Object + ((ramdskSize + pageSize - 1) / pageSize) * pageSize + ((secondSize + pageSize - 1) / pageSize) * pageSize; + int headerVersion = image.getInt(); // boot image header version + if (headerVersion > 0) { + image.position(BOOT_IMAGE_HEADER_V1_RECOVERY_DTBO_SIZE_OFFSET); + int recoveryDtboLength = image.getInt(); + length += ((recoveryDtboLength + pageSize - 1) / pageSize) * pageSize; + + image.getLong(); // recovery_dtbo address + if (headerVersion == 1) { + int headerSize = image.getInt(); + if (image.position() != headerSize) { + throw new IllegalArgumentException( + "Invalid image header: invalid header length"); + } + } + } + length = ((length + pageSize - 1) / pageSize) * pageSize; if (length <= 0) { -- cgit v1.2.3