Skip to content

Commit

Permalink
Mass update for ramdisk and lazybox
Browse files Browse the repository at this point in the history
lazybox: support bootchart
ramdisk: support cpio entry of type CHAR_DEV
  • Loading branch information
cfig committed Oct 16, 2023
1 parent d3b28f6 commit a8c3166
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
21 changes: 21 additions & 0 deletions bbootimg/src/main/kotlin/bootimg/cpio/AndroidCpio.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class AndroidCpio {
ino = inodeNumber++
)
}

Files.isDirectory(item.toPath()) -> {
log.debug("DIR: " + item.path + ", " + item.toPath())
AndroidCpioEntry(
Expand All @@ -79,6 +80,7 @@ class AndroidCpio {
ino = inodeNumber++
)
}

Files.isRegularFile(item.toPath()) -> {
log.debug("REG: " + item.path)
AndroidCpioEntry(
Expand All @@ -88,6 +90,7 @@ class AndroidCpio {
ino = inodeNumber++
)
}

else -> {
throw IllegalArgumentException("do not support file " + item.name)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -260,6 +266,7 @@ class AndroidCpio {
)
}
}

entry.isDirectory -> {
entryInfo.note = ("DIR " + entryInfo.note)
File(outEntryName).mkdir()
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion lazybox/src/main/kotlin/cfig/lazybox/App.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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") {
Expand All @@ -37,4 +41,7 @@ fun main(args: Array<String>) {
if (args.get(0) == "pidstat") {
Pidstat.run()
}
if (args.get(0) == "bootchart") {
BootChart.run()
}
}
41 changes: 41 additions & 0 deletions lazybox/src/main/kotlin/cfig/lazybox/sysinfo/BootChart.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
15 changes: 15 additions & 0 deletions lazybox/src/main/kotlin/cfig/lazybox/sysinfo/SysInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
"""
Expand Down
2 changes: 2 additions & 0 deletions tools/factory_image_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a8c3166

Please sign in to comment.