Update scripts

This commit is contained in:
topjohnwu 2020-02-08 03:26:39 -08:00
parent e5f50bb7e0
commit 4dd8d75cc0

View File

@ -135,6 +135,7 @@ recovery_cleanup() {
# Installation Related # Installation Related
####################### #######################
# find_block [partname...]
find_block() { find_block() {
for BLOCK in "$@"; do for BLOCK in "$@"; do
DEVICE=`find /dev/block -type l -iname $BLOCK | head -n 1` 2>/dev/null DEVICE=`find /dev/block -type l -iname $BLOCK | head -n 1` 2>/dev/null
@ -157,7 +158,8 @@ find_block() {
return 1 return 1
} }
setup_mountpoint() { # setup_mntpoint <mountpoint>
setup_mntpoint() {
local POINT=$1 local POINT=$1
[ -L $POINT ] && mv -f $POINT ${POINT}_link [ -L $POINT ] && mv -f $POINT ${POINT}_link
if [ ! -d $POINT ]; then if [ ! -d $POINT ]; then
@ -166,12 +168,12 @@ setup_mountpoint() {
fi fi
} }
# mount_name <partname> <mountpoint> <flag> # mount_name <partname(s)> <mountpoint> <flag>
mount_name() { mount_name() {
local PART=$1 local PART=$1
local POINT=$2 local POINT=$2
local FLAG=$3 local FLAG=$3
setup_mountpoint $POINT setup_mntpoint $POINT
is_mounted $POINT && return is_mounted $POINT && return
ui_print "- Mounting $POINT" ui_print "- Mounting $POINT"
# First try mounting with fstab # First try mounting with fstab
@ -182,6 +184,7 @@ mount_name() {
fi fi
} }
# mount_ro_ensure <partname(s)> <mountpoint>
mount_ro_ensure() { mount_ro_ensure() {
# We handle ro partitions only in recovery # We handle ro partitions only in recovery
$BOOTMODE && return $BOOTMODE && return
@ -204,7 +207,7 @@ mount_partitions() {
mount_ro_ensure "system$SLOT app$SLOT" /system mount_ro_ensure "system$SLOT app$SLOT" /system
if [ -f /system/init.rc ]; then if [ -f /system/init.rc ]; then
SYSTEM_ROOT=true SYSTEM_ROOT=true
setup_mountpoint /system_root setup_mntpoint /system_root
mount --move /system /system_root mount --move /system /system_root
mount -o bind /system_root/system /system mount -o bind /system_root/system /system
else else
@ -230,53 +233,69 @@ mount_partitions() {
fi fi
} }
# loop_setup <ext4_img>, sets LOOPDEV
loop_setup() {
unset LOOPDEV
local LOOP
local MINORX=1
[ -e /dev/block/loop1 ] && MINORX=$(stat -Lc '%T' /dev/block/loop1)
local NUM=0
while [ $NUM -lt 64 ]; do
LOOP=/dev/block/loop$NUM
[ -e $LOOP ] || mknod $LOOP b 7 $((NUM * MINORX))
if losetup $LOOP "$1" 2>/dev/null; then
LOOPDEV=$LOOP
break
fi
NUM=$((NUM + 1))
done
}
mount_apex() { mount_apex() {
[ -d /system/apex ] || return $BOOTMODE || [ ! -d /system/apex ] && return
# APEX files present; need to extract and mount the payload imgs or if already extracted, mount folders local APEX DEST
local APEX DEST LOOP MINORX NUM setup_mntpoint /apex
setup_mountpoint /apex
[ -e /dev/block/loop1 ] && MINORX=$(ls -l /dev/block/loop1 | awk '{ print $6 }') || MINORX=1
NUM=0
for APEX in /system/apex/*; do for APEX in /system/apex/*; do
DEST=/apex/$(basename $APEX .apex) DEST=/apex/$(basename $APEX .apex)
[ "$DEST" == /apex/com.android.runtime.release ] && DEST=/apex/com.android.runtime [ "$DEST" == /apex/com.android.runtime.release ] && DEST=/apex/com.android.runtime
mkdir -p $DEST mkdir -p $DEST 2>/dev/null
case $APEX in if [ -f $APEX ]; then
*.apex) # APEX APKs, extract and loop mount
unzip -qo $APEX apex_payload.img -d /apex unzip -qo $APEX apex_payload.img -d /apex
mv -f /apex/apex_payload.img $DEST.img loop_setup apex_payload.img
mount -t ext4 -o ro,noatime $DEST.img $DEST 2>/dev/null if [ ! -z $LOOPDEV ]; then
if [ $? != 0 ]; then ui_print "- Mounting $DEST"
while [ $NUM -lt 64 ]; do mount -t ext4 -o ro,noatime $LOOPDEV $DEST
LOOP=/dev/block/loop$NUM; fi
(mknod $LOOP b 7 $((NUM * MINORX)) rm -f apex_payload.img
losetup $LOOP $DEST.img) 2>/dev/null elif [ -d $APEX ]; then
NUM=$((NUM + 1)) # APEX folders, bind mount directory
losetup $LOOP | grep -q $DEST.img && break ui_print "- Mounting $DEST"
done mount -o bind $APEX $DEST
mount -t ext4 -o ro,loop,noatime $LOOP $DEST fi
if [ $? != 0 ]; then
losetup -d $LOOP 2>/dev/null
fi
fi
;;
*) mount -o bind $APEX $DEST;;
esac
done done
export ANDROID_RUNTIME_ROOT=/apex/com.android.runtime export ANDROID_RUNTIME_ROOT=/apex/com.android.runtime
export ANDROID_TZDATA_ROOT=/apex/com.android.tzdata export ANDROID_TZDATA_ROOT=/apex/com.android.tzdata
export BOOTCLASSPATH=/apex/com.android.runtime/javalib/core-oj.jar:/apex/com.android.runtime/javalib/core-libart.jar:/apex/com.android.runtime/javalib/okhttp.jar:/apex/com.android.runtime/javalib/bouncycastle.jar:/apex/com.android.runtime/javalib/apache-xml.jar:/system/framework/framework.jar:/system/framework/ext.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/android.test.base.jar:/system/framework/telephony-ext.jar:/apex/com.android.conscrypt/javalib/conscrypt.jar:/apex/com.android.media/javalib/updatable-media.jar; local APEXRJPATH=/apex/com.android.runtime/javalib
local SYSFRAME=/system/framework
export BOOTCLASSPATH=\
$APEXRJPATH/core-oj.jar:$APEXRJPATH/core-libart.jar:$APEXRJPATH/okhttp.jar:\
$APEXRJPATH/bouncycastle.jar:$APEXRJPATH/apache-xml.jar:$SYSFRAME/framework.jar:\
$SYSFRAME/ext.jar:$SYSFRAME/telephony-common.jar:$SYSFRAME/voip-common.jar:\
$SYSFRAME/ims-common.jar:$SYSFRAME/android.test.base.jar:$SYSFRAME/telephony-ext.jar:\
/apex/com.android.conscrypt/javalib/conscrypt.jar:\
/apex/com.android.media/javalib/updatable-media.jar
} }
umount_apex() { umount_apex() {
[ -d /apex ] || return [ -d /apex ] || return
local DEST LOOP local DEST SRC
for DEST in $(find /apex -type d -mindepth 1 -maxdepth 1); do for DEST in /apex/*; do
if [ -f $DEST.img ]; then [ "$DEST" = '/apex/*' ] && break
LOOP=$(mount | grep $DEST | cut -d" " -f1) SRC=$(grep $DEST /proc/mounts | awk '{ print $1 }')
fi umount -l $DEST
(umount -l $DEST; # Detach loop device just in case
losetup -d $LOOP) 2>/dev/null losetup -d $SRC 2>/dev/null
done done
rm -rf /apex rm -rf /apex
unset ANDROID_RUNTIME_ROOT unset ANDROID_RUNTIME_ROOT