Skip to content

Commit 38dd70a

Browse files
committed
vendor boot update for abe
1 parent 67cdef2 commit 38dd70a

File tree

7 files changed

+59
-48
lines changed

7 files changed

+59
-48
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,3 @@ https://developers.google.cn/android/images<br/>
362362

363363
</details>
364364

365-
This project is developed with products by Jetbrains.
366-
367-
<a href="https://jb.gg/OpenSource">
368-
<img src="https://user-images.githubusercontent.com/1133314/116802621-c076be80-ab46-11eb-8a14-9454a933de7d.png" alt="drawing" width="80">
369-
</a>

bbootimg/src/main/kotlin/bootimg/v3/VendorBoot.kt

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ data class VendorBoot(
6767
)
6868

6969
data class MiscInfo(
70-
var output: String = "",
70+
var input: String = "",
71+
var role: String = "",
7172
var json: String = "",
7273
var headerVersion: Int = 0,
7374
var product: String = "",
@@ -182,7 +183,8 @@ data class VendorBoot(
182183
val ret = VendorBoot()
183184
FileInputStream(fileName).use { fis ->
184185
val header = VendorBootHeader(fis)
185-
ret.info.output = File(fileName).name
186+
ret.info.input = File(fileName).canonicalPath
187+
ret.info.role = File(fileName).name
186188
ret.info.json = File(fileName).name.removeSuffix(".img") + ".json"
187189
ret.info.headerSize = header.headerSize
188190
ret.info.product = header.product
@@ -192,14 +194,14 @@ data class VendorBoot(
192194
ret.info.pageSize = header.pageSize
193195
ret.info.headerVersion = header.headerVersion
194196
//ramdisk
195-
ret.ramdisk.file = workDir + "ramdisk.img"
197+
ret.ramdisk.file = Helper.joinPath(workDir!!, "ramdisk.img")
196198
ret.ramdisk.size = header.vndRamdiskTotalSize
197199
ret.ramdisk.loadAddr = header.ramdiskLoadAddr
198200
ret.ramdisk.position = Helper.round_to_multiple(
199201
VendorBootHeader.VENDOR_BOOT_IMAGE_HEADER_V3_SIZE, header.pageSize
200202
).toLong()
201203
//dtb
202-
ret.dtb.file = workDir + "dtb"
204+
ret.dtb.file = Helper.joinPath(workDir, "dtb")
203205
ret.dtb.size = header.dtbSize
204206
ret.dtb.loadAddr = header.dtbLoadAddr
205207
ret.dtb.position = ret.ramdisk.position + Helper.round_to_multiple(ret.ramdisk.size, header.pageSize)
@@ -209,10 +211,10 @@ data class VendorBoot(
209211
ret.ramdisk_table.eachEntrySize = header.vrtEntrySize
210212
ret.ramdisk_table.position =
211213
ret.dtb.position + Helper.round_to_multiple(ret.dtb.size, header.pageSize)
212-
FileInputStream(ret.info.output).use {
214+
FileInputStream(ret.info.input).use {
213215
it.skip(ret.ramdisk_table.position)
214216
for (item in 0 until header.vrtEntryNum) {
215-
ret.ramdisk_table.ramdidks.add(VrtEntry(it, workDir + "ramdisk.${item + 1}"))
217+
ret.ramdisk_table.ramdidks.add(VrtEntry(it, Helper.joinPath(workDir, "ramdisk.${item + 1}")))
216218
}
217219
}
218220
ret.ramdisk_table.ramdidks.forEach {
@@ -221,7 +223,7 @@ data class VendorBoot(
221223
}
222224
//bootconfig
223225
if (header.bootconfigSize > 0) {
224-
ret.bootconfig.file = workDir + "bootconfig"
226+
ret.bootconfig.file = Helper.joinPath(workDir, "bootconfig")
225227
ret.bootconfig.size = header.bootconfigSize
226228
ret.bootconfig.position =
227229
ret.ramdisk_table.position + Helper.round_to_multiple(ret.ramdisk_table.size, header.pageSize)
@@ -235,7 +237,7 @@ data class VendorBoot(
235237
fun pack(): VendorBoot {
236238
when (this.info.headerVersion) {
237239
3 -> {
238-
if (File(workDir + this.ramdisk.file).exists() && !File(workDir + "root").exists()) {
240+
if (File(workDir, this.ramdisk.file).exists() && !File(workDir, "root").exists()) {
239241
//do nothing if we have ramdisk.img.gz but no /root
240242
log.warn("Use prebuilt ramdisk file: ${this.ramdisk.file}")
241243
} else {
@@ -251,8 +253,8 @@ data class VendorBoot(
251253
else -> {
252254
this.ramdisk_table.ramdidks.forEachIndexed { index, it ->
253255
File(it.file).deleleIfExists()
254-
log.info(workDir + "root.${index + 1} -> " + it.file)
255-
C.packRootfs(workDir + "root.${index + 1}", it.file, this.ramdisk.xzFlags)
256+
log.info(Helper.joinPath(workDir!!, "/root.${index + 1}") + " -> " + it.file)
257+
C.packRootfs(Helper.joinPath(workDir, "root.${index + 1}"), it.file, this.ramdisk.xzFlags)
256258
}
257259
this.ramdisk.size = this.ramdisk_table.ramdidks.sumOf { File(it.file).length() }.toInt()
258260
}
@@ -263,7 +265,7 @@ data class VendorBoot(
263265
}
264266
this.dtb.size = File(this.dtb.file).length().toInt()
265267
//header
266-
FileOutputStream(this.info.output + ".clear", false).use { fos ->
268+
FileOutputStream(this.info.role + ".clear", false).use { fos ->
267269
val encodedHeader = this.toHeader().encode()
268270
fos.write(encodedHeader)
269271
fos.write(ByteArray(Helper.round_to_multiple(encodedHeader.size, this.info.pageSize) - encodedHeader.size))
@@ -301,34 +303,34 @@ data class VendorBoot(
301303
}
302304
}
303305
//write
304-
FileOutputStream("${this.info.output}.clear", true).use { fos ->
306+
FileOutputStream("${this.info.role}.clear", true).use { fos ->
305307
fos.write(bf.array(), 0, bf.position())
306308
}
307309

308310
//google way
309-
this.toCommandLine().addArgument(this.info.output + ".google").let {
311+
this.toCommandLine().addArgument(this.info.role + ".google").let {
310312
log.info(it.toString())
311313
DefaultExecutor().execute(it)
312314
}
313315

314-
Helper.assertFileEquals(this.info.output + ".clear", this.info.output + ".google")
316+
Helper.assertFileEquals(this.info.role + ".clear", this.info.role + ".google")
315317
return this
316318
}
317319

318320
fun sign(): VendorBoot {
319321
val avbtool = String.format(Helper.prop("avbtool")!!, "v1.2")
320-
File(Avb.getJsonFileName(info.output)).let {
322+
File(Avb.getJsonFileName(info.role)).let {
321323
if (it.exists()) {
322-
Signer.signAVB(info.output, this.info.imageSize, avbtool)
324+
Signer.signAVB(info.role, this.info.imageSize, avbtool)
323325
} else {
324-
log.warn("skip signing of ${info.output}")
326+
log.warn("skip signing of ${info.role}")
325327
}
326328
}
327329
return this
328330
}
329331

330332
fun updateVbmeta(): VendorBoot {
331-
Avb.updateVbmeta(info.output)
333+
Avb.updateVbmeta(info.role)
332334
return this
333335
}
334336

@@ -354,11 +356,11 @@ data class VendorBoot(
354356

355357
fun extractImages(): VendorBoot {
356358
//header
357-
ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(File(workDir + this.info.json), this)
359+
ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(File(workDir, this.info.json), this)
358360
//ramdisk
359361
//@formatter:off
360362
val fmt = C.dumpRamdisk(
361-
Helper.Slice(info.output, ramdisk.position.toInt(), ramdisk.size, ramdisk.file), File(workDir, "root").path,
363+
Helper.Slice(info.input, ramdisk.position.toInt(), ramdisk.size, ramdisk.file), File(workDir, "root").path,
362364
this.ramdisk_table.ramdidks.isEmpty())
363365
//@formatter:on
364366
this.ramdisk.file = this.ramdisk.file + ".$fmt"
@@ -368,7 +370,7 @@ data class VendorBoot(
368370
}
369371
//dtb
370372
run {
371-
C.dumpDtb(Helper.Slice(info.output, dtb.position.toInt(), dtb.size, dtb.file), false)
373+
C.dumpDtb(Helper.Slice(info.input, dtb.position.toInt(), dtb.size, dtb.file), false)
372374
if (dtb.size > 0) {
373375
dtb.dtbList = DTC.parseMultiple(dtb.file)
374376
DTC.extractMultiple(dtb.file, dtb.dtbList)
@@ -378,23 +380,23 @@ data class VendorBoot(
378380
this.ramdisk_table.ramdidks.forEachIndexed { index, it ->
379381
log.info("dumping vendor ramdisk ${index + 1}/${this.ramdisk_table.ramdidks.size} ...")
380382
val s = Helper.Slice(ramdisk.file, it.offset, it.size, it.file)
381-
C.dumpRamdisk(s, workDir + "root.${index + 1}")
383+
C.dumpRamdisk(s, File(workDir, "root.${index + 1}").toString())
382384
it.file = it.file + ".$fmt"
383385
}
384386
//bootconfig
385387
if (bootconfig.size > 0) {
386-
Helper.Slice(info.output, bootconfig.position.toInt(), bootconfig.size, bootconfig.file).let { s ->
388+
Helper.Slice(info.input, bootconfig.position.toInt(), bootconfig.size, bootconfig.file).let { s ->
387389
Helper.extractFile(s.srcFile, s.dumpFile, s.offset.toLong(), s.length)
388390
}
389391
}
390392
//dump info again
391-
ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(File(workDir + this.info.json), this)
393+
ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(File(File(workDir, this.info.json).toString()), this)
392394
return this
393395
}
394396

395397
fun extractVBMeta(): VendorBoot {
396398
try {
397-
AVBInfo.parseFrom(Dumpling(info.output)).dumpDefault(info.output)
399+
AVBInfo.parseFrom(Dumpling(info.input)).dumpDefault(info.role)
398400
} catch (e: Exception) {
399401
log.error("extraceVBMeta(): $e")
400402
}
@@ -414,8 +416,9 @@ data class VendorBoot(
414416
}
415417
val tab = AsciiTable().let {
416418
it.addRule()
417-
it.addRow("image info", workDir + info.output.removeSuffix(".img") + ".json")
418-
prints.add(Pair("image info", workDir + info.output.removeSuffix(".img") + ".json"))
419+
val imageInfoJsonFile = Helper.joinPath(workDir!!, info.role.removeSuffix(".img"), ".json")
420+
it.addRow("image info", imageInfoJsonFile)
421+
prints.add(Pair("image info", imageInfoJsonFile))
419422
it.addRule()
420423
it.addRow("ramdisk", this.ramdisk.file)
421424
prints.add(Pair("ramdisk", this.ramdisk.file))
@@ -452,7 +455,7 @@ data class VendorBoot(
452455
prints.add(Pair("bootconfig", this.bootconfig.file))
453456
}
454457
it.addRule()
455-
Avb.getJsonFileName(info.output).let { jsonFile ->
458+
Avb.getJsonFileName(info.role).let { jsonFile ->
456459
if (File(jsonFile).exists()) {
457460
it.addRow("AVB info", jsonFile)
458461
prints.add(Pair("AVB info", jsonFile))
@@ -483,14 +486,14 @@ data class VendorBoot(
483486
log.info("\n" + Common.table2String(prints))
484487
} else {
485488
//@formatter:off
486-
log.info("\n\t\t\tUnpack Summary of ${info.output}\n{}\n{}{}", tableHeader.render(), tab.render(), tabVBMeta)
489+
log.info("\n\t\t\tUnpack Summary of ${info.role}\n{}\n{}{}", tableHeader.render(), tab.render(), tabVBMeta)
487490
//@formatter:on
488491
}
489492
return this
490493
}
491494

492495
fun printPackSummary(): VendorBoot {
493-
Common.printPackSummary(info.output)
496+
Common.printPackSummary(info.role)
494497
return this
495498
}
496499

bbootimg/src/main/kotlin/packable/BootImgParser.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class BootImgParser : IPackable {
143143
packInternal(fileName, outDir, fileName)
144144
}
145145

146-
override fun flash(fileName: String, deviceName: String) {
146+
fun flash(fileName: String) {
147147
val stem = fileName.substring(0, fileName.indexOf("."))
148148
super.flash("$fileName.signed", stem)
149149

@@ -175,8 +175,8 @@ class BootImgParser : IPackable {
175175
super.`@verify`(fileName)
176176
}
177177

178-
override fun pull(fileName: String, deviceName: String) {
179-
super.pull(fileName, deviceName)
178+
fun pull(fileName: String) {
179+
super.pull(fileName, File(fileName).nameWithoutExtension)
180180
try {
181181
super.pull("vbmeta.img", "vbmeta")
182182
} catch (e: Exception) {

bbootimg/src/main/kotlin/packable/VBMetaParser.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class VBMetaParser : IPackable {
6060
super.`@verify`(fileName)
6161
}
6262

63-
override fun pull(fileName: String, deviceName: String) {
64-
super.pull(fileName, deviceName)
63+
fun pull(fileName: String) {
64+
super.pull(fileName, File(fileName).nameWithoutExtension)
6565
}
6666

6767
fun clear(fileName: String) {

bbootimg/src/main/kotlin/packable/VendorBootParser.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package cfig.packable
1616

1717
import cfig.bootimg.v3.VendorBoot
18+
import cfig.helper.Helper
1819
import com.fasterxml.jackson.databind.ObjectMapper
1920
import org.slf4j.LoggerFactory
2021
import java.io.File
@@ -38,6 +39,18 @@ class VendorBootParser : IPackable {
3839
log.debug(vb.toString())
3940
}
4041

42+
fun unpackInternal(targetFile: String, fileName: String, unpackDir: String) {
43+
log.info("unpackInternal(fileName: $fileName, unpackDir: $unpackDir)")
44+
Helper.setProp("workDir", unpackDir)
45+
clear()
46+
val vb = VendorBoot
47+
.parse(fileName)
48+
.extractImages()
49+
.extractVBMeta()
50+
.printUnpackSummary()
51+
log.debug(vb.toString())
52+
}
53+
4154
override fun pack(fileName: String) {
4255
val cfgFile = "$outDir/${fileName.removeSuffix(".img")}.json"
4356
log.info("Loading config from $cfgFile")
@@ -52,8 +65,8 @@ class VendorBootParser : IPackable {
5265
super.`@verify`(fileName)
5366
}
5467

55-
override fun pull(fileName: String, deviceName: String) {
56-
super.pull(fileName, deviceName)
68+
fun pull(fileName: String) {
69+
super.pull(fileName, File(fileName).nameWithoutExtension)
5770
super.pull("vbmeta.img", "vbmeta")
5871
}
5972

@@ -65,7 +78,7 @@ class VendorBootParser : IPackable {
6578
VBMetaParser().clear("vbmeta.img")
6679
}
6780

68-
override fun flash(fileName: String, deviceName: String) {
81+
fun flash(fileName: String) {
6982
val stem = fileName.substring(0, fileName.indexOf("."))
7083
super.flash("$fileName.signed", stem)
7184

lazybox/tools/lazybox

1.88 KB
Binary file not shown.

tools/factory_image_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"system_ext.img",
3333
"system.img",
3434
"system_other.img",
35-
"userdata.img",
3635
"vbmeta.img",
3736
"vbmeta_system.img",
3837
"vbmeta_vendor.img",
@@ -43,20 +42,21 @@
4342
]
4443

4544
unknown_list = [
46-
"cmnlib.img", #Pixel3
4745
"abl.img", #Pixel3
4846
"aop.img", #Pixel3
4947
"cmnlib64.img", #Pixel3
48+
"cmnlib.img", #Pixel3
5049
"devcfg.img", #Pixel3
5150
"hyp.img", #Pixel3
5251
"keymaster.img", #Pixel3
5352
"modem.img", #Pixel3
53+
"pvmfw.img", #Pixel7
5454
"qupfw.img", #Pixel3
55+
"super_empty.img",
5556
"tz.img", #Pixel3
56-
"xbl.img", #Pixel3
57+
"userdata.img",
5758
"xbl_config.img", #Pixel3
58-
"pvmfw.img", #Pixel7
59-
"super_empty.img"
59+
"xbl.img", #Pixel3
6060
]
6161

6262
tmp2 = "tmp2"

0 commit comments

Comments
 (0)