From 3f0136362b4cafa7597653c40bfaec6bc047fa2d Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 25 Jan 2021 03:37:41 -0800 Subject: [PATCH] Move nand flash handling into boot_patch.sh --- .../magisk/core/tasks/MagiskInstaller.kt | 29 +++++++------------ scripts/boot_patch.sh | 10 +++++++ scripts/util_functions.sh | 12 +------- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index ab4123d1f..e34fce356 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -327,23 +327,19 @@ abstract class MagiskInstallImpl protected constructor( private fun patchBoot(): Boolean { "cd $installDir".sh() - var srcNand: File? = null - if ("[ -c $srcBoot ] && nanddump -f boot.img $srcBoot".sh().isSuccess) { - srcNand = srcBoot - srcBoot = installDirFile("boot.img") - } - - var isSigned: Boolean - try { - SuFileInputStream(srcBoot).use { - isSigned = SignBoot.verifySignature(it, null) - if (isSigned) { - console.add("- Boot image is signed with AVB 1.0") + var isSigned = false + if (srcBoot.let { it !is SuFile || !it.isCharacter }) { + try { + SuFileInputStream(srcBoot).use { + if (SignBoot.verifySignature(it, null)) { + isSigned = true + console.add("- Boot image is signed with AVB 1.0") + } } + } catch (e: IOException) { + console.add("! Unable to check signature") + return false } - } catch (e: IOException) { - console.add("! Unable to check signature") - return false } val FLAGS = @@ -354,9 +350,6 @@ abstract class MagiskInstallImpl protected constructor( if (!"$FLAGS sh boot_patch.sh $srcBoot".sh().isSuccess) return false - if (srcNand != null) - srcBoot = srcNand - val job = Shell.sh("./magiskboot cleanup", "cd /") val patched = installDirFile("new-boot.img") diff --git a/scripts/boot_patch.sh b/scripts/boot_patch.sh index 16818c680..4c2c9bb22 100644 --- a/scripts/boot_patch.sh +++ b/scripts/boot_patch.sh @@ -60,6 +60,13 @@ fi BOOTIMAGE="$1" [ -e "$BOOTIMAGE" ] || abort "$BOOTIMAGE does not exist!" +# Dump image for MTD/NAND character device boot partitions +if [ -c "$BOOTIMAGE" ]; then + nanddump -f boot.img "$BOOTIMAGE" + BOOTNAND="$BOOTIMAGE" + BOOTIMAGE=boot.img +fi + # Flags [ -z $KEEPVERITY ] && KEEPVERITY=false [ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false @@ -188,5 +195,8 @@ ui_print "- Repacking boot image" # Sign chromeos boot $CHROMEOS && sign_chromeos +# Restore the original boot partition path +[ -e "$BOOTNAND" ] && BOOTIMAGE="$BOOTNAND" + # Reset any error code true diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index 3ab2b0412..8b2e24ced 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -438,14 +438,7 @@ flash_image() { install_magisk() { cd $MAGISKBIN - # Dump image for MTD/NAND character device boot partitions - if [ -c $BOOTIMAGE ]; then - nanddump -f boot.img $BOOTIMAGE - local BOOTNAND=$BOOTIMAGE - BOOTIMAGE=boot.img - fi - - if [ $API -ge 21 ]; then + if [ $API -ge 21 -a ! -c $BOOTIMAGE ]; then eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true $BOOTSIGNED && ui_print "- Boot image is signed with AVB 1.0" fi @@ -455,9 +448,6 @@ install_magisk() { . ./boot_patch.sh "$BOOTIMAGE" ui_print "- Flashing new boot image" - - # Restore the original boot partition path - [ "$BOOTNAND" ] && BOOTIMAGE=$BOOTNAND flash_image new-boot.img "$BOOTIMAGE" case $? in 1)