diff --git a/LICENSE b/LICENSE index 5b6c68220fc1..20a447ebe28b 100644 --- a/LICENSE +++ b/LICENSE @@ -75,6 +75,54 @@ busybox: GPLv2 https://github.com/osm0sis/android-busybox-ndk (pre-patched source tree used to build available upon request) +lptools_static: Apache License 2.0 +fec: Apache License 2.0 +snapshotupdater_static: Apache License 2.0 + + Copyright their respective authors, (linked below). + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Source not required, however, respective sources are provided: + https://github.com/phhusson/vendor_lptools + https://android.googlesource.com/platform/system/extras/+/master/verity/fec/ + https://github.com/capntrips/SnapshotUpdater + +httools_static: MIT License + + Copyright (c) 2022 capntrips + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + Source not required, however, respective source is provided: + https://github.com/capntrips/HashtreePatcher + ## Optional Binary Licenses: @@ -100,7 +148,7 @@ boot_signer*.jar: Apache License 2.0 https://github.com/osm0sis/mkbootfs https://github.com/osm0sis/mkbootimg https://github.com/osm0sis/mkmtkhdr - https://android.googlesource.com/platform/system/extras/+/master + https://android.googlesource.com/platform/system/extras/+/master/verity/ flash_erase, nanddump, nandwrite (mtd-utils): GPLv2 dumpimage, mkimage (U-Boot): GPLv2+ @@ -191,5 +239,5 @@ rkcrc: BSD 2-Clause License ## Additional Build Scripts for Listed Binaries (where used): osm0sis' Odds and Ends Thread - Knowledge Base: -https://forum.xda-developers.com/showthread.php?p=53554719 +https://forum.xda-developers.com/t/tools-zips-scripts-osm0sis-odds-and-ends-multiple-devices-platforms.2239421/#post-53554719 diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index 07f78e70c74c..9b321d0e6e78 100755 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -2,8 +2,8 @@ # AnyKernel3 Backend (DO NOT CHANGE) # osm0sis @ xda-developers -OUTFD=/proc/self/fd/$2; -ZIPFILE="$3"; +export OUTFD=$2; +export ZIPFILE="$3"; BOOTMODE=false; ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true; @@ -11,88 +11,101 @@ $BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMO DIR=/sdcard; $BOOTMODE || DIR=$(dirname "$ZIPFILE"); +[ $DIR == "/sideload" ] && DIR=/tmp; [ -d /postinstall/tmp ] && POSTINSTALL=/postinstall; -[ "$AKHOME" ] || AKHOME=$POSTINSTALL/tmp/anykernel; +[ "$AKHOME" ] || export AKHOME=$POSTINSTALL/tmp/anykernel; [ "$ANDROID_ROOT" ] || ANDROID_ROOT=/system; ui_print() { until [ ! "$1" ]; do echo "ui_print $1 - ui_print" >> $OUTFD; + ui_print" >> /proc/self/fd/$OUTFD; shift; done; } ui_printfile() { - while IFS='' read -r line || $BB [[ -n "$line" ]]; do - ui_print "$line"; + local line losrpad; + $BOOTMODE || [ -e /twres ] || losrpad='| '; # work around LOS Recovery eating leading whitespace + while IFS='' read -r line || [[ -n "$line" ]]; do + ui_print "$losrpad$line"; done < $1; } -show_progress() { echo "progress $1 $2" >> $OUTFD; } -file_getprop() { $BB grep "^$2=" "$1" | $BB tail -n1 | $BB cut -d= -f2-; } +show_progress() { echo "progress $1 $2" >> /proc/self/fd/$OUTFD; } +file_getprop() { grep "^$2=" "$1" | tail -n1 | cut -d= -f2-; } find_slot() { local slot=$(getprop ro.boot.slot_suffix 2>/dev/null); - [ "$slot" ] || slot=$($BB grep -o 'androidboot.slot_suffix=.*$' /proc/cmdline | $BB cut -d\ -f1 | $BB cut -d= -f2); + [ "$slot" ] || slot=$(grep -o 'androidboot.slot_suffix=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); if [ ! "$slot" ]; then slot=$(getprop ro.boot.slot 2>/dev/null); - [ "$slot" ] || slot=$($BB grep -o 'androidboot.slot=.*$' /proc/cmdline | $BB cut -d\ -f1 | $BB cut -d= -f2); + [ "$slot" ] || slot=$(grep -o 'androidboot.slot=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); [ "$slot" ] && slot=_$slot; fi; + [ "$slot" == "normal" ] && unset slot; [ "$slot" ] && echo "$slot"; } setup_mountpoint() { - [ -L $1 ] && $BB mv -f $1 ${1}_link; + [ -L $1 ] && mv -f $1 ${1}_link; if [ ! -d $1 ]; then - $BB rm -f $1; - $BB mkdir -p $1; + rm -f $1; + mkdir -p $1; fi; } -is_mounted() { $BB mount | $BB grep -q " $1 "; } +is_mounted() { mount | grep -q " $1 "; } mount_apex() { [ -d /system_root/system/apex ] || return 1; - local apex dest loop minorx num var; + local apex dest loop minorx num shcon var; setup_mountpoint /apex; - $BB mount -t tmpfs tmpfs /apex -o mode=755 && $BB touch /apex/apextmp; + mount -t tmpfs tmpfs /apex -o mode=755 && touch /apex/apextmp; + shcon=$(cat /proc/self/attr/current); + echo "u:r:su:s0" > /proc/self/attr/current 2>/dev/null; # work around LOS Recovery not allowing loop mounts in recovery context minorx=1; - [ -e /dev/block/loop1 ] && minorx=$($BB ls -l /dev/block/loop1 | $BB awk '{ print $6 }'); + [ -e /dev/block/loop1 ] && minorx=$(ls -l /dev/block/loop1 | awk '{ print $6 }'); num=0; for apex in /system_root/system/apex/*; do - dest=/apex/$($BB basename $apex | $BB sed -E -e 's;\.apex$|\.capex$;;' -e 's;\.current$|\.release$;;'); - $BB mkdir -p $dest; + dest=/apex/$(basename $apex | sed -E -e 's;\.apex$|\.capex$;;' -e 's;\.current$|\.release$;;'); + mkdir -p $dest; case $apex in *.apex|*.capex) - $BB unzip -qo $apex original_apex -d /apex; + unzip -qo $apex original_apex -d /apex; [ -f /apex/original_apex ] && apex=/apex/original_apex; - $BB unzip -qo $apex apex_payload.img -d /apex; - $BB mv -f /apex/original_apex $dest.apex 2>/dev/null; - $BB mv -f /apex/apex_payload.img $dest.img; - $BB mount -t ext4 -o ro,noatime $dest.img $dest 2>/dev/null; + unzip -qo $apex apex_payload.img -d /apex; + mv -f /apex/original_apex $dest.apex 2>/dev/null; + mv -f /apex/apex_payload.img $dest.img; + mount -t ext4 -o ro,noatime $dest.img $dest 2>/dev/null && echo "$dest (direct)" >&2; if [ $? != 0 ]; then while [ $num -lt 64 ]; do loop=/dev/block/loop$num; - [ -e $loop ] || $BB mknod $loop b 7 $((num * minorx)); - $BB losetup $loop $dest.img 2>/dev/null; + [ -e $loop ] || mknod $loop b 7 $((num * minorx)); + losetup $loop $dest.img 2>/dev/null; num=$((num + 1)); - $BB losetup $loop | $BB grep -q $dest.img && break; + losetup $loop | grep -q $dest.img && break; done; - $BB mount -t ext4 -o ro,loop,noatime $loop $dest; + mount -t ext4 -o ro,loop,noatime $loop $dest && echo "$dest (loop)" >&2; if [ $? != 0 ]; then - $BB losetup -d $loop 2>/dev/null; + losetup -d $loop 2>/dev/null; + if [ $num -eq 64 -a $(losetup -f) == "/dev/block/loop0" ]; then + echo "Aborting apex mounts due to broken environment..." >&2; + break; + fi; fi; fi; ;; - *) $BB mount -o bind $apex $dest;; + *) mount -o bind $apex $dest && echo "$dest (bind)" >&2;; esac; done; - for var in $($BB grep -o 'export .* /.*' /system_root/init.environ.rc | $BB awk '{ print $2 }'); do + echo "$shcon" > /proc/self/attr/current 2>/dev/null; + for var in $(grep -o 'export .* /.*' /system_root/init.environ.rc | awk '{ print $2 }'); do eval OLD_${var}=\$$var; done; - $($BB grep -o 'export .* /.*' /system_root/init.environ.rc | $BB sed 's; /;=/;'); unset export; + $(grep -o 'export .* /.*' /system_root/init.environ.rc | sed 's; /;=/;'); unset export; + touch /apex/apexak3; } umount_apex() { - [ -d /apex ] || return 1; + [ -f /apex/apexak3 ] || return 1; + echo "Unmounting apex..." >&2; local dest loop var; - for var in $($BB grep -o 'export .* /.*' /system_root/init.environ.rc 2>/dev/null | $BB awk '{ print $2 }'); do + for var in $(grep -o 'export .* /.*' /system_root/init.environ.rc 2>/dev/null | awk '{ print $2 }'); do if [ "$(eval echo \$OLD_$var)" ]; then eval $var=\$OLD_${var}; else @@ -100,99 +113,91 @@ umount_apex() { fi; unset OLD_${var}; done; - for dest in $($BB find /apex -type d -mindepth 1 -maxdepth 1); do - loop=$($BB mount | $BB grep $dest | $BB grep loop | $BB cut -d\ -f1); - $BB umount -l $dest; - [ "$loop" ] && $BB losetup -d $loop; + for dest in $(find /apex -type d -mindepth 1 -maxdepth 1); do + loop=$(mount | grep $dest | grep loop | cut -d\ -f1); + umount -l $dest; + losetup $loop >/dev/null 2>&1 && losetup -d $loop; done; - [ -f /apex/apextmp ] && $BB umount /apex; - $BB rm -rf /apex 2>/dev/null; + [ -f /apex/apextmp ] && umount /apex; + rm -rf /apex/apexak3 /apex 2>/dev/null; } mount_all() { local byname mount slot system; - if ! is_mounted /cache; then - $BB mount /cache 2>/dev/null && UMOUNT_CACHE=1; - fi; - if ! is_mounted /data; then - $BB mount /data && UMOUNT_DATA=1; - fi; - (for mount in /vendor /product /system_ext /persist; do - $BB mount -o ro -t auto $mount; - done) 2>/dev/null; + echo "Mounting..." >&2; + byname=bootdevice/by-name; + [ -d /dev/block/$byname ] || byname=$(find /dev/block/platform -type d -name by-name 2>/dev/null | head -n1 | cut -d/ -f4-); + [ -e /dev/block/$byname/super -a -d /dev/block/mapper ] && byname=mapper; + [ -e /dev/block/$byname/system ] || slot=$(find_slot); + for mount in /cache /data /metadata /persist; do + if ! is_mounted $mount; then + mount $mount 2>/dev/null && echo "$mount (fstab)" >&2 && UMOUNTLIST="$UMOUNTLIST $mount"; + if [ $? != 0 -a -e /dev/block/$byname$mount ]; then + setup_mountpoint $mount; + mount -o ro -t auto /dev/block/$byname$mount $mount && echo "$mount (direct)" >&2 && UMOUNTLIST="$UMOUNTLIST $mount"; + fi; + fi; + done; setup_mountpoint $ANDROID_ROOT; if ! is_mounted $ANDROID_ROOT; then - $BB mount -o ro -t auto $ANDROID_ROOT 2>/dev/null; + mount -o ro -t auto $ANDROID_ROOT 2>/dev/null && echo "$ANDROID_ROOT (\$ANDROID_ROOT)" >&2; fi; - byname=bootdevice/by-name; - [ -d /dev/block/$byname ] || byname=$($BB find /dev/block/platform -type d -name by-name 2>/dev/null | $BB head -n1 | $BB cut -d/ -f4-); - [ -d /dev/block/mapper ] && byname=mapper; - [ -e /dev/block/$byname/system ] || slot=$(find_slot); case $ANDROID_ROOT in /system_root) setup_mountpoint /system;; /system) if ! is_mounted /system && ! is_mounted /system_root; then setup_mountpoint /system_root; - $BB mount -o ro -t auto /system_root; + mount -o ro -t auto /system_root && echo "/system_root (fstab)" >&2; elif [ -f /system/system/build.prop ]; then setup_mountpoint /system_root; - $BB mount --move /system /system_root; + mount --move /system /system_root && echo "/system_root (moved)" >&2; fi; if [ $? != 0 ]; then - ($BB umount /system; - $BB umount -l /system) 2>/dev/null; - $BB mount -o ro -t auto /dev/block/$byname/system$slot /system_root; + (umount /system; + umount -l /system) 2>/dev/null; + mount -o ro -t auto /dev/block/$byname/system$slot /system_root && echo "/system_root (direct)" >&2; fi; ;; esac; [ -f /system_root/system/build.prop ] && system=/system; for mount in /vendor /product /system_ext; do - if ! is_mounted $mount && [ -L /system$mount -o -L /system_root$system$mount ]; then + mount -o ro -t auto $mount 2>/dev/null && echo "$mount (fstab)" >&2; + if [ $? != 0 ] && [ -L /system$mount -o -L /system_root$system$mount ]; then setup_mountpoint $mount; - $BB mount -o ro -t auto /dev/block/$byname$mount$slot $mount; + mount -o ro -t auto /dev/block/$byname$mount$slot $mount && echo "$mount (direct)" >&2; fi; done; if is_mounted /system_root; then mount_apex; - $BB mount -o bind /system_root$system /system; - fi; - if ! is_mounted /persist && [ -e /dev/block/bootdevice/by-name/persist ]; then - setup_mountpoint /persist; - $BB mount -o ro -t auto /dev/block/bootdevice/by-name/persist /persist; + mount -o bind /system_root$system /system && echo "/system (bind)" >&2; fi; + echo " " >&2; } umount_all() { local mount; + echo "Unmounting..." >&2; (if [ ! -d /postinstall/tmp ]; then - $BB umount /system; - $BB umount -l /system; + umount /system; + umount -l /system; fi) 2>/dev/null; umount_apex; (if [ ! -d /postinstall/tmp ]; then - $BB umount /system_root; - $BB umount -l /system_root; + umount /system_root; + umount -l /system_root; fi; - umount /vendor; # busybox umount /vendor breaks recovery on some hacky devices - umount -l /vendor; - for mount in /mnt/system /mnt/vendor /product /mnt/product /system_ext /mnt/system_ext /persist; do - $BB umount $mount; - $BB umount -l $mount; - done; - if [ "$UMOUNT_DATA" ]; then - $BB umount /data; - $BB umount -l /data; - fi; - if [ "$UMOUNT_CACHE" ]; then - $BB umount /cache; - $BB umount -l /cache; - fi) 2>/dev/null; + PATH="$OLD_PATH" umount /vendor; # busybox umount /vendor breaks recovery on some hacky devices + PATH="$OLD_PATH" umount -l /vendor; + for mount in /mnt/system /mnt/vendor /product /mnt/product /system_ext /mnt/system_ext $UMOUNTLIST; do + umount $mount; + umount -l $mount; + done) 2>/dev/null; } setup_env() { $BOOTMODE && return 1; - $BB mount -o bind /dev/urandom /dev/random; + mount -o bind /dev/urandom /dev/random; if [ -L /etc ]; then setup_mountpoint /etc; - $BB cp -af /etc_link/* /etc; - $BB sed -i 's; / ; /system_root ;' /etc/fstab; + cp -af /etc_link/* /etc; + sed -i 's; / ; /system_root ;' /etc/fstab; fi; umount_all; mount_all; @@ -203,7 +208,7 @@ setup_env() { if [ ! "$(getprop 2>/dev/null)" ]; then getprop() { local propdir propfile propval; - for propdir in / /system_root /system /vendor /product /system_ext /odm; do + for propdir in / /system_root /system /vendor /product /product/etc /system_ext/etc /odm/etc; do for propfile in default.prop build.prop; do if [ "$propval" ]; then break 2; @@ -212,15 +217,11 @@ setup_env() { fi; done; done; - if [ "$propval" ]; then - echo "$propval"; - else - echo ""; - fi; + echo "$propval"; } elif [ ! "$(getprop ro.build.type 2>/dev/null)" ]; then getprop() { - ($(which getprop) | $BB grep "$1" | $BB cut -d[ -f3 | $BB cut -d] -f1) 2>/dev/null; + ($(which getprop) | grep "$1" | cut -d[ -f3 | cut -d] -f1) 2>/dev/null; } fi; } @@ -232,27 +233,51 @@ restore_env() { [ "$OLD_LD_PRE" ] && export LD_PRELOAD=$OLD_LD_PRE; [ "$OLD_LD_CFG" ] && export LD_CONFIG_FILE=$OLD_LD_CFG; unset OLD_LD_PATH OLD_LD_PRE OLD_LD_CFG; + sleep 1; umount_all; - [ -L /etc_link ] && $BB rm -rf /etc/*; - (for dir in /etc /apex /system_root /system /vendor /product /system_ext /persist; do + [ -L /etc_link ] && rm -rf /etc/*; + (for dir in /etc /apex /system_root /system /vendor /product /system_ext /metadata /persist; do if [ -L "${dir}_link" ]; then rmdir $dir; - $BB mv -f ${dir}_link $dir; + mv -f ${dir}_link $dir; fi; done; - $BB umount -l /dev/random) 2>/dev/null; + umount -l /dev/random) 2>/dev/null; +} +setup_bb() { + local arch32 bb; + for arch32 in x86 arm; do + if [ -d $AKHOME/tools/$arch32 ]; then + bb=$AKHOME/tools/$arch32/busybox; + chmod 755 $bb; + $bb >/dev/null 2>&1; + if [ $? == 0 ]; then + $bb mv -f $AKHOME/tools/$arch32/* $AKHOME/tools; + break; + fi; + fi; + done; + bb=$AKHOME/tools/busybox; + chmod 755 $bb; + $bb chmod -R 755 tools bin; + $bb --install -s bin; } debugging() { - case $($BB basename "$ZIPFILE" .zip) in - *-debugging) - ui_print " " "Creating debugging archive in $DIR..."; - [ -f /tmp/recovery.log ] && local log=/tmp/recovery.log; - $BB tar -czf "$DIR/anykernel3-$(date +%Y-%m-%d_%H%M%S)-debug.tgz" $AKHOME $log; - ;; + local debug log path; + case $(basename "$ZIPFILE" .zip) in + *-debugging) debug=1;; esac; + for path in /tmp /cache /metadata /persist; do + [ -f $path/.ak3-debugging ] && debug=1; + done; + if [ "$debug" ]; then + ui_print " " "Creating debugging archive in $DIR..."; + [ -f /tmp/recovery.log ] && log=/tmp/recovery.log; + tar -czf "$DIR/anykernel3-$(date +%Y-%m-%d_%H%M%S)-debug.tgz" $AKHOME $log; + fi; } cleanup() { - cd $(dirname $AKHOME); + cd $AKHOME/../; rm -rf $AKHOME; } abort() { @@ -272,7 +297,7 @@ do_devicecheck() { product=$(getprop ro.build.product 2>/dev/null); vendordevice=$(getprop ro.product.vendor.device 2>/dev/null); vendorproduct=$(getprop ro.vendor.product.device 2>/dev/null); - for testname in $($BB grep '^device.name.*=' anykernel.sh | $BB cut -d= -f2-); do + for testname in $(grep '^device.name.*=' anykernel.sh | cut -d= -f2-); do for devicename in $device $product $vendordevice $vendorproduct; do if [ "$devicename" == "$testname" ]; then ui_print "$testname" " "; @@ -286,9 +311,9 @@ do_devicecheck() { fi; } int2ver() { - if $BB [ "$1" -eq "$1" ] 2>/dev/null; then + if [ "$1" -eq "$1" ] 2>/dev/null; then echo "$1.0.0"; - elif [ ! "$(echo "$1" | $BB cut -d. -f3)" ]; then + elif [ ! "$(echo "$1" | cut -d. -f3)" ]; then echo "$1.0"; else echo "$1"; @@ -298,17 +323,17 @@ do_versioncheck() { [ "$(file_getprop anykernel.sh supported.versions)" ] || return 1; local android_ver hi_ver lo_ver parsed_ver supported supported_ver; ui_print "Checking Android version..."; - supported_ver=$(file_getprop anykernel.sh supported.versions | $BB tr -d '[:space:]'); + supported_ver=$(file_getprop anykernel.sh supported.versions | tr -d '[:space:]'); android_ver=$(file_getprop /system/build.prop ro.build.version.release); parsed_ver=$(int2ver $android_ver); - if echo $supported_ver | $BB grep -q '-'; then - lo_ver=$(int2ver "$(echo $supported_ver | $BB cut -d- -f1)"); - hi_ver=$(int2ver "$(echo $supported_ver | $BB cut -d- -f2)"); - if echo -e "$hi_ver\n$lo_ver\n$parsed_ver" | $BB sort -g | $BB grep -n "$parsed_ver" | $BB grep -q '^2:'; then + if echo $supported_ver | grep -q '-'; then + lo_ver=$(int2ver "$(echo $supported_ver | cut -d- -f1)"); + hi_ver=$(int2ver "$(echo $supported_ver | cut -d- -f2)"); + if echo -e "$hi_ver\n$lo_ver\n$parsed_ver" | sort -g | grep -n "$parsed_ver" | grep -q '^2:'; then supported=1; fi; else - for ver in $(echo $supported_ver | $BB sed 's;,; ;g'); do + for ver in $(echo $supported_ver | sed 's;,; ;g'); do if [ "$(int2ver $ver)" == "$parsed_ver" ]; then supported=1; break; @@ -325,65 +350,127 @@ do_levelcheck() { [ "$(file_getprop anykernel.sh supported.patchlevels)" ] || return 1; local android_lvl hi_lvl lo_lvl parsed_lvl supported_lvl; ui_print "Checking Android security patch level..."; - supported_lvl=$(file_getprop anykernel.sh supported.patchlevels | $BB grep -oE '[0-9]{4}-[0-9]{2}|-'); + supported_lvl=$(file_getprop anykernel.sh supported.patchlevels | grep -oE '[0-9]{4}-[0-9]{2}|-'); android_lvl=$(file_getprop /system/build.prop ro.build.version.security_patch); - parsed_lvl=$(echo $android_lvl | $BB grep -oE '[0-9]{4}-[0-9]{2}'); - if echo $supported_lvl | $BB grep -q '^\-'; then + parsed_lvl=$(echo $android_lvl | grep -oE '[0-9]{4}-[0-9]{2}'); + if echo $supported_lvl | grep -q '^\-'; then lo_lvl=0000-00; - hi_lvl=$(echo $supported_lvl | $BB awk '{ print $2 }'); - elif echo $supported_lvl | $BB grep -q ' - '; then - lo_lvl=$(echo $supported_lvl | $BB awk '{ print $1 }'); - hi_lvl=$(echo $supported_lvl | $BB awk '{ print $3 }'); - elif echo $supported_lvl | $BB grep -q '\-$'; then - lo_lvl=$(echo $supported_lvl | $BB awk '{ print $1 }'); + hi_lvl=$(echo $supported_lvl | awk '{ print $2 }'); + elif echo $supported_lvl | grep -q ' - '; then + lo_lvl=$(echo $supported_lvl | awk '{ print $1 }'); + hi_lvl=$(echo $supported_lvl | awk '{ print $3 }'); + elif echo $supported_lvl | grep -q '\-$'; then + lo_lvl=$(echo $supported_lvl | awk '{ print $1 }'); hi_lvl=9999-99; fi; - if echo -e "$hi_lvl\n$lo_lvl\n$parsed_lvl" | $BB sort -g | $BB grep -n "$parsed_lvl" | $BB grep -q '^2:'; then + if echo -e "$hi_lvl\n$lo_lvl\n$parsed_lvl" | sort -g | grep -n "$parsed_lvl" | grep -q '^2:'; then ui_print "$android_lvl" " "; else abort " " "Unsupported Android security patch level. Aborting..."; fi; } +do_vendorlevelcheck() { + [ "$(file_getprop anykernel.sh supported.vendorpatchlevels)" ] || return 1; + local vendor_lvl hi_lvl lo_lvl parsed_lvl supported_lvl; + ui_print "Checking Vendor security patch level..."; + supported_lvl=$(file_getprop anykernel.sh supported.vendorpatchlevels | grep -oE '[0-9]{4}-[0-9]{2}|-'); + vendor_lvl=$(file_getprop /vendor/build.prop ro.vendor.build.security_patch); + parsed_lvl=$(echo $vendor_lvl | grep -oE '[0-9]{4}-[0-9]{2}'); + if echo $supported_lvl | grep -q '^\-'; then + lo_lvl=0000-00; + hi_lvl=$(echo $supported_lvl | awk '{ print $2 }'); + elif echo $supported_lvl | grep -q ' - '; then + lo_lvl=$(echo $supported_lvl | awk '{ print $1 }'); + hi_lvl=$(echo $supported_lvl | awk '{ print $3 }'); + elif echo $supported_lvl | grep -q '\-$'; then + lo_lvl=$(echo $supported_lvl | awk '{ print $1 }'); + hi_lvl=9999-99; + fi; + if echo -e "$hi_lvl\n$lo_lvl\n$parsed_lvl" | sort -g | grep -n "$parsed_lvl" | grep -q '^2:'; then + ui_print "$vendor_lvl" " "; + else + abort " " "Unsupported Vendor security patch level. Aborting..."; + fi; +} dump_moduleinfo() { -$BB cat < $1; +cat < $1; id=ak3-helper name=AK3 Helper Module -version=$($BB awk '{ print $3 }' $AKHOME/vertmp) $($BB grep -oE '#.[0-9]' $AKHOME/vertmp) +version=$(awk '{ print $3 }' $AKHOME/vertmp) $(grep -oE '#.[0-9]' $AKHOME/vertmp) versionCode=1 author=AnyKernel3 description=$KERNEL_STRING EOF } dump_moduleremover() { -$BB cat <<'EOF' > $1; +cat <<'EOF' > $1; #!/system/bin/sh MODDIR=${0%/*}; if [ "$(cat /proc/version)" != "$(cat $MODDIR/version)" ]; then rm -rf $MODDIR; + exit; fi; +rm -f $MODDIR/update; +. $MODDIR/post-fs-data.2.sh; EOF } do_modules() { [ "$(file_getprop anykernel.sh do.modules)" == 1 ] || return 1; - local block modcon moddir modtarget module slot umask; + local block modcon moddir modtarget module mount slot umask umountksu; if [ "$(file_getprop anykernel.sh do.systemless)" == 1 ]; then + if [ ! -d /data/adb -o ! -d /data/data/android ]; then + ui_print " " "Warning: No /data access for kernel helper systemless module!"; + return 1; + fi; cd $AKHOME/modules; - ui_print " " "Creating kernel helper Magisk module..."; - if [ -d /data/adb/magisk -a -f $AKHOME/magisk_patched ]; then + ui_print " " "Creating kernel helper systemless module..."; + if [ -d /data/adb/magisk -a -f $AKHOME/magisk_patched ] || [ -d /data/data/me.weishu.kernelsu -a -f $AKHOME/kernelsu_patched ]; then umask=$(umask); - umask 022; moddir=/data/adb/modules/ak3-helper; - $BB rm -rf $moddir; - $BB mkdir -p system $moddir; - ($BB mv -f product system; - $BB mv -f vendor system) 2>/dev/null; - $BB cp -rLf * $moddir; + # this may be the initial KernelSU install or first module so setup as needed + if [ -f $AKHOME/kernelsu_patched ]; then + umask 077; + if [ ! -f /data/adb/ksud ]; then + cp -f /data/app/*/me.weishu.kernelsu*/lib/*/libksud.so /data/adb/ksud; + chmod 755 /data/adb/ksud; + fi; + if [ ! -d /data/adb/modules ]; then + mkdir -p /data/adb/modules; + chmod 777 /data/adb/modules; + fi; + [ -d /data/adb/modules_update ] || mkdir -p /data/adb/modules_update; + [ -d /data/adb/ksu ] || mkdir -p /data/adb/ksu; + [ -f /data/adb/ksu/modules.img ] && cp -f /data/adb/ksu/modules.img /data/adb/ksu/modules_update.img; + if [ ! -f /data/adb/ksu/modules_update.img ]; then + /system/bin/make_ext4fs -b 1024 -l 256M /data/adb/ksu/modules_update.img 2>/dev/null \ + || /system/bin/mke2fs -b 1024 -t ext4 /data/adb/ksu/modules_update.img 256M; + fi; + mount -t ext4 -o rw /data/adb/ksu/modules_update.img /data/adb/modules_update && umountksu=1; + touch /data/adb/ksu/update; + umask 022; + rm -rf $moddir; + mkdir -p $moddir; + dump_moduleinfo $moddir/module.prop; + touch $moddir/update; + moddir=/data/adb/modules_update/ak3-helper; + fi; + umask 022; + rm -rf $moddir; + mkdir -p system $moddir; + (mv -f product system; + mv -f vendor system; + mv -f system_ext system; + mv -f post-fs-data.sh post-fs-data.2.sh) 2>/dev/null; + cp -rLf * $moddir; dump_moduleinfo $moddir/module.prop; dump_moduleremover $moddir/post-fs-data.sh; - $BB cp -f $AKHOME/vertmp $moddir/version; + cp -f $AKHOME/vertmp $moddir/version; + touch $moddir/update; umask $umask; + /system/bin/chcon -hR "u:object_r:system_file:s0" $moddir; + [ "$umountksu" ] && umount /data/adb/modules_update; else - ui_print "Magisk installation not found. Skipped!"; + ui_print "Magisk/KernelSU installation not found. Skipped!"; fi; else cd $AKHOME/modules; @@ -391,17 +478,19 @@ do_modules() { if [ -d /dev/block/mapper ]; then for block in system vendor product; do for slot in "" _a _b; do - $BB blockdev --setrw /dev/block/mapper/$block$slot 2>/dev/null; + blockdev --setrw /dev/block/mapper/$block$slot 2>/dev/null; done; done; fi; if [ ! -d /postinstall/tmp ]; then - $BB mount -o rw,remount -t auto /system; - ($BB mount -o rw,remount -t auto /vendor; - $BB mount -o rw,remount -t auto /product) 2>/dev/null; + for mount in /system /vendor /product; do + if is_mounted $mount; then + mount -o rw,remount -t auto $mount && echo "$mount (rw)" >&2; + fi; + done; fi; - for module in $($BB find . -name '*.ko'); do - modtarget=$POSTINSTALL$(echo $module | $BB cut -c2-); + for module in $(find . -name '*.ko'); do + modtarget=$POSTINSTALL$(echo $module | cut -c2-); if [ ! -e $modtarget ]; then case $module in */vendor/*) modcon=vendor;; @@ -410,29 +499,31 @@ do_modules() { esac; fi; if is_mounted $modtarget; then - $BB mount -o rw,remount -t auto $modtarget; + mount -o rw,remount -t auto $modtarget && echo "$modtarget (rw)" >&2; fi; - $BB mkdir -p $($BB dirname $modtarget); - $BB cp -rLf $module $modtarget; - $BB chown 0:0 $modtarget; - $BB chmod 644 $modtarget; + mkdir -p $(dirname $modtarget); + cp -rLf $module $modtarget; + chown 0:0 $modtarget; + chmod 644 $modtarget; if [ "$modcon" ]; then - chcon "u:object_r:${modcon}_file:s0" $modtarget; + /system/bin/chcon "u:object_r:${modcon}_file:s0" $modtarget; fi; if is_mounted $modtarget; then - $BB mount -o ro,remount -t auto $modtarget; + mount -o ro,remount -t auto $modtarget && echo "$modtarget (ro)" >&2; fi; done; if [ ! -d /postinstall/tmp ]; then - $BB mount -o ro,remount -t auto /system; - ($BB mount -o ro,remount -t auto /vendor; - $BB mount -o ro,remount -t auto /product) 2>/dev/null; + for mount in /system /vendor /product; do + if is_mounted $mount; then + mount -o ro,remount -t auto $mount && echo "$mount (ro)" >&2; + fi; + done; fi; fi; cd $AKHOME; } -show_progress 1.34 4; +show_progress 1.34 25; ui_print " "; cleanup; mkdir -p $AKHOME/bin; @@ -441,24 +532,12 @@ unzip -o "$ZIPFILE"; if [ $? != 0 -o ! "$(ls tools)" ]; then abort "Unzip failed. Aborting..."; fi; -for ARCH32 in x86 arm; do - if [ -d $AKHOME/tools/$ARCH32 ]; then - BB=$AKHOME/tools/$ARCH32/busybox; - chmod 755 $BB; - $BB >/dev/null 2>&1; - if [ $? == 0 ]; then - $BB mv -f $AKHOME/tools/$ARCH32/* $AKHOME/tools; - break; - fi; - fi; -done; -BB=$AKHOME/tools/busybox; -chmod 755 $BB; -$BB chmod -R 755 tools bin; -$BB --install -s bin; +setup_bb; if [ $? != 0 -o -z "$(ls bin)" ]; then abort "Busybox setup failed. Aborting..."; fi; +OLD_PATH="$PATH"; +export PATH="$AKHOME/tools:$AKHOME/bin:$PATH"; if [ -f banner ]; then ui_printfile banner; @@ -473,7 +552,7 @@ if [ -f version ]; then ui_print " "; fi; ui_print " " "AnyKernel3 by osm0sis @ xda-developers" " "; -$BB grep -oE 'AK_BASE.*' META-INF/com/google/android/updater-script >&2; +grep -oE 'AK_BASE.*' META-INF/com/google/android/updater-script >&2; ui_print " "; setup_env; @@ -481,11 +560,13 @@ setup_env; do_devicecheck; do_versioncheck; do_levelcheck; +do_vendorlevelcheck; ui_print "Installing..."; -CORE=$($BB grep -oE 'ak.*core.sh' anykernel.sh); -[ -f tools/$CORE ] || $BB ln -s $AKHOME/tools/ak*-core.sh $AKHOME/tools/$CORE; -PATH="$AKHOME/bin:$PATH" home=$AKHOME $BB ash anykernel.sh $2; +# hack to maintain support for anykernel.sh files that weren't updated correctly along with the AK core +CORE=$(grep -oE 'ak.*core.sh' anykernel.sh); +[ -f tools/$CORE ] || ln -s $AKHOME/tools/ak*-core.sh $AKHOME/tools/$CORE; +ash anykernel.sh; if [ $? != 0 ]; then abort; fi; @@ -493,10 +574,13 @@ fi; do_modules; debugging; +ui_print " "; restore_env; if [ "$(file_getprop anykernel.sh do.cleanup)" == 1 ]; then cleanup; fi; -ui_print " " " " "Done!"; +ui_print " " "Done!"; +export PATH="$OLD_PATH"; +unset OLD_PATH OUTFD ZIPFILE; diff --git a/META-INF/com/google/android/updater-script b/META-INF/com/google/android/updater-script index d9b2dec70a32..ae970e8f6800 100644 --- a/META-INF/com/google/android/updater-script +++ b/META-INF/com/google/android/updater-script @@ -3,4 +3,4 @@ # Dummy file; update-binary is a shell script (DO NOT CHANGE) # # -# AK_BASE_VERSION=20220428 +# AK_BASE_VERSION=20260225 diff --git a/README.md b/README.md index c73d3e0714bd..aacdec958238 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,19 @@ device.name3=toroplus device.name4=tuna supported.versions=6.0 - 7.1.2 supported.patchlevels=2019-07 - +supported.vendorpatchlevels=2013-07 -block=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot; -is_slot_device=0; -ramdisk_compression=auto; +BLOCK=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot; +IS_SLOT_DEVICE=0; +RAMDISK_COMPRESSION=auto; +PATCH_VBMETA_FLAG=auto; ``` __do.devicecheck=1__ specified requires at least device.name1 to be present. This should match ro.product.device, ro.build.product, ro.product.vendor.device or ro.vendor.product.device from the build.prop files for your device. There is support for as many device.name# properties as needed. You may remove any empty ones that aren't being used. __do.modules=1__ will push the .ko contents of the modules directory to the same location relative to root (/) and apply correct permissions. On A/B devices this can only be done to the active slot. -__do.systemless=1__ (with __do.modules=1__) will instead push the full contents of the modules directory to create a simple "ak3-helper" Magisk module, allowing developers to effectively replace system files, including .ko files. If the current kernel is changed then the kernel helper module automatically removes itself to prevent conflicts. +__do.systemless=1__ (with __do.modules=1__) will instead push the full contents of the modules directory to create a simple "ak3-helper" Magisk/KernelSU module, allowing developers to effectively replace system files, including .ko files. If the current kernel is changed then the kernel helper module automatically removes itself to prevent conflicts. __do.cleanup=0__ will keep the zip from removing its working directory in /tmp/anykernel (by default) - this can be useful if trying to debug in adb shell whether the patches worked correctly. @@ -41,21 +43,25 @@ __do.cleanuponabort=0__ will keep the zip from removing its working directory in __supported.versions=__ will match against ro.build.version.release from the current ROM's build.prop. It can be set to a list or range. As a list of one or more entries, e.g. `7.1.2` or `8.1.0, 9` it will look for exact matches, as a range, e.g. `7.1.2 - 9` it will check to make sure the current version falls within those limits. Whitespace optional, and supplied version values should be in the same number format they are in the build.prop value for that Android version. -__supported.patchlevels=__ will match against ro.build.version.security_patch from the current ROM's build.prop. It can be set as a closed or open-ended range of dates in the format YYYY-MM, whitespace optional, e.g. `2019-04 - 2019-06`, `2019-04 -` or `- 2019-06` where the last two examples show setting a minimum and maximum, respectively. +__supported.patchlevels=__ and __supported.vendorpatchlevels=__ will match against ro.build.version.security_patch and ro.vendor.build.security_patch, respectively, from the current system/vendor build.prop. They can be set as a closed or open-ended range of dates in the format YYYY-MM, whitespace optional, e.g. `2019-04 - 2019-06`, `2019-04 -` or `- 2019-06` where the last two examples show setting a minimum or maximum. -`block=auto` instead of a direct block filepath enables detection of the device boot partition for use with broad, device non-specific zips. Also accepts specifically `boot`, `recovery` or `vendor_boot`. +`BLOCK=auto` instead of a direct block filepath enables detection of the device boot partition for use with broad, device non-specific zips. Also accepts any partition filename (from by-name), e.g. `boot`, `recovery` or `vendor_boot`. -`is_slot_device=1` enables detection of the suffix for the active boot partition on slot-based devices and will add this to the end of the supplied `block=` path. Also accepts `auto` for use with broad, device non-specific zips. +`IS_SLOT_DEVICE=1` enables detection of the suffix for the active boot partition on slot-based devices and will add this to the end of the supplied `BLOCK=` path. Also accepts `auto` for use with broad, device non-specific zips. -`ramdisk_compression=auto` allows automatically repacking the ramdisk with the format detected during unpack. Changing `auto` to `gz`, `lzo`, `lzma`, `xz`, `bz2`, `lz4`, or `lz4-l` (for lz4 legacy) instead forces the repack as that format, and using `cpio` or `none` will (attempt to) force the repack as uncompressed. +`RAMDISK_COMPRESSION=auto` allows automatically repacking the ramdisk with the format detected during unpack. Changing `auto` to `gz`, `lzo`, `lzma`, `xz`, `bz2`, `lz4`, or `lz4-l` (for lz4 legacy) instead forces the repack as that format, and using `cpio` or `none` will (attempt to) force the repack as uncompressed. -`patch_vbmeta_flag=auto` allows automatically using the default AVBv2 vbmeta flag on repack, and use the Magisk configuration Canary 23016+. Set to `0` forces keeping whatever is in the original AVBv2 flags, and set to `1` forces patching the flag (only necessary on few devices). +`PATCH_VBMETA_FLAG=auto` allows automatically using the default AVBv2 vbmeta flag on repack, and use the Magisk configuration Canary 23016+. Set to `0` forces keeping whatever is in the original AVBv2 flags, and set to `1` forces patching the flag (only necessary on few devices). -`customdd=""` may be added to allow specifying additional dd parameters for devices that need to hack their kernel directly into a large partition like mmcblk0, or force use of dd for flashing. +`CUSTOMDD=""` may be added to allow specifying additional dd parameters for devices that need to hack their kernel directly into a large partition like mmcblk0, or force use of dd for flashing. -`slot_select=active|inactive` may be added to allow specifying the target slot. If omitted the default remains `active`. +`SLOT_SELECT=active|inactive` may be added to allow specifying the target slot. If omitted the default remains `active`. -`no_block_display=1` may be added to disable output of the detected final used partition+slot path for zips which choose to include their own custom output instead. +`NO_BLOCK_DISPLAY=1` may be added to disable output of the detected final used partition+slot path for zips which choose to include their own custom output instead. + +`NO_MAGISK_CHECK=1` may be added to disable detection of Magisk and related kernel/dtb repatching for special zips which don't require that. + +`NO_VBMETA_PARTITION_PATCH=1` may be added to skip vbmeta processing using httools, since GKI is bootable with verity/verification ON, as long as AVB is not enforced for boot stage partitions. ## // Command Methods ## ``` @@ -107,11 +113,11 @@ __"before|after"__ requires you simply specify __"before"__ or __"after"__ for t __"block|mount|fstype|options|flags"__ requires you specify which part (listed in order) of the fstab entry you want to check and alter. -_dump_boot_ and _write_boot_ are the default method of unpacking/repacking, but for more granular control, or omitting ramdisk changes entirely ("OG AK" mode), these can be separated into _split_boot; unpack_ramdisk_ and _repack_ramdisk; flash_boot_ respectively. _flash_generic_ can be used to flash an image to the corresponding partition. It is automatically included for dtbo and vendor_dlkm in _write_boot_ but can be called separately if using "OG AK" mode or creating a simple partition flashing only zip. +_dump_boot_ and _write_boot_ are the default method of unpacking/repacking, but for more granular control, or omitting ramdisk changes entirely ("OG AK" mode), these can be separated into _split_boot; unpack_ramdisk_ and _repack_ramdisk; flash_boot_ respectively. _flash_generic_ can be used to flash an image to the corresponding partition. It is automatically included for dtbo, system_dlkm and vendor_dlkm in _write_boot_ but can be called separately if using "OG AK" mode or creating a simple partition flashing only zip. -Multi-partition zips can be created by removing the ramdisk and patch folders from the zip and including instead "-files" folders named for the partition (without slot suffix), e.g. boot-files + recovery-files, or kernel-files + ramdisk-files (on some Treble devices). These then contain Image.gz, and ramdisk, patch, etc. subfolders for each partition. To setup for the next partition, simply set `block=` (without slot suffix) and `ramdisk_compression=` for the new target partition and use the _reset_ak_ command. +Multi-partition zips can be created by removing the ramdisk and patch folders from the zip and including instead "-files" folders named for the partition (without slot suffix), e.g. boot-files + recovery-files, or kernel-files + ramdisk-files (on some Treble devices). These then contain Image.gz, and ramdisk, patch, etc. subfolders for each partition. To setup for the next partition, simply set `BLOCK=` (without slot suffix) and `RAMDISK_COMPRESSION=` for the new target partition and use the _reset_ak_ command. -Similarly, multi-slot zips can be created with the normal zip layout for the active (current) slot, then resetting for the inactive slot by setting `block=` (without slot suffix) again, `slot_select=inactive` and `ramdisk_compression=` for the target slot and using the _reset_ak keep_ command, which will retain the patch and any added ramdisk files for the next slot. +Similarly, multi-slot zips can be created with the normal zip layout for the active (current) slot, then resetting for the inactive slot by setting `BLOCK=` (without slot suffix) again, `SLOT_SELECT=inactive` and `RAMDISK_COMPRESSION=` for the target slot and using the _reset_ak keep_ command, which will retain the patch and any added ramdisk files for the next slot. _backup_file_ may be used for testing to ensure ramdisk changes are made correctly, transparency for the end-user, or in a ramdisk-only "mod" zip. In the latter case _restore_file_ could also be used to create a "restore" zip to undo the changes, but should be used with caution since the underlying patched files could be changed with ROM/kernel updates. @@ -119,7 +125,7 @@ You may also use _ui_print "\"_ to write messages back to the recovery du ## // Binary Inclusion ## -The AK3 repo includes current ARM builds of `magiskboot`, `magiskpolicy` and `busybox` by default to keep the basic package small. Builds for other architectures and optional binaries (see below) are available from the latest Magisk zip, or my latest AIK-mobile and FlashIt packages, respectively, here: +The AK3 repo includes current ARM builds of `magiskboot`, `magiskpolicy`, `lptools_static`, `httools_static`, `fec`, `snapshotupdater_static` and `busybox` by default to keep the basic package small. Builds for other architectures and optional binaries (see below) are available from the latest Magisk zip, or my latest AIK-mobile and FlashIt packages, respectively, here: https://forum.xda-developers.com/t/tool-android-image-kitchen-unpack-repack-kernel-ramdisk-win-android-linux-mac.2073775/ (Android Image Kitchen thread) https://forum.xda-developers.com/t/tools-zips-scripts-osm0sis-odds-and-ends-multiple-devices-platforms.2239421/ (Odds and Ends thread) @@ -133,18 +139,18 @@ Optional supported binaries which may be placed in /tools to enable built-in exp * `elftool` (with `unpackelf`) - Sony ELF kernel.elf format support, repacking as ELF for older Sony devices * `mkmtkhdr` (with `unpackelf`) - MTK device boot image section headers support for Sony devices * `futility` + `chromeos` test keys directory - Google ChromeOS signature support -* `boot_signer-dexed.jar` + `avb` keys directory - Google Android Verified Boot 1.0 (AVBv1) signature support +* `boot_signer-dexed.jar` (deprecated) + `avb` keys directory - Google Android Verified Boot 1.0 (AVBv1) custom signature support * `rkcrc` - Rockchip KRNL ramdisk image support Optionally moving ARM builds to tools/arm and putting x86 builds in tools/x86 will enable architecture detection for use with broad, device non-specific zips. ## // Instructions ## -1. Place final kernel build product, e.g. Image.gz-dtb or zImage to name a couple, in the zip root (any separate dt, dtb or recovery_dtbo, dtbo and/or vendor_dlkm should also go here for devices that require custom ones, each will fallback to the original if not included) +1. Place final kernel build product, e.g. Image.gz-dtb or zImage to name a couple, in the zip root (any separate dt, dtb or recovery_dtbo, dtbo, system_dlkm and/or vendor_dlkm should also go here for devices that require custom ones, each will fallback to the original if not included) -2. Place any required ramdisk files in /ramdisk (/vendor_ramdisk for simple multi-partition vendor_boot support) and module files in /modules (with the full path like /modules/system/lib/modules) +2. Place any required ramdisk files in /ramdisk (/vendor_ramdisk for simple multi-partition vendor_boot v3 support) and module files in /modules (with the full path like /modules/system/lib/modules) -3. Place any required patch files (generally partial files which go with AK3 file editing commands) in /patch (/vendor_patch for simple multi-partition vendor_boot support) +3. Place any required patch files (generally partial files which go with AK3 file editing commands) in /patch (/vendor_patch for simple multi-partition vendor_boot v3 support) 4. Modify the anykernel.sh to add your kernel's name, boot partition location, permissions for any added ramdisk files, and use methods for any required ramdisk modifications (optionally, also place banner and/or version files in the root to have these displayed during flash) diff --git a/anykernel.sh b/anykernel.sh index 7906b22b6fc2..0ac823ada2be 100755 --- a/anykernel.sh +++ b/anykernel.sh @@ -1,8 +1,8 @@ -# AnyKernel3 Ramdisk Mod Script -# osm0sis @ xda-developers +### AnyKernel3 Ramdisk Mod Script +## osm0sis @ xda-developers -## AnyKernel setup -# begin properties +### AnyKernel setup +# global properties properties() { ' kernel.string=ExampleKernel by osm0sis @ xda-developers do.devicecheck=1 @@ -17,30 +17,28 @@ device.name4=tuna device.name5= supported.versions= supported.patchlevels= +supported.vendorpatchlevels= '; } # end properties -# shell variables -block=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot; -is_slot_device=0; -ramdisk_compression=auto; -patch_vbmeta_flag=auto; +### AnyKernel install +## boot files attributes +boot_attributes() { +set_perm_recursive 0 0 755 644 $RAMDISK/*; +set_perm_recursive 0 0 750 750 $RAMDISK/init* $RAMDISK/sbin; +} # end attributes -## AnyKernel methods (DO NOT CHANGE) -# import patching functions/variables - see for reference -. tools/ak3-core.sh; - - -## AnyKernel file attributes -# set permissions/ownership for included ramdisk files -set_perm_recursive 0 0 755 644 $ramdisk/*; -set_perm_recursive 0 0 750 750 $ramdisk/init* $ramdisk/sbin; +# boot shell variables +BLOCK=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot; +IS_SLOT_DEVICE=0; +RAMDISK_COMPRESSION=auto; +PATCH_VBMETA_FLAG=auto; +# import functions/variables and setup patching - see for reference (DO NOT REMOVE) +. tools/ak3-core.sh; -## AnyKernel boot install -dump_boot; - -# begin ramdisk changes +# boot install +dump_boot; # use split_boot to skip ramdisk unpack, e.g. for devices with init_boot ramdisk # init.rc backup_file init.rc; @@ -58,25 +56,66 @@ patch_fstab fstab.tuna /cache ext4 options "barrier=1" "barrier=0,nomblk_io_subm patch_fstab fstab.tuna /data ext4 options "data=ordered" "nomblk_io_submit,data=writeback"; append_file fstab.tuna "usbdisk" fstab; -# end ramdisk changes - -write_boot; +write_boot; # use flash_boot to skip ramdisk repack, e.g. for devices with init_boot ramdisk ## end boot install -# shell variables -#block=vendor_boot; -#is_slot_device=1; -#ramdisk_compression=auto; -#patch_vbmeta_flag=auto; +## init_boot files attributes +#init_boot_attributes() { +#set_perm_recursive 0 0 755 644 $RAMDISK/*; +#set_perm_recursive 0 0 750 750 $RAMDISK/init* $RAMDISK/sbin; +#} # end attributes -# reset for vendor_boot patching +# init_boot shell variables +#BLOCK=init_boot; +#IS_SLOT_DEVICE=1; +#RAMDISK_COMPRESSION=auto; +#PATCH_VBMETA_FLAG=auto; + +# reset for init_boot patching #reset_ak; +# init_boot install +#dump_boot; # unpack ramdisk since it is the new first stage init ramdisk where overlay.d must go + +#write_boot; +## end init_boot install -## AnyKernel vendor_boot install -#split_boot; # skip unpack/repack ramdisk since we don't need vendor_ramdisk access + +## vendor_kernel_boot shell variables +#BLOCK=vendor_kernel_boot; +#IS_SLOT_DEVICE=1; +#RAMDISK_COMPRESSION=auto; +#PATCH_VBMETA_FLAG=auto; + +# reset for vendor_kernel_boot patching +#reset_ak; + +# vendor_kernel_boot install +#split_boot; # skip unpack/repack ramdisk, e.g. for dtb on devices with hdr v4 and vendor_kernel_boot #flash_boot; +## end vendor_kernel_boot install + + +## vendor_boot files attributes +#vendor_boot_attributes() { +#set_perm_recursive 0 0 755 644 $RAMDISK/*; +#set_perm_recursive 0 0 750 750 $RAMDISK/init* $RAMDISK/sbin; +#} # end attributes + +# vendor_boot shell variables +#BLOCK=vendor_boot; +#IS_SLOT_DEVICE=1; +#RAMDISK_COMPRESSION=auto; +#PATCH_VBMETA_FLAG=auto; + +# reset for vendor_boot patching +#reset_ak; + +# vendor_boot install +#dump_boot; # use split_boot to skip ramdisk unpack, e.g. for dtb on devices with hdr v4 but no vendor_kernel_boot + +#write_boot; # use flash_boot to skip ramdisk repack, e.g. for dtb on devices with hdr v4 but no vendor_kernel_boot ## end vendor_boot install diff --git a/tools/ak3-core.sh b/tools/ak3-core.sh index 01e1c96d52dd..c09ca7fe2d2b 100755 --- a/tools/ak3-core.sh +++ b/tools/ak3-core.sh @@ -1,15 +1,15 @@ ### AnyKernel methods (DO NOT CHANGE) ## osm0sis @ xda-developers -OUTFD=$1; +[ "$OUTFD" ] || OUTFD=$1; # set up working directory variables -[ "$home" ] || home=$PWD; -bootimg=$home/boot.img; -bin=$home/tools; -patch=$home/patch; -ramdisk=$home/ramdisk; -split_img=$home/split_img; +[ "$AKHOME" ] || AKHOME=$PWD; +BOOTIMG=$AKHOME/boot.img; +BIN=$AKHOME/tools; +PATCH=$AKHOME/patch; +RAMDISK=$AKHOME/ramdisk; +SPLITIMG=$AKHOME/split_img; ### output/testing functions: # ui_print "" [...] @@ -65,37 +65,39 @@ set_perm_recursive() { ### dump_boot functions: # split_boot (dump and split image only) split_boot() { - local dumpfail; + local splitfail; - if [ ! -e "$(echo $block | cut -d\ -f1)" ]; then + if [ ! -e "$(echo "$BLOCK" | cut -d\ -f1)" ]; then abort "Invalid partition. Aborting..."; fi; - if [ "$(echo $block | grep ' ')" ]; then - block=$(echo $block | cut -d\ -f1); - customdd=$(echo $block | cut -d\ -f2-); - elif [ ! "$customdd" ]; then - local customdd="bs=1048576"; + if echo "$BLOCK" | grep -q ' '; then + BLOCK=$(echo "$BLOCK" | cut -d\ -f1); + CUSTOMDD=$(echo "$BLOCK" | cut -d\ -f2-); + elif [ ! "$CUSTOMDD" ]; then + CUSTOMDD="bs=1048576"; fi; - if [ -f "$bin/nanddump" ]; then - $bin/nanddump -f $bootimg $block; + if [ -f "$BIN/nanddump" ]; then + nanddump -f $BOOTIMG $BLOCK; else - dd if=$block of=$bootimg $customdd; + dd if=$BLOCK of=$BOOTIMG $CUSTOMDD; + fi; + if [ $? != 0 ]; then + abort "Dumping image failed. Aborting..."; fi; - [ $? != 0 ] && dumpfail=1; - mkdir -p $split_img; - cd $split_img; - if [ -f "$bin/unpackelf" ] && $bin/unpackelf -i $bootimg -h -q 2>/dev/null; then - if [ -f "$bin/elftool" ]; then + mkdir -p $SPLITIMG; + cd $SPLITIMG; + if [ -f "$BIN/unpackelf" ] && unpackelf -i $BOOTIMG -h -q 2>/dev/null; then + if [ -f "$BIN/elftool" ]; then mkdir elftool_out; - $bin/elftool unpack -i $bootimg -o elftool_out; + elftool unpack -i $BOOTIMG -o elftool_out; fi; - $bin/unpackelf -i $bootimg; - [ $? != 0 ] && dumpfail=1; + unpackelf -i $BOOTIMG; + [ $? != 0 ] && splitfail=1; mv -f boot.img-kernel kernel.gz; mv -f boot.img-ramdisk ramdisk.cpio.gz; mv -f boot.img-cmdline cmdline.txt 2>/dev/null; - if [ -f boot.img-dt -a ! -f "$bin/elftool" ]; then + if [ -f boot.img-dt -a ! -f "$BIN/elftool" ]; then case $(od -ta -An -N4 boot.img-dt | sed -e 's/ del//' -e 's/ //g') in QCDT|ELF) mv -f boot.img-dt dt;; *) @@ -105,11 +107,11 @@ split_boot() { ;; esac; fi; - elif [ -f "$bin/mboot" ]; then - $bin/mboot -u -f $bootimg; - elif [ -f "$bin/dumpimage" ]; then - dd bs=$(($(printf '%d\n' 0x$(hexdump -n 4 -s 12 -e '16/1 "%02x""\n"' $bootimg)) + 64)) count=1 conv=notrunc if=$bootimg of=boot-trimmed.img; - $bin/dumpimage -l boot-trimmed.img > header; + elif [ -f "$BIN/mboot" ]; then + mboot -u -f $BOOTIMG; + elif [ -f "$BIN/dumpimage" ]; then + dd bs=$(($(printf '%d\n' 0x$(hexdump -n 4 -s 12 -e '16/1 "%02x""\n"' $BOOTIMG)) + 64)) count=1 conv=notrunc if=$BOOTIMG of=boot-trimmed.img; + dumpimage -l boot-trimmed.img > header; grep "Name:" header | cut -c15- > boot.img-name; grep "Type:" header | cut -c15- | cut -d\ -f1 > boot.img-arch; grep "Type:" header | cut -c15- | cut -d\ -f2 > boot.img-os; @@ -117,35 +119,35 @@ split_boot() { grep "Type:" header | cut -d\( -f2 | cut -d\) -f1 | cut -d\ -f1 | cut -d- -f1 > boot.img-comp; grep "Address:" header | cut -c15- > boot.img-addr; grep "Point:" header | cut -c15- > boot.img-ep; - $bin/dumpimage -p 0 -o kernel.gz boot-trimmed.img; - [ $? != 0 ] && dumpfail=1; + dumpimage -p 0 -o kernel.gz boot-trimmed.img; + [ $? != 0 ] && splitfail=1; case $(cat boot.img-type) in - Multi) $bin/dumpimage -p 1 -o ramdisk.cpio.gz boot-trimmed.img;; + Multi) dumpimage -p 1 -o ramdisk.cpio.gz boot-trimmed.img;; RAMDisk) mv -f kernel.gz ramdisk.cpio.gz;; esac; - elif [ -f "$bin/rkcrc" ]; then - dd bs=4096 skip=8 iflag=skip_bytes conv=notrunc if=$bootimg of=ramdisk.cpio.gz; + elif [ -f "$BIN/rkcrc" ]; then + dd bs=4096 skip=8 iflag=skip_bytes conv=notrunc if=$BOOTIMG of=ramdisk.cpio.gz; else - $bin/magiskboot unpack -h $bootimg; + (set -o pipefail; magiskboot unpack -h $BOOTIMG 2>&1 | tee infotmp >&2); case $? in - 1) dumpfail=1;; + 1) splitfail=1;; 2) touch chromeos;; esac; fi; - if [ $? != 0 -o "$dumpfail" ]; then - abort "Dumping/splitting image failed. Aborting..."; + if [ $? != 0 -o "$splitfail" ]; then + abort "Splitting image failed. Aborting..."; fi; - cd $home; + cd $AKHOME; } # unpack_ramdisk (extract ramdisk only) unpack_ramdisk() { local comp; - cd $split_img; + cd $SPLITIMG; if [ -f ramdisk.cpio.gz ]; then - if [ -f "$bin/mkmtkhdr" ]; then + if [ -f "$BIN/mkmtkhdr" ]; then mv -f ramdisk.cpio.gz ramdisk.cpio.gz-mtk; dd bs=512 skip=1 conv=notrunc if=ramdisk.cpio.gz-mtk of=ramdisk.cpio.gz; fi; @@ -153,30 +155,30 @@ unpack_ramdisk() { fi; if [ -f ramdisk.cpio ]; then - comp=$($bin/magiskboot decompress ramdisk.cpio 2>&1 | grep -v 'raw' | sed -n 's;.*\[\(.*\)\];\1;p'); + comp=$(magiskboot decompress ramdisk.cpio 2>&1 | grep -v 'raw' | sed -n 's;.*\[\(.*\)\];\1;p'); else abort "No ramdisk found to unpack. Aborting..."; fi; if [ "$comp" ]; then mv -f ramdisk.cpio ramdisk.cpio.$comp; - $bin/magiskboot decompress ramdisk.cpio.$comp ramdisk.cpio; + magiskboot decompress ramdisk.cpio.$comp ramdisk.cpio; if [ $? != 0 ] && $comp --help 2>/dev/null; then echo "Attempting ramdisk unpack with busybox $comp..." >&2; $comp -dc ramdisk.cpio.$comp > ramdisk.cpio; fi; fi; - [ -d $ramdisk ] && mv -f $ramdisk $home/rdtmp; - mkdir -p $ramdisk; - chmod 755 $ramdisk; + [ -d $RAMDISK ] && mv -f $RAMDISK $AKHOME/rdtmp; + mkdir -p $RAMDISK; + chmod 755 $RAMDISK; - cd $ramdisk; - EXTRACT_UNSAFE_SYMLINKS=1 cpio -d -F $split_img/ramdisk.cpio -i; + cd $RAMDISK; + EXTRACT_UNSAFE_SYMLINKS=1 cpio -d -F $SPLITIMG/ramdisk.cpio -i; if [ $? != 0 -o ! "$(ls)" ]; then abort "Unpacking ramdisk failed. Aborting..."; fi; - if [ -d "$home/rdtmp" ]; then - cp -af $home/rdtmp/* .; + if [ -d "$AKHOME/rdtmp" ]; then + cp -af $AKHOME/rdtmp/* .; fi; } ### dump_boot (dump and split image, then extract ramdisk) @@ -191,31 +193,37 @@ dump_boot() { repack_ramdisk() { local comp packfail mtktype; - cd $home; - case $ramdisk_compression in - auto|"") comp=$(ls $split_img/ramdisk.cpio.* 2>/dev/null | grep -v 'mtk' | rev | cut -d. -f1 | rev);; + cd $AKHOME; + if [ "$RAMDISK_COMPRESSION" != "auto" ] && [ "$(grep HEADER_VER $SPLITIMG/infotmp | sed -n 's;.*\[\(.*\)\];\1;p')" -gt 3 ]; then + ui_print " " "Warning: Only lz4-l ramdisk compression is allowed with hdr v4+ images. Resetting to auto..."; + RAMDISK_COMPRESSION=auto; + fi; + case $RAMDISK_COMPRESSION in + auto|"") comp=$(ls $SPLITIMG/ramdisk.cpio.* 2>/dev/null | grep -v 'mtk' | rev | cut -d. -f1 | rev);; none|cpio) comp="";; gz) comp=gzip;; lzo) comp=lzop;; bz2) comp=bzip2;; lz4-l) comp=lz4_legacy;; - *) comp=$ramdisk_compression;; + *) comp=$RAMDISK_COMPRESSION;; esac; - if [ -f "$bin/mkbootfs" ]; then - $bin/mkbootfs $ramdisk > ramdisk-new.cpio; + if [ -f "$BIN/mkbootfs" ]; then + mkbootfs $RAMDISK > ramdisk-new.cpio; else - cd $ramdisk; - find . | cpio -H newc -o > $home/ramdisk-new.cpio; + cd $RAMDISK; + find . | cpio -H newc -o > $AKHOME/ramdisk-new.cpio; fi; [ $? != 0 ] && packfail=1; - cd $home; - $bin/magiskboot cpio ramdisk-new.cpio test; - magisk_patched=$?; - [ $((magisk_patched & 3)) -eq 1 ] && $bin/magiskboot cpio ramdisk-new.cpio "extract .backup/.magisk $split_img/.magisk"; + cd $AKHOME; + if [ ! "$NO_MAGISK_CHECK" ]; then + magiskboot cpio ramdisk-new.cpio test; + magisk_patched=$?; + fi; + [ "$magisk_patched" -eq 1 ] && magiskboot cpio ramdisk-new.cpio "extract .backup/.magisk $SPLITIMG/.magisk"; if [ "$comp" ]; then - $bin/magiskboot compress=$comp ramdisk-new.cpio; + magiskboot compress=$comp ramdisk-new.cpio; if [ $? != 0 ] && $comp --help 2>/dev/null; then echo "Attempting ramdisk repack with busybox $comp..." >&2; $comp -9c ramdisk-new.cpio > ramdisk-new.cpio.$comp; @@ -227,22 +235,22 @@ repack_ramdisk() { abort "Repacking ramdisk failed. Aborting..."; fi; - if [ -f "$bin/mkmtkhdr" -a -f "$split_img/boot.img-base" ]; then - mtktype=$(od -ta -An -N8 -j8 $split_img/ramdisk.cpio.gz-mtk | sed -e 's/ nul//g' -e 's/ //g' | tr '[:upper:]' '[:lower:]'); + if [ -f "$BIN/mkmtkhdr" -a -f "$SPLITIMG/boot.img-base" ]; then + mtktype=$(od -ta -An -N8 -j8 $SPLITIMG/ramdisk.cpio.gz-mtk | sed -e 's/ nul//g' -e 's/ //g' | tr '[:upper:]' '[:lower:]'); case $mtktype in - rootfs|recovery) $bin/mkmtkhdr --$mtktype ramdisk-new.cpio*;; + rootfs|recovery) mkmtkhdr --$mtktype ramdisk-new.cpio*;; esac; fi; } # flash_boot (build, sign and write image only) flash_boot() { - local varlist i kernel ramdisk fdt cmdline comp part0 part1 nocompflag signfail pk8 cert avbtype; + local varlist i kernel ramdisk fdt cmdline comp part0 part1 needskernelpatch nocompflag signfail pk8 cert avbtype; - cd $split_img; - if [ -f "$bin/mkimage" ]; then + cd $SPLITIMG; + if [ -f "$BIN/mkimage" ]; then varlist="name arch os type comp addr ep"; - elif [ -f "$bin/mkbootimg" -a -f "$bin/unpackelf" -a -f boot.img-base ]; then + elif [ -f "$BIN/mk" -a -f "$BIN/unpackelf" -a -f boot.img-base ]; then mv -f cmdline.txt boot.img-cmdline 2>/dev/null; varlist="cmdline base pagesize kernel_offset ramdisk_offset tags_offset"; fi; @@ -252,30 +260,30 @@ flash_boot() { fi; done; - cd $home; + cd $AKHOME; for i in zImage zImage-dtb Image Image-dtb Image.gz Image.gz-dtb Image.bz2 Image.bz2-dtb Image.lzo Image.lzo-dtb Image.lzma Image.lzma-dtb Image.xz Image.xz-dtb Image.lz4 Image.lz4-dtb Image.fit; do if [ -f $i ]; then - kernel=$home/$i; + kernel=$AKHOME/$i; break; fi; done; if [ "$kernel" ]; then - if [ -f "$bin/mkmtkhdr" -a -f "$split_img/boot.img-base" ]; then - $bin/mkmtkhdr --kernel $kernel; + if [ -f "$BIN/mkmtkhdr" -a -f "$SPLITIMG/boot.img-base" ]; then + mkmtkhdr --kernel $kernel; kernel=$kernel-mtk; fi; - elif [ "$(ls $split_img/kernel* 2>/dev/null)" ]; then - kernel=$(ls $split_img/kernel* | grep -v 'kernel_dtb' | tail -n1); + elif [ "$(ls $SPLITIMG/kernel* 2>/dev/null)" ]; then + kernel=$(ls $SPLITIMG/kernel* | grep -v 'kernel_dtb' | tail -n1); fi; if [ "$(ls ramdisk-new.cpio* 2>/dev/null)" ]; then - ramdisk=$home/$(ls ramdisk-new.cpio* | tail -n1); - elif [ -f "$bin/mkmtkhdr" -a -f "$split_img/boot.img-base" ]; then - ramdisk=$split_img/ramdisk.cpio.gz-mtk; + ramdisk=$AKHOME/$(ls ramdisk-new.cpio* | tail -n1); + elif [ -f "$BIN/mkmtkhdr" -a -f "$SPLITIMG/boot.img-base" ]; then + ramdisk=$SPLITIMG/ramdisk.cpio.gz-mtk; else - ramdisk=$(ls $split_img/ramdisk.cpio* 2>/dev/null | tail -n1); + ramdisk=$(ls $SPLITIMG/ramdisk.cpio* 2>/dev/null | tail -n1); fi; for fdt in dt recovery_dtbo dtb; do - for i in $home/$fdt $home/$fdt.img $split_img/$fdt; do + for i in $AKHOME/$fdt $AKHOME/$fdt.img $SPLITIMG/$fdt; do if [ -f $i ]; then eval local $fdt=$i; break; @@ -283,28 +291,28 @@ flash_boot() { done; done; - cd $split_img; - if [ -f "$bin/mkimage" ]; then + cd $SPLITIMG; + if [ -f "$BIN/mkimage" ]; then [ "$comp" == "uncompressed" ] && comp=none; part0=$kernel; case $type in Multi) part1=":$ramdisk";; RAMDisk) part0=$ramdisk;; esac; - $bin/mkimage -A $arch -O $os -T $type -C $comp -a $addr -e $ep -n "$name" -d $part0$part1 $home/boot-new.img; - elif [ -f "$bin/elftool" ]; then + mkimage -A $arch -O $os -T $type -C $comp -a $addr -e $ep -n "$name" -d $part0$part1 $AKHOME/boot-new.img; + elif [ -f "$BIN/elftool" ]; then [ "$dt" ] && dt="$dt,rpm"; [ -f cmdline.txt ] && cmdline="cmdline.txt@cmdline"; - $bin/elftool pack -o $home/boot-new.img header=elftool_out/header $kernel $ramdisk,ramdisk $dt $cmdline; - elif [ -f "$bin/mboot" ]; then + elftool pack -o $AKHOME/boot-new.img header=elftool_out/header $kernel $ramdisk,ramdisk $dt $cmdline; + elif [ -f "$BIN/mboot" ]; then cp -f $kernel kernel; cp -f $ramdisk ramdisk.cpio.gz; - $bin/mboot -d $split_img -f $home/boot-new.img; - elif [ -f "$bin/rkcrc" ]; then - $bin/rkcrc -k $ramdisk $home/boot-new.img; - elif [ -f "$bin/mkbootimg" -a -f "$bin/unpackelf" -a -f boot.img-base ]; then + mboot -d $SPLITIMG -f $AKHOME/boot-new.img; + elif [ -f "$BIN/rkcrc" ]; then + rkcrc -k $ramdisk $AKHOME/boot-new.img; + elif [ -f "$BIN/mkbootimg" -a -f "$BIN/unpackelf" -a -f boot.img-base ]; then [ "$dt" ] && dt="--dt $dt"; - $bin/mkbootimg --kernel $kernel --ramdisk $ramdisk --cmdline "$cmdline" --base $base --pagesize $pagesize --kernel_offset $kernel_offset --ramdisk_offset $ramdisk_offset --tags_offset "$tags_offset" $dt --output $home/boot-new.img; + mkbootimg --kernel $kernel --ramdisk $ramdisk --cmdline "$cmdline" --base $base --pagesize $pagesize --kernel_offset $kernel_offset --ramdisk_offset $ramdisk_offset --tags_offset "$tags_offset" $dt --output $AKHOME/boot-new.img; else [ "$kernel" ] && cp -f $kernel kernel; [ "$ramdisk" ] && cp -f $ramdisk ramdisk.cpio; @@ -314,78 +322,115 @@ flash_boot() { done; case $kernel in *Image*) - if [ ! "$magisk_patched" ]; then - $bin/magiskboot cpio ramdisk.cpio test; + if [ ! "$magisk_patched" -a ! "$NO_MAGISK_CHECK" ]; then + magiskboot cpio ramdisk.cpio test; magisk_patched=$?; fi; - if [ $((magisk_patched & 3)) -eq 1 ]; then + if [ "$magisk_patched" -eq 1 ]; then ui_print " " "Magisk detected! Patching kernel so reflashing Magisk is not necessary..."; - comp=$($bin/magiskboot decompress kernel 2>&1 | grep -vE 'raw|zimage' | sed -n 's;.*\[\(.*\)\];\1;p'); - ($bin/magiskboot split $kernel || $bin/magiskboot decompress $kernel kernel) 2>/dev/null; + comp=$(magiskboot decompress kernel 2>&1 | grep -vE 'raw|zimage' | sed -n 's;.*\[\(.*\)\];\1;p'); + (magiskboot split $kernel || magiskboot decompress $kernel kernel) >&2; + if [ $? != 0 -a "$comp" ] && $comp --help 2>/dev/null; then + echo "Attempting kernel unpack with busybox $comp..." >&2; + $comp -dc $kernel > kernel; + fi; + # legacy SAR kernel string skip_initramfs -> want_initramfs + magiskboot hexpatch kernel 736B69705F696E697472616D6673 77616E745F696E697472616D6673 && needskernelpatch=1; + if [ "$(file_getprop $AKHOME/anykernel.sh do.modules)" == 1 ] && [ "$(file_getprop $AKHOME/anykernel.sh do.systemless)" == 1 ]; then + strings kernel 2>/dev/null | grep -E -m1 'Linux version.*#' > $AKHOME/vertmp; + fi; + if [ "$needskernelpatch" ]; then + if [ "$comp" ]; then + magiskboot compress=$comp kernel kernel.$comp; + if [ $? != 0 ] && $comp --help 2>/dev/null; then + echo "Attempting kernel repack with busybox $comp..." >&2; + $comp -9c kernel > kernel.$comp; + fi; + mv -f kernel.$comp kernel; + fi; + else + echo "Restoring untouched new kernel since no patching required..." >&2; + (magiskboot split -n $kernel || cp -f $kernel kernel) >&2; + fi; + [ ! -f .magisk ] && magiskboot cpio ramdisk.cpio "extract .backup/.magisk .magisk"; + export $(cat .magisk); + for fdt in dtb extra kernel_dtb recovery_dtbo; do + [ -f $fdt ] && magiskboot dtb $fdt patch; # remove dtb verity/avb + done; + elif [ -d /data/data/me.weishu.kernelsu ] && [ "$(file_getprop $AKHOME/anykernel.sh do.modules)" == 1 ] && [ "$(file_getprop $AKHOME/anykernel.sh do.systemless)" == 1 ]; then + ui_print " " "KernelSU detected! Setting up for kernel helper module..."; + comp=$(magiskboot decompress kernel 2>&1 | grep -vE 'raw|zimage' | sed -n 's;.*\[\(.*\)\];\1;p'); + (magiskboot split $kernel || magiskboot decompress $kernel kernel) >&2; if [ $? != 0 -a "$comp" ] && $comp --help 2>/dev/null; then echo "Attempting kernel unpack with busybox $comp..." >&2; $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 -m1 'Linux version.*#' > $home/vertmp; + strings kernel > stringstmp 2>/dev/null; + if grep -q -E '^/data/adb/ksud$' stringstmp; then + touch $AKHOME/kernelsu_patched; + grep -E -m1 'Linux version.*#' stringstmp > $AKHOME/vertmp; + [ -d $RAMDISK/overlay.d ] && ui_print " " "Warning: overlay.d detected in ramdisk but not currently supported by KernelSU!"; + else + ui_print " " "Warning: No KernelSU support detected in kernel!"; fi; + rm -f stringstmp; if [ "$comp" ]; then - $bin/magiskboot compress=$comp kernel kernel.$comp; + magiskboot compress=$comp kernel kernel.$comp; if [ $? != 0 ] && $comp --help 2>/dev/null; then echo "Attempting kernel repack with busybox $comp..." >&2; $comp -9c kernel > kernel.$comp; fi; mv -f kernel.$comp kernel; fi; - [ ! -f .magisk ] && $bin/magiskboot cpio ramdisk.cpio "extract .backup/.magisk .magisk"; - export $(cat .magisk); - [ $((magisk_patched & 8)) -ne 0 ] && export TWOSTAGEINIT=true; - for fdt in dtb extra kernel_dtb recovery_dtbo; do - [ -f $fdt ] && $bin/magiskboot dtb $fdt patch; - done; else case $kernel in *-dtb) rm -f kernel_dtb;; esac; fi; - unset magisk_patched KEEPFORCEENCRYPT KEEPVERITY SHA1 TWOSTAGEINIT; # leave PATCHVBMETAFLAG set for repack + unset magisk_patched KEEPVERITY KEEPFORCEENCRYPT RECOVERYMODE PREINITDEVICE SHA1 RANDOMSEED; # leave PATCHVBMETAFLAG set for repack ;; esac; - case $ramdisk_compression in + case $RAMDISK_COMPRESSION in none|cpio) nocompflag="-n";; esac; - case $patch_vbmeta_flag in + case $PATCH_VBMETA_FLAG in auto|"") [ "$PATCHVBMETAFLAG" ] || export PATCHVBMETAFLAG=false;; 1) export PATCHVBMETAFLAG=true;; *) export PATCHVBMETAFLAG=false;; esac; - $bin/magiskboot repack $nocompflag $bootimg $home/boot-new.img; - unset PATCHVBMETAFLAG; + magiskboot repack $nocompflag $BOOTIMG $AKHOME/boot-new.img; fi; if [ $? != 0 ]; then abort "Repacking image failed. Aborting..."; fi; - [ -f .magisk ] && touch $home/magisk_patched; + [ "$PATCHVBMETAFLAG" ] && unset PATCHVBMETAFLAG; + [ -f .magisk ] && touch $AKHOME/magisk_patched; - cd $home; - if [ -f "$bin/futility" -a -d "$bin/chromeos" ]; then - if [ -f "$split_img/chromeos" ]; then + cd $AKHOME; + if [ -f "$BIN/futility" -a -d "$BIN/chromeos" ]; then + if [ -f "$SPLITIMG/chromeos" ]; then echo "Signing with CHROMEOS..." >&2; - $bin/futility vbutil_kernel --pack boot-new-signed.img --keyblock $bin/chromeos/kernel.keyblock --signprivate $bin/chromeos/kernel_data_key.vbprivk --version 1 --vmlinuz boot-new.img --bootloader $bin/chromeos/empty --config $bin/chromeos/empty --arch arm --flags 0x1; + futility vbutil_kernel --pack boot-new-signed.img --keyblock $BIN/chromeos/kernel.keyblock --signprivate $BIN/chromeos/kernel_data_key.vbprivk --version 1 --vmlinuz boot-new.img --bootloader $BIN/chromeos/empty --config $BIN/chromeos/empty --arch arm --flags 0x1; fi; [ $? != 0 ] && signfail=1; fi; - if [ -f "$bin/boot_signer-dexed.jar" -a -d "$bin/avb" ]; then - pk8=$(ls $bin/avb/*.pk8); - cert=$(ls $bin/avb/*.x509.*); - case $block in - *recovery*|*SOS*) avbtype=recovery;; + if [ -d "$BIN/avb" ]; then + pk8=$(ls $BIN/avb/*.pk8); + cert=$(ls $BIN/avb/*.x509.*); + case $BLOCK in + *recovery*|*RECOVERY*|*SOS*) avbtype=recovery;; *) avbtype=boot;; esac; - if [ "$(/system/bin/dalvikvm -Xnoimage-dex2oat -cp $bin/boot_signer-dexed.jar com.android.verity.BootSignature -verify boot.img 2>&1 | grep VALID)" ]; then - echo "Signing with AVBv1..." >&2; - /system/bin/dalvikvm -Xnoimage-dex2oat -cp $bin/boot_signer-dexed.jar com.android.verity.BootSignature /$avbtype boot-new.img $pk8 $cert boot-new-signed.img; + if [ -f "$BIN/boot_signer-dexed.jar" ]; then + if [ -f /system/bin/dalvikvm ] && [ "$(/system/bin/dalvikvm -Xnoimage-dex2oat -cp $BIN/boot_signer-dexed.jar com.android.verity.BootSignature -verify boot.img 2>&1 | grep VALID)" ]; then + echo "Signing with AVBv1 /$avbtype..." >&2; + /system/bin/dalvikvm -Xnoimage-dex2oat -cp $BIN/boot_signer-dexed.jar com.android.verity.BootSignature /$avbtype boot-new.img $pk8 $cert boot-new-signed.img; + fi; + else + if magiskboot verify boot.img; then + echo "Signing with AVBv1 /$avbtype..." >&2; + magiskboot sign /$avbtype boot-new.img $cert $pk8; + fi; fi; fi; if [ $? != 0 -o "$signfail" ]; then @@ -398,15 +443,15 @@ flash_boot() { elif [ "$(wc -c < boot-new.img)" -gt "$(wc -c < boot.img)" ]; then abort "New image larger than target partition. Aborting..."; fi; - blockdev --setrw $block 2>/dev/null; - if [ -f "$bin/flash_erase" -a -f "$bin/nandwrite" ]; then - $bin/flash_erase $block 0 0; - $bin/nandwrite -p $block boot-new.img; - elif [ "$customdd" ]; then - dd if=/dev/zero of=$block $customdd 2>/dev/null; - dd if=boot-new.img of=$block $customdd; + blockdev --setrw $BLOCK 2>/dev/null; + if [ -f "$BIN/flash_erase" -a -f "$BIN/nandwrite" ]; then + flash_erase $BLOCK 0 0; + nandwrite -p $BLOCK boot-new.img; + elif [ "$CUSTOMDD" ]; then + dd if=/dev/zero of=$BLOCK $CUSTOMDD 2>/dev/null; + dd if=boot-new.img of=$BLOCK $CUSTOMDD; else - cat boot-new.img /dev/zero > $block 2>/dev/null || true; + cat boot-new.img /dev/zero > $BLOCK 2>/dev/null || true; fi; if [ $? != 0 ]; then abort "Flashing image failed. Aborting..."; @@ -415,9 +460,9 @@ flash_boot() { # flash_generic flash_generic() { - local file img imgblock isro path; + local avb avbblock avbpath file flags img imgblock imgsz isro isunmounted path; - cd $home; + cd $AKHOME; for file in $1 $1.img; do if [ -f $file ]; then img=$file; @@ -426,8 +471,8 @@ flash_generic() { done; if [ "$img" -a ! -f ${1}_flashed ]; then - for path in /dev/block/bootdevice/by-name /dev/block/mapper; do - for file in $1 $1$slot; do + for path in /dev/block/mapper /dev/block/by-name /dev/block/bootdevice/by-name; do + for file in $1 $1$SLOT; do if [ -e $path/$file ]; then imgblock=$path/$file; break 2; @@ -437,19 +482,70 @@ flash_generic() { if [ ! "$imgblock" ]; then abort "$1 partition could not be found. Aborting..."; fi; - # TODO: add dynamic partition resizing using lptools_static instead of aborting - if [ "$(wc -c < $img)" -gt "$(wc -c < $imgblock)" ]; then + if [ ! "$NO_BLOCK_DISPLAY" ]; then + ui_print " " "$imgblock"; + fi; + if [ "$path" == "/dev/block/mapper" ]; then + avb=$(httools_static avb $1); + [ $? == 0 ] || abort "Failed to parse fstab entry for $1. Aborting..."; + if [ "$avb" ] && [ ! "$NO_VBMETA_PARTITION_PATCH" ]; then + flags=$(httools_static disable-flags); + [ $? == 0 ] || abort "Failed to parse top-level vbmeta. Aborting..."; + if [ "$flags" == "enabled" ]; then + ui_print " " "dm-verity detected! Patching $avb..."; + for avbpath in /dev/block/mapper /dev/block/by-name /dev/block/bootdevice/by-name; do + for file in $avb $avb$SLOT; do + if [ -e $avbpath/$file ]; then + avbblock=$avbpath/$file; + break 2; + fi; + done; + done; + cd $BIN; + httools_static patch $1 $AKHOME/$img $avbblock || abort "Failed to patch $1 on $avb. Aborting..."; + cd $AKHOME; + fi + fi + imgsz=$(wc -c < $img); + if [ "$imgsz" != "$(wc -c < $imgblock)" ]; then + if [ -d /postinstall/tmp -a "$SLOT_SELECT" == "inactive" ]; then + echo "Resizing $1$SLOT snapshot..." >&2; + snapshotupdater_static update $1 $imgsz || abort "Resizing $1$SLOT snapshot failed. Aborting..."; + else + echo "Removing any existing $1_ak3..." >&2; + lptools_static remove $1_ak3; + echo "Clearing any merged cow partitions..." >&2; + lptools_static clear-cow; + echo "Attempting to create $1_ak3..." >&2; + if lptools_static create $1_ak3 $imgsz; then + echo "Replacing $1$SLOT with $1_ak3..." >&2; + lptools_static unmap $1_ak3 || abort "Unmapping $1_ak3 failed. Aborting..."; + lptools_static map $1_ak3 || abort "Mapping $1_ak3 failed. Aborting..."; + lptools_static replace $1_ak3 $1$SLOT || abort "Replacing $1$SLOT failed. Aborting..."; + imgblock=/dev/block/mapper/$1_ak3; + ui_print " " "Warning: $1$SLOT replaced in super. Reboot before further logical partition operations."; + else + echo "Creating $1_ak3 failed. Attempting to resize $1$SLOT..." >&2; + httools_static umount $1 || abort "Unmounting $1 failed. Aborting..."; + if [ -e $path/$1-verity ]; then + lptools_static unmap $1-verity || abort "Unmapping $1-verity failed. Aborting..."; + fi + lptools_static unmap $1$SLOT || abort "Unmapping $1$SLOT failed. Aborting..."; + lptools_static resize $1$SLOT $imgsz || abort "Resizing $1$SLOT failed. Aborting..."; + lptools_static map $1$SLOT || abort "Mapping $1$SLOT failed. Aborting..."; + isunmounted=1; + fi + fi + fi + elif [ "$(wc -c < $img)" -gt "$(wc -c < $imgblock)" ]; then abort "New $1 image larger than $1 partition. Aborting..."; fi; isro=$(blockdev --getro $imgblock 2>/dev/null); blockdev --setrw $imgblock 2>/dev/null; - if [ ! "$no_block_display" ]; then - ui_print " " "$imgblock"; - fi; - if [ -f "$bin/flash_erase" -a -f "$bin/nandwrite" ]; then - $bin/flash_erase $imgblock 0 0; - $bin/nandwrite -p $imgblock $img; - elif [ "$customdd" ]; then + if [ -f "$BIN/flash_erase" -a -f "$BIN/nandwrite" ]; then + flash_erase $imgblock 0 0; + nandwrite -p $imgblock $img; + elif [ "$CUSTOMDD" ]; then dd if=/dev/zero of=$imgblock 2>/dev/null; dd if=$img of=$imgblock; else @@ -461,6 +557,9 @@ flash_generic() { if [ "$isro" != 0 ]; then blockdev --setro $imgblock 2>/dev/null; fi; + if [ "$isunmounted" -a "$path" == "/dev/block/mapper" ]; then + httools_static mount $1 || abort "Mounting $1 failed. Aborting..."; + fi touch ${1}_flashed; fi; } @@ -470,10 +569,12 @@ flash_dtbo() { flash_generic dtbo; } ### write_boot (repack ramdisk then build, sign and write image, vendor_dlkm and dtbo) write_boot() { - flash_generic vendor_dlkm; # TODO: move below boot once resizing is supported repack_ramdisk; flash_boot; flash_generic vendor_boot; # temporary until hdr v4 can be unpacked/repacked fully by magiskboot + flash_generic vendor_kernel_boot; # temporary until hdr v4 can be unpacked/repacked fully by magiskboot + flash_generic vendor_dlkm; + flash_generic system_dlkm; flash_generic dtbo; } ### @@ -579,7 +680,7 @@ remove_line() { # prepend_file prepend_file() { if ! grep -q "$2" $1; then - echo "$(cat $patch/$3 $1)" > $1; + echo "$(cat $PATCH/$3 $1)" > $1; fi; } @@ -593,7 +694,7 @@ insert_file() { esac; line=$((`grep -n -m1 "$4" $1 | cut -d: -f1` + offset)); sed -i "${line}s;^;\n;" $1; - sed -i "$((line - 1))r $patch/$5" $1; + sed -i "$((line - 1))r $PATCH/$5" $1; fi; } @@ -601,14 +702,14 @@ insert_file() { append_file() { if ! grep -q "$2" $1; then echo -ne "\n" >> $1; - cat $patch/$3 >> $1; + cat $PATCH/$3 >> $1; echo -ne "\n" >> $1; fi; } # replace_file replace_file() { - cp -pf $patch/$3 $1; + cp -pf $PATCH/$3 $1; chmod $2 $1; } @@ -633,22 +734,22 @@ patch_fstab() { # patch_cmdline patch_cmdline() { local cmdfile cmdtmp match; - if [ -f "$split_img/cmdline.txt" ]; then - cmdfile=$split_img/cmdline.txt; + if [ -f "$SPLITIMG/cmdline.txt" ]; then + cmdfile=$SPLITIMG/cmdline.txt; else - cmdfile=$home/cmdtmp; - grep "^cmdline=" $split_img/header | cut -d= -f2- > $cmdfile; + cmdfile=$AKHOME/cmdtmp; + grep "^cmdline=" $SPLITIMG/header | cut -d= -f2- > $cmdfile; fi; if ! grep -q "$1" $cmdfile; then cmdtmp=$(cat $cmdfile); echo "$cmdtmp $2" > $cmdfile; - sed -i -e 's; *; ;g' -e 's;[ \t]*$;;' $cmdfile; + sed -i -e 's;^[ \t]*;;' -e 's; *; ;g' -e 's;[ \t]*$;;' $cmdfile; else match=$(grep -o "$1.*$" $cmdfile | cut -d\ -f1); - sed -i -e "s;${match};${2};" -e 's; *; ;g' -e 's;[ \t]*$;;' $cmdfile; + sed -i -e "s;${match};${2};" -e 's;^[ \t]*;;' -e 's; *; ;g' -e 's;[ \t]*$;;' $cmdfile; fi; - if [ -f "$home/cmdtmp" ]; then - sed -i "s|^cmdline=.*|cmdline=$(cat $cmdfile)|" $split_img/header; + if [ -f "$AKHOME/cmdtmp" ]; then + sed -i "s|^cmdline=.*|cmdline=$(cat $cmdfile)|" $SPLITIMG/header; rm -f $cmdfile; fi; } @@ -684,24 +785,28 @@ patch_ueventd() { reset_ak() { local current i; - current=$(dirname $home/*-files/current); + # Backwards compatibility for old API + [ "$no_block_display" ] && NO_BLOCK_DISPLAY="$no_block_display"; + unset no_block_display; + + current=$(dirname $AKHOME/*-files/current); if [ -d "$current" ]; then - for i in $bootimg $home/boot-new.img; do + for i in $BOOTIMG $AKHOME/boot-new.img; do [ -e $i ] && cp -af $i $current; done; for i in $current/*; do - [ -f $i ] && rm -f $home/$(basename $i); + [ -f $i ] && rm -f $AKHOME/$(basename $i); done; fi; - [ -d $split_img ] && rm -rf $ramdisk; - rm -rf $bootimg $split_img $home/*-new* $home/*-files/current; + [ -d $SPLITIMG ] && rm -rf $RAMDISK; + rm -rf $BOOTIMG $SPLITIMG $AKHOME/*-new* $AKHOME/*-files/current; if [ "$1" == "keep" ]; then - [ -d $home/rdtmp ] && mv -f $home/rdtmp $ramdisk; + [ -d $AKHOME/rdtmp ] && mv -f $AKHOME/rdtmp $RAMDISK; else - rm -rf $patch $home/rdtmp; + rm -rf $PATCH $AKHOME/rdtmp; fi; - if [ ! "$no_block_display" ]; then + if [ ! "$NO_BLOCK_DISPLAY" ]; then ui_print " "; fi; setup_ak; @@ -709,44 +814,68 @@ reset_ak() { # setup_ak setup_ak() { - local blockfiles parttype name part mtdmount mtdpart mtdname target; - - # slot detection enabled by is_slot_device=1 or auto (from anykernel.sh) - case $is_slot_device in + local blockfiles plistboot plistinit plistreco parttype name part mtdmount mtdpart mtdname target; + + # Backwards compatibility for old API + [ "$block" ] && BLOCK="$block"; + [ "$is_slot_device" ] && IS_SLOT_DEVICE="$is_slot_device"; + [ "$ramdisk_compression" ] && RAMDISK_COMPRESSION="$ramdisk_compression"; + [ "$patch_vbmeta_flag" ] && PATCH_VBMETA_FLAG="$patch_vbmeta_flag"; + [ "$customdd" ] && CUSTOMDD="$customdd"; + [ "$slot_select" ] && SLOT_SELECT="$slot_select"; + [ "$no_block_display" ] && NO_BLOCK_DISPLAY="$no_block_display"; + [ "$no_magisk_check" ] && NO_MAGISK_CHECK="$no_magisk_check"; + unset block is_slot_device ramdisk_compression patch_vbmeta_flag customdd slot_select no_block_display no_magisk_check; + + # slot detection enabled by IS_SLOT_DEVICE=1 or auto (from anykernel.sh) + case $IS_SLOT_DEVICE in 1|auto) - slot=$(getprop ro.boot.slot_suffix 2>/dev/null); - [ "$slot" ] || slot=$(grep -o 'androidboot.slot_suffix=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); - if [ ! "$slot" ]; then - slot=$(getprop ro.boot.slot 2>/dev/null); - [ "$slot" ] || slot=$(grep -o 'androidboot.slot=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); - [ "$slot" ] && slot=_$slot; + SLOT=$(getprop ro.boot.slot_suffix 2>/dev/null); + [ "$SLOT" ] || SLOT=$(grep -o 'androidboot.slot_suffix=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); + if [ ! "$SLOT" ]; then + SLOT=$(getprop ro.boot.slot 2>/dev/null); + [ "$SLOT" ] || SLOT=$(grep -o 'androidboot.slot=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); + [ "$SLOT" ] && SLOT=_$SLOT; fi; - if [ "$slot" ]; then - if [ -d /postinstall/tmp -a ! "$slot_select" ]; then - slot_select=inactive; + [ "$SLOT" == "normal" ] && unset SLOT; + if [ "$SLOT" ]; then + if [ -d /postinstall/tmp -a ! "$SLOT_SELECT" ]; then + SLOT_SELECT=inactive; fi; - case $slot_select in + case $SLOT_SELECT in inactive) - case $slot in - _a) slot=_b;; - _b) slot=_a;; + case $SLOT in + _a) SLOT=_b;; + _b) SLOT=_a;; esac; ;; esac; fi; - if [ ! "$slot" -a "$is_slot_device" == 1 ]; then + if [ ! "$SLOT" -a "$IS_SLOT_DEVICE" == 1 ]; then abort "Unable to determine active slot. Aborting..."; fi; ;; esac; # clean up any template placeholder files - cd $home; + cd $AKHOME; rm -f modules/system/lib/modules/placeholder patch/placeholder ramdisk/placeholder; - rmdir -p modules patch ramdisk; + rmdir -p modules patch ramdisk 2>/dev/null; - # automate simple multi-partition setup for boot_img_hdr_v3 + vendor_boot - if [ -e "/dev/block/bootdevice/by-name/vendor_boot$slot" -a ! -f vendor_setup ] && [ -f dtb -o -d vendor_ramdisk -o -d vendor_patch ]; then + # automate simple multi-partition setup for hdr_v4 boot + init_boot + vendor_kernel_boot (for dtb only until magiskboot supports hdr v4 vendor_ramdisk unpack/repack) + if [ -e "/dev/block/bootdevice/by-name/init_boot$SLOT" -a -e "/dev/block/bootdevice/by-name/vendor_kernel_boot$SLOT" -a ! -f init_v4_setup ] && [ -f dtb -o -d vendor_ramdisk -o -d vendor_patch ]; then + echo "Setting up for simple automatic init_boot flashing..." >&2; + (mkdir boot-files; + mv -f Image* boot-files; + mkdir init_boot-files; + mv -f ramdisk patch init_boot-files; + mkdir vendor_kernel_boot-files; + mv -f dtb vendor_kernel_boot-files; + mv -f vendor_ramdisk vendor_kernel_boot-files/ramdisk; + mv -f vendor_patch vendor_kernel_boot-files/patch) 2>/dev/null; + touch init_v4_setup; + # automate simple multi-partition setup for hdr_v3+ boot + vendor_boot with dtb/dlkm (for v3 only until magiskboot supports hdr v4 vendor_ramdisk unpack/repack) + elif [ -e "/dev/block/bootdevice/by-name/vendor_boot$SLOT" -a ! -f vendor_v3_setup ] && [ -f dtb -o -d vendor_ramdisk -o -d vendor_patch ]; then echo "Setting up for simple automatic vendor_boot flashing..." >&2; (mkdir boot-files; mv -f Image* ramdisk patch boot-files; @@ -754,44 +883,41 @@ setup_ak() { mv -f dtb vendor_boot-files; mv -f vendor_ramdisk vendor_boot-files/ramdisk; mv -f vendor_patch vendor_boot-files/patch) 2>/dev/null; - touch vendor_setup; - fi; - - # allow multi-partition ramdisk modifying configurations (using reset_ak) - if [ "$block" ] && [ ! -d "$ramdisk" -a ! -d "$patch" ]; then - blockfiles=$home/$(basename $block)-files; - if [ "$(ls $blockfiles 2>/dev/null)" ]; then - cp -af $blockfiles/* $home; - else - mkdir $blockfiles; - fi; - touch $blockfiles/current; + touch vendor_v3_setup; fi; - # target block partition detection enabled by block=boot recovery or auto (from anykernel.sh) - case $block in - auto|"") block=boot;; - esac; - case $block in - boot|recovery|vendor_boot) - case $block in - boot) parttype="ramdisk init_boot boot BOOT LNX android_boot bootimg KERN-A kernel KERNEL";; - recovery) parttype="ramdisk_recovery recovery RECOVERY SOS android_recovery";; - vendor_boot) parttype="vendor_boot";; + # target block partition detection enabled by BLOCK= or auto (from anykernel.sh) + case $BLOCK in + /dev/*) + if [ "$SLOT" ] && [ -e "$BLOCK$SLOT" ]; then + target=$BLOCK$SLOT; + elif [ -e "$BLOCK" ]; then + target=$BLOCK; + fi; + ;; + *) + # maintain brief lists of historic matching partition type names for boot, recovery and init_boot/ramdisk + plistboot="boot BOOT LNX android_boot bootimg KERN-A kernel KERNEL"; + plistreco="recovery RECOVERY SOS android_recovery recovery_ramdisk"; + plistinit="init_boot ramdisk"; + case $BLOCK in + auto) parttype="$plistinit $plistboot";; + boot|kernel) parttype=$plistboot;; + recovery|recovery_ramdisk) parttype=$plistreco;; + init_boot|ramdisk) parttype=$plistinit;; + *) parttype=$BLOCK;; esac; for name in $parttype; do - for part in $name$slot $name; do - if [ "$(grep -w "$part" /proc/mtd 2> /dev/null)" ]; then + for part in $name$SLOT $name; do + if [ "$(grep -w "$part" /proc/mtd 2>/dev/null)" ]; then mtdmount=$(grep -w "$part" /proc/mtd); - mtdpart=$(echo $mtdmount | cut -d\" -f2); + mtdpart=$(echo "$mtdmount" | cut -d\" -f2); if [ "$mtdpart" == "$part" ]; then - mtdname=$(echo $mtdmount | cut -d: -f1); + mtdname=$(echo "$mtdmount" | cut -d: -f1); else - abort "Unable to determine mtd $block partition. Aborting..."; - fi; - if [ -e /dev/mtd/$mtdname ]; then - target=/dev/mtd/$mtdname; + abort "Unable to determine mtd $BLOCK partition. Aborting..."; fi; + [ -e /dev/mtd/$mtdname ] && target=/dev/mtd/$mtdname; elif [ -e /dev/block/by-name/$part ]; then target=/dev/block/by-name/$part; elif [ -e /dev/block/bootdevice/by-name/$part ]; then @@ -806,21 +932,32 @@ setup_ak() { [ "$target" ] && break 2; done; done; - if [ "$target" ]; then - block=$(ls $target 2>/dev/null); - else - abort "Unable to determine $block partition. Aborting..."; - fi; - ;; - *) - if [ "$slot" ]; then - [ -e "$block$slot" ] && block=$block$slot; - fi; ;; esac; - if [ ! "$no_block_display" ]; then - ui_print "$block"; + if [ "$target" ]; then + BLOCK=$(ls $target 2>/dev/null); + else + abort "Unable to determine $BLOCK partition. Aborting..."; + fi; + if [ ! "$NO_BLOCK_DISPLAY" ]; then + ui_print "$BLOCK"; + fi; + + # allow multi-partition ramdisk modifying configurations (using reset_ak) + name=$(basename $BLOCK | sed -e 's/_a$//' -e 's/_b$//'); + if [ "$BLOCK" ] && [ ! -d "$RAMDISK" -a ! -d "$PATCH" ]; then + blockfiles=$AKHOME/$name-files; + if [ "$(ls $blockfiles 2>/dev/null)" ]; then + cp -af $blockfiles/* $AKHOME; + else + mkdir $blockfiles; + fi; + touch $blockfiles/current; fi; + + # run attributes function for current block if it exists + type attributes >/dev/null 2>&1 && attributes; # backwards compatibility + type ${name}_attributes >/dev/null 2>&1 && ${name}_attributes; } ### diff --git a/tools/busybox b/tools/busybox index 0df546b295cd..fed2d543b114 100755 Binary files a/tools/busybox and b/tools/busybox differ diff --git a/tools/fec b/tools/fec new file mode 100755 index 000000000000..5507b6e43e77 Binary files /dev/null and b/tools/fec differ diff --git a/tools/httools_static b/tools/httools_static new file mode 100755 index 000000000000..574fcfb9c311 Binary files /dev/null and b/tools/httools_static differ diff --git a/tools/lptools_static b/tools/lptools_static new file mode 100755 index 000000000000..7e17e9873d81 Binary files /dev/null and b/tools/lptools_static differ diff --git a/tools/magiskboot b/tools/magiskboot index 61c1c10f4b19..56207debdf74 100755 Binary files a/tools/magiskboot and b/tools/magiskboot differ diff --git a/tools/magiskpolicy b/tools/magiskpolicy index a12ad87eed7f..503ce96bb2fa 100755 Binary files a/tools/magiskpolicy and b/tools/magiskpolicy differ diff --git a/tools/snapshotupdater_static b/tools/snapshotupdater_static new file mode 100755 index 000000000000..062a54b78400 Binary files /dev/null and b/tools/snapshotupdater_static differ