No kernel repack if it isn't patched at all

It turns out that decompressing and recompressing the kernel is enough to break booting on many devices that use MT6763.
Fix #5124, fix #6204, fix #6566 

Co-authored-by: LoveSy <shana@zju.edu.cn>
Co-authored-by: 南宫雪珊 <vvb2060@gmail.com>
This commit is contained in:
残页 2023-02-18 07:00:14 +08:00 committed by GitHub
parent 79a85f5937
commit ae34659b26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -601,6 +601,9 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
// zImage size shall remain the same
hdr->kernel_size() = boot.hdr->kernel_size();
}
} else if (boot.hdr->kernel_size() != 0) {
xwrite(fd, boot.kernel, boot.hdr->kernel_size());
hdr->kernel_size() = boot.hdr->kernel_size();
}
if (boot.flags[ZIMAGE_KERNEL]) {
// Copy zImage tail and adjust size accordingly

View File

@ -6,7 +6,7 @@
# Usage: boot_patch.sh <bootimage>
#
# The following flags can be set in environment variables:
# KEEPVERITY, KEEPFORCEENCRYPT, PATCHVBMETAFLAG, RECOVERYMODE
# KEEPVERITY, KEEPFORCEENCRYPT, PATCHVBMETAFLAG, RECOVERYMODE, SYSTEM_ROOT
#
# This script should be placed in a directory with the following files:
#
@ -73,6 +73,7 @@ fi
[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false
[ -z $PATCHVBMETAFLAG ] && PATCHVBMETAFLAG=false
[ -z $RECOVERYMODE ] && RECOVERYMODE=false
[ -z $SYSTEM_ROOT ] && SYSTEM_ROOT=false
[ -z $ISENCRYPTED ] && ISENCRYPTED=false
export KEEPVERITY
export KEEPFORCEENCRYPT
@ -203,21 +204,28 @@ for dt in dtb kernel_dtb extra; do
done
if [ -f kernel ]; then
PATCHEDKERNEL=false
# Remove Samsung RKP
./magiskboot hexpatch kernel \
49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054 \
&& PATCHEDKERNEL=true
# Remove Samsung defex
# Before: [mov w2, #-221] (-__NR_execve)
# After: [mov w2, #-32768]
./magiskboot hexpatch kernel 821B8012 E2FF8F12
./magiskboot hexpatch kernel 821B8012 E2FF8F12 && PATCHEDKERNEL=true
# Force kernel to load rootfs
# Force kernel to load rootfs for legacy SAR devices
# skip_initramfs -> want_initramfs
./magiskboot hexpatch kernel \
$SYSTEM_ROOT && ./magiskboot hexpatch kernel \
736B69705F696E697472616D667300 \
77616E745F696E697472616D667300
77616E745F696E697472616D667300 \
&& PATCHEDKERNEL=true
# If the kernel doesn't need to be patched at all,
# keep raw kernel to avoid bootloops on some weird devices
$PATCHEDKERNEL || rm -f kernel
fi
#################