Skip to content

Commit

Permalink
Issue #67: support boot/vendor_boot headerVersion downgrade from 4 to 3
Browse files Browse the repository at this point in the history
boot: correct header size, trim bootSignature
vendor_boot: correct header size, trim vrt
  • Loading branch information
cfig committed Aug 25, 2021
1 parent 1b8fdbe commit 190c801
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
16 changes: 16 additions & 0 deletions bbootimg/src/main/kotlin/bootimg/v3/BootHeaderV3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ class BootHeaderV3(
)
}

fun feature67(): BootHeaderV3 {
val newHeaderSize = when (headerVersion) {
3 -> BOOT_IMAGE_HEADER_V3_SIZE
else -> BOOT_IMAGE_HEADER_V4_SIZE
}
if (newHeaderSize != headerSize) {
log.warn("wrong headerSize, fixed.($headerSize -> $newHeaderSize)")
headerSize = newHeaderSize
}
if (signatureSize != 0 && headerVersion == 3) {
log.warn("trim bootSignature for headerVersion=3")
signatureSize = 0
}
return this
}

override fun toString(): String {
return "BootImgHeaderV3(kernelSize=$kernelSize, ramdiskSize=$ramdiskSize, osVersion=$osVersion, osPatchLevel=$osPatchLevel, headerSize=$headerSize, headerVersion=$headerVersion, cmdline='$cmdline')"
}
Expand Down
2 changes: 1 addition & 1 deletion bbootimg/src/main/kotlin/bootimg/v3/BootV3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ data class BootV3(
headerSize = info.headerSize,
cmdline = info.cmdline,
signatureSize = info.signatureSize
)
).feature67()
}

fun extractImages(): BootV3 {
Expand Down
2 changes: 1 addition & 1 deletion bbootimg/src/main/kotlin/bootimg/v3/VendorBoot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ data class VendorBoot(
vrtEntryNum = ramdisk_table.ramdidks.size,
vrtEntrySize = ramdisk_table.eachEntrySize,
bootconfigSize = File(bootconfig.file).length().toInt()
)
).feature67()
}

fun extractImages(): VendorBoot {
Expand Down
20 changes: 20 additions & 0 deletions bbootimg/src/main/kotlin/bootimg/v3/VendorBootHeader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ class VendorBootHeader(
}
}

// https://github.com/cfig/Android_boot_image_editor/issues/67
// support vendor_boot headerVersion downgrade from 4 to 3 during re-pack
fun feature67(): VendorBootHeader {
val newHeaderSize = when (this.headerVersion) {
3 -> VendorBootHeader.VENDOR_BOOT_IMAGE_HEADER_V3_SIZE
else -> VendorBootHeader.VENDOR_BOOT_IMAGE_HEADER_V4_SIZE
}
if (newHeaderSize != headerSize) {
log.warn("wrong headerSize, fixed.($headerSize -> $newHeaderSize)")
headerSize = newHeaderSize
}
if (vrtSize != 0 && headerVersion == 3) {
log.warn("trim vrt for headerVersion=3")
vrtSize = 0
vrtEntryNum = 0
vrtEntrySize = 0
}
return this
}

fun encode(): ByteArray {
return Struct3(FORMAT_STRING).pack(
magic,
Expand Down

0 comments on commit 190c801

Please sign in to comment.