@@ -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\t Unpack Summary of ${info.output } \n {}\n {}{}" , tableHeader.render(), tab.render(), tabVBMeta)
489+ log.info(" \n\t\t\t Unpack 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
0 commit comments