Issue #123: better support dtb/dts

● support dumping /proc/device-tree from a running rooted Android
● support editing standalone dtb file
pull/140/head
cfig 2 years ago
parent ec6f4780a6
commit e5c6a41ede
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -53,15 +53,16 @@ Well done you did it! The last step is to star this repo :smile
## Supported ROM image types
| Image Type | file names | platforms | note |
| --------------- | ----------------------------------- |-------------|-------------------------|
| boot | boot.img, init_boot.img, boot(-debug|-test-harness).img | all | |
|vendor boot | vendor_boot.img, vendor_boot-debug.img, vendor_kernel_boot.img | all | |
| recovery | recovery.img, recovery-two-step.img | all | |
| vbmeta | vbmeta.img, vbmeta_system.img etc. | all | |
| dtbo | dtbo.img | linux & mac | |
| sparse images | system.img, vendor.img, product.img etc.| linux | |
| OTA payload | payload.bin | all | Windows git-bash |
| Image Type | file names | platforms | note |
| --------------- |----------------------------------------------------------------|-------------|-------------------------|
| boot | boot.img, init_boot.img, boot-debug.img, boot-test-harness.img | all | |
|vendor boot | vendor_boot.img, vendor_boot-debug.img, vendor_kernel_boot.img | all | |
| recovery | recovery.img, recovery-two-step.img | all | |
| vbmeta | vbmeta.img, vbmeta_system.img etc. | all | |
| dtbo | dtbo.img | linux & mac | |
| dtb | *.dtb | linux & mac | |
| sparse images | system.img, vendor.img, product.img etc. | linux | |
| OTA payload | payload.bin | all | Windows git-bash |
Please note that the boot.img MUST follows AOSP verified boot flow, either [Boot image signature](https://source.android.com/security/verifiedboot/verified-boot#signature_format) in VBoot 1.0 or [AVB HASH footer](https://android.googlesource.com/platform/external/avb/+/master/README.md#The-VBMeta-struct) (a.k.a. AVB) in VBoot 2.0.
@ -69,6 +70,7 @@ Please note that the boot.img MUST follows AOSP verified boot flow, either [Boot
| Device Model | Manufacturer | Compatible | Android Version | Note |
|--------------------------------|--------------|----------------------|--------------------------|------|
| Pixel 7 (panther) | Google | Y | 13 (TQ2A.230505.002) <Br>2023)| |
| ADT-3 (adt3) | Askey/Google | Y | 12 (spp2.210219.010) | amlogic inside, <Br>Android TV |
| Pixel 3 (blueline) | Google | Y | 12 (spp2.210219.008, <Br>2021)| |
| Pixel 3 (blueline) | Google | Y | 11 (RP1A.200720.009, <Br>2020)| [more ...](doc/additional_tricks.md#pixel-3-blueline) |
@ -156,7 +158,7 @@ Please note that to use 'gradle flash', your host machine must be connectted to
</details>
<details>
<summary>edit device-tree blob(dtb) inside vendor_boot.img</summary>
<summary>How to edit device tree blob(dtb) inside vendor_boot.img</summary>
If you want to edit the device-tree blob in place:
@ -184,6 +186,55 @@ cp <your_dtb> build/unzip_boot/dtb
</details>
<details>
<summary>How to pull device tree blob(dtb) from a rooted device</summary>
If you have a rooted device and want to pull /proc/device-tree
```bash
touch fake.dtb
./gradlew pull
```
This tool will copy `dtc` to the target device via `adb`, and dump the dtb and dts file. Eventually you should get something like this
```
+--------+------------------------------+
| What | Where |
+--------+------------------------------+
| source | /proc/device-tree |
+--------+------------------------------+
| DTB | panther.dtb |
+--------+------------------------------+
| DTS | build/unzip_boot/panther.dts |
+--------+------------------------------+
```
</details>
<details>
<summary>How to work edit device tree blob(dtb) file</summary>
If you have a dtb file and want to edit its content
```bash
cp <your_dtb_file> .
./gradlew unpack
```
This tool will decompile it and put the decompiled source to build/unzip_boot.
```
Unpack Summary of panther.dtb
+------+------------------------------+
| What | Where |
+------+------------------------------+
| DTB | panther.dtb |
+------+------------------------------+
| DTS | build/unzip_boot/panther.dts |
+------+------------------------------+
```
</details>
<details>
<summary>working with system.img</summary>
@ -255,11 +306,10 @@ https://android.googlesource.com/platform/system/core/+/refs/heads/master/libspa
Android Nexus/Pixle factory images<br/>
https://developers.google.cn/android/images<br/>
This project is developed with products by Jetbrains.
</details>
This project is developed with products by Jetbrains.
<a href="https://jb.gg/OpenSource">
<img src="https://user-images.githubusercontent.com/1133314/116802621-c076be80-ab46-11eb-8a14-9454a933de7d.png" alt="drawing" width="80">
</a>
</details>

@ -0,0 +1,83 @@
package packable
import cfig.bootimg.Common
import cfig.helper.Helper
import cfig.helper.Helper.Companion.check_call
import cfig.helper.Helper.Companion.check_output
import cfig.helper.Helper.Companion.deleteIfExists
import cfig.packable.IPackable
import cfig.utils.DTC
import org.slf4j.LoggerFactory
import java.io.File
class DeviceTreeParser : IPackable {
override fun capabilities(): List<String> {
return listOf("^.*\\.dtb$")
}
override val loopNo: Int
get() = 1
override fun unpack(fileName: String) {
super.clear()
log.info("unpacking $fileName")
val outFile = workDir + fileName.removeSuffix(".dtb") + "." + Helper.prop("config.dts_suffix")
DTC().decompile(fileName, outFile)
//print summary
val prints: MutableList<Pair<String, String>> = mutableListOf()
prints.add(Pair("DTB", fileName))
prints.add(Pair("DTS", outFile))
log.info("\n\t\t\tUnpack Summary of {}\n{}\n", fileName, Common.table2String(prints))
}
override fun pack(fileName: String) {
log.info("packing $fileName")
val outFile = workDir + fileName.removeSuffix(".dtb") + "." + Helper.prop("config.dts_suffix")
check(DTC().compile(outFile, "$fileName.new")) { "fail to compile dts" }
//print summary
val prints: MutableList<Pair<String, String>> = mutableListOf()
prints.add(Pair("DTS", outFile))
prints.add(Pair("updated DTB", "$fileName.new"))
log.info("\n\t\t\tPack Summary of {}\n{}\n", fileName, Common.table2String(prints))
}
override fun pull(fileName: String, deviceName: String) {
//prepare
super.clear()
File(workDir).mkdir()
//pull
"adb root".check_call()
"adb push tools/bin/dtc-android /data/vendor/dtc-android".check_call()
val hw = "adb shell getprop ro.hardware".check_output()
log.info("ro.hardware=$hw")
"adb shell /data/vendor/dtc-android -I fs /proc/device-tree -o /data/vendor/file.to.pull".check_call()
"adb pull /data/vendor/file.to.pull $workDir$hw.dts".check_call()
"adb shell /data/vendor/dtc-android -I fs -O dtb /proc/device-tree -o /data/vendor/file.to.pull".check_call()
"adb pull /data/vendor/file.to.pull $hw.dtb".check_call()
"adb shell rm /data/vendor/file.to.pull".check_call()
"adb shell rm /data/vendor/dtc-android".check_call()
if (fileName != "$hw.dtb") {
File(fileName).delete()
log.warn("deleting intermediate dtb file: $fileName")
}
//print summary
val prints: MutableList<Pair<String, String>> = mutableListOf()
prints.add(Pair("source", "/proc/device-tree"))
prints.add(Pair("DTB", "$hw.dtb"))
prints.add(Pair("DTS", "$workDir$hw.dts"))
log.info("\n\t\t\tPull Summary of {}\n{}\n", "$hw.dtb", Common.table2String(prints))
}
fun clear(fileName: String) {
super.clear()
listOf(".new").forEach {
"$fileName$it".deleteIfExists()
}
}
private val log = LoggerFactory.getLogger(DeviceTreeParser::class.java)
private val workDir = Helper.prop("workDir")
}

@ -16,6 +16,7 @@ package cfig.packable
import cfig.utils.SparseImgParser
import org.slf4j.LoggerFactory
import packable.DeviceTreeParser
import java.io.File
import java.util.regex.Pattern
import kotlin.reflect.KClass
@ -30,7 +31,8 @@ fun main(args: Array<String>) {
val packablePool = mutableMapOf<List<String>, KClass<IPackable>>()
listOf(
DtboParser(), VBMetaParser(), BootImgParser(), SparseImgParser(), VendorBootParser(), PayloadBinParser(),
MiscImgParser()
MiscImgParser(),
DeviceTreeParser()
).forEach {
@Suppress("UNCHECKED_CAST")
packablePool.put(it.capabilities(), it::class as KClass<IPackable>)

@ -15,13 +15,10 @@
package cfig.packable
import avb.AVBInfo
import avb.alg.Algorithms
import cfig.Avb
import cfig.helper.CryptoHelper
import cfig.helper.Dumpling
import cfig.helper.Helper
import cfig.helper.Helper.Companion.deleteIfExists
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import org.slf4j.LoggerFactory
import java.io.File

@ -180,6 +180,8 @@ def main():
verifySingleDir(resDir2, "issue_117_xz_crc")
# Issue 122: ramdisk.img, boot image v0
verifySingleDir(resDir2, "issue_122_ramdisk_img")
# Issue 123: dtb
verifySingleDir(resDir2, "issue_123_dtb")
log.info(successLogo)

@ -1 +1 @@
Subproject commit 5fdce9cd65d5b286f8c15fffe3ae142b64e0013a
Subproject commit 517ca7a72425c6b8b913feea0b505f07879549c9

Binary file not shown.
Loading…
Cancel
Save