Skip to content

Commit

Permalink
patcher: add patch_boot function
Browse files Browse the repository at this point in the history
According to Magisk 25.0 release notes "Magisk no longer patches fstabs in most scenarios, which means AVB will remain intact; some custom kernels rely on AVB being stripped out for them by Magisk."
This means that a device like S9 will no longer boot stock fw after flashing just Magisk, so in order to ensure minimum compatibility we migrated the patches to multidisabler and added FBE disabler for ramdisk fstab for 8 and 9 flagship series for now, since neither no-verity-opt-encrypt can be flashed.
  • Loading branch information
corsicanu committed Jun 10, 2022
1 parent de68bc0 commit 3947c00
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,67 @@ patch_libbluetooth() {
fi
}

patch_boot() {
# Set up tools for boot.img patching
basedir=$(pwd)
unzip -o "$ZIPFILE" -d /tmp
chmod +x /tmp/tools/magiskboot
chmod +x /tmp/tools/busybox
magiskboot=/tmp/tools/magiskboot
busybox=/tmp/tools/busybox

boot=$($bb find /dev/block/platform -iname boot)
mkdir -p /tmp/bootimg && cd /tmp/bootimg
dd if=$boot of=/tmp/bootimg/old-boot.img bs=4096
$magiskboot unpack /tmp/bootimg/old-boot.img

# Boot.img patches - © topjohnwu - https://github.com/topjohnwu/Magisk/blob/master/scripts/boot_patch.sh
KEEPVERITY=false
KEEPFORCEENCRYPT=false
for dt in dtb kernel_dtb extra; do
[ -f $dt ] && $magiskboot dtb $dt patch && ui_print " - Patching fstab in $dt"
done

if [ -f kernel ]; then
ui_print " - Patching kernel for RKP/DEFEX/initramfs"
# Remove Samsung RKP
$magiskboot hexpatch kernel \
49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054

# Remove Samsung defex
# Before: [mov w2, #-221] (-__NR_execve)
# After: [mov w2, #-32768]
$magiskboot hexpatch kernel 821B8012 E2FF8F12

# Force kernel to load rootfs
# skip_initramfs -> want_initramfs
$magiskboot hexpatch kernel \
736B69705F696E697472616D667300 \
77616E745F696E697472616D667300
fi

if [ -f ramdisk.cpio ]; then
$magiskboot cpio ramdisk.cpio extract
for i in fstab.*exynos* ; do
if [ -f $i ]; then
ui_print " - Found $i, disabling encryption..."
md5=$( md5 $i )
# This comments out the offending line and adds an edited one.
sed -i -e 's/^\([^#].*\)fileencryption=[^,]*\(.*\)$/# &\n\1encryptable\2/g' $i
sed -i -e 's/^\([^#].*\)forceencrypt=[^,]*\(.*\)$/# &\n\1encryptable\2/g' $i

$magiskboot cpio ramdisk.cpio "add 0640 $i $i"
# file_changed $i $md5
fi
done
fi

$magiskboot repack old-boot.img
dd if=/tmp/bootimg/new-boot.img of=$boot bs=4096
cd $basedir
}

ui_print " "
print_full_bar
print_justified "Multi-disabler custom for Samsung devices"
Expand Down Expand Up @@ -364,6 +425,9 @@ fi

vendor_free_size_check
disable_fbe
if echo $device | grep -E '[GN]9[56][05][FN]' >/dev/null; then
patch_boot
fi
disable_recovery_restoration

if [ "$dp" != true ]; then
Expand Down

0 comments on commit 3947c00

Please sign in to comment.