Commit 32ee8e46 authored by topjohnwu's avatar topjohnwu

Properly and fully support dtbo patching

parent e79aa54b
Subproject commit 99c74b31be15a239fdffe4a727d2d83feb52b8bb Subproject commit 389299afd103337ec3ab787278ac56ac249f9195
...@@ -621,10 +621,11 @@ void post_fs_data(int client) { ...@@ -621,10 +621,11 @@ void post_fs_data(int client) {
rm_rf(DATABIN); rm_rf(DATABIN);
cp_afc(bin_path, DATABIN); cp_afc(bin_path, DATABIN);
rm_rf(bin_path); rm_rf(bin_path);
// Lazy.... use shell blob to match files
exec_command_sync("sh", "-c", "mv /data/magisk/stock_boot* /data", NULL);
} }
// Lazy.... use shell blob to match files
exec_command_sync("sh", "-c", "mv -f /data/magisk/stock_*.img.gz /data", NULL);
// Initialize // Initialize
daemon_init(); daemon_init();
......
...@@ -102,7 +102,7 @@ $BOOTMODE || recovery_actions ...@@ -102,7 +102,7 @@ $BOOTMODE || recovery_actions
# Boot patching # Boot patching
########################################################################################## ##########################################################################################
find_boot_image [ -z $BOOTIMAGE ] && find_boot_image
[ -z $BOOTIMAGE ] && abort "! Unable to detect boot image" [ -z $BOOTIMAGE ] && abort "! Unable to detect boot image"
ui_print "- Found boot image: $BOOTIMAGE" ui_print "- Found boot image: $BOOTIMAGE"
......
...@@ -100,7 +100,7 @@ resolve_link() { ...@@ -100,7 +100,7 @@ resolve_link() {
} }
find_boot_image() { find_boot_image() {
if [ -z "$BOOTIMAGE" ]; then BOOTIMAGE=
if [ ! -z $SLOT ]; then if [ ! -z $SLOT ]; then
BOOTIMAGE=`find /dev/block -iname boot$SLOT | head -n 1` 2>/dev/null BOOTIMAGE=`find /dev/block -iname boot$SLOT | head -n 1` 2>/dev/null
else else
...@@ -109,7 +109,6 @@ find_boot_image() { ...@@ -109,7 +109,6 @@ find_boot_image() {
[ ! -z $BOOTIMAGE ] && break [ ! -z $BOOTIMAGE ] && break
done done
fi fi
fi
# Recovery fallback # Recovery fallback
if [ -z "$BOOTIMAGE" ]; then if [ -z "$BOOTIMAGE" ]; then
for FSTAB in /etc/*fstab*; do for FSTAB in /etc/*fstab*; do
...@@ -123,8 +122,7 @@ find_boot_image() { ...@@ -123,8 +122,7 @@ find_boot_image() {
migrate_boot_backup() { migrate_boot_backup() {
# Update the broken boot backup # Update the broken boot backup
if [ -f /data/stock_boot_.img.gz ]; then if [ -f /data/stock_boot_.img.gz ]; then
$MAGISKBIN/magiskboot --decompress /data/stock_boot_.img.gz $MAGISKBIN/magiskboot --decompress /data/stock_boot_.img.gz /data/stock_boot.img
mv /data/stock_boot_.img /data/stock_boot.img
fi fi
# Update our previous backup to new format if exists # Update our previous backup to new format if exists
if [ -f /data/stock_boot.img ]; then if [ -f /data/stock_boot.img ]; then
...@@ -171,13 +169,18 @@ patch_dtbo_image() { ...@@ -171,13 +169,18 @@ patch_dtbo_image() {
$MAGISKBIN/magiskboot --compress $DTBOIMAGE $MAGISKBIN/stock_dtbo.img.gz $MAGISKBIN/magiskboot --compress $DTBOIMAGE $MAGISKBIN/stock_dtbo.img.gz
ui_print "- Patching fstab in dtbo to remove avb-verity" ui_print "- Patching fstab in dtbo to remove avb-verity"
$MAGISKBIN/magiskboot --dtb-patch $DTBOIMAGE $MAGISKBIN/magiskboot --dtb-patch $DTBOIMAGE
return 0
fi fi
fi fi
return 1
} }
restore_imgs() { restore_imgs() {
STOCKBOOT=/data/stock_boot_${1}.img.gz STOCKBOOT=/data/stock_boot_${1}.img.gz
STOCKDTBO=/data/stock_dtbo.img.gz STOCKDTBO=/data/stock_dtbo.img.gz
# Make sure all blocks are writable
$MAGISKBIN/magisk --unlock-blocks 2>/dev/null
find_dtbo_image find_dtbo_image
if [ ! -z "$DTBOIMAGE" -a -f "$STOCKDTBO" ]; then if [ ! -z "$DTBOIMAGE" -a -f "$STOCKDTBO" ]; then
ui_print "- Restoring stock dtbo image" ui_print "- Restoring stock dtbo image"
...@@ -187,7 +190,7 @@ restore_imgs() { ...@@ -187,7 +190,7 @@ restore_imgs() {
find_boot_image find_boot_image
if [ ! -z "$BOOTIMAGE" -a -f "$STOCKBOOT" ]; then if [ ! -z "$BOOTIMAGE" -a -f "$STOCKBOOT" ]; then
ui_print "- Restoring stock boot image" ui_print "- Restoring stock boot image"
flash_boot_image $STOCKBOOT "$BOOTIMAGE" gzip -d < $STOCKBOOT | cat - /dev/zero 2>/dev/null | dd of="$BOOTIMAGE" bs=4096 2>/dev/null
return 0 return 0
fi fi
return 1 return 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment