diff options
author | osm0sis <osm0sis@outlook.com> | 2020-01-18 07:21:46 -0400 |
---|---|---|
committer | osm0sis <osm0sis@outlook.com> | 2020-01-18 07:21:46 -0400 |
commit | b37d7e225f22ce9d93e8d14a5ee711dad4848690 (patch) | |
tree | 47b67188862bf3ac554b55adabe855817b94902f | |
parent | 0a712cce0d9c8a1ef23ed5a28d31c1d5d4fa6671 (diff) |
AK3+Backend: introduce systemless kernel modules support
- with do.systemless prop enabled in anykernel.sh, will push the contents of modules/ to create a simple "ak3-helper" Magisk module, where testing on devices thus far shows it loads early enough that even replacement kernel object .ko modules will get loaded
- the ak3-helper module info is populated from the kernel.string and parsed kernel version from the kernel being flashed, and if at boot time a different kernel is detected the module automatically removes itself before being loaded to avoid conflicts
- since logical partitions and ext4-dedup on Android 10 now prevent mounting /system or /vendor rw under any circumstances, this feature gives kernel developers back the freedom they had before all this to improve kernel .ko modules, .conf files, etc. with the added bonus of it cleaning up after itself
-rwxr-xr-x | META-INF/com/google/android/update-binary | 94 | ||||
-rwxr-xr-x | tools/ak3-core.sh | 3 |
2 files changed, 69 insertions, 28 deletions
diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index aa8492b..e8d240d 100755 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -140,6 +140,24 @@ abort() { fi; exit 1; } +dump_moduleinfo() { +cat <<EOF > $1; +name=AK3 Helper Module +version=$($bb awk '{ print $3 }' $home/vertmp) $($bb grep -oE '#.[0-9]' $home/vertmp) +versionCode=1 +author=AnyKernel3 +description=$kernel_string +EOF +} +dump_moduleremover() { +cat <<EOF > $1; +#!/system/bin/sh +MODDIR=\${0%/*}; +if [ "\$(cat /proc/version)" != "\$(cat \$MODDIR/version)" ]; then + rm -rf \$MODDIR; +fi; +EOF +} show_progress 1.34 4; ui_print " "; @@ -174,7 +192,8 @@ if [ -f banner ]; then ui_print " " " "; fi; -ui_print "$(file_getprop anykernel.sh kernel.string)"; +kernel_string="$(file_getprop anykernel.sh kernel.string)"; +ui_print "$kernel_string"; if [ -f version ]; then ui_print " "; ui_printfile version; @@ -310,35 +329,54 @@ if [ $? != 0 ]; then fi; if [ "$(file_getprop anykernel.sh do.modules)" == 1 ]; then - ui_print " " "Pushing modules..."; - $bb mount -o rw,remount -t auto /system; - $bb mount -o rw,remount -t auto /vendor 2>/dev/null; - cd $home/modules; - for module in $(find . -name '*.ko'); do - modtarget=$(echo $module | $bb cut -c2-); - if [ ! -e $modtarget ]; then - case $module in - */vendor/*) modcon=vendor;; - *) modcon=system;; - esac; - fi; - if is_mounted $modtarget; then - $bb mount -o rw,remount -t auto $modtarget; + if [ "$(file_getprop anykernel.sh do.systemless)" == 1 ]; then + cd $home/modules; + ui_print " " "Creating kernel helper Magisk module..."; + if [ -d /data/adb/magisk -a -f $home/split_img/.magisk ]; then + umask 022; + moddir=/data/adb/modules/ak3-helper; + rm -rf $moddir; + mkdir -p system $moddir; + ($bb mv -f product system; + $bb mv -f vendor system) 2>/dev/null; + $bb cp -rLf * $moddir; + dump_moduleinfo $moddir/module.prop; + dump_moduleremover $moddir/post-fs-data.sh; + cp -f $home/vertmp $moddir/version; + else + ui_print "Magisk installation not found. Skipped!"; fi; - mkdir -p $(dirname $modtarget); - $bb cp -rLf $module $modtarget; - $bb chown 0:0 $modtarget; - $bb chmod 644 $modtarget; - if [ "$modcon" ]; then - chcon "u:object_r:${modcon}_file:s0" $modtarget; - fi; - if is_mounted $modtarget; then - $bb mount -o ro,remount -t auto $modtarget; - fi; - done; + else + cd $home/modules; + ui_print " " "Pushing modules..."; + $bb mount -o rw,remount -t auto /system; + $bb mount -o rw,remount -t auto /vendor 2>/dev/null; + for module in $(find . -name '*.ko'); do + modtarget=$(echo $module | $bb cut -c2-); + if [ ! -e $modtarget ]; then + case $module in + */vendor/*) modcon=vendor;; + *) modcon=system;; + esac; + fi; + if is_mounted $modtarget; then + $bb mount -o rw,remount -t auto $modtarget; + fi; + mkdir -p $(dirname $modtarget); + $bb cp -rLf $module $modtarget; + $bb chown 0:0 $modtarget; + $bb chmod 644 $modtarget; + if [ "$modcon" ]; then + chcon "u:object_r:${modcon}_file:s0" $modtarget; + fi; + if is_mounted $modtarget; then + $bb mount -o ro,remount -t auto $modtarget; + fi; + done; + $bb mount -o ro,remount -t auto /system; + $bb mount -o ro,remount -t auto /vendor 2>/dev/null; + fi; cd $home; - $bb mount -o ro,remount -t auto /system; - $bb mount -o ro,remount -t auto /vendor 2>/dev/null; fi; debugging; diff --git a/tools/ak3-core.sh b/tools/ak3-core.sh index 9822a08..9c325d0 100755 --- a/tools/ak3-core.sh +++ b/tools/ak3-core.sh @@ -326,6 +326,9 @@ flash_boot() { $comp -dc $kernel > kernel; fi; $bin/magiskboot hexpatch kernel 736B69705F696E697472616D667300 77616E745F696E697472616D667300; + if [ "$(file_getprop $home/anykernel.sh do.systemless)" == 1 ]; then + strings kernel | grep -E 'Linux version.*#' > $home/vertmp; + fi; if [ "$comp" ]; then $bin/magiskboot compress=$comp kernel kernel.$comp; if [ $? != 0 ]; then |