From 859300e3b99e068b799e71ce45614e39b767f15b Mon Sep 17 00:00:00 2001 From: cfig Date: Tue, 16 Apr 2024 11:11:35 +0800 Subject: [PATCH] Issue #138: support customized dtc binary path --- bbootimg/src/main/kotlin/bootimg/Common.kt | 2 +- bbootimg/src/main/kotlin/bootimg/Signer.kt | 8 ++++---- bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt | 4 ++-- bbootimg/src/main/kotlin/bootimg/v2/BootV2Dialects.kt | 4 ++-- bbootimg/src/main/kotlin/bootimg/v3/BootV3.kt | 4 ++-- bbootimg/src/main/kotlin/bootimg/v3/VendorBoot.kt | 2 +- bbootimg/src/main/kotlin/packable/IPackable.kt | 2 +- bbootimg/src/main/kotlin/packable/OTAzipParser.kt | 2 +- bbootimg/src/main/kotlin/rom/fdt/DTC.kt | 7 ++++--- bbootimg/src/main/kotlin/rom/fdt/Dtbo.kt | 2 +- bbootimg/src/main/kotlin/rom/sparse/BaseGenerator.kt | 2 +- bbootimg/src/main/kotlin/rom/sparse/SparseImage.kt | 2 +- bbootimg/src/main/kotlin/utils/KernelExtractor.kt | 4 ++-- bbootimg/src/main/resources/general.cfg | 3 ++- helper/src/main/kotlin/cfig/helper/Helper.kt | 2 +- 15 files changed, 26 insertions(+), 24 deletions(-) diff --git a/bbootimg/src/main/kotlin/bootimg/Common.kt b/bbootimg/src/main/kotlin/bootimg/Common.kt index 5817349..9c86f44 100644 --- a/bbootimg/src/main/kotlin/bootimg/Common.kt +++ b/bbootimg/src/main/kotlin/bootimg/Common.kt @@ -234,7 +234,7 @@ class Common { //using mkbootfs fun packRootfs(rootDir: String, ramdiskGz: String, osMajor: Int = 10) { - val mkbootfs = String.format(Locale.getDefault(), Helper.prop("mkbootfsBin"), osMajor) + val mkbootfs = String.format(Locale.getDefault(), Helper.prop("mkbootfsBin")!!, osMajor) log.info("Packing rootfs $rootDir ...") val outputStream = ByteArrayOutputStream() DefaultExecutor().let { exec -> diff --git a/bbootimg/src/main/kotlin/bootimg/Signer.kt b/bbootimg/src/main/kotlin/bootimg/Signer.kt index a88769f..7609967 100644 --- a/bbootimg/src/main/kotlin/bootimg/Signer.kt +++ b/bbootimg/src/main/kotlin/bootimg/Signer.kt @@ -80,14 +80,14 @@ class Signer { val bootSigner = Helper.prop("bootSigner") log.info("Signing with verified-boot 1.0 style") val sig = Common.VeritySignature( - verity_pk8 = Helper.prop("verity_pk8"), - verity_pem = Helper.prop("verity_pem"), - jarPath = Helper.prop("bootSigner") + verity_pk8 = Helper.prop("verity_pk8")!!, + verity_pem = Helper.prop("verity_pem")!!, + jarPath = Helper.prop("bootSigner")!! ) val bootSignCmd = "java -jar $bootSigner " + "${sig.path} $src " + "${sig.verity_pk8} ${sig.verity_pem} " + - "$tgt" + tgt log.info(bootSignCmd) DefaultExecutor().execute(CommandLine.parse(bootSignCmd)) } diff --git a/bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt b/bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt index 79f6029..ed5e8e3 100644 --- a/bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt +++ b/bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt @@ -118,7 +118,7 @@ data class BootV2( theInfo.osPatchLevel = bh2.osPatchLevel if (Avb.hasAvbFooter(fileName)) { theInfo.verify = "VB2.0" - if (Avb.verifyAVBIntegrity(fileName, String.format(Helper.prop("avbtool"), "v1.2"))) { + if (Avb.verifyAVBIntegrity(fileName, String.format(Helper.prop("avbtool")!!, "v1.2"))) { theInfo.verify += " PASS" } else { theInfo.verify += " FAIL" @@ -597,7 +597,7 @@ data class BootV2( fun sign(): BootV2 { //unify with v1.1/v1.2 avbtool - val avbtool = String.format(Helper.prop("avbtool"), "v1.2") + val avbtool = String.format(Helper.prop("avbtool")!!, "v1.2") if (info.verify.startsWith("VB2.0")) { Signer.signAVB(info.output, this.info.imageSize, avbtool) log.info("Adding hash_footer with verified-boot 2.0 style") diff --git a/bbootimg/src/main/kotlin/bootimg/v2/BootV2Dialects.kt b/bbootimg/src/main/kotlin/bootimg/v2/BootV2Dialects.kt index 2972de8..de8b396 100644 --- a/bbootimg/src/main/kotlin/bootimg/v2/BootV2Dialects.kt +++ b/bbootimg/src/main/kotlin/bootimg/v2/BootV2Dialects.kt @@ -105,7 +105,7 @@ data class BootV2Dialects( theInfo.osPatchLevel = bh2.osPatchLevel if (Avb.hasAvbFooter(fileName)) { theInfo.verify = "VB2.0" - if (Avb.verifyAVBIntegrity(fileName, String.format(Helper.prop("avbtool"), "v1.2"))) { + if (Avb.verifyAVBIntegrity(fileName, String.format(Helper.prop("avbtool")!!, "v1.2"))) { theInfo.verify += " PASS" } else { theInfo.verify += " FAIL" @@ -528,7 +528,7 @@ data class BootV2Dialects( fun sign(): BootV2Dialects { //unify with v1.1/v1.2 avbtool - val avbtool = String.format(Helper.prop("avbtool"), "v1.2") + val avbtool = String.format(Helper.prop("avbtool")!!, "v1.2") if (info.verify.startsWith("VB2.0")) { Signer.signAVB(info.output, this.info.imageSize, avbtool) log.info("Adding hash_footer with verified-boot 2.0 style") diff --git a/bbootimg/src/main/kotlin/bootimg/v3/BootV3.kt b/bbootimg/src/main/kotlin/bootimg/v3/BootV3.kt index 9dfd840..0d1f59c 100644 --- a/bbootimg/src/main/kotlin/bootimg/v3/BootV3.kt +++ b/bbootimg/src/main/kotlin/bootimg/v3/BootV3.kt @@ -204,7 +204,7 @@ data class BootV3( fun sign(fileName: String): BootV3 { if (File(Avb.getJsonFileName(info.output)).exists()) { - Signer.signAVB(fileName, this.info.imageSize, String.format(Helper.prop("avbtool"), "v1.2")) + 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") } @@ -475,7 +475,7 @@ data class BootV3( val alg = Algorithms.get(origSig.header!!.algorithm_type)!! ret.addArgument("--gki_signing_algorithm").addArgument(alg.name) ret.addArgument("--gki_signing_key").addArgument(alg.defaultKey) - ret.addArgument("--gki_signing_avbtool_path").addArgument(String.format(Helper.prop("avbtool"), "v1.2")) + ret.addArgument("--gki_signing_avbtool_path").addArgument(String.format(Helper.prop("avbtool")!!, "v1.2")) } ret.addArgument(" --id ") ret.addArgument(" --output ") diff --git a/bbootimg/src/main/kotlin/bootimg/v3/VendorBoot.kt b/bbootimg/src/main/kotlin/bootimg/v3/VendorBoot.kt index c655eee..81521a2 100644 --- a/bbootimg/src/main/kotlin/bootimg/v3/VendorBoot.kt +++ b/bbootimg/src/main/kotlin/bootimg/v3/VendorBoot.kt @@ -316,7 +316,7 @@ data class VendorBoot( } fun sign(): VendorBoot { - val avbtool = String.format(Helper.prop("avbtool"), "v1.2") + val avbtool = String.format(Helper.prop("avbtool")!!, "v1.2") File(Avb.getJsonFileName(info.output)).let { if (it.exists()) { Signer.signAVB(info.output, this.info.imageSize, avbtool) diff --git a/bbootimg/src/main/kotlin/packable/IPackable.kt b/bbootimg/src/main/kotlin/packable/IPackable.kt index 3b2ee1b..8e098c3 100644 --- a/bbootimg/src/main/kotlin/packable/IPackable.kt +++ b/bbootimg/src/main/kotlin/packable/IPackable.kt @@ -29,7 +29,7 @@ import kotlin.io.path.deleteIfExists interface IPackable { val loopNo: Int val outDir: String - get() = Helper.prop("workDir") + get() = Helper.prop("workDir")!! fun capabilities(): List { return listOf("^dtbo\\.img$") diff --git a/bbootimg/src/main/kotlin/packable/OTAzipParser.kt b/bbootimg/src/main/kotlin/packable/OTAzipParser.kt index 34e4fb2..60d4da1 100644 --- a/bbootimg/src/main/kotlin/packable/OTAzipParser.kt +++ b/bbootimg/src/main/kotlin/packable/OTAzipParser.kt @@ -80,6 +80,6 @@ class OTAzipParser : IPackable { companion object { private val log = LoggerFactory.getLogger(OTAzipParser::class.java) - private val workDir = Helper.prop("workDir") + private val workDir = Helper.prop("workDir")!! } } diff --git a/bbootimg/src/main/kotlin/rom/fdt/DTC.kt b/bbootimg/src/main/kotlin/rom/fdt/DTC.kt index 7387e36..dd27053 100644 --- a/bbootimg/src/main/kotlin/rom/fdt/DTC.kt +++ b/bbootimg/src/main/kotlin/rom/fdt/DTC.kt @@ -27,6 +27,7 @@ import java.io.InputStream class DTC { private val log = LoggerFactory.getLogger(DTC::class.java) + private val dtcBin = Helper.prop("dtcBin") ?: "dtc" data class DtbEntry( var seqNo: Int = 0, @@ -84,7 +85,7 @@ class DTC { //dtb-> dts DefaultExecutor().let { try { - val cmd = CommandLine.parse("dtc -q -I dtb -O dts").apply { + val cmd = CommandLine.parse("$dtcBin -q -I dtb -O dts").apply { addArguments(dtbFile) addArguments("-o $outFile") } @@ -98,7 +99,7 @@ class DTC { //dts -> yaml DefaultExecutor().let { try { - val cmd = CommandLine.parse("dtc -q -I dts -O yaml").apply { + val cmd = CommandLine.parse("$dtcBin -q -I dts -O yaml").apply { addArguments(outFile) addArguments("-o $outFile.yaml") } @@ -114,7 +115,7 @@ class DTC { fun compile(dtsFile: String, outFile: String): Boolean { log.info("compiling DTS: $dtsFile") - val cmd = CommandLine.parse("dtc -q -I dts -O dtb").let { + val cmd = CommandLine.parse("$dtcBin -q -I dts -O dtb").let { it.addArguments(dtsFile) it.addArguments("-o $outFile") } diff --git a/bbootimg/src/main/kotlin/rom/fdt/Dtbo.kt b/bbootimg/src/main/kotlin/rom/fdt/Dtbo.kt index 2a8c018..ac263cb 100644 --- a/bbootimg/src/main/kotlin/rom/fdt/Dtbo.kt +++ b/bbootimg/src/main/kotlin/rom/fdt/Dtbo.kt @@ -241,7 +241,7 @@ class Dtbo( } fun sign(): Dtbo { - val avbtool = String.format(Helper.prop("avbtool"), "v1.2") + val avbtool = String.format(Helper.prop("avbtool")!!, "v1.2") Signer.signAVB(info.output, info.imageSize.toLong(), avbtool) return this } diff --git a/bbootimg/src/main/kotlin/rom/sparse/BaseGenerator.kt b/bbootimg/src/main/kotlin/rom/sparse/BaseGenerator.kt index 85e1def..2e7dc83 100644 --- a/bbootimg/src/main/kotlin/rom/sparse/BaseGenerator.kt +++ b/bbootimg/src/main/kotlin/rom/sparse/BaseGenerator.kt @@ -14,7 +14,7 @@ open class BaseGenerator( var keyPath: String = "" var algorithm: String = "" var salt: String = "" - val avbtool = String.format(Helper.prop("avbtool"), "v1.2") + val avbtool = String.format(Helper.prop("avbtool")!!, "v1.2") var signingArgs = "--hash_algorithm sha256 " + "--prop com.android.build.the_partition_name.os_version:14 " + "--prop com.android.build.the_partition_name.fingerprint:anonymous/device/device:14/UD1A.230803.041/buildid:userdebug/test-keys" diff --git a/bbootimg/src/main/kotlin/rom/sparse/SparseImage.kt b/bbootimg/src/main/kotlin/rom/sparse/SparseImage.kt index 5a58fd6..0a1a1b0 100644 --- a/bbootimg/src/main/kotlin/rom/sparse/SparseImage.kt +++ b/bbootimg/src/main/kotlin/rom/sparse/SparseImage.kt @@ -139,7 +139,7 @@ data class SparseImage(var info: SparseInfo = SparseInfo()) { companion object { private val SPARSE_MAGIC: UInt = 0x3aff26edu private val log = LoggerFactory.getLogger(SparseImage::class.java) - private val workDir = Helper.prop("workDir") + private val workDir = Helper.prop("workDir")!! private val simg2imgBin = "simg2img" private val img2simgBin = "img2simg" diff --git a/bbootimg/src/main/kotlin/utils/KernelExtractor.kt b/bbootimg/src/main/kotlin/utils/KernelExtractor.kt index acd5c90..6feb3eb 100644 --- a/bbootimg/src/main/kotlin/utils/KernelExtractor.kt +++ b/bbootimg/src/main/kotlin/utils/KernelExtractor.kt @@ -32,8 +32,8 @@ class KernelExtractor { fun run(fileName: String, workDir: File? = null): List { val ret: MutableList = mutableListOf() - val kernelVersionFile = Helper.prop("kernelVersionFile") - val kernelConfigFile = Helper.prop("kernelConfigFile") + val kernelVersionFile = Helper.prop("kernelVersionFile")!! + val kernelConfigFile = Helper.prop("kernelConfigFile")!! val cmdPrefix = if (EnvironmentVerifier().isWindows) "python " else "" val cmd = CommandLine.parse(cmdPrefix + Helper.prop("kernelExtracter")).let { it.addArgument("--input") diff --git a/bbootimg/src/main/resources/general.cfg b/bbootimg/src/main/resources/general.cfg index ca6f271..38a75e8 100644 --- a/bbootimg/src/main/resources/general.cfg +++ b/bbootimg/src/main/resources/general.cfg @@ -11,4 +11,5 @@ mkbootimg = aosp/system/tools/mkbootimg/mkbootimg.py dtboMaker = aosp/system/libufdt/utils/src/mkdtboimg.py payloadDir = build/payload/ config.allow_cpio_duplicate = true -config.dts_suffix = dts \ No newline at end of file +config.dts_suffix = dts +dtcBin = dtc diff --git a/helper/src/main/kotlin/cfig/helper/Helper.kt b/helper/src/main/kotlin/cfig/helper/Helper.kt index 2712a75..0a444be 100644 --- a/helper/src/main/kotlin/cfig/helper/Helper.kt +++ b/helper/src/main/kotlin/cfig/helper/Helper.kt @@ -43,7 +43,7 @@ class Helper { load(Helper::class.java.classLoader.getResourceAsStream("general.cfg")) } - fun prop(k: String): String { + fun prop(k: String): String? { return gcfg.getProperty(k) }