Skip to content

Commit

Permalink
Issue #107: accept the new change in dtc 1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cfig committed Jan 7, 2023
1 parent e148871 commit d7ea80a
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- name: Unit Test
run: ./gradlew check && ./gradlew clean || true

- name: enable gradle native
run: sed -i "s/bHackingMode = false/bHackingMode = true/g" build.gradle.kts

# Runs a set of commands using the runners shell
- name: Integration Test
run: |
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,20 @@ If you want to edit the device-tree blob in place:
cp <your_vendor_boot_image> vendor_boot.img
cp <your_vbmeta_image> vbmeta.img
./gradlew unpack
==> now you can edit build/unzip_boot/dtb.src directly
==> now you can edit build/unzip_boot/dtb.dts directly
./gradlew pack
```

During unpack stage, dtb will be dumped to file `build/unzip_boot/dtb`, dts will be decompiled to `build/unzip_boot/dtb.src`.
You can edit `dtb.src` directly, and it will be compiled to dtb duing repack stage.
During unpack stage, dtb will be dumped to file `build/unzip_boot/dtb`, dts will be decompiled to `build/unzip_boot/dtb.dts`.
You can edit `dtb.dts` directly, and it will be compiled to dtb duing repack stage.

If you just want to replace the dtb with the one that is compiled outside this tool, please

```bash
cp <your_vendor_boot_image> vendor_boot.img
cp <your_vbmeta_image> vbmeta.img
./gradlew unpack
rm build/unzip_boot/dtb.src
rm build/unzip_boot/dtb.dts
cp <your_dtb> build/unzip_boot/dtb
./gradlew pack
```
Expand Down
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 @@ -182,7 +182,7 @@ class Common {
Helper.extractFile(s.srcFile, s.dumpFile, s.offset.toLong(), s.length)
//extract DTB
if (EnvironmentVerifier().hasDtc) {
DTC().decompile(s.dumpFile, s.dumpFile + ".src")
DTC().decompile(s.dumpFile, s.dumpFile + "." + Helper.prop("config.dts_suffix"))
}
}

Expand Down
9 changes: 5 additions & 4 deletions bbootimg/src/main/kotlin/bootimg/v2/BootV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ data class BootV2(
private val log = LoggerFactory.getLogger(BootV2::class.java)
private val workDir = Helper.prop("workDir")
private val mapper = ObjectMapper()
private val dtsSuffix = Helper.prop("config.dts_suffix")

fun parse(fileName: String): BootV2 {
val ret = BootV2()
Expand Down Expand Up @@ -305,8 +306,8 @@ data class BootV2(
if (theDtb.size > 0) {
it.addRule()
it.addRow("dtb", theDtb.file)
if (File(theDtb.file + ".src").exists()) {
it.addRow("\\-- decompiled dts", theDtb.file + ".src")
if (File(theDtb.file + ".${dtsSuffix}").exists()) {
it.addRow("\\-- decompiled dts", theDtb.file + ".${dtsSuffix}")
}
}
}
Expand Down Expand Up @@ -386,8 +387,8 @@ data class BootV2(
}
//refresh dtb size
dtb?.let { theDtb ->
if (File(theDtb.file!! + ".src").exists()) {
check(DTC().compile(theDtb.file!! + ".src", theDtb.file!!)) { "fail to compile dts" }
if (File(theDtb.file!! + ".${dtsSuffix}").exists()) {
check(DTC().compile(theDtb.file!! + ".${dtsSuffix}", theDtb.file!!)) { "fail to compile dts" }
}
theDtb.size = File(theDtb.file!!).length().toInt()
}
Expand Down
5 changes: 3 additions & 2 deletions bbootimg/src/main/kotlin/bootimg/v2/BootV2Dialects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ data class BootV2Dialects(
companion object {
private val log = LoggerFactory.getLogger(BootV2Dialects::class.java)
private val workDir = Helper.prop("workDir")
private val dtsSuffix = Helper.prop("config.dts_suffix")

fun parse(fileName: String): BootV2Dialects {
val ret = BootV2Dialects()
Expand Down Expand Up @@ -313,8 +314,8 @@ data class BootV2Dialects(
if (theDtb.size > 0) {
it.addRule()
it.addRow("dtb", theDtb.file)
if (File(theDtb.file + ".src").exists()) {
it.addRow("\\-- decompiled dts", theDtb.file + ".src")
if (File(theDtb.file + ".${dtsSuffix}").exists()) {
it.addRow("\\-- decompiled dts", theDtb.file + ".${dtsSuffix}")
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions bbootimg/src/main/kotlin/bootimg/v3/VendorBoot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ data class VendorBoot(
private val log = LoggerFactory.getLogger(VendorBoot::class.java)
private val workDir = Helper.prop("workDir")
private val mapper = ObjectMapper()
private val dtsSuffix = Helper.prop("config.dts_suffix")
fun parse(fileName: String): VendorBoot {
val ret = VendorBoot()
FileInputStream(fileName).use { fis ->
Expand Down Expand Up @@ -266,8 +267,8 @@ data class VendorBoot(
}
}
//update dtb
if (File(this.dtb.file + ".src").exists()) {
check(DTC().compile(this.dtb.file + ".src", this.dtb.file)) { "fail to compile dts" }
if (File(this.dtb.file + ".${dtsSuffix}").exists()) {
check(DTC().compile(this.dtb.file + ".${dtsSuffix}", this.dtb.file)) { "fail to compile dts" }
}
this.dtb.size = File(this.dtb.file).length().toInt()
//header
Expand Down Expand Up @@ -421,8 +422,8 @@ data class VendorBoot(
}
it.addRule()
it.addRow("dtb", this.dtb.file)
if (File(this.dtb.file + ".src").exists()) {
it.addRow("\\-- decompiled dts", dtb.file + ".src")
if (File(this.dtb.file + ".${dtsSuffix}").exists()) {
it.addRow("\\-- decompiled dts", dtb.file + ".${dtsSuffix}")
}
if (this.bootconfig.size > 0) {
it.addRule()
Expand Down
3 changes: 2 additions & 1 deletion bbootimg/src/main/kotlin/packable/DtboParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DtboParser(val workDir: File) : IPackable {
private val log = LoggerFactory.getLogger(DtboParser::class.java)
private val envv = EnvironmentVerifier()
private val dtboMaker = Helper.prop("dtboMaker")
private val dtsSuffix = Helper.prop("config.dts_suffix")

override fun capabilities(): List<String> {
return listOf("^dtbo\\.img$")
Expand Down Expand Up @@ -139,7 +140,7 @@ class DtboParser(val workDir: File) : IPackable {
if (envv.hasDtc) {
for (i in 0 until Integer.parseInt(props.getProperty("dt_entry_count"))) {
val inputDtb = "$dtbPath.$i"
val outputSrc = File(outDir + "/" + File(inputDtb).name + ".src").path
val outputSrc = File(outDir + "/" + File(inputDtb).name + ".${dtsSuffix}").path
DTC().decompile(inputDtb, outputSrc)
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions bbootimg/src/main/kotlin/utils/Dtbo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Dtbo(

private val log = LoggerFactory.getLogger(Dtbo::class.java)
private val outDir = Helper.prop("workDir")
private val dtsSuffix = Helper.prop("config.dts_suffix")
}

fun extractVBMeta(): Dtbo {
Expand Down Expand Up @@ -186,7 +187,7 @@ class Dtbo(
.toInt()
// Part II - a
for (index in 0 until dtEntries.size) {
DTC().compile("${outDir}dt/dt.${index}.src", "${outDir}dt/dt.${index}")
DTC().compile("${outDir}dt/dt.${index}.${dtsSuffix}", "${outDir}dt/dt.${index}")
}
// Part II - b
var offset = DtboHeader.SIZE + (header.entryCount * DeviceTreeTableEntry.SIZE)
Expand Down Expand Up @@ -221,7 +222,7 @@ class Dtbo(
it.addRow("image info", outDir + info.output.removeSuffix(".img") + ".json")
it.addRule()
it.addRow("device-tree blob (${this.header.entryCount} blobs)", "${outDir}dt/dt.*")
it.addRow("\\-- device-tree source ", "${outDir}dt/dt.*.src")
it.addRow("\\-- device-tree source ", "${outDir}dt/dt.*.${dtsSuffix}")
it.addRule()
it.addRow("AVB info", Avb.getJsonFileName(info.output))
it.addRule()
Expand Down
1 change: 1 addition & 0 deletions bbootimg/src/main/resources/general.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ 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
7 changes: 3 additions & 4 deletions integrationTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def verifySingleJson(jsonFile, func = None):
subprocess.check_call(gradleWrapper + " pack", shell = True)
for k, v in verifyItems["hash"].items():
log.info("%s : %s" % (k, v))
unittest.TestCase().assertEqual(v, hashFile(k))
unittest.TestCase().assertIn(hashFile(k), v.split())
try:
subprocess.check_call(gradleWrapper + " clear", shell = True)
except Exception as e:
Expand Down Expand Up @@ -161,9 +161,8 @@ def main():
verifySingleJson("%s/issue_59/recovery.json" % resDir2, func = lambda: shutil.rmtree("build/unzip_boot/root", ignore_errors = False))
# Issue 71: dtbo
if platform.system() != "Darwin":
pass
#verifySingleDir(resDir2, "issue_71")
#verifySingleDir(resDir2, "issue_71/redfin")
verifySingleDir(resDir2, "issue_71")
verifySingleDir(resDir2, "issue_71/redfin")
else:
log.info("dtbo not fully supported on MacOS, skip testing")
# Issue 83: init_boot
Expand Down
2 changes: 1 addition & 1 deletion src/integrationTest/resources
2 changes: 1 addition & 1 deletion src/integrationTest/resources_2
Submodule resources_2 updated from 03c9b4 to be8c5a

0 comments on commit d7ea80a

Please sign in to comment.