Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6205e11a authored by Rohit Sekhar's avatar Rohit Sekhar
Browse files

Merge branch '8171-t-FP5_flash_script' into 'v1-t'

flash_FP5_factory.sh Check if phone is unlocked

See merge request !147
parents 4e0f92d9 8ad62f55
Loading
Loading
Loading
Loading
Loading
+36 −6
Original line number Diff line number Diff line
@@ -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.
#
##########

@@ -56,7 +56,6 @@ find_device() {
        ;;
      1)
        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"
@@ -117,7 +145,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.
@@ -139,7 +166,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: <device serial number> <partition name without slot> <image file>
flash_image_ab_or_abort() {
  flash_image_or_abort "${1}" "${2}_a" "${3}"
@@ -190,6 +217,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
# Reboot device