mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 21:27:41 +02:00
Update boot patch method and scripts
This commit is contained in:
@ -16,6 +16,11 @@ main() {
|
||||
# This script always run in recovery
|
||||
BOOTMODE=false
|
||||
|
||||
if [ ! -d $MAGISKBIN ]; then
|
||||
echo "! Cannot find Magisk binaries!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Wait for post addon.d processes to finish
|
||||
sleep 5
|
||||
|
||||
@ -23,11 +28,6 @@ main() {
|
||||
mount -o ro /vendor 2>/dev/null
|
||||
mount /data 2>/dev/null
|
||||
|
||||
if [ ! -d $MAGISKBIN ]; then
|
||||
echo "! Cannot find Magisk binaries!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load all functions
|
||||
. $MAGISKBIN/util_functions.sh
|
||||
|
||||
@ -37,6 +37,8 @@ main() {
|
||||
ui_print "* MAGISK_VERSION_STUB"
|
||||
ui_print "************************"
|
||||
|
||||
api_level_arch_detect
|
||||
|
||||
recovery_actions
|
||||
|
||||
find_boot_image
|
||||
@ -61,9 +63,7 @@ main() {
|
||||
|
||||
cd /
|
||||
|
||||
mv /sbin_tmp /sbin
|
||||
ui_print "- Unmounting partitions"
|
||||
umount -l /system
|
||||
recovery_cleanup
|
||||
|
||||
ui_print "- Done"
|
||||
exit 0
|
||||
|
@ -194,16 +194,8 @@ esac
|
||||
|
||||
ui_print_wrap "- Patching ramdisk"
|
||||
|
||||
# The common patches
|
||||
$KEEPVERITY || ./magiskboot --cpio-patch-dmverity ramdisk.cpio
|
||||
$KEEPFORCEENCRYPT || ./magiskboot --cpio-patch-forceencrypt ramdisk.cpio
|
||||
|
||||
# Add magisk entrypoint
|
||||
cpio_extract init.rc init.rc
|
||||
grep "import /init.magisk.rc" init.rc >/dev/null || sed -i '1,/.*import.*/s/.*import.*/import \/init.magisk.rc\n&/' init.rc
|
||||
sed -i "/selinux.reload_policy/d" init.rc
|
||||
cpio_add 750 init.rc init.rc
|
||||
rm -f init.rc
|
||||
./magiskboot --cpio-patch ramdisk.cpio $KEEPVERITY $KEEPFORCEENCRYPT
|
||||
|
||||
# sepolicy patches
|
||||
cpio_extract sepolicy sepolicy
|
||||
@ -237,8 +229,6 @@ rm -f ramdisk.cpio.orig
|
||||
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
|
||||
|
||||
ui_print_wrap "- Repacking boot image"
|
||||
./magiskboot --repack "$BOOTIMAGE"
|
||||
|
||||
[ $? -ne 0 ] && abort_wrap "! Unable to repack boot image!"
|
||||
./magiskboot --repack "$BOOTIMAGE" || abort_wrap "! Unable to repack boot image!"
|
||||
|
||||
./magiskboot --cleanup
|
||||
|
@ -67,7 +67,7 @@ ui_print "************************"
|
||||
ui_print "* MAGISK_VERSION_STUB"
|
||||
ui_print "************************"
|
||||
|
||||
ui_print "- Mounting /system(ro), /vendor(ro), /cache, /data"
|
||||
ui_print "- Mounting /system, /vendor, /cache, /data"
|
||||
mount -o ro /system 2>/dev/null
|
||||
mount -o ro /vendor 2>/dev/null
|
||||
mount /cache 2>/dev/null
|
||||
@ -83,17 +83,8 @@ getvar BOOTIMAGE
|
||||
# Check if system root is installed and remove
|
||||
remove_system_su
|
||||
|
||||
API=`grep_prop ro.build.version.sdk`
|
||||
ABI=`grep_prop ro.product.cpu.abi | cut -c-3`
|
||||
ABI2=`grep_prop ro.product.cpu.abi2 | cut -c-3`
|
||||
ABILONG=`grep_prop ro.product.cpu.abi`
|
||||
|
||||
ARCH=arm
|
||||
BBPATH=armeabi-v7a
|
||||
if [ "$ABI" = "x86" ]; then ARCH=x86; fi;
|
||||
if [ "$ABI2" = "x86" ]; then ARCH=x86; fi;
|
||||
if [ "$ABILONG" = "arm64-v8a" ]; then ARCH=arm64; fi;
|
||||
if [ "$ABILONG" = "x86_64" ]; then ARCH=x64; fi;
|
||||
# Detect version and architecture
|
||||
api_level_arch_detect
|
||||
|
||||
[ $API -lt 21 ] && abort "! Magisk is only for Lollipop 5.0+ (SDK 21+)"
|
||||
|
||||
@ -110,8 +101,6 @@ find_boot_image
|
||||
##########################################################################################
|
||||
|
||||
ui_print "- Constructing environment"
|
||||
|
||||
$BOOTMODE || recovery_actions
|
||||
|
||||
is_mounted /data && MAGISKBIN=/data/magisk || MAGISKBIN=/cache/data_bin
|
||||
|
||||
@ -119,9 +108,7 @@ is_mounted /data && MAGISKBIN=/data/magisk || MAGISKBIN=/cache/data_bin
|
||||
rm -rf $MAGISKBIN 2>/dev/null
|
||||
mkdir -p $MAGISKBIN
|
||||
cp -af $BINDIR/. $COMMONDIR/. $MAGISKBIN
|
||||
|
||||
chmod -R 755 $MAGISKBIN
|
||||
chcon -hR u:object_r:system_file:s0 $MAGISKBIN
|
||||
|
||||
# addon.d
|
||||
if [ -d /system/addon.d ]; then
|
||||
@ -135,6 +122,8 @@ fi
|
||||
# Magisk Image
|
||||
##########################################################################################
|
||||
|
||||
$BOOTMODE || recovery_actions
|
||||
|
||||
# Fix SuperSU.....
|
||||
$BOOTMODE && $BINDIR/magisk magiskpolicy --live "allow fsck * * *"
|
||||
|
||||
@ -206,19 +195,16 @@ ui_print "- Flashing new boot image"
|
||||
if [ -L "$BOOTIMAGE" ]; then
|
||||
dd if=new-boot.img of="$BOOTIMAGE" bs=4096
|
||||
else
|
||||
cat new-boot.img /dev/zero | dd of="$BOOTIMAGE" bs=4096
|
||||
cat new-boot.img /dev/zero | dd of="$BOOTIMAGE" bs=4096 >/dev/null 2>&1
|
||||
fi
|
||||
rm -f new-boot.img
|
||||
|
||||
cd /
|
||||
|
||||
if ! $BOOTMODE; then
|
||||
ui_print "- Unmounting partitions"
|
||||
$BINDIR/magisk --umountimg /magisk $MAGISKLOOP
|
||||
rmdir /magisk
|
||||
mv /sbin_tmp /sbin
|
||||
umount -l /system
|
||||
umount -l /vendor 2>/dev/null
|
||||
recovery_cleanup
|
||||
fi
|
||||
|
||||
ui_print "- Done"
|
||||
|
@ -32,15 +32,15 @@ getvar() {
|
||||
|
||||
find_boot_image() {
|
||||
if [ -z "$BOOTIMAGE" ]; then
|
||||
for PARTITION in kern-a android_boot kernel boot lnx; do
|
||||
BOOTIMAGE=`find /dev/block -iname "$PARTITION" | head -n 1`
|
||||
for BLOCK in boot_a BOOT_A kern-a KERN-A android_boot ANDROID_BOOT kernel KERNEL boot BOOT lnx LNX; do
|
||||
BOOTIMAGE=`ls /dev/block/by-name/$BLOCK || ls /dev/block/platform/*/by-name/$BLOCK || ls /dev/block/platform/*/*/by-name/$BLOCK` 2>/dev/null
|
||||
[ ! -z $BOOTIMAGE ] && break
|
||||
done
|
||||
fi
|
||||
# Recovery fallback
|
||||
if [ -z "$BOOTIMAGE" ]; then
|
||||
for FSTAB in /etc/*fstab*; do
|
||||
BOOTIMAGE=`grep -E '\b/boot\b' $FSTAB | grep -oE '/dev/[a-zA-Z0-9_./-]*'`
|
||||
BOOTIMAGE=`grep -E '\b/boot\b' $FSTAB | grep -v "#" | grep -oE '/dev/[a-zA-Z0-9_./-]*'`
|
||||
[ ! -z $BOOTIMAGE ] && break
|
||||
done
|
||||
fi
|
||||
@ -91,13 +91,38 @@ remove_system_su() {
|
||||
fi
|
||||
}
|
||||
|
||||
api_level_arch_detect() {
|
||||
API=`grep_prop ro.build.version.sdk`
|
||||
ABI=`grep_prop ro.product.cpu.abi | cut -c-3`
|
||||
ABI2=`grep_prop ro.product.cpu.abi2 | cut -c-3`
|
||||
ABILONG=`grep_prop ro.product.cpu.abi`
|
||||
|
||||
ARCH=arm
|
||||
IS64BIT=false
|
||||
if [ "$ABI" = "x86" ]; then ARCH=x86; fi;
|
||||
if [ "$ABI2" = "x86" ]; then ARCH=x86; fi;
|
||||
if [ "$ABILONG" = "arm64-v8a" ]; then ARCH=arm64; IS64BIT=true; fi;
|
||||
if [ "$ABILONG" = "x86_64" ]; then ARCH=x64; IS64BIT=true; fi;
|
||||
}
|
||||
|
||||
recovery_actions() {
|
||||
# TWRP bug fix
|
||||
mount -o bind /dev/urandom /dev/random
|
||||
# Clear out possible lib paths, let the binaries find them itself
|
||||
export LD_LIBRARY_PATH=
|
||||
# Temporarily block out all custom recovery binaries/libs
|
||||
mv /sbin /sbin_tmp
|
||||
# Add all possible library paths
|
||||
OLD_LD_PATH=$LD_LIBRARY_PATH
|
||||
$IS64BIT && export LD_LIBRARY_PATH=/system/lib64:/system/vendor/lib64 || export LD_LIBRARY_PATH=/system/lib:/system/vendor/lib
|
||||
}
|
||||
|
||||
recovery_cleanup() {
|
||||
mv /sbin_tmp /sbin
|
||||
# Clear LD_LIBRARY_PATH
|
||||
export LD_LIBRARY_PATH=$OLD_LD_PATH
|
||||
ui_print "- Unmounting partitions"
|
||||
umount -l /system
|
||||
umount -l /vendor 2>/dev/null
|
||||
umount -l /dev/random
|
||||
}
|
||||
|
||||
abort() {
|
||||
|
Reference in New Issue
Block a user