From d52e182a09553a27848c43a291a9dda6ff4ae053 Mon Sep 17 00:00:00 2001 From: cfig Date: Sun, 28 Apr 2024 18:53:34 +0800 Subject: [PATCH] lazybox: pull vbmeta partition for subcmd sysinfo --- .../kotlin/cfig/lazybox/sysinfo/SysInfo.kt | 25 +++++++++++++++++++ tools/factory_image_parser.py | 4 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lazybox/src/main/kotlin/cfig/lazybox/sysinfo/SysInfo.kt b/lazybox/src/main/kotlin/cfig/lazybox/sysinfo/SysInfo.kt index 0df0419..6b06be3 100644 --- a/lazybox/src/main/kotlin/cfig/lazybox/sysinfo/SysInfo.kt +++ b/lazybox/src/main/kotlin/cfig/lazybox/sysinfo/SysInfo.kt @@ -5,10 +5,12 @@ import cfig.helper.Helper.Companion.check_call import cfig.helper.ZipHelper import org.slf4j.LoggerFactory import java.io.File +import java.io.FileInputStream import java.io.FileOutputStream import java.io.OutputStream import java.nio.file.Files import java.nio.file.Paths +import java.util.* import kotlin.io.path.Path import kotlin.io.path.deleteIfExists import kotlin.io.path.writeText @@ -75,6 +77,24 @@ makeTar("%s", "%s") FileOutputStream("$prefix/0_prop").use { runAndWrite("adb shell getprop", it, true) } + val theSlot: String = FileInputStream("$prefix/0_prop").use { inputStream -> + Properties().apply { + load(inputStream) + }.getProperty("[ro.boot.slot_suffix]")?.let { slot -> + when (slot) { + "[_a]" -> "_a" + "[_b]" -> "_b" + else -> { + log.warn("Unknown slot_suffix: $slot") + "" + } + } + } ?: run { + log.warn("slot_suffix not found") + "" + } + } + FileOutputStream("$prefix/1_partitions").use { file -> runAndWrite("adb shell cat /proc/partitions", file, false) //HMOS runAndWrite("adb shell ls -l /dev/block/by-name", file, false) @@ -83,6 +103,7 @@ makeTar("%s", "%s") FileOutputStream("$prefix/2_mount").use { file -> runAndWrite("adb shell mount", file, true) } + FileOutputStream("$prefix/3_kernel_cmdline").use { file -> file.write("[version]\n".toByteArray()) runAndWrite("adb shell cat /proc/version", file, true) @@ -106,6 +127,10 @@ makeTar("%s", "%s") } "adb pull /proc/device-tree".check_call(prefix) Files.move(Paths.get("$prefix/device-tree"), Paths.get("$prefix/device_tree")) + + if (theSlot.isNotBlank()) { + "adb pull /dev/block/by-name/vbmeta$theSlot".check_call(prefix) + } makeTar("sysinfo.tar.xz", "sysinfo") File("sysinfo").deleteRecursively() } diff --git a/tools/factory_image_parser.py b/tools/factory_image_parser.py index 62879ff..3cf63f1 100755 --- a/tools/factory_image_parser.py +++ b/tools/factory_image_parser.py @@ -32,6 +32,7 @@ known_list = [ "system_ext.img", "system.img", "system_other.img", + "userdata.img", "vbmeta.img", "vbmeta_system.img", "vbmeta_vendor.img", @@ -87,6 +88,7 @@ def prepare(zipFile): item = os.path.join(tmp1, item1, item2) log.info(">> %s" % item) if (item2.endswith(".zip")): + # show the zip file log.info("+ %s" % item) if not imgZip: imgZip = item @@ -108,7 +110,7 @@ def prepare(zipFile): log.info("- %s" % item1) list2.append(item1) else: - raise + raise Exception("Unknown image: %s" % item1) purgeFolder(tmp1) return (list1, list2)