Skip to content

Commit 17f43c1

Browse files
committed
Add Flash using mkbootfs option
1 parent 3f53430 commit 17f43c1

File tree

13 files changed

+90
-4
lines changed

13 files changed

+90
-4
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/system/bin/sh
2+
3+
## setup for testing:
4+
unzip -p "$Z" tools*/busybox > $F/busybox;
5+
unzip -p "$Z" META-INF/com/google/android/update-binary > $F/update-binary;
6+
##
7+
8+
chmod 755 $F/busybox;
9+
$F/busybox chmod 755 $F/update-binary;
10+
$F/busybox chown root:root $F/busybox $F/update-binary;
11+
12+
TMP=$F/tmp;
13+
14+
$F/busybox umount $TMP 2>/dev/null;
15+
$F/busybox rm -rf $TMP 2>/dev/null;
16+
$F/busybox mkdir -p $TMP;
17+
18+
$F/busybox mount -t tmpfs -o noatime tmpfs $TMP;
19+
#$F/busybox mount | $F/busybox grep -q " $TMP " || exit 1;
20+
21+
PATTERN='\$[Bb][Bb] chmod -R 755 tools bin;';
22+
sed -i "/$PATTERN/i cp -f \"\$F/mkbootfs\" \$AKHOME/tools;" "$F/update-binary";
23+
24+
# update-binary <RECOVERY_API_VERSION> <OUTFD> <ZIPFILE>
25+
AKHOME=$TMP/anykernel $F/busybox ash $F/update-binary 3 1 "$Z";
26+
RC=$?;
27+
28+
$F/busybox umount $TMP;
29+
$F/busybox rm -rf $TMP;
30+
$F/busybox mount -o ro,remount -t auto /;
31+
$F/busybox rm -f $F/update-binary $F/busybox;
32+
33+
# work around libsu not cleanly accepting return or exit as last line
34+
safereturn() { return $RC; }
35+
safereturn;

app/src/main/assets/mkbootfs

11.8 KB
Binary file not shown.

app/src/main/java/com/github/capntrips/kernelflasher/MainActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ class MainActivity : ComponentActivity() {
187187
copyNativeBinary("lptools_static") // v20220825
188188
copyNativeBinary("httools_static") // v3.2.0
189189
copyNativeBinary("magiskboot") // v29.0
190+
copyAsset("mkbootfs")
190191
copyAsset("flash_ak3.sh")
192+
copyAsset("flash_ak3_mkbootfs.sh")
191193
} catch (e: Exception) {
192194
Log.e(TAG, e.message, e)
193195
setContent {

app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/backups/SlotBackupsContent.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ fun ColumnScope.SlotBackupsContent(
129129
) {
130130
Text(stringResource(R.string.flash))
131131
}
132+
OutlinedButton(
133+
modifier = Modifier
134+
.fillMaxWidth(),
135+
shape = RoundedCornerShape(4.dp),
136+
onClick = {
137+
slotViewModel.flashAk3_mkbootfs(context, backupsViewModel.currentBackup!!, currentBackup.filename!!)
138+
navController.navigate("slot$slotSuffix/backups/${backupsViewModel.currentBackup!!}/flash/ak3") {
139+
popUpTo("slot$slotSuffix")
140+
}
141+
}
142+
) {
143+
Text(stringResource(R.string.flash_ak3_zip_mkbootfs))
144+
}
132145
}
133146
}
134147
OutlinedButton(

app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotFlashContent.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ fun ColumnScope.SlotFlashContent(
8484
}
8585
viewModel.flashAk3(context, uri)
8686
})
87+
FlashButton(stringResource(R.string.flash_ak3_zip_mkbootfs), callback = { uri ->
88+
navController.navigate("slot$slotSuffix/flash/ak3") {
89+
popUpTo("slot$slotSuffix")
90+
}
91+
viewModel.flashAk3_mkbootfs(context, uri)
92+
})
8793
OutlinedButton(
8894
modifier = Modifier
8995
.fillMaxWidth(),

app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotViewModel.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ class SlotViewModel(
545545
}
546546

547547
@Suppress("FunctionName")
548-
private suspend fun _flashAk3(context: Context) {
548+
private suspend fun _flashAk3(context: Context, type: String) {
549549
if (!isActive) {
550550
resetSlot()
551551
}
@@ -555,7 +555,7 @@ class SlotViewModel(
555555
if (zip.exists()) {
556556
_wasFlashSuccess.value = false
557557
val files = File(context.filesDir.canonicalPath)
558-
val flashScript = File(files, "flash_ak3.sh")
558+
val flashScript = File(files, "flash_ak3$type.sh")
559559
val result = Shell.Builder.create().setFlags(Shell.FLAG_MOUNT_MASTER).build().newJob().add("F=$files Z=\"$zip\" /system/bin/sh $flashScript").to(flashOutput, flashOutput).exec()
560560
if (result.isSuccess) {
561561
log(context, "Kernel flashed successfully")
@@ -610,15 +610,31 @@ class SlotViewModel(
610610
launch {
611611
_clearFlash()
612612
_copyFile(context, currentBackup, filename)
613-
_flashAk3(context)
613+
_flashAk3(context, "")
614614
}
615615
}
616616

617617
fun flashAk3(context: Context, uri: Uri) {
618618
launch {
619619
_clearFlash()
620620
_copyFile(context, uri)
621-
_flashAk3(context)
621+
_flashAk3(context, "")
622+
}
623+
}
624+
625+
fun flashAk3_mkbootfs(context: Context, currentBackup: String, filename: String) {
626+
launch {
627+
_clearFlash()
628+
_copyFile(context, currentBackup, filename)
629+
_flashAk3(context, "_mkbootfs")
630+
}
631+
}
632+
633+
fun flashAk3_mkbootfs(context: Context, uri: Uri) {
634+
launch {
635+
_clearFlash()
636+
_copyFile(context, uri)
637+
_flashAk3(context, "_mkbootfs")
622638
}
623639
}
624640

app/src/main/res/values-ja/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
<string name="backup">バックアップ</string>
2828
<string name="updates">更新</string>
2929
<string name="flash">フラッシュ</string>
30+
<string name="flash_mkbootfs">mkbootfsを使用してフラッシュする</string>
3031
<string name="flash_ak3_zip">AK3 Zip をフラッシュ</string>
32+
<string name="flash_ak3_zip_mkbootfs">mkbootfs を使って AK3 Zip をフラッシュする</string>
3133
<string name="flash_partition_image">パーティションイメージをフラッシュ</string>
3234
<string name="restore">復元</string>
3335
<string name="check_kernel_version">カーネルバージョンを確認</string>

app/src/main/res/values-pl/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
<string name="backup">Utwórz kopię zapasową</string>
2828
<string name="updates">Aktualizacje</string>
2929
<string name="flash">Sflashuj</string>
30+
<string name="flash_mkbootfs">Sflashuj przy użyciu mkbootfs</string>
3031
<string name="flash_ak3_zip">Sflashuj archiwum AK3</string>
32+
<string name="flash_ak3_zip_mkbootfs">Flashuj archiwum AK3 za pomocą mkbootfs</string>
3133
<string name="flash_partition_image">Sflashuj obraz partycji</string>
3234
<string name="restore">Przywróć</string>
3335
<string name="check_kernel_version">Sprawdź wersję jądra</string>

app/src/main/res/values-pt-rBR/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
<string name="backup">Backup</string>
2727
<string name="updates">Atualizações</string>
2828
<string name="flash">Flash</string>
29+
<string name="flash_mkbootfs">Flash using mkbootfs</string>
2930
<string name="flash_ak3_zip">Flash AK3 ZIP</string>
31+
<string name="flash_ak3_zip_mkbootfs">Flash AK3 Zip using mkbootfs</string>
3032
<string name="flash_partition_image">Flashar imagem de partição</string>
3133
<string name="restore">Restaurar</string>
3234
<string name="check_kernel_version">Verificar versão do kernel</string>

app/src/main/res/values-ru/string.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
<string name="backup">Резервное копирование</string>
2727
<string name="updates">Обновления</string>
2828
<string name="flash">Прошивка</string>
29+
<string name="flash_mkbootfs">Прошить помощью mkbootfs</string>
2930
<string name="flash_ak3_zip">Прошить AK3 Zip</string>
31+
<string name="flash_ak3_zip_mkbootfs">Прошить AK3 Zip с помощью mkbootfs</string>
3032
<string name="flash_partition_image">Прошить образ раздела</string>
3133
<string name="restore">Восстановить</string>
3234
<string name="check_kernel_version">Проверить версию ядра</string>

0 commit comments

Comments
 (0)