Skip to content

Commit

Permalink
Issue #109: support vendor_boot.img w/o dtb
Browse files Browse the repository at this point in the history
Now for boot V4, dtb may be in vendor_boot or vendor_kernel_boot.
Google Change:
https://android.googlesource.com/platform/system/tools/mkbootimg/+/053c389f03f3c14f86b808608ccb5669ff8b887a
  • Loading branch information
cfig committed Jan 15, 2023
1 parent 130789c commit de69dbf
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 24 deletions.
3 changes: 3 additions & 0 deletions bbootimg/src/main/kotlin/avb/Avb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ class Avb {
}
}

/**
* verify the AVBInfo of [ai], the raw data is boxed into [dp].
*/
fun verify(ai: AVBInfo, dp: Dumpling<*>, parent: String = ""): Array<Any> {
val ret: Array<Any> = arrayOf(true, "")
val localParent = parent.ifEmpty { dp.getLabel() }
Expand Down
34 changes: 24 additions & 10 deletions bbootimg/src/main/kotlin/bootimg/v3/VendorBoot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,15 @@ data class VendorBoot(
else -> {
ByteBuffer.allocate(1024 * 1024 * 128).let {
it.order(ByteOrder.LITTLE_ENDIAN)
//1. vendor ramdisks and dtb
//1. vendor ramdisks
C.writePaddedFiles(it, this.ramdisk_table.ramdidks.map { rd -> rd.file }, this.info.pageSize)
C.writePaddedFile(it, this.dtb.file, this.info.pageSize)
//2. vrt
//2. dtb
if (this.dtb.size > 0) {
C.writePaddedFile(it, this.dtb.file, this.info.pageSize)
}
//3. vrt
it.put(this.ramdisk_table.update().encode(this.info.pageSize))
//3. bootconfig
//4. bootconfig
if (this.bootconfig.file.isNotBlank()) {
C.writePaddedFile(it, this.bootconfig.file, this.info.pageSize)
}
Expand Down Expand Up @@ -394,19 +397,26 @@ data class VendorBoot(
it.addRow("-- ${entry.type} ramdisk[${index + 1}/${this.ramdisk_table.ramdidks.size}]", entry.file)
it.addRow("------- extracted rootfs", "${workDir}root.${index + 1}")
//basic ascii
//@formatter:off
prints.add(Pair(" -- ${entry.type} ramdisk[${index + 1}/${this.ramdisk_table.ramdidks.size}]", entry.file))
//@formatter:on
prints.add(Pair(" ------- extracted rootfs", "${workDir}root.${index + 1}"))
}
} else {
it.addRow("\\-- extracted ramdisk rootfs", "${workDir}root")
prints.add(Pair("\\-- extracted ramdisk rootfs", "${workDir}root"))
}
it.addRule()
it.addRow("dtb", this.dtb.file)
prints.add(Pair("dtb", this.dtb.file))
if (File(this.dtb.file + ".${dtsSuffix}").exists()) {
it.addRow("\\-- decompiled dts", dtb.file + ".${dtsSuffix}")
prints.add(Pair("\\-- decompiled dts", dtb.file + ".${dtsSuffix}"))
if (this.dtb.size > 0) {
it.addRow("dtb", this.dtb.file)
prints.add(Pair("dtb", this.dtb.file))
if (File(this.dtb.file + ".${dtsSuffix}").exists()) {
it.addRow("\\-- decompiled dts", dtb.file + ".${dtsSuffix}")
prints.add(Pair("\\-- decompiled dts", dtb.file + ".${dtsSuffix}"))
}
} else {
it.addRow("dtb", "-")
prints.add(Pair("dtb", "-"))
}
if (this.bootconfig.size > 0) {
it.addRule()
Expand Down Expand Up @@ -444,7 +454,9 @@ data class VendorBoot(
if (EnvironmentVerifier().isWindows) {
log.info("\n" + Common.table2String(prints))
} else {
//@formatter:off
log.info("\n\t\t\tUnpack Summary of ${info.output}\n{}\n{}{}", tableHeader.render(), tab.render(), tabVBMeta)
//@formatter:on
}
return this
}
Expand Down Expand Up @@ -485,7 +497,9 @@ data class VendorBoot(
if (info.product.isNotBlank()) {
addArgument("--board").addArgument(info.product)
}
addArgument("--dtb").addArgument(dtb.file)
if (dtb.size > 0) {
addArgument("--dtb").addArgument(dtb.file)
}
addArgument("--vendor_cmdline").addArgument(info.cmdline, false)
addArgument("--header_version").addArgument(info.headerVersion.toString())
addArgument("--base").addArgument("0")
Expand Down
13 changes: 13 additions & 0 deletions bbootimg/src/main/resources/known_keys.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,18 @@
"algorithm" : "SHA256_RSA2048",
"pubk" : "AAAIAN3C1onuaVOoEOIIpxRB4slj0xuKT7t2yrvDzvHQhOAlM8vz+rnR//6imJ+ET07/dMvAE893FM5LnFQLNcUJ+FYIGjbYdzFCVSYErfVTq96e37/sxVT86Zuz392q8OBkY4UFzpNdwwzWq6J+0tAsEyu778ECITiPceTJgol7IxzjIljHccK3ffP9dQf1FziB6BBTOQBKj26J2KCqtSmXM3Kk4GeV0wdCMZUUcuWXGrt0UjmrD+xHa8jSj9+YRb7BWe+RfYCXtqrAaree/Q24GAm4nSznDjfSH4T50JiNBkaeOf9YZwQlh67JtFZbueUP5prlQ3eXmubddodnA0LdDkOJooBHvMZAM/73+AWtsf145vMRUdtuvj5Dp9shR+kHaBoB78kQ2vUcrT7eetQynrH1TtwpXzXqAfzHRfv1tw2icvPnjFYV7m3njNcrb05Bx/oMvqKzrx99kCZEWuVm8un3gC/ucW9cXkAB+onTQnfJbeS5XcbEPcZkuQ0b7BepCScYnMrlOMSClYYl8OPNK576YRa2KQxdWEbdukihNIhaZhBN/tqdszA2w2960rO70ektljBVPP6m2jcT5iV0spMiers5KtqZ8cy++Urhvg0mWiuPcnue4L7W59lf9bJVlkaFrBfOHvxMdgmmrHCgZd9278zJrYDgFK17kojwSqqqwCkoFQ==",
"sha1" : "b2a02f1e56e366d727a1a8e089762fe0b91bbc84"
},
{
"device" : "Pixel 7 Pro",
"manufacturer" : "Google",
"algorithm" : "SHA256_RSA4096",
"pubk" : "AAAQAEnai4emBts8xKHH5hbkA/kKbIf+BAdgbGeWPJGs/c9M/q7jBvp0iN2yER93RWPM3sgCb0NVpwgAhB0kaKRNm9TtbA0CdzB/k+wCO38/sr24t+eBTCka0bwgxwUD0TGYNS5tZLB595jnRsM/zMxp6J5aus+pyqF8wDejJH3WCjIy2aQ3yM6xn+8qJGL+mRrpgtTG6q3rjWupuldAsS5X1ACPnekK7glTL3rOXE32wqCeDH3fVpUSZDoZB9vo/qoj29nU3EwCnGWybRfYo1KPua4IaKDcUnOhxe4APHKzwzN8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/Di2KcVugDUOGblb6X4XNR++ZTnZiBw6IbY85eL2YddPJg4ZH1zNIWa9rRuv9q6VWX1XD5+J92bd34EPuMLrmGvXgYpbfzfuqqLGpPBvbqoRfdgHe7CSe0xa3lDePOTll8sDsKKnr8jOW9CvsbS1s6+x8Nie2UFPwsb/LvfmhhsRTmlZaESRltCOjdZ+XbnSaCw7of/4oQfjk3gLiFNlH6uHDOTdi/QuFsGselWCi8I3NsMf57+1FXiQZsXbR59D+uooDC+J75IDlp2/fkBOVsyTEXe3C4gznsbvoN9GjzkAEo7uti2hjTwhaXHTQ2o3T6XpEBQzj"
}
]

30 changes: 16 additions & 14 deletions doc/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,29 @@ Value at 0x28 is one of {0x00,0x01,0x02,0x03,0x04}, this filed should be read fi

## 2. boot.img v3-v4

For partitions: `/boot` and `/init_boot`.
For partitions: `/boot`, `/init_boot` or `/recovery`.

### header

item size in bytes position
+-----------------------------------------------------------+ --> 0
|<MAGIC HEADER> | 8 (value=ANDROID!) |
|<MAGIC HEADER> | 8 (value=ANDROID!) |
|--------------------------------+--------------------------| --> 8
|<kernel size> | 4 |
|<kernel size> | 4 |
|--------------------------------+--------------------------| --> 12
|<ramdisk size> | 4 |
|<ramdisk size> | 4 |
|--------------------------------+--------------------------| --> 16
|<os version & os patch level> | 4 |
|<os version & os patch level> | 4 |
|--------------------------------+--------------------------| --> 20
|<header size> | 4 |
|<header size> | 4 |
|--------------------------------+--------------------------| --> 24
|<reserved> | 4 * 4 |
|<reserved> | 4 * 4 |
|--------------------------------+--------------------------| --> 40 (0x28)
|<header version> | 4 (value in [3|4]) |
|<header version> | 4 (value in [3|4]) |
|--------------------------------+--------------------------| --> 44
|<cmdline> | 1024+512=1536 |
|<cmdline> | 1024+512=1536 |
|--------------------------------+--------------------------| --> 1580
|<signature_size> (v4 only) | 4 |
|<signature_size> (v4 only) | 4 (values in [4096|0]) |
|--------------------------------+--------------------------| --> 1584
|<padding> | min(n * page_size |
| | - header_size) |
Expand All @@ -131,17 +131,19 @@ For partitions: `/boot` and `/init_boot`.

+-----------------------------------------------------------+ --> pagesize
|<kernel> | kernel length |
+-----------------------------------------------------------+
+-----------------------------------------------------------+ --> + kernel len
|<ramdisk> | ramdisk length |
+-----------------------------------------------------------+
+-----------------------------------------------------------+ --> + ramdisk len
|<boot signature> (v4 only) | boot signature length |
+--------------------------------+--------------------------+
| | GKI 1.0 : 4K |
| | GKI 2.0 : 16K |
+--------------------------------+--------------------------+ --> + boot sig len
|<padding> | min(n * page_size - len) |
+-----------------------------------------------------------+

## 3. vendor\_boot.img v3-v4

For partitions: `/vendor_boot`.
For partitions: `/vendor_boot` or `/vendor_kernel_boot`.

### header

Expand Down
6 changes: 6 additions & 0 deletions helper/src/main/kotlin/cfig/helper/Dumpling.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import java.io.File
import java.io.FileInputStream
import java.io.InputStream

/**
* Dumpling: Boxed type of data sources, which is the [filling] of the dumpling.
* Constructor:
* [filling] can be of type String (file name) or ByteArray
* [label] optional name of the Dumpling
*/
class Dumpling<in T>(private val filling: T, private val label: String? = null) {
fun getLabel(): String {
return label ?: getName()
Expand Down

0 comments on commit de69dbf

Please sign in to comment.