Skip to content

Commit

Permalink
Issue #138: support customized dtc binary path
Browse files Browse the repository at this point in the history
  • Loading branch information
cfig committed Apr 16, 2024
1 parent 95ed740 commit 859300e
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bbootimg/src/main/kotlin/bootimg/Common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
8 changes: 4 additions & 4 deletions bbootimg/src/main/kotlin/bootimg/Signer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions bbootimg/src/main/kotlin/bootimg/v2/BootV2Dialects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions bbootimg/src/main/kotlin/bootimg/v3/BootV3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 ")
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 @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bbootimg/src/main/kotlin/packable/IPackable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
return listOf("^dtbo\\.img$")
Expand Down
2 changes: 1 addition & 1 deletion bbootimg/src/main/kotlin/packable/OTAzipParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")!!
}
}
7 changes: 4 additions & 3 deletions bbootimg/src/main/kotlin/rom/fdt/DTC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion bbootimg/src/main/kotlin/rom/fdt/Dtbo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion bbootimg/src/main/kotlin/rom/sparse/BaseGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bbootimg/src/main/kotlin/rom/sparse/SparseImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions bbootimg/src/main/kotlin/utils/KernelExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class KernelExtractor {

fun run(fileName: String, workDir: File? = null): List<String> {
val ret: MutableList<String> = 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")
Expand Down
3 changes: 2 additions & 1 deletion bbootimg/src/main/resources/general.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
config.dts_suffix = dts
dtcBin = dtc
2 changes: 1 addition & 1 deletion helper/src/main/kotlin/cfig/helper/Helper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 859300e

Please sign in to comment.