@@ -53,6 +53,7 @@ class SlotViewModel(
5353 const val HEADER_VER = " HEADER_VER"
5454 const val KERNEL_FMT = " KERNEL_FMT"
5555 const val RAMDISK_FMT = " RAMDISK_FMT"
56+ const val VND_RAMDISK = " VND_RAMDISK"
5657 }
5758
5859 data class BootSlotInfo (
@@ -119,8 +120,8 @@ class SlotViewModel(
119120 refresh(context)
120121 }
121122
122- private fun extractKernelValues (input : String , key : String ): String? {
123- val regex = Regex (" $key \\ s*\\ [([^]]+)]" )
123+ private fun extractKernelValues (input : String , key : String , isVendor_boot : Boolean = false ): String? {
124+ val regex = if (isVendor_boot == true ) Regex ( " VND_RAMDISK.*fmt= \\ [([^]]+)] " ) else Regex (" $key \\ s*\\ [([^]]+)]" )
124125 return regex.find(input)?.groupValues?.get(1 )
125126 }
126127
@@ -169,6 +170,17 @@ class SlotViewModel(
169170 _slotInfo .value.ramdiskInfo.ramdiskLocation = " init_boot.img"
170171 }
171172 }
173+ else
174+ {
175+ var vendor_boot = PartitionUtil .findPartitionBlockDevice(context, " vendor_boot" , slotSuffix)
176+ val unpackVendorBootOutput = mutableListOf<String >()
177+ if (Shell .cmd(" $magiskboot unpack $vendor_boot " ).to(unpackVendorBootOutput, unpackVendorBootOutput).exec().isSuccess)
178+ {
179+ val vendorBootUnpackOp = unpackVendorBootOutput.joinToString(" \n " )
180+ _slotInfo .value.ramdiskInfo.ramdiskFmt = extractKernelValues(vendorBootUnpackOp.trimIndent(), VND_RAMDISK , true )
181+ _slotInfo .value.ramdiskInfo.ramdiskLocation = " vendor_boot.img"
182+ }
183+ }
172184
173185 val ramdisk = File (context.filesDir, " ramdisk.cpio" )
174186 val kernel = File (context.filesDir, " kernel" )
@@ -702,6 +714,7 @@ class SlotViewModel(
702714 }
703715 }
704716
717+ @OptIn(ExperimentalSerializationApi ::class )
705718 fun flashKsuDriver (context : Context , uri : Uri ) {
706719 launch {
707720 _clearFlash ()
@@ -720,49 +733,38 @@ class SlotViewModel(
720733 val partitionName = _slotInfo .value.ramdiskInfo.ramdiskLocation?.removeSuffix(" .img" ) ? : " boot"
721734 val magiskboot = File (context.filesDir, " magiskboot" )
722735 val ksuinit = File (context.filesDir, " ksuinit" )
736+ addMessage(" Unpacking $partitionName " )
737+ var ramdisk = File (context.filesDir, " ramdisk.cpio" )
723738 if (partitionName == " boot" )
724- {
725- addMessage(" Unpacking boot.img" )
726739 Shell .cmd(" $magiskboot unpack $boot " ).exec()
727- }
728- else
729- {
730- addMessage(" Unpacking init_boot" )
740+ else if (partitionName == " init_boot" )
731741 Shell .cmd(" $magiskboot unpack $initBoot " ).exec()
742+ else {
743+ var vendor_boot = PartitionUtil .findPartitionBlockDevice(context, " vendor_boot" , slotSuffix)
744+ Shell .cmd(" $magiskboot unpack $vendor_boot " ).exec()
745+ ramdisk = File (context.filesDir, " vendor_ramdisk/ramdisk.cpio" )
746+ if (! ramdisk.exists())
747+ ramdisk = File (context.filesDir, " vendor_ramdisk/init_boot.cpio" )
732748 }
733749
734- val ramdisk = File (context.filesDir, " ramdisk.cpio " )
750+
735751
736752 if (ramdisk.exists()) {
737753 addMessage(" Patching Ramdisk" )
738754
739- if (Shell .cmd(" $magiskboot cpio ramdisk.cpio 'exists kernelsu.ko'" ).to(flashOutput, flashOutput).exec().isSuccess) {
740- Shell .cmd(" $magiskboot cpio ramdisk.cpio 'rm init'" )
741- .to(flashOutput, flashOutput).exec()
742- Shell .cmd(" $magiskboot cpio ramdisk.cpio 'add 0755 init $ksuinit '" )
743- .to(flashOutput, flashOutput).exec()
744- Shell .cmd(" $magiskboot cpio ramdisk.cpio 'rm kernelsu.ko'" )
745- .to(flashOutput, flashOutput).exec()
746- Shell .cmd(" $magiskboot cpio ramdisk.cpio 'add 0755 kernelsu.ko $driver '" )
747- .to(flashOutput, flashOutput).exec()
748- }
755+ if (Shell .cmd(" $magiskboot cpio $ramdisk 'exists kernelsu.ko'" ).to(flashOutput, flashOutput).exec().isSuccess)
756+ Shell .cmd(" $magiskboot cpio $ramdisk 'rm init' 'add 0755 init $ksuinit ' 'rm kernelsu.ko' 'add 0755 kernelsu.ko $driver '" ).to(flashOutput, flashOutput).exec()
749757 else
750- {
751- Shell .cmd(" $magiskboot cpio ramdisk.cpio 'mv init init.real'" ).to(flashOutput, flashOutput).exec()
752- Shell .cmd(" $magiskboot cpio ramdisk.cpio 'add 0755 init $ksuinit '" )
753- .to(flashOutput, flashOutput).exec()
754- Shell .cmd(" $magiskboot cpio ramdisk.cpio 'add 0755 kernelsu.ko $driver '" )
755- .to(flashOutput, flashOutput).exec()
756- }
758+ Shell .cmd(" $magiskboot cpio $ramdisk 'mv init init.real' 'add 0755 init $ksuinit ' 'add 0755 kernelsu.ko $driver '" ).to(flashOutput, flashOutput).exec()
759+
760+ addMessage(" Repacking $partitionName " )
757761 if (partitionName == " boot" )
758- {
759- addMessage(" Repacking boot.img" )
760762 Shell .cmd(" $magiskboot repack $boot " ).exec()
761- }
762- else
763- {
764- addMessage(" Repacking init_boot.img" )
763+ else if (partitionName == " init_boot" )
765764 Shell .cmd(" $magiskboot repack $initBoot " ).exec()
765+ else {
766+ var vendor_boot = PartitionUtil .findPartitionBlockDevice(context, " vendor_boot" , slotSuffix)
767+ Shell .cmd(" $magiskboot repack $vendor_boot " ).exec()
766768 }
767769
768770 if (newBootImg.exists()) {
0 commit comments