From 4f4a9412a32bb0d589ecb317bc804ed4c23f59a6 Mon Sep 17 00:00:00 2001 From: osm0sis Date: Thu, 4 Jul 2019 03:05:44 -0300 Subject: [PATCH] SignBoot: updates from AOSP for boot_img_hdr_v1 and v2 "Allow recovery-dtbo in recovery.img to be signed" by Hridya Valsaraju: https://android.googlesource.com/platform/system/extras/+/9bb9f8f857170c5865944bdc9e4700a73a6e7434 "boot_signer should support boot header version 2" by Hridya Valsaraju https://android.googlesource.com/platform/system/extras/+/590e58454d25218bc295cf0fbdc241b0d1b8ae8e --- .../java/com/topjohnwu/signing/SignBoot.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/signing/src/main/java/com/topjohnwu/signing/SignBoot.java b/signing/src/main/java/com/topjohnwu/signing/SignBoot.java index 11ed30bc1..e75357e8b 100644 --- a/signing/src/main/java/com/topjohnwu/signing/SignBoot.java +++ b/signing/src/main/java/com/topjohnwu/signing/SignBoot.java @@ -162,6 +162,24 @@ public class SignBoot { + ((kernelSize + pageSize - 1) / pageSize) * pageSize + ((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 + int headerSize = image.getInt(); + if (headerVersion == 2) { + image.position(BOOT_IMAGE_HEADER_V2_DTB_SIZE_OFFSET); + int dtbLength = image.getInt(); + length += ((dtbLength + pageSize - 1) / pageSize) * pageSize; + image.getLong(); // dtb address + } + if (image.position() != headerSize) { + throw new IllegalArgumentException( + "Invalid image header: invalid header length"); + } + } length = ((length + pageSize - 1) / pageSize) * pageSize; if (length <= 0) { throw new IllegalArgumentException("Invalid image header: invalid length"); @@ -178,6 +196,8 @@ public class SignBoot { private DEROctetString signature; private PublicKey publicKey; private static final int FORMAT_VERSION = 1; + private static final int BOOT_IMAGE_HEADER_V1_RECOVERY_DTBO_SIZE_OFFSET = 1632; + private static final int BOOT_IMAGE_HEADER_V2_DTB_SIZE_OFFSET = 1648; /** * Initializes the object for signing an image file