Mass update for ramdisk and lazybox

lazybox: support bootchart
ramdisk: support cpio entry of type CHAR_DEV
pull/140/head
cfig 1 year ago
parent d3b28f664c
commit a8c3166994
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -70,6 +70,7 @@ class AndroidCpio {
ino = inodeNumber++
)
}
Files.isDirectory(item.toPath()) -> {
log.debug("DIR: " + item.path + ", " + item.toPath())
AndroidCpioEntry(
@ -79,6 +80,7 @@ class AndroidCpio {
ino = inodeNumber++
)
}
Files.isRegularFile(item.toPath()) -> {
log.debug("REG: " + item.path)
AndroidCpioEntry(
@ -88,6 +90,7 @@ class AndroidCpio {
ino = inodeNumber++
)
}
else -> {
throw IllegalArgumentException("do not support file " + item.name)
}
@ -142,10 +145,12 @@ class AndroidCpio {
log.warn("${entry.name} has NO fsconfig/prefix match")
}
}
1 -> {
log.debug("${entry.name} == preset fsconfig")
entry.statMode = itemConfig[0].statMode
}
else -> {
//Issue #75: https://github.com/cfig/Android_boot_image_editor/issues/75
//Reason: cpio may have multiple entries with the same name, that's caused by man-made errors
@ -248,6 +253,7 @@ class AndroidCpio {
Files.createSymbolicLink(Paths.get(outEntryName), Paths.get(String(buffer)))
}
}
entry.isRegularFile -> {
entryInfo.note = ("REG " + entryInfo.note)
File(outEntryName).also { it.parentFile.mkdirs() }.writeBytes(buffer)
@ -260,6 +266,7 @@ class AndroidCpio {
)
}
}
entry.isDirectory -> {
entryInfo.note = ("DIR " + entryInfo.note)
File(outEntryName).mkdir()
@ -272,6 +279,20 @@ class AndroidCpio {
//Windows
}
}
entry.isCharacterDevice -> {
entryInfo.note = ("CHAR " + entryInfo.note)
File(outEntryName).also { it.parentFile.mkdirs() }.writeBytes(buffer)
if (EnvironmentVerifier().isWindows) {
//Windows: Posix not supported
} else {
Files.setPosixFilePermissions(
Paths.get(outEntryName),
Helper.modeToPermissions(((entry.mode and PERM_MASK) or 0b111_000_000).toInt())
)
}
}
else -> throw IllegalArgumentException("??? type unknown")
}
File(outEntryName).setLastModified(entry.time)

@ -1,5 +1,6 @@
package cfig.lazybox
import cfig.lazybox.sysinfo.BootChart
import cfig.lazybox.sysinfo.CpuInfo
import cfig.lazybox.sysinfo.Pidstat
import cfig.lazybox.sysinfo.SysInfo
@ -16,7 +17,10 @@ fun main(args: Array<String>) {
println("Usage: args: (Array<String>) ...")
println(" or: function [arguments]...")
println("\nCurrently defined functions:")
println("\tcpuinfo sysinfo sysstat pidstat")
println("\tcpuinfo sysinfo sysstat pidstat bootchart")
println("\nCommand Usage:")
println("bootchart: generate Android bootchart")
println("pidstat : given a pid, profile its CPU usage")
exitProcess(0)
}
if (args.get(0) == "cpuinfo") {
@ -37,4 +41,7 @@ fun main(args: Array<String>) {
if (args.get(0) == "pidstat") {
Pidstat.run()
}
if (args.get(0) == "bootchart") {
BootChart.run()
}
}

@ -0,0 +1,41 @@
package cfig.lazybox.sysinfo
import cfig.helper.Helper
import cfig.helper.Helper.Companion.check_call
import org.slf4j.LoggerFactory
import java.util.concurrent.TimeUnit
class BootChart {
companion object {
private val log = LoggerFactory.getLogger(BootChart::class.java)
fun run() {
"adb wait-for-device".check_call()
"adb root".check_call()
"adb wait-for-device".check_call()
"adb shell touch /data/bootchart/enabled".check_call()
Helper.adbCmd("reboot")
"adb wait-for-device".check_call()
"adb root".check_call()
"adb wait-for-device".check_call()
Helper.adbCmd("rm -fv /data/bootchart/enabled")
while (true) {
val comp = Helper.adbCmd("getprop sys.boot_completed")
if (comp == "1") {
log.info("boot completed")
TimeUnit.SECONDS.sleep(3)
break
} else {
log.info("still booting ...")
TimeUnit.SECONDS.sleep(1)
}
}
"header proc_stat.log proc_ps.log proc_diskstats.log".split("\\s".toRegex()).forEach {
val LOGROOT = "/data/bootchart/"
"adb pull ${LOGROOT}$it".check_call()
}
"tar -czf bootchart.tgz header proc_stat.log proc_ps.log proc_diskstats.log".check_call()
"pybootchartgui bootchart.tgz".check_call()
"xdg-open bootchart.png".check_call()
}
}
}

@ -30,6 +30,21 @@ class SysInfo {
}
}
fun makeTar(tarFile: String, srcDir: String, fmt: String) {
val pyScript =
"""
import os, sys, subprocess, gzip, logging, shutil, tarfile, os.path
def makeTar(output_filename, source_dir):
with tarfile.open(output_filename, "w:%s") as tar:
tar.add(source_dir, arcname=os.path.basename(source_dir))
makeTar("%s", "%s")
""".trim()
val tmp = Files.createTempFile(Paths.get("."), "xx.", ".yy")
tmp.writeText(String.format(fmt, pyScript, tarFile, srcDir))
("python " + tmp.fileName).check_call()
tmp.deleteIfExists()
}
private fun makeTar(tarFile: String, srcDir: String) {
val pyScript =
"""

@ -74,6 +74,8 @@ def prepare(zipFile):
list2 = []
purgeFolder(tmp1)
purgeFolder(tmp2)
os.mkdir(tmp1)
os.mkdir(tmp2)
with ZipFile(zipFile, 'r') as zf:
zf.extractall(path=tmp1)

Loading…
Cancel
Save