Skip to content

Commit

Permalink
Repartitioning fixes
Browse files Browse the repository at this point in the history
Change-Id: I97fbfdd48202944fb37948189033badb350115ec
  • Loading branch information
cosmicdan committed Jun 5, 2018
1 parent 9728cc9 commit d1ccc62
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 25 deletions.
26 changes: 24 additions & 2 deletions recovery/root/tissot_manager/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,29 @@ abort() { ui_print "$*"; umount /system; umount /data; exit 1; }

ui_print " ";
ui_print "[#] Unmounting all eMMC partitions..."
# This qseecomd jerk sometimes refuses to die, keeping mmcblk0 locked
stop sbinqseecomd
sleep 2
kill `pidof qseecomd`
mount | grep /dev/block/mmcblk0p | while read -r line ; do
thispart=`echo "$line" | awk '{ print $3 }'`
umount -f $thispart
sleep 0.5
done
mount | grep /dev/block/bootdevice/ | while read -r line ; do
thispart=`echo "$line" | awk '{ print $3 }'`
umount -f $thispart
sleep 0.5
done
sleep 2
blockdev --rereadpt /dev/block/mmcblk0

source /tissot_manager/constants.sh
/sbin/sh /tissot_manager/get_partition_status.sh
partition_status=$?
partition_status=`cat /tmp/partition_status`
if [ ! $partition_status -ge 0 ]; then
ui_print "[!] Error - partition status unknown! Was /tmp wiped? Aborting..."
exit 1
fi

choice=`file_getprop /tmp/aroma/choice_repartition.prop root`
if [ "$choice" == "stock" ]; then
Expand All @@ -51,6 +61,9 @@ if [ "$choice" == "stock" ]; then
sgdisk /dev/block/mmcblk0 --delete $vendor_a_partnum
ui_print "[#] Deleting vendor_b..."
sgdisk /dev/block/mmcblk0 --delete $vendor_b_partnum
sleep 1
blockdev --rereadpt /dev/block/mmcblk0
sleep 0.5
if [ "$partition_status" == "2" ]; then
# system is shrunk
ui_print "[#] Growing system_a..."
Expand Down Expand Up @@ -109,6 +122,10 @@ if [ "$choice" == "stock" ]; then
sleep 1
# Calculate the length of userdata for make_ext4fs minus 16KB (for the encryption footer reservation)
userdata_new_partlength_sectors=`echo $((userdata_partend_current-userdata_stock_partstart))`
if [ "$partition_status" == "4" ]; then
# we want the userdata_b end sector instead
userdata_new_partlength_sectors=`echo $((userdata_b_partend_current-userdata_stock_partstart))`
fi
userdata_new_partlength_bytes=`echo $((userdata_new_partlength_sectors*512))`
userdata_new_ext4size=`echo $((userdata_new_partlength_bytes-16384))`
make_ext4fs -a /data -l $userdata_new_ext4size /dev/block/mmcblk0p$userdata_partnum_current
Expand Down Expand Up @@ -220,6 +237,11 @@ elif [ "$choice" == "treble_system" ]; then
ui_print "[i] You are now ready to install a Treble ROM and/or Vendor pack. Non-Treble ROM's are now incompatible."
fi;

blockdev --rereadpt /dev/block/mmcblk0
sleep 0.2
sync /dev/block/mmcblk0
sleep 0.2

ui_print " ";
ui_print " ";
while read line || [ -n "$line" ]; do
Expand Down
46 changes: 25 additions & 21 deletions recovery/root/tissot_manager/slot_switch_helper.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
#!/sbin/sh
#

if [ "$2" != "real" ]; then
umount -f /system
umount -f /vendor
if [ -b "/dev/block/bootdevice/by-name/userdata_$1" ]; then
if [ "$2" != "real" ]; then
umount -f /system
umount -f /vendor
umount -f /sdcard
umount -f /data
$0 $1 "real" &
exit
fi

while true; do
userdata_link=`readlink /dev/block/bootdevice/by-name/userdata`
slot_suffix=`echo -n $userdata_link | tail -c 1`
if [ "$slot_suffix" = "$1" ]; then
break
fi
sleep 0.1
done

umount -f /sdcard
umount -f /data
$0 $1 "real" &
exit
fi

while true; do
userdata_link=`readlink /dev/block/bootdevice/by-name/userdata`
slot_suffix=`echo -n $userdata_link | tail -c 1`
if [ "$slot_suffix" = "$1" ]; then
break

mount /dev/block/bootdevice/by-name/userdata_$1 /data
if [ ! -d /data/media ]; then
mkdir /data/media
chmod 0770 /data/media
fi
sleep 0.1
done

mount /dev/block/bootdevice/by-name/userdata_$1 /data
if [ ! -d /data/media ]; then
mkdir /data/media
chmod 0770 /data/media
fi
mount -o bind /data/media /sdcard
fi
20 changes: 20 additions & 0 deletions recovery/root/tissot_manager/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ isHotBoot() {
fi
}

isTrebleKernel() {
if cat /sys/firmware/devicetree/base/firmware/android/fstab/vendor/fsmgr_flags | grep -Fqe "slotselect"; then
# true/success
return 0
else
# false/error
return 1
fi
}

# Checks if current slot vendor is dualboot patched or not.
# returns:
# "dualboot" for dualboot patched
Expand Down Expand Up @@ -355,10 +365,20 @@ resumeTwrp() {

if [ "$1" == "userdata_calc" ]; then
userdataCalcUsageRemainingForSlotA "$@"
exit 0
elif [ "$1" == "vendorDualbootCheck" ]; then
vendorDualbootCheck
exit 0
elif [ "$1" == "vendorDualbootPatch" ]; then
vendorDualbootPatch
exit 0
elif [ "$1" == "hasDualbootUserdata" ]; then
hasDualbootUserdata
exit $?
elif [ "$1" == "isTrebleKernel" ]; then
isTrebleKernel
exit $?
elif [ "$1" == "isHotBoot" ]; then
isHotBoot
exit $?
fi
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ if (!getvar("device") == "tissot" ) then
exit("");
endif;

# check for treble compatible kernel, abort if not
setvar("isTrebleKernel", exec("/sbin/sh", "/tissot_manager/tools.sh", "isTrebleKernel"));
if getvar("isTrebleKernel")==1 then
ini_set("text_next", "Exit");
ini_set("icon_next", "");
textbox(
"Error",
"Incompatible Kernel",
"@warning",
"Tissot Manager only contains Treble related functions, but your kernel is not Treble-ready. Cannot continue."
);
exit("");
endif;

# Abort on hotboot
setvar("isHotBoot", exec("/sbin/sh", "/tissot_manager/tools.sh", "isHotBoot"));
if getvar("isHotBoot")==0 then
ini_set("text_next", "Exit");
ini_set("icon_next", "");
textbox(
"Error",
"Unavailable on Hotboot",
"@warning",
"Tissot Manager cannot function correctly in hotboot mode. Please flash it via the installer ZIP to use."
);
exit("");
endif;

# extract common files
ziptotmp("version.prop", "version.prop");
ziptotmp("changelog.txt", "changelog.txt");
Expand Down Expand Up @@ -240,10 +268,10 @@ if prop("choice_main_menu.prop","selected")=="2" then
setvar("vendorDualbootCheck", getvar("exec_buffer"));
setvar("dualboot_subtext", "Current vendor is empty or incompatible, cannot patch.");
if getvar("vendorDualbootCheck")=="singleboot" then
setvar("dualboot_subtext", "Patch current slot vendor for <#00c>dual boot</#> support.");
setvar("dualboot_subtext", "Current slot vendor is <#c00>single boot</#>. Tap to patch for <#00c>dual boot</#>.");
endif;
if getvar("vendorDualbootCheck")=="dualboot" then
setvar("dualboot_subtext", "Revert current slot vendor dual boot back to <#c00>single boot</#> only.");
setvar("dualboot_subtext", "Current slot vendor is <#00c>dual boot</#>. Tap to revert to <#c00>single boot</#> only.");
endif;
if getvar("hasDualbootUserdata")==1 then
setvar("dualboot_subtext", "Unavailable - Userdata is not partitioned for dual boot.");
Expand Down Expand Up @@ -335,6 +363,9 @@ endif;
###################

if prop("choice_main_menu.prop", "selected") == "1" then
# cache the partition status value for install process
write("/tmp/partition_status", getvar("partition_status"));

ini_set("text_next", "Reboot TWRP");
ini_set("icon_next", "@exit");
setvar("retstatus",
Expand Down
1 change: 1 addition & 0 deletions recovery/twrp-res/portrait.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3523,6 +3523,7 @@
<placement x="%center_x%" y="%row19_y%"/>
<text>{@tissot_manager=Tissot Manager}</text>
<actions>
<action function="stopmtp"/>
<action function="set">tw_back=advanced</action>
<action function="queueclear"/>
<action function="cmd">
Expand Down

0 comments on commit d1ccc62

Please sign in to comment.