@@ -53,6 +53,7 @@ class SlotViewModel(
53
53
const val HEADER_VER = " HEADER_VER"
54
54
const val KERNEL_FMT = " KERNEL_FMT"
55
55
const val RAMDISK_FMT = " RAMDISK_FMT"
56
+ const val VND_RAMDISK = " VND_RAMDISK"
56
57
}
57
58
58
59
data class BootSlotInfo (
@@ -119,8 +120,8 @@ class SlotViewModel(
119
120
refresh(context)
120
121
}
121
122
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*\\ [([^]]+)]" )
124
125
return regex.find(input)?.groupValues?.get(1 )
125
126
}
126
127
@@ -169,6 +170,17 @@ class SlotViewModel(
169
170
_slotInfo .value.ramdiskInfo.ramdiskLocation = " init_boot.img"
170
171
}
171
172
}
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
+ }
172
184
173
185
val ramdisk = File (context.filesDir, " ramdisk.cpio" )
174
186
val kernel = File (context.filesDir, " kernel" )
@@ -702,6 +714,7 @@ class SlotViewModel(
702
714
}
703
715
}
704
716
717
+ @OptIn(ExperimentalSerializationApi ::class )
705
718
fun flashKsuDriver (context : Context , uri : Uri ) {
706
719
launch {
707
720
_clearFlash ()
@@ -720,49 +733,38 @@ class SlotViewModel(
720
733
val partitionName = _slotInfo .value.ramdiskInfo.ramdiskLocation?.removeSuffix(" .img" ) ? : " boot"
721
734
val magiskboot = File (context.filesDir, " magiskboot" )
722
735
val ksuinit = File (context.filesDir, " ksuinit" )
736
+ addMessage(" Unpacking $partitionName " )
737
+ var ramdisk = File (context.filesDir, " ramdisk.cpio" )
723
738
if (partitionName == " boot" )
724
- {
725
- addMessage(" Unpacking boot.img" )
726
739
Shell .cmd(" $magiskboot unpack $boot " ).exec()
727
- }
728
- else
729
- {
730
- addMessage(" Unpacking init_boot" )
740
+ else if (partitionName == " init_boot" )
731
741
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" )
732
748
}
733
749
734
- val ramdisk = File (context.filesDir, " ramdisk.cpio " )
750
+
735
751
736
752
if (ramdisk.exists()) {
737
753
addMessage(" Patching Ramdisk" )
738
754
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()
749
757
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 " )
757
761
if (partitionName == " boot" )
758
- {
759
- addMessage(" Repacking boot.img" )
760
762
Shell .cmd(" $magiskboot repack $boot " ).exec()
761
- }
762
- else
763
- {
764
- addMessage(" Repacking init_boot.img" )
763
+ else if (partitionName == " init_boot" )
765
764
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()
766
768
}
767
769
768
770
if (newBootImg.exists()) {
0 commit comments