From 75986e14d17759bddeb364a57ba0c2ce53c52c59 Mon Sep 17 00:00:00 2001 From: osm0sis Date: Fri, 13 Jul 2018 01:20:04 -0300 Subject: [PATCH] AK2: add auto detection of named block (e.g. boot, recovery) partitions (#19, #26) - search using a list of known ramdisk/kernel or recovery by-name partition names - block=auto is equivalent to block=boot - for use with broad, device non-specific AK2-based mod zips --- tools/ak2-core.sh | 68 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/tools/ak2-core.sh b/tools/ak2-core.sh index 0d1f73a..f23f008 100755 --- a/tools/ak2-core.sh +++ b/tools/ak2-core.sh @@ -503,22 +503,58 @@ if [ ! -d "$ramdisk" -a ! -d "$patch" ]; then fi; test ! -d "$ramdisk" && mkdir -p $ramdisk; -# slot detection enabled by is_slot_device=1 (from anykernel.sh) -if [ "$is_slot_device" == 1 -o "$is_slot_device" == "auto" ]; then - slot=$(getprop ro.boot.slot_suffix 2>/dev/null); - test ! "$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); - test ! "$slot" && slot=$(grep -o 'androidboot.slot=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); - test "$slot" && slot=_$slot; - fi; - if [ "$slot" ]; then - test -e "$block$slot" && block=$block$slot; - fi; - if [ $? != 0 -a "$is_slot_device" == 1 ]; then - ui_print " "; ui_print "Unable to determine active boot slot. Aborting..."; exit 1; - fi; -fi; +# 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); + test ! "$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); + test ! "$slot" && slot=$(grep -o 'androidboot.slot=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); + test "$slot" && slot=_$slot; + fi; + if [ ! "$slot" -a "$is_slot_device" == 1 ]; then + ui_print " "; ui_print "Unable to determine active boot slot. Aborting..."; exit 1; + fi; + ;; +esac; + +# target block partition detection enabled by block=boot recovery or auto (from anykernel.sh) +test "$block" == "auto" && block=boot; +case $block in + boot|recovery) + case $block in + boot) parttype="ramdisk boot BOOT LNX android_boot KERN-A kernel KERNEL";; + recovery) parttype="ramdisk_recovey recovery RECOVERY SOS android_recovery";; + esac; + for name in $parttype; do + for part in $name $name$slot; do + if [ "$(grep -w "$part" /proc/mtd 2> /dev/null)" ]; then + mtdmount=$(grep -w "$part" /proc/mtd); + mtdpart=$(echo $mtdmount | cut -d\" -f2); + if [ "$mtdpart" == "$part" ]; then + mtd=$(echo $mtdmount | cut -d: -f1); + else + ui_print " "; ui_print "Unable to determine mtd $block partition. Aborting..."; exit 1; + fi; + target=/dev/mtd/$mtd; + elif [ -e /dev/block/bootdevice/by-name/$part ]; then + target=/dev/block/bootdevice/by-name/$part; + elif [ -e /dev/block/platform/*/by-name/$part ]; then + target=/dev/block/platform/*/by-name/$part; + elif [ -e /dev/block/platform/*/*/by-name/$part ]; then + target=/dev/block/platform/*/*/by-name/$part; + fi; + test -e "$target" && break 2; + done; + done; + if [ "$target" ]; then + block=$(echo -n $target); + else + ui_print " "; ui_print "Unable to determine $block partition. Aborting..."; exit 1; + fi; + ;; +esac; ## end methods