Issue #59: support clear V3 boot images

pull/66/head
cfig 4 years ago
parent 9d2a7a14c2
commit 577b970811
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -2,10 +2,10 @@ package cfig.bootimg.v3
import cfig.Avb import cfig.Avb
import cfig.EnvironmentVerifier import cfig.EnvironmentVerifier
import cfig.helper.Helper
import cfig.bootimg.Common.Companion.deleleIfExists import cfig.bootimg.Common.Companion.deleleIfExists
import cfig.bootimg.Common.Companion.getPaddingSize import cfig.bootimg.Common.Companion.getPaddingSize
import cfig.bootimg.Signer import cfig.bootimg.Signer
import cfig.helper.Helper
import cfig.packable.VBMetaParser import cfig.packable.VBMetaParser
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import de.vandermeer.asciitable.AsciiTable import de.vandermeer.asciitable.AsciiTable
@ -112,7 +112,7 @@ data class BootV3(
//data //data
log.info("Writing data ...") log.info("Writing data ...")
//BootV3 should have correct image size //BootV3 should have correct image size
val bf = ByteBuffer.allocate(maxOf(info.imageSize.toInt(), 64 *1024 *1024)) val bf = ByteBuffer.allocate(maxOf(info.imageSize.toInt(), 64 * 1024 * 1024))
bf.order(ByteOrder.LITTLE_ENDIAN) bf.order(ByteOrder.LITTLE_ENDIAN)
C.writePaddedFile(bf, this.kernel.file, this.info.pageSize) C.writePaddedFile(bf, this.kernel.file, this.info.pageSize)
C.writePaddedFile(bf, this.ramdisk.file, this.info.pageSize) C.writePaddedFile(bf, this.ramdisk.file, this.info.pageSize)
@ -132,8 +132,16 @@ data class BootV3(
} }
fun sign(fileName: String): BootV3 { fun sign(fileName: String): BootV3 {
val avbtool = String.format(Helper.prop("avbtool"), "v1.2") val tab = AsciiTable().let {
Signer.signAVB(fileName, this.info.imageSize, avbtool) it.addRule()
it.addRow("")
it
}
if (File(Avb.getJsonFileName(info.output)).exists()) {
Signer.signAVB(fileName, this.info.imageSize, String.format(Helper.prop("avbtool"), "v1.2"))
} else {
log.warn("no AVB info found, assume it's clear image")
}
return this return this
} }
@ -175,10 +183,15 @@ data class BootV3(
} }
fun extractVBMeta(): BootV3 { fun extractVBMeta(): BootV3 {
Avb().parseVbMeta(info.output) try {
if (File("vbmeta.img").exists()) { Avb().parseVbMeta(info.output)
log.warn("Found vbmeta.img, parsing ...") if (File("vbmeta.img").exists()) {
VBMetaParser().unpack("vbmeta.img") log.warn("Found vbmeta.img, parsing ...")
VBMetaParser().unpack("vbmeta.img")
}
} catch (e: IllegalArgumentException) {
log.warn(e.message)
log.warn("failed to parse vbmeta info")
} }
return this return this
} }
@ -215,8 +228,9 @@ data class BootV3(
it.addRow("\\-- decoded boot signature", Avb.getJsonFileName(this.bootSignature.file)) it.addRow("\\-- decoded boot signature", Avb.getJsonFileName(this.bootSignature.file))
it.addRule() it.addRule()
} }
Avb.getJsonFileName(info.output).let { jsonFile ->
it.addRow("AVB info", Avb.getJsonFileName(info.output)) it.addRow("AVB info", if (File(jsonFile).exists()) jsonFile else "NONE")
}
it.addRule() it.addRule()
it it
} }

@ -65,6 +65,16 @@ class BootImgParser() : IPackable {
ObjectMapper().readValue(File(cfgFile), BootV3::class.java) ObjectMapper().readValue(File(cfgFile), BootV3::class.java)
.pack() .pack()
.sign(fileName) .sign(fileName)
.let {
val tab = AsciiTable().let { tab ->
tab.addRule()
val outFileSuffix = if (File(Avb.getJsonFileName(it.info.output)).exists()) ".signed" else ""
tab.addRow("${it.info.output}${outFileSuffix} is ready")
tab.addRule()
tab
}
log.info("\n{}", tab.render())
}
} else { } else {
ObjectMapper().readValue(File(cfgFile), BootV2::class.java) ObjectMapper().readValue(File(cfgFile), BootV2::class.java)
.pack() .pack()

Loading…
Cancel
Save