AK3: auto kernel patch improvements

- also check patch status as part of repack_ramdisk() to avoid any issues if developer is forcing a compression format change
- get full Magisk patch status value and extract Magisk config to export correct environment variables for dtb patching
This commit is contained in:
osm0sis committed 2020-01-13 01:03:22 -04:00
1 parent bf9e9fd487
commit 23dd83d8e4
1 file changed
+13 -4
+13 -4
View File
@@ -210,6 +210,9 @@ repack_ramdisk() {
test $? != 0 && packfail=1; test $? != 0 && packfail=1;
cd $home; cd $home;
$bin/magiskboot cpio ramdisk-new.cpio test;
magisk_patched=$?;
$bin/magiskboot cpio ramdisk-new.cpio "extract .backup/.magisk $split_img/.magisk";
if [ "$comp" ]; then if [ "$comp" ]; then
$bin/magiskboot compress=$comp ramdisk-new.cpio; $bin/magiskboot compress=$comp ramdisk-new.cpio;
if [ $? != 0 ]; then if [ $? != 0 ]; then
@@ -233,7 +236,7 @@ repack_ramdisk() {
# flash_boot (build, sign and write image only) # flash_boot (build, sign and write image only)
flash_boot() { flash_boot() {
local varlist i kernel ramdisk fdt cmdline comp part0 part1 patched nocompflag signfail pk8 cert avbtype; local varlist i kernel ramdisk fdt cmdline comp part0 part1 nocompflag signfail pk8 cert avbtype;
cd $split_img; cd $split_img;
if [ -f "$bin/mkimage" ]; then if [ -f "$bin/mkimage" ]; then
@@ -302,10 +305,14 @@ flash_boot() {
test "$dt" && dt="--dt $dt"; test "$dt" && dt="--dt $dt";
$bin/mkbootimg --kernel $kernel --ramdisk $ramdisk --cmdline "$cmdline" --base $home --pagesize $pagesize --kernel_offset $kerneloff --ramdisk_offset $ramdiskoff --tags_offset "$tagsoff" $dt --output $home/boot-new.img; $bin/mkbootimg --kernel $kernel --ramdisk $ramdisk --cmdline "$cmdline" --base $home --pagesize $pagesize --kernel_offset $kerneloff --ramdisk_offset $ramdiskoff --tags_offset "$tagsoff" $dt --output $home/boot-new.img;
else else
$bin/magiskboot cpio ramdisk.cpio test || patched=1; if [ ! "$magisk_patched" ]; then
$bin/magiskboot cpio ramdisk.cpio test;
magisk_patched=$?;
$bin/magiskboot cpio ramdisk.cpio "extract .backup/.magisk .magisk";
fi;
if [ "$kernel" ]; then if [ "$kernel" ]; then
cp -f $kernel kernel; cp -f $kernel kernel;
if [ "$patched" ]; then if [ $((magisk_patched & 3)) -eq 1 ]; then
ui_print " " "Magisk detected! Patching kernel so reflashing Magisk is not necessary..."; ui_print " " "Magisk detected! Patching kernel so reflashing Magisk is not necessary...";
comp=$($bin/magiskboot decompress kernel 2>&1 | grep -v 'raw' | sed -n 's;.*\[\(.*\)\];\1;p'); comp=$($bin/magiskboot decompress kernel 2>&1 | grep -v 'raw' | sed -n 's;.*\[\(.*\)\];\1;p');
($bin/magiskboot split $kernel || $bin/magiskboot decompress $kernel kernel) 2>/dev/null; ($bin/magiskboot split $kernel || $bin/magiskboot decompress $kernel kernel) 2>/dev/null;
@@ -333,7 +340,9 @@ flash_boot() {
for i in dtb recovery_dtbo; do for i in dtb recovery_dtbo; do
test "$(eval echo \$$i)" -a -f $i && cp -f $(eval echo \$$i) $i; test "$(eval echo \$$i)" -a -f $i && cp -f $(eval echo \$$i) $i;
done; done;
if [ "$patched" ]; then if [ $((magisk_patched & 3)) -eq 1 ]; then
export $(cat .magisk);
test $((magisk_patched & 8)) -ne 0 && export TWOSTAGEINIT=true;
for fdt in dtb extra kernel_dtb recovery_dtbo; do for fdt in dtb extra kernel_dtb recovery_dtbo; do
test -f $fdt && $bin/magiskboot dtb $fdt patch; test -f $fdt && $bin/magiskboot dtb $fdt patch;
done; done;