From 2aede97754fec67d393bde0c7725ed84d8c3c112 Mon Sep 17 00:00:00 2001 From: osm0sis Date: Tue, 21 Apr 2020 14:56:04 -0300 Subject: [PATCH] scripts: fix find_block false positives /dev/log/kernel and /dev/BOOT - try /dev/block first with full depth to catch all platform/soc variations to the by-name directory, and the new dynamic partition /dev/block/mapper - next try uevent for block devices as before - lastly try /dev with maxdepth 1 (immediate directory) to find /dev/bootimg, /dev/recovery, etc. while avoiding /dev/log/kernel - move bootimg higher in the list than boot so /dev/bootimg gets found first and avoids /dev/BOOT - recovery_a/_b now also exists - minor touch-ups for readability and consistency Fixes #2720 --- scripts/util_functions.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index ec3be90e2..d3bfc121c 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -170,24 +170,33 @@ recovery_cleanup() { # find_block [partname...] find_block() { + local BLOCK DEV DEVICE DEVNAME PARTNAME UEVENT for BLOCK in "$@"; do - DEVICE=`find /dev \( -type b -o -type c -o -type l \) -iname $BLOCK | head -n 1` 2>/dev/null + DEVICE=`find /dev/block \( -type b -o -type c -o -type l \) -iname $BLOCK | head -n 1` 2>/dev/null if [ ! -z $DEVICE ]; then readlink -f $DEVICE return 0 fi done # Fallback by parsing sysfs uevents - for uevent in /sys/dev/block/*/uevent; do - local DEVNAME=`grep_prop DEVNAME $uevent` - local PARTNAME=`grep_prop PARTNAME $uevent` + for UEVENT in /sys/dev/block/*/uevent; do + DEVNAME=`grep_prop DEVNAME $UEVENT` + PARTNAME=`grep_prop PARTNAME $UEVENT` for BLOCK in "$@"; do - if [ "`toupper $BLOCK`" = "`toupper $PARTNAME`" ]; then + if [ "$(toupper $BLOCK)" = "$(toupper $PARTNAME)" ]; then echo /dev/block/$DEVNAME return 0 fi done done + # Look just in /dev in case we're dealing with MTD/NAND without /dev/block devices/links + for DEV in "$@"; do + DEVICE=`find /dev \( -type b -o -type c -o -type l \) -maxdepth 1 -iname $DEV | head -n 1` 2>/dev/null + if [ ! -z $DEVICE ]; then + readlink -f $DEVICE + return 0 + fi + done return 1 } @@ -370,11 +379,11 @@ get_flags() { find_boot_image() { BOOTIMAGE= if $RECOVERYMODE; then - BOOTIMAGE=`find_block recovery_ramdisk$SLOT recovery sos` + BOOTIMAGE=`find_block recovery_ramdisk$SLOT recovery$SLOT sos` elif [ ! -z $SLOT ]; then BOOTIMAGE=`find_block ramdisk$SLOT recovery_ramdisk$SLOT boot$SLOT` else - BOOTIMAGE=`find_block ramdisk recovery_ramdisk kern-a android_boot kernel boot lnx bootimg boot_a` + BOOTIMAGE=`find_block ramdisk recovery_ramdisk kern-a android_boot kernel bootimg boot lnx boot_a` fi if [ -z $BOOTIMAGE ]; then # Lets see what fstabs tells me