Skip to content

Commit

Permalink
Issue #135: check bzcat/xzcat when unpacking payload.bin
Browse files Browse the repository at this point in the history
also: support "-Dpart=XXX" in release package
  • Loading branch information
cfig committed Jan 17, 2024
1 parent bdab70b commit 374aab8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
4 changes: 4 additions & 0 deletions bbootimg/src/main/kotlin/ota/Payload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import cc.cfig.io.Struct
import cfig.helper.CryptoHelper.Hasher
import cfig.helper.Dumpling
import cfig.helper.Helper
import cfig.utils.EnvironmentVerifier
import chromeos_update_engine.UpdateMetadata
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
Expand Down Expand Up @@ -45,6 +46,7 @@ class Payload {
companion object {
private val log = LoggerFactory.getLogger(Payload::class.java)
val workDir = Helper.prop("payloadDir")
val envv = EnvironmentVerifier()

fun parse(inFileName: String): Payload {
val ret = Payload()
Expand Down Expand Up @@ -172,6 +174,8 @@ class Payload {
}

private fun decompress(inBytes: ByteArray, opType: UpdateMetadata.InstallOperation.Type): ByteArray {
check(envv.hasXzcat) { "xzcat not found" }
check(envv.hasBzcat) { "bzcat not found" }
val baosO = ByteArrayOutputStream()
val baosE = ByteArrayOutputStream()
val bais = ByteArrayInputStream(inBytes)
Expand Down
28 changes: 28 additions & 0 deletions bbootimg/src/main/kotlin/utils/EnvironmentVerifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ class EnvironmentVerifier {
return true
}

val hasXzcat: Boolean
get(): Boolean {
var ret = false
try {
val process = Runtime.getRuntime().exec(arrayOf("xzcat", "-V"), null, null)
log.debug("xzcat available")
val exitCode = process.waitFor()
ret = (exitCode == 0 && process.exitValue() == 0)
} catch (e: Exception) {
log.warn("xzcat unavailable")
}
return ret
}

val hasBzcat: Boolean
get(): Boolean {
var ret = false
try {
val process = Runtime.getRuntime().exec(arrayOf("bzcat", "-V"), null, null)
log.debug("bzcat available")
val exitCode = process.waitFor()
ret = (exitCode == 0 && process.exitValue() == 0)
} catch (e: Exception) {
log.warn("bzcat unavailable")
}
return ret
}

val has7z: Boolean
get(): Boolean {
try {
Expand Down
20 changes: 17 additions & 3 deletions bbootimg/src/test/kotlin/EnvironmentVerifierTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,40 @@

import cfig.utils.EnvironmentVerifier
import org.junit.Test
import org.slf4j.LoggerFactory

class EnvironmentVerifierTest {
private val envv = EnvironmentVerifier()
private val log = LoggerFactory.getLogger(EnvironmentVerifier::class.java)

@Test
fun getHasDtc() {
val hasDtc = envv.hasDtc
println("hasDtc = $hasDtc")
log.info("hasDtc = $hasDtc")

}

@Test
fun getHasXz() {
val hasXz = envv.hasXz
println("hasXz = $hasXz")
log.info("hasXz = $hasXz")
}

@Test
fun getGzip() {
val h = envv.hasGzip
println("hasGzip = $h")
log.info("hasGzip = $h")
}

@Test
fun getXzcat() {
val h = envv.hasXzcat
log.info("hasXzcat = $h")
}

@Test
fun getBzcat() {
val h = envv.hasBzcat
log.info("hasBzcat = $h")
}
}
12 changes: 9 additions & 3 deletions tools/release.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#
# release.mk
# yu, 2020-12-20 00:19
# yuyezhong@gmail.com, 2020-12-20 00:19
#
define gw
#!/usr/bin/env sh\n
#!/usr/bin/bash\n
if [ "x$$1" = "xassemble" ]; then\n
echo "already assembled"\n
exit\n
Expand All @@ -16,7 +16,13 @@ if [ "x$$1" = "xclean" ]; then\n
echo "no cleaning is needed"\n
exit 0\n
fi\n
java -jar bbootimg/bbootimg.jar $$*
if [[ "$$2" == "-Dpart="* ]]; then\n
set -x\n
java $$2 -jar bbootimg/bbootimg.jar $$1\n
else\n
set -x\n
java -jar bbootimg/bbootimg.jar $$*\n
fi

endef

Expand Down

0 comments on commit 374aab8

Please sign in to comment.