Skip to content

Commit

Permalink
surya: Optimize FBE script
Browse files Browse the repository at this point in the history
  • Loading branch information
rxuglr committed Jan 28, 2023
1 parent 6fdd44e commit d1464aa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
70 changes: 34 additions & 36 deletions recovery/root/system/bin/patchfstab.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#!/system/bin/sh
#
# This script is needed to support wrappedkey and fbe v2
# Version: 1.2
# Date : 2023/01/19
# Author : brigudav
#

n=1
reclog=/tmp/recovery.log
tmpv=/tmp/vendor_fstab
fstabd=$tmpv/etc/fstab.default
fstabq=$tmpv/etc/fstab.qcom
fstabr=/system/etc/recovery.fstab

while [ $n -le 2 ]; do
send_log() {
echo "I:$1" >> $reclog
}

finish() {
sleep 1
Expand All @@ -14,40 +23,29 @@ finish() {
exit 1
}

logf=/tmp/recovery.log
tmpv=/tmp/vendor_fstab
mkdir -p $tmpv
fstabd=$tmpv/etc/fstab.default
fstabq=$tmpv/etc/fstab.qcom
fstabr=/system/etc/recovery.fstab
mount -o ro -t auto /dev/block/mapper/vendor $tmpv || true
if [ -f $fstabq ]; then
fbev2=$(grep "/userdata" ${fstabq} | grep ":v2")
echo "I:Find $fstabq" >> $logf
if [ -z "$fbev2" ]; then
echo "I:This ROM not support FBE v2. Changing flags in fstab" >> $logf
cp $fstabr.bak $fstabr
wrapv=$(grep "/userdata" ${fstabq} | grep "wrappedkey")
if [ -n "$wrapv" ]; then
echo "I:And enabled supports wrappedkey..." >> $logf
sed -i -e "s/formattable/formattable,wrappedkey/g" $fstabr
patch_fstab() {
mkdir -p $tmpv
mount -o ro -t auto /dev/block/mapper/vendor $tmpv || true

for i in $fstabq $fstabd; do
if [ -f $i ]; then
send_log "Find $i"
if [[ ! $(grep "/userdata" $i | grep ":v2") = "" ]]; then
send_log "ROM FBE v2 support..."
finish
else
send_log "Change FBE v1 support..."
cp $fstabr.bak $fstabr
if [[ ! $(grep "/userdata" $i | grep wrappedkey) = "" ]]; then
send_log "...and enabled wrappedkey."
sed -i -e "s/formattable/formattable,wrappedkey/g" $fstabr
fi
finish
fi
fi
finish
else
echo "I:This ROM with FBE v2. Continuing with the default fstab." >> $logf
finish
fi
elif [ -f $fstabd ]; then
cp $fstabr.bak $fstabr
wrap=$(grep "/userdata" ${fstabd} | grep "wrappedkey")
echo "I:Find $fstabd" >> $logf
if [ -n "$wrap" ]; then
echo "I:This ROM supports wrappedkey. Changing flags in fstab" >> $logf
sed -i -e "s/formattable/formattable,wrappedkey/g" $fstabr
fi
finish
fi
sleep 1
done
done
}

patch_fstab

exit 0
2 changes: 1 addition & 1 deletion recovery/root/system/etc/recovery.fstab.bak
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ product /product ext4 ro,barrier=1,discard
vendor /vendor ext4 ro,barrier=1,discard wait,logical
/dev/block/bootdevice/by-name/cache /cache ext4 nosuid,noatime,nodev,barrier=1 wait
/dev/block/bootdevice/by-name/metadata /metadata ext4 noatime,nosuid,nodev,discard wait,formattable
/dev/block/bootdevice/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier,inlinecrypt wait,check,formattable,fileencryption=ice,quota
/dev/block/bootdevice/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier,inlinecrypt wait,check,formattable,fileencryption=ice,reservedsize=128M,quota
/dev/block/bootdevice/by-name/misc /misc emmc defaults defaults

0 comments on commit d1464aa

Please sign in to comment.