diff --git a/flash/FP4/flash_FP4_factory.sh b/flash/FP4/flash_FP4_factory.sh index 06764a1c1ed8939ae5fedf20973202bfbb23e844..608b770aac08ccae726035b0e5e0396514497b56 100755 --- a/flash/FP4/flash_FP4_factory.sh +++ b/flash/FP4/flash_FP4_factory.sh @@ -7,7 +7,7 @@ ########## ########## -# This script flashes a software release and complete wipes the device. +# This script flashes a software release and completely wipes the device. # ########## @@ -55,8 +55,7 @@ find_device() { echo "WARNING: Make sure that a ${PRODUCT} is connected." ;; 1) - echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." - + echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." DEVICE_FOUND="true" break ;; @@ -82,9 +81,38 @@ find_device() { done } +# Check if the device is properly unlocked +check_unlock_status() { + PHONE_IS_READY=true + if (fastboot getvar is-userspace 2>&1 | grep -q yes); then + echo "Info: Your phone is in fastbootD mode." + if (fastboot getvar unlocked 2>&1 | grep -q no); then + echo "Error: Your phone is still locked." + echo "Did you execute 'fastboot flashing unlock'?" + PHONE_IS_READY=false + fi + else + echo "Info: Your phone is in regular bootloader mode." + if (fastboot getvar unlocked 2>&1 | grep -q no); then + echo "Error: Your phone is still locked." + echo "Did you execute 'fastboot flashing unlock'?" + PHONE_IS_READY=false + fi + if (fastboot oem device-info 2>&1 | grep -q "critical unlocked: false"); then + echo "Error: Critical partitions are still locked." + echo "Did you execute 'fastboot flashing unlock_critical'?" + PHONE_IS_READY=false + fi + fi + + if [ "$PHONE_IS_READY" = "false" ]; then + echo "Error: Your phone is not ready for flashing yet (see above), aborting..." + exit 1 + fi +} + # Flash (or manipulate) relevant partitions flash_device() { - flash_image_ab_or_abort "${sn}" bluetooth "${IMAGES_DIR}/bluetooth.img" flash_image_ab_or_abort "${sn}" devcfg "${IMAGES_DIR}/devcfg.img" flash_image_ab_or_abort "${sn}" dsp "${IMAGES_DIR}/dsp.img" @@ -115,7 +143,6 @@ flash_device() { "$FASTBOOT_BIN" -s "${sn}" erase metadata "$FASTBOOT_BIN" -s "${sn}" --set-active=a - } # Flash an image to a partition. Abort on failure. @@ -137,7 +164,7 @@ flash_image_or_abort() { fi } -# Flash an image to both A and B slot of partition. Abort on failure. +# Flash an image to both A and B slots of a partition. Abort on failure. # Arguments: flash_image_ab_or_abort() { flash_image_or_abort "${1}" "${2}_a" "${3}" @@ -192,6 +219,9 @@ os_checks # If only one device is found $sn will store its serial number find_device +# Check if the device is properly unlocked +check_unlock_status + # Flash the device flash_device