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
This commit is contained in:
osm0sis 2020-04-21 14:56:04 -03:00 committed by John Wu
parent 9b8a5e9bf3
commit 2aede97754

View File

@ -170,24 +170,33 @@ recovery_cleanup() {
# find_block [partname...] # find_block [partname...]
find_block() { find_block() {
local BLOCK DEV DEVICE DEVNAME PARTNAME UEVENT
for BLOCK in "$@"; do 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 if [ ! -z $DEVICE ]; then
readlink -f $DEVICE readlink -f $DEVICE
return 0 return 0
fi fi
done done
# Fallback by parsing sysfs uevents # Fallback by parsing sysfs uevents
for uevent in /sys/dev/block/*/uevent; do for UEVENT in /sys/dev/block/*/uevent; do
local DEVNAME=`grep_prop DEVNAME $uevent` DEVNAME=`grep_prop DEVNAME $UEVENT`
local PARTNAME=`grep_prop PARTNAME $uevent` PARTNAME=`grep_prop PARTNAME $UEVENT`
for BLOCK in "$@"; do for BLOCK in "$@"; do
if [ "`toupper $BLOCK`" = "`toupper $PARTNAME`" ]; then if [ "$(toupper $BLOCK)" = "$(toupper $PARTNAME)" ]; then
echo /dev/block/$DEVNAME echo /dev/block/$DEVNAME
return 0 return 0
fi fi
done done
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 return 1
} }
@ -370,11 +379,11 @@ get_flags() {
find_boot_image() { find_boot_image() {
BOOTIMAGE= BOOTIMAGE=
if $RECOVERYMODE; then if $RECOVERYMODE; then
BOOTIMAGE=`find_block recovery_ramdisk$SLOT recovery sos` BOOTIMAGE=`find_block recovery_ramdisk$SLOT recovery$SLOT sos`
elif [ ! -z $SLOT ]; then elif [ ! -z $SLOT ]; then
BOOTIMAGE=`find_block ramdisk$SLOT recovery_ramdisk$SLOT boot$SLOT` BOOTIMAGE=`find_block ramdisk$SLOT recovery_ramdisk$SLOT boot$SLOT`
else 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 fi
if [ -z $BOOTIMAGE ]; then if [ -z $BOOTIMAGE ]; then
# Lets see what fstabs tells me # Lets see what fstabs tells me