add 'flash' task for vbmeta/boot
parent
1bcf9389a0
commit
b8aba9992e
@ -1,12 +1,33 @@
|
|||||||
package cfig.packable
|
package cfig.packable
|
||||||
|
|
||||||
|
import cfig.Helper.Companion.check_call
|
||||||
|
import cfig.Helper.Companion.check_output
|
||||||
|
import org.slf4j.Logger
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
interface IPackable {
|
interface IPackable {
|
||||||
fun capabilities(): List<String> {
|
fun capabilities(): List<String> {
|
||||||
return listOf("^dtbo\\.img$")
|
return listOf("^dtbo\\.img$")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unpack(fileName: String = "dtbo.img")
|
fun unpack(fileName: String = "dtbo.img")
|
||||||
fun pack(fileName: String = "dtbo.img")
|
fun pack(fileName: String = "dtbo.img")
|
||||||
fun flash(fileName: String = "dtbo.img") {
|
fun flash(fileName: String = "dtbo.img", deviceName: String = "dtbo") {
|
||||||
|
"adb root".check_call()
|
||||||
|
val abUpdateProp = "adb shell getprop ro.build.ab_update".check_output()
|
||||||
|
log.info("ro.build.ab_update=$abUpdateProp")
|
||||||
|
val slotSuffix = if (abUpdateProp == "true") {
|
||||||
|
"adb shell getprop ro.boot.slot_suffix".check_output()
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
log.info("slot suffix = $slotSuffix")
|
||||||
|
"adb push $fileName /cache/file.to.burn".check_call()
|
||||||
|
"adb shell dd if=/cache/file.to.burn of=/dev/block/by-name/$deviceName$slotSuffix".check_call()
|
||||||
|
"adb shell rm /cache/file.to.burn".check_call()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val log: Logger = LoggerFactory.getLogger(IPackable::class.java)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,167 +0,0 @@
|
|||||||
apply plugin: "java"
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath "org.apache.commons:commons-exec:1.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
subprojects {
|
|
||||||
tasks.withType(JavaCompile) {
|
|
||||||
//options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// global
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
import java.util.regex.Matcher
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
import org.apache.commons.exec.CommandLine
|
|
||||||
import org.apache.commons.exec.DefaultExecutor
|
|
||||||
import org.apache.commons.exec.PumpStreamHandler
|
|
||||||
|
|
||||||
if (parseGradleVersion(gradle.gradleVersion) < 5) {
|
|
||||||
logger.error("ERROR: Gradle Version MUST >= 5.0, current is {}", gradle.gradleVersion)
|
|
||||||
throw new RuntimeException("ERROR: Gradle Version")
|
|
||||||
} else {
|
|
||||||
logger.info("Gradle Version {}", gradle.gradleVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
def GROUP_ANDROID = "Android"
|
|
||||||
project.ext.bootSigner = new File("boot_signer/build/libs/boot_signer.jar").getAbsolutePath()
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// tasks
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
task _setup(type: Copy) {
|
|
||||||
group GROUP_ANDROID
|
|
||||||
from 'src/test/resources/boot.img'
|
|
||||||
into '.'
|
|
||||||
}
|
|
||||||
|
|
||||||
task pull() {
|
|
||||||
group GROUP_ANDROID
|
|
||||||
doFirst {
|
|
||||||
println("Pulling ...")
|
|
||||||
}
|
|
||||||
|
|
||||||
doLast {
|
|
||||||
String avb_version = adbCmd("getprop ro.boot.avb_version2")
|
|
||||||
Boolean isAvbEnabled = false
|
|
||||||
if (avb_version.isEmpty()) {
|
|
||||||
isAvbEnabled = true
|
|
||||||
}
|
|
||||||
println("AVB: $isAvbEnabled")
|
|
||||||
if (project.findProperty("group")) {
|
|
||||||
println("Pull: $group")
|
|
||||||
} else {
|
|
||||||
println("Pull /boot, /recovery, /vbmeta")
|
|
||||||
pullDefault(isAvbEnabled)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pullDefault(Boolean avb = true) {
|
|
||||||
Run(["adb", "shell", "dd if=/dev/block/by-name/boot of=/cache/boot.img"])
|
|
||||||
Run(["adb", "shell", "dd if=/dev/block/by-name/recovery of=/cache/recovery.img"])
|
|
||||||
if (avb) Run(["adb", "shell", "dd if=/dev/block/by-name/vbmeta of=/cache/vbmeta.img"])
|
|
||||||
|
|
||||||
Run(["adb", "pull", "/cache/boot.img"])
|
|
||||||
Run(["adb", "pull", "/cache/recovery.img"])
|
|
||||||
if (avb) Run(["adb", "pull", "/cache/vbmeta.img"])
|
|
||||||
|
|
||||||
Run(["adb", "shell", "rm /cache/boot.img"])
|
|
||||||
Run(["adb", "shell", "rm /cache/recovery.img"])
|
|
||||||
if (avb) Run(["adb", "shell", "rm /cache/vbmeta.img"])
|
|
||||||
}
|
|
||||||
|
|
||||||
void Run(List<String> inCmd, String inWorkdir = null) {
|
|
||||||
println("CMD:" + inCmd)
|
|
||||||
if (inWorkdir == null) {
|
|
||||||
inWorkdir = ".";
|
|
||||||
}
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(inCmd)
|
|
||||||
.directory(new File(inWorkdir))
|
|
||||||
.redirectErrorStream(true);
|
|
||||||
Process p = pb.start()
|
|
||||||
p.inputStream.eachLine { println it }
|
|
||||||
p.waitFor();
|
|
||||||
assert 0 == p.exitValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
void Run(String inCmd, String inWorkdir = null) {
|
|
||||||
Run(Arrays.asList(inCmd.split()), inWorkdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
void rebootRecovery() {
|
|
||||||
Run("adb reboot recovery")
|
|
||||||
}
|
|
||||||
|
|
||||||
task rr {
|
|
||||||
group GROUP_ANDROID
|
|
||||||
doLast {
|
|
||||||
rebootRecovery()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task unpack(type: JavaExec, dependsOn: ["bbootimg:jar"]) {
|
|
||||||
group GROUP_ANDROID
|
|
||||||
main = "cfig.packable.PackableLauncherKt"
|
|
||||||
classpath = files("bbootimg/build/libs/bbootimg.jar")
|
|
||||||
maxHeapSize '512m'
|
|
||||||
args "unpack"
|
|
||||||
}
|
|
||||||
|
|
||||||
task pack(type: JavaExec, dependsOn: ["bbootimg:jar", "aosp:boot_signer:build"]) {
|
|
||||||
group GROUP_ANDROID
|
|
||||||
main = "cfig.packable.PackableLauncherKt"
|
|
||||||
classpath = files("bbootimg/build/libs/bbootimg.jar")
|
|
||||||
maxHeapSize '512m'
|
|
||||||
args "pack"
|
|
||||||
}
|
|
||||||
|
|
||||||
task flash(type: JavaExec, dependsOn: ["bbootimg:jar"]) {
|
|
||||||
group GROUP_ANDROID
|
|
||||||
main = "cfig.packable.PackableLauncherKt"
|
|
||||||
classpath = files("bbootimg/build/libs/bbootimg.jar")
|
|
||||||
maxHeapSize '512m'
|
|
||||||
args "flash"
|
|
||||||
}
|
|
||||||
|
|
||||||
//sparse image dependencies
|
|
||||||
if (System.getProperty("os.name").contains("Mac")) {
|
|
||||||
unpack.dependsOn("aosp:libsparse:simg2img:installReleaseMacos")
|
|
||||||
pack.dependsOn("aosp:libsparse:img2simg:installReleaseMacos")
|
|
||||||
pack.dependsOn("aosp:mkbootfs:installReleaseMacos")
|
|
||||||
} else {
|
|
||||||
unpack.dependsOn("aosp:libsparse:simg2img:installReleaseLinux")
|
|
||||||
pack.dependsOn("aosp:libsparse:img2simg:installReleaseLinux")
|
|
||||||
pack.dependsOn("aosp:mkbootfs:installReleaseLinux")
|
|
||||||
}
|
|
||||||
|
|
||||||
int parseGradleVersion(String version) {
|
|
||||||
Pattern VERSION_PATTERN = Pattern.compile("((\\d+)(\\.\\d+)+)(-(\\p{Alpha}+)-(\\w+))?(-(SNAPSHOT|\\d{14}([-+]\\d{4})?))?")
|
|
||||||
Matcher matcher = VERSION_PATTERN.matcher(version)
|
|
||||||
if (!matcher.matches()) {
|
|
||||||
throw new IllegalArgumentException(format("'%s' is not a valid Gradle version string (examples: '1.0', '1.0-rc-1')", version))
|
|
||||||
}
|
|
||||||
String versionPart = matcher.group(1)
|
|
||||||
int majorPart = Integer.parseInt(matcher.group(2), 10)
|
|
||||||
logger.info("Gradle: versionPart {}, majorPart {}", versionPart, majorPart)
|
|
||||||
return majorPart
|
|
||||||
}
|
|
||||||
|
|
||||||
String adbCmd(String cmd) {
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
|
|
||||||
def exec = new DefaultExecutor()
|
|
||||||
exec.streamHandler = new PumpStreamHandler(outputStream)
|
|
||||||
def cmdline = "adb shell $cmd"
|
|
||||||
//println(cmdline)
|
|
||||||
exec.execute(CommandLine.parse(cmdline))
|
|
||||||
//println(outputStream)
|
|
||||||
return outputStream.toString().trim()
|
|
||||||
}
|
|
@ -0,0 +1,74 @@
|
|||||||
|
import java.util.regex.Matcher
|
||||||
|
import java.util.regex.Pattern
|
||||||
|
import org.apache.commons.exec.CommandLine
|
||||||
|
import org.apache.commons.exec.DefaultExecutor
|
||||||
|
import org.apache.commons.exec.PumpStreamHandler
|
||||||
|
|
||||||
|
val GROUP_ANDROID = "android"
|
||||||
|
if (parseGradleVersion(gradle.gradleVersion) < 5) {
|
||||||
|
logger.error("ERROR: Gradle Version MUST >= 5.0, current is {}", gradle.gradleVersion)
|
||||||
|
throw RuntimeException("ERROR: Gradle Version")
|
||||||
|
} else {
|
||||||
|
logger.info("Gradle Version {}", gradle.gradleVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath("org.apache.commons:commons-exec:1.3")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
val unpackTask by register<JavaExec>("unpack") {
|
||||||
|
group = GROUP_ANDROID
|
||||||
|
main = "cfig.packable.PackableLauncherKt"
|
||||||
|
classpath = files("bbootimg/build/libs/bbootimg.jar")
|
||||||
|
this.maxHeapSize = "512m"
|
||||||
|
args("unpack")
|
||||||
|
}
|
||||||
|
unpackTask.dependsOn("bbootimg:jar")
|
||||||
|
|
||||||
|
val packTask by register<JavaExec>("pack") {
|
||||||
|
group = GROUP_ANDROID
|
||||||
|
main = "cfig.packable.PackableLauncherKt"
|
||||||
|
classpath = files("bbootimg/build/libs/bbootimg.jar")
|
||||||
|
this.maxHeapSize = "512m"
|
||||||
|
args("pack")
|
||||||
|
}
|
||||||
|
packTask.dependsOn("bbootimg:jar", "aosp:boot_signer:build")
|
||||||
|
|
||||||
|
val flashTask by register("flash", JavaExec::class) {
|
||||||
|
group = GROUP_ANDROID
|
||||||
|
main = "cfig.packable.PackableLauncherKt"
|
||||||
|
classpath = files("bbootimg/build/libs/bbootimg.jar")
|
||||||
|
this.maxHeapSize = "512m"
|
||||||
|
args("flash")
|
||||||
|
}
|
||||||
|
flashTask.dependsOn("bbootimg:jar")
|
||||||
|
|
||||||
|
//sparse image dependencies
|
||||||
|
if (System.getProperty("os.name").contains("Mac")) {
|
||||||
|
unpackTask.dependsOn("aosp:libsparse:simg2img:installReleaseMacos")
|
||||||
|
packTask.dependsOn("aosp:libsparse:img2simg:installReleaseMacos")
|
||||||
|
packTask.dependsOn("aosp:mkbootfs:installReleaseMacos")
|
||||||
|
} else {
|
||||||
|
unpackTask.dependsOn("aosp:libsparse:simg2img:installReleaseLinux")
|
||||||
|
packTask.dependsOn("aosp:libsparse:img2simg:installReleaseLinux")
|
||||||
|
packTask.dependsOn("aosp:mkbootfs:installReleaseLinux")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parseGradleVersion(version: String): Int {
|
||||||
|
val VERSION_PATTERN = Pattern.compile("((\\d+)(\\.\\d+)+)(-(\\p{Alpha}+)-(\\w+))?(-(SNAPSHOT|\\d{14}([-+]\\d{4})?))?")
|
||||||
|
val matcher = VERSION_PATTERN.matcher(version)
|
||||||
|
if (!matcher.matches()) {
|
||||||
|
throw IllegalArgumentException(String.format("'%s' is not a valid Gradle version string (examples: '1.0', '1.0-rc-1')", version))
|
||||||
|
}
|
||||||
|
val versionPart: String = matcher.group(1)
|
||||||
|
val majorPart = Integer.parseInt(matcher.group(2), 10)
|
||||||
|
logger.info("Gradle: versionPart {}, majorPart {}", versionPart, majorPart)
|
||||||
|
return majorPart
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
include "bbootimg"
|
|
||||||
include "aosp:boot_signer"
|
|
||||||
include "aosp:mkbootfs"
|
|
||||||
include "aosp:libsparse:base"
|
|
||||||
include "aosp:libsparse:sparse"
|
|
||||||
include "aosp:libsparse:img2simg"
|
|
||||||
include "aosp:libsparse:simg2img"
|
|
||||||
include "aosp:libsparse:simg2simg"
|
|
||||||
include "aosp:libsparse:append2simg"
|
|
@ -0,0 +1,9 @@
|
|||||||
|
include("bbootimg")
|
||||||
|
include("aosp:boot_signer")
|
||||||
|
include("aosp:mkbootfs")
|
||||||
|
include("aosp:libsparse:base")
|
||||||
|
include("aosp:libsparse:sparse")
|
||||||
|
include("aosp:libsparse:img2simg")
|
||||||
|
include("aosp:libsparse:simg2img")
|
||||||
|
include("aosp:libsparse:simg2simg")
|
||||||
|
include("aosp:libsparse:append2simg")
|
Loading…
Reference in New Issue