14
14
15
15
package cfig.packable
16
16
17
- import avb.blob.Footer
18
- import cfig.utils.EnvironmentVerifier
19
- import cfig.utils.DTC
20
17
import cfig.helper.Helper
18
+ import cfig.utils.DTC
19
+ import cfig.utils.EnvironmentVerifier
21
20
import com.fasterxml.jackson.databind.ObjectMapper
22
21
import org.apache.commons.exec.CommandLine
23
22
import org.apache.commons.exec.DefaultExecutor
24
23
import org.slf4j.LoggerFactory
24
+ import utils.Dtbo
25
25
import java.io.File
26
26
import java.io.FileInputStream
27
27
import java.util.*
@@ -34,7 +34,6 @@ class DtboParser(val workDir: File) : IPackable {
34
34
35
35
private val log = LoggerFactory .getLogger(DtboParser ::class .java)
36
36
private val envv = EnvironmentVerifier ()
37
- private val outDir = Helper .prop(" workDir" )
38
37
private val dtboMaker = Helper .prop(" dtboMaker" )
39
38
40
39
override fun capabilities (): List <String > {
@@ -43,32 +42,39 @@ class DtboParser(val workDir: File) : IPackable {
43
42
44
43
override fun unpack (fileName : String ) {
45
44
cleanUp()
46
- val dtbPath = File (" $outDir /dtb" ).path
47
- val headerPath = File (" $outDir /dtbo.header" ).path
48
- val cmdPrefix = if (EnvironmentVerifier ().isWindows) " python " else " "
49
- val cmd = CommandLine .parse(" $cmdPrefix$dtboMaker dump $fileName " ).let {
50
- it.addArguments(" --dtb $dtbPath " )
51
- it.addArguments(" --output $headerPath " )
52
- }
53
- execInDirectory(cmd, this .workDir)
45
+ Dtbo .parse(fileName)
46
+ .unpack(outDir)
47
+ .extractVBMeta()
48
+ .printSummary()
49
+ }
54
50
55
- val props = Properties ().apply {
56
- FileInputStream (File (headerPath)).use { fis ->
57
- load(fis)
58
- }
59
- }
60
- if (envv.hasDtc) {
61
- for (i in 0 until Integer .parseInt(props.getProperty(" dt_entry_count" ))) {
62
- val inputDtb = " $dtbPath .$i "
63
- val outputSrc = File (outDir + " /" + File (inputDtb).name + " .src" ).path
64
- DTC ().decompile(inputDtb, outputSrc)
51
+ override fun pack (fileName : String ) {
52
+ ObjectMapper ().readValue(File (outDir + " dtbo.json" ), Dtbo ::class .java)
53
+ .pack()
54
+ .sign()
55
+ .updateVbmeta()
56
+ .printPackSummary()
57
+ }
58
+
59
+ override fun `@verify` (fileName : String ) {
60
+ super .`@verify`(fileName)
61
+ }
62
+
63
+ private fun execInDirectory (cmd : CommandLine , inWorkDir : File ) {
64
+ DefaultExecutor ().let {
65
+ it.workingDirectory = inWorkDir
66
+ try {
67
+ log.info(cmd.toString())
68
+ it.execute(cmd)
69
+ } catch (e: org.apache.commons.exec.ExecuteException ) {
70
+ log.error(" can not exec command" )
71
+ return
65
72
}
66
- } else {
67
- log.error(" 'dtc' is unavailable, task aborted" )
68
73
}
69
74
}
70
75
71
- override fun pack (fileName : String ) {
76
+ @Deprecated(" for debugging purpose only" )
77
+ fun packLegacy (fileName : String ) {
72
78
if (! envv.hasDtc) {
73
79
log.error(" 'dtc' is unavailable, task aborted" )
74
80
return
@@ -91,33 +97,31 @@ class DtboParser(val workDir: File) : IPackable {
91
97
execInDirectory(cmd, this .workDir)
92
98
}
93
99
94
- override fun `@verify` (fileName : String ) {
95
- super .`@verify`(fileName)
96
- }
100
+ @Deprecated(" for debugging purpose only" )
101
+ fun unpackLegacy (fileName : String ) {
102
+ cleanUp()
103
+ val dtbPath = File (" $outDir /dtb" ).path
104
+ val headerPath = File (" $outDir /dtbo.header" ).path
105
+ val cmdPrefix = if (EnvironmentVerifier ().isWindows) " python " else " "
106
+ val cmd = CommandLine .parse(" $cmdPrefix$dtboMaker dump $fileName " ).let {
107
+ it.addArguments(" --dtb $dtbPath " )
108
+ it.addArguments(" --output $headerPath " )
109
+ }
110
+ execInDirectory(cmd, this .workDir)
97
111
98
- // invoked solely by reflection
99
- fun `@footer` (fileName : String ) {
100
- FileInputStream (fileName).use { fis ->
101
- fis.skip(File (fileName).length() - Footer .SIZE )
102
- try {
103
- val footer = Footer (fis)
104
- log.info(" \n " + ObjectMapper ().writerWithDefaultPrettyPrinter().writeValueAsString(footer))
105
- } catch (e: IllegalArgumentException ) {
106
- log.info(" image $fileName has no AVB Footer" )
112
+ val props = Properties ().apply {
113
+ FileInputStream (File (headerPath)).use { fis ->
114
+ load(fis)
107
115
}
108
116
}
109
- }
110
-
111
- private fun execInDirectory (cmd : CommandLine , inWorkDir : File ) {
112
- DefaultExecutor ().let {
113
- it.workingDirectory = inWorkDir
114
- try {
115
- log.info(cmd.toString())
116
- it.execute(cmd)
117
- } catch (e: org.apache.commons.exec.ExecuteException ) {
118
- log.error(" can not exec command" )
119
- return
117
+ if (envv.hasDtc) {
118
+ for (i in 0 until Integer .parseInt(props.getProperty(" dt_entry_count" ))) {
119
+ val inputDtb = " $dtbPath .$i "
120
+ val outputSrc = File (outDir + " /" + File (inputDtb).name + " .src" ).path
121
+ DTC ().decompile(inputDtb, outputSrc)
120
122
}
123
+ } else {
124
+ log.error(" 'dtc' is unavailable, task aborted" )
121
125
}
122
126
}
123
127
}
0 commit comments