From d1ccc6206378fe144a07fc56340408517e5a9058 Mon Sep 17 00:00:00 2001 From: CosmicDan Date: Wed, 6 Jun 2018 02:39:07 +1000 Subject: [PATCH] Repartitioning fixes Change-Id: I97fbfdd48202944fb37948189033badb350115ec --- recovery/root/tissot_manager/installer.sh | 26 ++++++++++- .../root/tissot_manager/slot_switch_helper.sh | 46 ++++++++++--------- recovery/root/tissot_manager/tools.sh | 20 ++++++++ .../META-INF/com/google/android/aroma-config | 35 +++++++++++++- recovery/twrp-res/portrait.xml | 1 + 5 files changed, 103 insertions(+), 25 deletions(-) diff --git a/recovery/root/tissot_manager/installer.sh b/recovery/root/tissot_manager/installer.sh index 0bdfb29..2bb15fb 100644 --- a/recovery/root/tissot_manager/installer.sh +++ b/recovery/root/tissot_manager/installer.sh @@ -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 @@ -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..." @@ -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 @@ -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 diff --git a/recovery/root/tissot_manager/slot_switch_helper.sh b/recovery/root/tissot_manager/slot_switch_helper.sh index 0f73a4a..83a3328 100644 --- a/recovery/root/tissot_manager/slot_switch_helper.sh +++ b/recovery/root/tissot_manager/slot_switch_helper.sh @@ -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 \ No newline at end of file diff --git a/recovery/root/tissot_manager/tools.sh b/recovery/root/tissot_manager/tools.sh index 6f334f1..ca5f1a4 100644 --- a/recovery/root/tissot_manager/tools.sh +++ b/recovery/root/tissot_manager/tools.sh @@ -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 @@ -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 diff --git a/recovery/tissot_manager_resources/META-INF/com/google/android/aroma-config b/recovery/tissot_manager_resources/META-INF/com/google/android/aroma-config index 2a7f54c..6e87c27 100644 --- a/recovery/tissot_manager_resources/META-INF/com/google/android/aroma-config +++ b/recovery/tissot_manager_resources/META-INF/com/google/android/aroma-config @@ -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"); @@ -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."); @@ -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", diff --git a/recovery/twrp-res/portrait.xml b/recovery/twrp-res/portrait.xml index 023ed0b..3ef3f79 100644 --- a/recovery/twrp-res/portrait.xml +++ b/recovery/twrp-res/portrait.xml @@ -3523,6 +3523,7 @@ {@tissot_manager=Tissot Manager} + tw_back=advanced