mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-23 18:15:30 +00:00
Add dtbo.img patch support
This commit is contained in:
parent
e9d0f615ba
commit
912c188b53
@ -43,7 +43,7 @@ main() {
|
||||
|
||||
find_boot_image
|
||||
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
|
||||
ui_print "- Found Boot Image: $BOOTIMAGE"
|
||||
ui_print "- Found boot image: $BOOTIMAGE"
|
||||
|
||||
SOURCEDMODE=true
|
||||
cd $MAGISKBIN
|
||||
@ -51,13 +51,20 @@ main() {
|
||||
# Source the boot patcher
|
||||
. $MAGISKBIN/boot_patch.sh "$BOOTIMAGE"
|
||||
|
||||
flash_boot_image new-boot.img "$BOOTIMAGE"
|
||||
rm -f new-boot.img
|
||||
|
||||
if [ -f stock_boot* ]; then
|
||||
rm -f /data/stock_boot* 2>/dev/null
|
||||
mv stock_boot* /data
|
||||
is_mounted /data && mv stock_boot* /data
|
||||
fi
|
||||
|
||||
flash_boot_image new-boot.img $BOOTIMAGE
|
||||
rm -f new-boot.img
|
||||
patch_dtbo_image
|
||||
|
||||
if [ -f stock_dtbo* ]; then
|
||||
rm -f /data/stock_dtbo* 2>/dev/null
|
||||
is_mounted /data && mv stock_dtbo* /data
|
||||
fi
|
||||
|
||||
cd /
|
||||
recovery_cleanup
|
||||
|
@ -110,9 +110,8 @@ case $? in
|
||||
ui_print "- Stock boot image detected!"
|
||||
ui_print "- Backing up stock boot image"
|
||||
SHA1=`./magiskboot --sha1 "$BOOTIMAGE" 2>/dev/null`
|
||||
STOCKDUMP=stock_boot_${SHA1}.img
|
||||
dd if="$BOOTIMAGE" of=$STOCKDUMP
|
||||
./magiskboot --compress $STOCKDUMP
|
||||
STOCKDUMP=stock_boot_${SHA1}.img.gz
|
||||
./magiskboot --compress "$BOOTIMAGE" $STOCKDUMP
|
||||
cp -af ramdisk.cpio ramdisk.cpio.orig
|
||||
;;
|
||||
1 ) # Magisk patched
|
||||
@ -129,10 +128,10 @@ case $? in
|
||||
ui_print "! Cannot restore from internal backup"
|
||||
# If we are root and SHA1 known, we try to find the stock backup
|
||||
if [ ! -z $SHA1 ]; then
|
||||
STOCKDUMP=/data/stock_boot_${SHA1}.img
|
||||
if [ -f ${STOCKDUMP}.gz ]; then
|
||||
STOCKDUMP=/data/stock_boot_${SHA1}.img.gz
|
||||
if [ -f $STOCKDUMP ]; then
|
||||
ui_print "- Stock boot image backup found"
|
||||
./magiskboot --decompress ${STOCKDUMP}.gz stock_boot.img
|
||||
./magiskboot --decompress $STOCKDUMP stock_boot.img
|
||||
./magiskboot --unpack stock_boot.img
|
||||
rm -f stock_boot.img
|
||||
OK=true
|
||||
@ -163,17 +162,15 @@ ui_print "- Patching ramdisk"
|
||||
# Create ramdisk backups
|
||||
./magiskboot --cpio-backup ramdisk.cpio ramdisk.cpio.orig $SHA1
|
||||
|
||||
if ! $KEEPVERITY && [ -f dtb ]; then
|
||||
./magiskboot --dtb-patch dtb && ui_print "- Patching fstab in dtb to remove dm-verity"
|
||||
fi
|
||||
|
||||
rm -f ramdisk.cpio.orig
|
||||
|
||||
##########################################################################################
|
||||
# Repack and flash
|
||||
# Binary patches
|
||||
##########################################################################################
|
||||
|
||||
# Hexpatches
|
||||
if ! $KEEPVERITY && [ -f dtb ]; then
|
||||
./magiskboot --dtb-patch dtb && ui_print "- Patching fstab in dtb to remove dm-verity"
|
||||
fi
|
||||
|
||||
# Remove Samsung RKP in stock kernel
|
||||
./magiskboot --hexpatch kernel \
|
||||
@ -185,6 +182,10 @@ A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
|
||||
736B69705F696E697472616D6673 \
|
||||
77616E745F696E697472616D6673
|
||||
|
||||
##########################################################################################
|
||||
# Repack and flash
|
||||
##########################################################################################
|
||||
|
||||
ui_print "- Repacking boot image"
|
||||
./magiskboot --repack "$BOOTIMAGE" || abort "! Unable to repack boot image!"
|
||||
|
||||
|
@ -115,14 +115,21 @@ cd $MAGISKBIN
|
||||
# Source the boot patcher
|
||||
. $COMMONDIR/boot_patch.sh "$BOOTIMAGE"
|
||||
|
||||
if [ -f stock_boot* ]; then
|
||||
rm -f /data/stock_boot* 2>/dev/null
|
||||
mv stock_boot* /data
|
||||
fi
|
||||
|
||||
flash_boot_image new-boot.img "$BOOTIMAGE"
|
||||
rm -f new-boot.img
|
||||
|
||||
if [ -f stock_boot* ]; then
|
||||
rm -f /data/stock_boot* 2>/dev/null
|
||||
is_mounted /data && mv stock_boot* /data
|
||||
fi
|
||||
|
||||
patch_dtbo_image
|
||||
|
||||
if [ -f stock_dtbo* ]; then
|
||||
rm -f /data/stock_dtbo* 2>/dev/null
|
||||
is_mounted /data && mv stock_dtbo* /data
|
||||
fi
|
||||
|
||||
cd /
|
||||
# Cleanups
|
||||
$BOOTMODE || recovery_cleanup
|
||||
|
@ -79,17 +79,16 @@ case $? in
|
||||
ui_print "- Magisk patched image detected!"
|
||||
# Find SHA1 of stock boot image
|
||||
[ -z $SHA1 ] && SHA1=`./magiskboot --cpio-stocksha1 ramdisk.cpio 2>/dev/null`
|
||||
[ ! -z $SHA1 ] && STOCKBOOT=/data/stock_boot_${SHA1}.img.gz
|
||||
if [ -f "$STOCKBOOT" ]; then
|
||||
ui_print "- Boot image backup found!"
|
||||
else
|
||||
OK=false
|
||||
[ ! -z $SHA1 ] && restore_imgs $SHA1 && OK=true
|
||||
if ! $OK; then
|
||||
ui_print "! Boot image backup unavailable"
|
||||
ui_print "- Restoring ramdisk with internal backup"
|
||||
./magiskboot --cpio-restore ramdisk.cpio
|
||||
./magiskboot --repack $BOOTIMAGE
|
||||
# Sign chromeos boot
|
||||
$CHROMEOS && sign_chromeos
|
||||
STOCKBOOT=new-boot.img
|
||||
flash_boot_image new-boot.img "$BOOTIMAGE"
|
||||
fi
|
||||
;;
|
||||
2 ) # Other patched
|
||||
@ -98,13 +97,11 @@ case $? in
|
||||
;;
|
||||
esac
|
||||
|
||||
flash_boot_image $STOCKBOOT "$BOOTIMAGE"
|
||||
|
||||
cd /
|
||||
|
||||
ui_print "- Removing Magisk files"
|
||||
rm -rf /cache/*magisk* /cache/unblock /data/*magisk* /data/cache/*magisk* /data/property/*magisk* \
|
||||
/data/Magisk.apk /data/busybox /data/custom_ramdisk_patch.sh \
|
||||
/data/app/com.topjohnwu.magisk* /data/user*/*/com.topjohnwu.magisk 2>/dev/null
|
||||
/data/Magisk.apk /data/busybox /data/custom_ramdisk_patch.sh /data/app/com.topjohnwu.magisk* \
|
||||
/data/user*/*/magisk.db /data/user*/*/com.topjohnwu.magisk 2>/dev/null
|
||||
|
||||
$BOOTMODE && reboot
|
||||
|
@ -41,8 +41,11 @@ ui_print() {
|
||||
mount_partitions() {
|
||||
# Check A/B slot
|
||||
SLOT=`getprop ro.boot.slot_suffix`
|
||||
[ -z $SLOT ] && SLOT=_`getprop ro.boot.slot`
|
||||
[ $SLOT = "_" ] || ui_print "- A/B partition detected, current slot: $SLOT"
|
||||
if [ -z $SLOT ]; then
|
||||
SLOT=_`getprop ro.boot.slot`
|
||||
[ $SLOT = "_" ] && SLOT=
|
||||
fi
|
||||
[ -z $SLOT ] || ui_print "- A/B partition detected, current slot: $SLOT"
|
||||
ui_print "- Mounting /system, /vendor"
|
||||
is_mounted /system || [ -f /system/build.prop ] || mount -o ro /system 2>/dev/null
|
||||
if ! is_mounted /system && ! [ -f /system/build.prop ]; then
|
||||
@ -136,24 +139,60 @@ migrate_boot_backup() {
|
||||
|
||||
flash_boot_image() {
|
||||
# Make sure all blocks are writable
|
||||
$MAGISKBIN/magisk --unlock-blocks
|
||||
$MAGISKBIN/magisk --unlock-blocks 2>/dev/null
|
||||
case "$1" in
|
||||
*.gz) COMMAND="gzip -d < \"$1\"";;
|
||||
*) COMMAND="cat \"$1\"";;
|
||||
*.gz) COMMAND="gzip -d < '$1'";;
|
||||
*) COMMAND="cat '$1'";;
|
||||
esac
|
||||
$BOOTSIGNED && SIGNCOM="$BOOTSIGNER -sign" || SIGNCOM="cat -"
|
||||
case "$2" in
|
||||
/dev/block/*)
|
||||
ui_print "- Flashing new boot image"
|
||||
eval $COMMAND | eval $SIGNCOM | cat - /dev/zero | dd of="$2" bs=4096 >/dev/null 2>&1
|
||||
eval $COMMAND | eval $SIGNCOM | cat - /dev/zero 2>/dev/null | dd of="$2" bs=4096 2>/dev/null
|
||||
;;
|
||||
*)
|
||||
ui_print "- Storing new boot image"
|
||||
eval $COMMAND | eval $SIGNCOM | dd of="$2" bs=4096 >/dev/null 2>&1
|
||||
eval $COMMAND | eval $SIGNCOM | dd of="$2" bs=4096 2>/dev/null
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
find_dtbo_image() {
|
||||
DTBOIMAGE=`find /dev/block -iname dtbo$SLOT | head -n 1` 2>/dev/null
|
||||
[ ! -z $DTBOIMAGE ] && DTBOIMAGE=`resolve_link $DTBOIMAGE`
|
||||
}
|
||||
|
||||
patch_dtbo_image() {
|
||||
find_dtbo_image
|
||||
if [ ! -z $DTBOIMAGE ]; then
|
||||
ui_print "- Found dtbo image: $DTBOIMAGE"
|
||||
if $MAGISKBIN/magiskboot --dtb-test $DTBOIMAGE; then
|
||||
ui_print "- Backing up stock dtbo image"
|
||||
$MAGISKBIN/magiskboot --compress $DTBOIMAGE $MAGISKBIN/stock_dtbo.img.gz
|
||||
ui_print "- Patching fstab in dtbo to remove avb-verity"
|
||||
$MAGISKBIN/magiskboot --dtb-patch $DTBOIMAGE
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
restore_imgs() {
|
||||
STOCKBOOT=/data/stock_boot_${1}.img.gz
|
||||
STOCKDTBO=/data/stock_dtbo.img.gz
|
||||
find_dtbo_image
|
||||
if [ ! -z "$DTBOIMAGE" -a -f "$STOCKDTBO" ]; then
|
||||
ui_print "- Restoring stock dtbo image"
|
||||
gzip -d < $STOCKDTBO | dd of=$DTBOIMAGE
|
||||
fi
|
||||
BOOTSIGNED=false
|
||||
find_boot_image
|
||||
if [ ! -z "$BOOTIMAGE" -a -f "$STOCKBOOT" ]; then
|
||||
ui_print "- Restoring stock boot image"
|
||||
flash_boot_image $STOCKBOOT "$BOOTIMAGE"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
sign_chromeos() {
|
||||
ui_print "- Signing ChromeOS boot image"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user