diff --git a/flash/Android.mk b/flash/Android.mk index f6e471191cc671cb350d61867d5a188c6dc0b91d..a4a836d01b29257cc4fa5418ef78446554234a33 100644 --- a/flash/Android.mk +++ b/flash/Android.mk @@ -19,9 +19,11 @@ INSTALLED_HLOS_IMAGES_TARGET := $(addprefix $(PRODUCT_OUT)/,$(HLOS_IMAGES_TARGET INCLUDE_IN_IMG_PACKAGE += $(INSTALLED_HLOS_IMAGES_TARGET) ifneq (,$(wildcard $(LOCAL_PATH)/$(TARGET_DEVICE)/flash_$(TARGET_DEVICE)_factory.sh)) +INCLUDE_IN_IMG_PACKAGE += $(LOCAL_PATH)/factory.common INCLUDE_IN_IMG_PACKAGE += $(LOCAL_PATH)/$(TARGET_DEVICE)/flash_$(TARGET_DEVICE)_factory.sh INCLUDE_IN_IMG_PACKAGE += $(LOCAL_PATH)/fastboot/bin-msys INCLUDE_IN_IMG_PACKAGE += $(LOCAL_PATH)/fastboot/bin-linux-x86 +INCLUDE_IN_IMG_PACKAGE += $(LOCAL_PATH)/fastboot/bin-darwin endif $(INSTALLED_IMG_PACKAGE_TARGET): $(INCLUDE_IN_IMG_PACKAGE) $(INSTALLED_RADIOIMAGE_TARGET) $(SOONG_ZIP) diff --git a/flash/FP3/flash_FP3_factory.sh b/flash/FP3/flash_FP3_factory.sh index 71c9b995137f9a9ab21237ae5a9840a83daac31f..355b3f0c3435015b530ec13d99455f0ec91d3950 100755 --- a/flash/FP3/flash_FP3_factory.sh +++ b/flash/FP3/flash_FP3_factory.sh @@ -1,221 +1,19 @@ #!/usr/bin/env bash -########## -# This script is created and maintained by -# Bharath(@teamb58).org -# Feel free to connect for any queries or suggestions. -########## - -########## -# This script flashes a software release and complete wipes the device. -# -# The script wipes both user data and the Google factory reset protection -# information. It will unlock the phone, delete the data, and re-lock it. -########## - -set -e -set -u - -CLEAN_FLASH="true" # Control data wipe behavior. Default is "true". - # Target device info PRODUCT="Fairphone 3" PRODUCT_ID="FP3" -# Paths/files -ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -IMAGES_DIR="${ROOT_DIR}" - -# Abort the script (and wait for a key to be pressed). -abort_now() { - echo "" - read -rp "ERROR: Aborting now (press Enter to terminate)." a - exit 1 -} - -# Check for connected phone -find_device() { - echo "INFO: Looking for connected device(s)..." - DEVICE_FOUND="false" - while [ ${DEVICE_FOUND} = "false" ] - do - serial_numbers= - - for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+') - do - # Checking the product ID - PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1) - # Add serial, if product matches - if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]] - then - serial_numbers="${serial_numbers} $sn" - fi - done - - case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in - 0) - echo "" - echo "WARNING: No ${PRODUCT} found in fastboot mode." - echo "WARNING: Make sure that a ${PRODUCT} is connected." - ;; - 1) - echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." - - DEVICE_FOUND="true" - break - ;; - *) - echo "" - echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected." - echo "WARNING: Please connect only one ${PRODUCT}." - ;; - esac - - echo "" - while true - do - read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a - if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ] - then - break - elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ] - then - exit 0 - fi - done - done -} - -# Flash (or manipulate) relevant partitions -flash_device() { - - flash_image_ab_or_abort "${sn}" modem "${IMAGES_DIR}/modem.img" - flash_image_ab_or_abort "${sn}" sbl1 "${IMAGES_DIR}/sbl1.img" - flash_image_ab_or_abort "${sn}" rpm "${IMAGES_DIR}/rpm.img" - flash_image_ab_or_abort "${sn}" tz "${IMAGES_DIR}/tz.img" - flash_image_ab_or_abort "${sn}" devcfg "${IMAGES_DIR}/devcfg.img" - flash_image_ab_or_abort "${sn}" dsp "${IMAGES_DIR}/dsp.img" - flash_image_ab_or_abort "${sn}" aboot "${IMAGES_DIR}/aboot.img" - - flash_image_ab_or_abort "${sn}" boot "${IMAGES_DIR}/boot.img" - flash_image_ab_or_abort "${sn}" dtbo "${IMAGES_DIR}/dtbo.img" - flash_image_ab_or_abort "${sn}" system "${IMAGES_DIR}/system.img" - flash_image_ab_or_abort "${sn}" vbmeta "${IMAGES_DIR}/vbmeta.img" - flash_image_ab_or_abort "${sn}" vendor "${IMAGES_DIR}/vendor.img" - flash_image_ab_or_abort "${sn}" mdtp "${IMAGES_DIR}/mdtp.img" - flash_image_ab_or_abort "${sn}" lksecapp "${IMAGES_DIR}/lksecapp.img" - flash_image_ab_or_abort "${sn}" cmnlib "${IMAGES_DIR}/cmnlib.img" - flash_image_ab_or_abort "${sn}" cmnlib64 "${IMAGES_DIR}/cmnlib64.img" - flash_image_ab_or_abort "${sn}" keymaster "${IMAGES_DIR}/keymaster.img" - - - if [ "${CLEAN_FLASH}" = "true" ] - then - flash_image_or_abort "${sn}" userdata "${IMAGES_DIR}/userdata.img" - fi - - "$FASTBOOT_BIN" -s "${sn}" --set-active=a - - echo "INFO: Locking bootloader" - "${FASTBOOT_BIN}" -s "${sn}" oem lock - echo - echo "****** READ CAREFULLY ******" - echo "" - echo "INFO: The device is waiting for you to lock the bootloader." - echo " You can do so on the device itself. Use the volume buttons" - echo " to choose the correct option, then the power button to select." - echo " The device will then reboot." - read -rp " Press any key to close this script." a - exit 0 - -} - -# Flash an image to a partition. Abort on failure. -# Arguments: -flash_image_or_abort() { - local retval=0 - "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${3}" || retval=$? - - if [ "${retval}" -ne 0 ] - then - echo "" - echo "ERROR: Could not flash the ${2} partition on device ${1}." - echo "" - echo "ERROR: Please unplug the phone, take the battery out, boot the device into" - echo "ERROR: fastboot mode, and start this script again." - echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" - echo "ERROR: (cable until the fastboot menu appears.)" - abort_now - fi -} - -# Flash an image to both A and B slot of partition. Abort on failure. -# Arguments: -flash_image_ab_or_abort() { - flash_image_or_abort "${1}" "${2}_a" "${3}" - flash_image_or_abort "${1}" "${2}_b" "${3}" -} - -# Operating system checks and variable definition -os_checks() { - case "$(uname -s 2> /dev/null)" in - Linux|GNU/Linux) - echo "INFO: You are using a Linux distribution." - FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot" - ;; - msys|MINGW*) - echo "INFO: You are using MinGW on Windows" - FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe" - ;; - *) - echo "ERROR: Unsupported operating system (${OSTYPE})." - echo "ERROR: Only GNU/Linux, and MinGW on Windows are currently supported." - abort_now - ;; - esac -} - -# Warn about data wipe, and ask for confirmation -data_wipe_check() { - if [ "${CLEAN_FLASH}" = "true" ] - then - echo "" - echo "WARNING: Flashing this image wipes all user data and settings on the phone." - echo " Are you sure you want to wipe data and continue?" - echo "" - # Read user's input - read -rp " Type \"Yes\" (case sensitive) and press enter to wipe data and continue. Else, just press enter: " a - echo "" - if [ "_${a:-"No"}" != '_Yes' ] - # NOTE: $a is being set by the read command above, - # so the check for a to be set is mostly redundant - then - echo "WARNING: You DID NOT type \"Yes\", proceeding without data wipe." - echo "" - CLEAN_FLASH="false" - else - echo "WARNING: You typed \"Yes\", proceeding with data wipe." - CLEAN_FLASH="true" - fi - fi -} - -echo "" -echo "*** ${PRODUCT} flashing script ***" -echo "" -echo "INFO: The procedure will start soon. Please wait..." -echo "Note that this will detect and flash only on FP3 or FP3+ devices." -sleep 2 - -# Begin with some OS checks and variable definition -os_checks +# Target Flashing Images info +FLASH_AB_FW_IMGS="modem sbl1 rpm tz devcfg dsp aboot mdtp lksecapp cmnlib cmnlib64 keymaster" +FLASH_AB_IMGS="boot dtbo system vbmeta vendor" +FLASH_A_IMGS="userdata" -# Call function to look for device(s) -# If only one device is found $sn will store its serial number -find_device +# Target flash process behavior +CLEAN_FLASH=true +VIRTUAL_AB=true -# Call function to look for data wipe check -data_wipe_check +source factory.common -# Flash the device -flash_device +# Common flashing function +flash_factory diff --git a/flash/FP4/flash_FP4_factory.sh b/flash/FP4/flash_FP4_factory.sh index fa35ef46f4929880ad02c2778040085732d591e6..0ec7e37c435a0434704095b9c69918c22ab513a7 100755 --- a/flash/FP4/flash_FP4_factory.sh +++ b/flash/FP4/flash_FP4_factory.sh @@ -1,195 +1,20 @@ #!/usr/bin/env bash -########## -# This script is created and maintained by -# Bharath(@teamb58).org -# Feel free to connect for any queries or suggestions. -########## - -########## -# This script flashes a software release and complete wipes the device. -# -########## - -set -e -set -u - # Target device info PRODUCT="Fairphone 4" PRODUCT_ID="FP4" -# Paths/files -ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -IMAGES_DIR="${ROOT_DIR}" - -# Abort the script (and wait for a key to be pressed). -abort_now() { - echo "" - read -rp "ERROR: Aborting now (press Enter to terminate)." a - exit 1 -} - -# Check for connected phone -find_device() { - echo "INFO: Looking for connected device(s)..." - DEVICE_FOUND="false" - while [ ${DEVICE_FOUND} = "false" ] - do - serial_numbers= - - for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+') - do - # Checking the product ID - PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1) - # Add serial, if product matches - if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]] - then - serial_numbers="${serial_numbers} $sn" - fi - done - - case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in - 0) - echo "" - echo "WARNING: No ${PRODUCT} found in fastboot mode." - echo "WARNING: Make sure that a ${PRODUCT} is connected." - ;; - 1) - echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." - - DEVICE_FOUND="true" - break - ;; - *) - echo "" - echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected." - echo "WARNING: Please connect only one ${PRODUCT}." - ;; - esac - - echo "" - while true - do - read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a - if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ] - then - break - elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ] - then - exit 0 - fi - done - done -} - -# 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" - flash_image_ab_or_abort "${sn}" modem "${IMAGES_DIR}/modem.img" - flash_image_ab_or_abort "${sn}" xbl "${IMAGES_DIR}/xbl.img" - flash_image_ab_or_abort "${sn}" tz "${IMAGES_DIR}/tz.img" - flash_image_ab_or_abort "${sn}" hyp "${IMAGES_DIR}/hyp.img" - flash_image_ab_or_abort "${sn}" keymaster "${IMAGES_DIR}/keymaster.img" - - flash_image_ab_or_abort "${sn}" abl "${IMAGES_DIR}/abl.img" - flash_image_ab_or_abort "${sn}" boot "${IMAGES_DIR}/boot.img" - flash_image_ab_or_abort "${sn}" recovery "${IMAGES_DIR}/recovery.img" - flash_image_ab_or_abort "${sn}" dtbo "${IMAGES_DIR}/dtbo.img" - flash_image_ab_or_abort "${sn}" vbmeta_system "${IMAGES_DIR}/vbmeta_system.img" - flash_image_ab_or_abort "${sn}" vbmeta "${IMAGES_DIR}/vbmeta.img" - flash_image_or_abort "${sn}" super "${IMAGES_DIR}/super.img" - - flash_image_ab_or_abort "${sn}" aop "${IMAGES_DIR}/aop.img" - flash_image_ab_or_abort "${sn}" featenabler "${IMAGES_DIR}/featenabler.img" - flash_image_ab_or_abort "${sn}" imagefv "${IMAGES_DIR}/imagefv.img" - flash_image_ab_or_abort "${sn}" multiimgoem "${IMAGES_DIR}/multiimgoem.img" - flash_image_ab_or_abort "${sn}" qupfw "${IMAGES_DIR}/qupfw.img" - flash_image_ab_or_abort "${sn}" uefisecapp "${IMAGES_DIR}/uefisecapp.img" - flash_image_ab_or_abort "${sn}" xbl_config "${IMAGES_DIR}/xbl_config.img" - flash_image_ab_or_abort "${sn}" core_nhlos "${IMAGES_DIR}/core_nhlos.img" - - "$FASTBOOT_BIN" -s "${sn}" erase userdata - "$FASTBOOT_BIN" -s "${sn}" erase metadata - - "$FASTBOOT_BIN" -s "${sn}" --set-active=a - -} - -# Flash an image to a partition. Abort on failure. -# Arguments: -flash_image_or_abort() { - local retval=0 - "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${3}" || retval=$? - - if [ "${retval}" -ne 0 ] - then - echo "" - echo "ERROR: Could not flash the ${2} partition on device ${1}." - echo "" - echo "ERROR: Please unplug the phone, take the battery out, boot the device into" - echo "ERROR: fastboot mode, and start this script again." - echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" - echo "ERROR: (cable until the fastboot menu appears.)" - abort_now - fi -} - -# Flash an image to both A and B slot of partition. Abort on failure. -# Arguments: -flash_image_ab_or_abort() { - flash_image_or_abort "${1}" "${2}_a" "${3}" - flash_image_or_abort "${1}" "${2}_b" "${3}" -} - -# Operating system checks and variable definition -os_checks() { - case "$(uname -s 2> /dev/null)" in - Linux|GNU/Linux) - echo "INFO: You are using a Linux distribution." - FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot" - ;; - msys|MINGW*) - echo "INFO: You are using MinGW on Windows" - FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe" - ;; - *) - echo "ERROR: Unsupported operating system (${OSTYPE})." - echo "ERROR: Only GNU/Linux, and MinGW on Windows are currently supported." - abort_now - ;; - esac -} - -# Control the reboot sequence -reboot_device() { - echo "-----------" - echo "" - echo "INFO: Done. The device will reboot now." - "${FASTBOOT_BIN}" -s "${sn}" reboot - echo "" - echo "INFO: You can unplug the USB cable now." - echo "" -} - -echo "" -echo "*** ${PRODUCT} flashing script ***" -echo "" -echo "INFO: The procedure will start soon. Please wait..." -echo "Note that this will detect and flash only on FP4 device." -sleep 2 - -# Begin with some OS checks and variable definition -os_checks +# Target Flashing Images info +FLASH_AB_FW_IMGS="bluetooth devcfg dsp modem xbl tz hyp keymaster abl aop featenabler imagefv multiimgoem qupfw uefisecapp xbl_config core_nhlos" +FLASH_AB_IMGS="boot dtbo recovery vbmeta vbmeta_system" +FLASH_A_IMGS="super" +ERASE_IMGS="userdata metadata" -# Call function to look for device(s) -# If only one device is found $sn will store its serial number -find_device +# Target flash process behavior +CLEAN_FLASH=true +VIRTUAL_AB=true -# Flash the device -flash_device +source factory.common -# Reboot device -reboot_device +# Common flashing function +flash_factory diff --git a/flash/FP5/flash_FP5_factory.sh b/flash/FP5/flash_FP5_factory.sh index facdbf3e849d951629b28a6b44cfacb32e4dea23..cad5a5d0a0c3413a0b87c1966b30166c8585b673 100755 --- a/flash/FP5/flash_FP5_factory.sh +++ b/flash/FP5/flash_FP5_factory.sh @@ -1,196 +1,20 @@ #!/usr/bin/env bash -########## -# This script is created and maintained by -# Bharath(@teamb58).org -# Feel free to connect for any queries or suggestions. -########## - -########## -# This script flashes a software release and complete wipes the device. -# -########## - -set -e -set -u - # Target device info PRODUCT="Fairphone 5" PRODUCT_ID="FP5" -# Paths/files -ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -IMAGES_DIR="${ROOT_DIR}" - -# Abort the script (and wait for a key to be pressed). -abort_now() { - echo "" - read -rp "ERROR: Aborting now (press Enter to terminate)." a - exit 1 -} - -# Check for connected phone -find_device() { - echo "INFO: Looking for connected device(s)..." - DEVICE_FOUND="false" - while [ ${DEVICE_FOUND} = "false" ] - do - serial_numbers= - - for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+') - do - # Checking the product ID - PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1) - # Add serial, if product matches - if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]] - then - serial_numbers="${serial_numbers} $sn" - fi - done - - case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in - 0) - echo "" - echo "WARNING: No ${PRODUCT} found in fastboot mode." - echo "WARNING: Make sure that a ${PRODUCT} is connected." - ;; - 1) - echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." - - DEVICE_FOUND="true" - break - ;; - *) - echo "" - echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected." - echo "WARNING: Please connect only one ${PRODUCT}." - ;; - esac - - echo "" - while true - do - read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a - if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ] - then - break - elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ] - then - exit 0 - fi - done - done -} - -# 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" - flash_image_ab_or_abort "${sn}" modem "${IMAGES_DIR}/modem.img" - flash_image_ab_or_abort "${sn}" xbl "${IMAGES_DIR}/xbl.img" - flash_image_ab_or_abort "${sn}" tz "${IMAGES_DIR}/tz.img" - flash_image_ab_or_abort "${sn}" hyp "${IMAGES_DIR}/hyp.img" - flash_image_ab_or_abort "${sn}" keymaster "${IMAGES_DIR}/keymaster.img" - - flash_image_ab_or_abort "${sn}" abl "${IMAGES_DIR}/abl.img" - flash_image_ab_or_abort "${sn}" boot "${IMAGES_DIR}/boot.img" - flash_image_ab_or_abort "${sn}" dtbo "${IMAGES_DIR}/dtbo.img" - flash_image_ab_or_abort "${sn}" vendor_boot "${IMAGES_DIR}/vendor_boot.img" - flash_image_ab_or_abort "${sn}" vbmeta_system "${IMAGES_DIR}/vbmeta_system.img" - flash_image_ab_or_abort "${sn}" vbmeta "${IMAGES_DIR}/vbmeta.img" - flash_image_or_abort "${sn}" super "${IMAGES_DIR}/super.img" - - flash_image_ab_or_abort "${sn}" aop "${IMAGES_DIR}/aop.img" - flash_image_ab_or_abort "${sn}" featenabler "${IMAGES_DIR}/featenabler.img" - flash_image_ab_or_abort "${sn}" imagefv "${IMAGES_DIR}/imagefv.img" - flash_image_ab_or_abort "${sn}" multiimgoem "${IMAGES_DIR}/multiimgoem.img" - flash_image_ab_or_abort "${sn}" qupfw "${IMAGES_DIR}/qupfw.img" - flash_image_ab_or_abort "${sn}" uefisecapp "${IMAGES_DIR}/uefisecapp.img" - flash_image_ab_or_abort "${sn}" xbl_config "${IMAGES_DIR}/xbl_config.img" - - flash_image_ab_or_abort "${sn}" cpucp "${IMAGES_DIR}/cpucp.img" - flash_image_ab_or_abort "${sn}" shrm "${IMAGES_DIR}/shrm.img" - - "$FASTBOOT_BIN" -s "${sn}" erase userdata - "$FASTBOOT_BIN" -s "${sn}" erase metadata - - "$FASTBOOT_BIN" -s "${sn}" --set-active=a - -} - -# Flash an image to a partition. Abort on failure. -# Arguments: -flash_image_or_abort() { - local retval=0 - "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${3}" || retval=$? - - if [ "${retval}" -ne 0 ] - then - echo "" - echo "ERROR: Could not flash the ${2} partition on device ${1}." - echo "" - echo "ERROR: Please unplug the phone, take the battery out, boot the device into" - echo "ERROR: fastboot mode, and start this script again." - echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" - echo "ERROR: (cable until the fastboot menu appears.)" - abort_now - fi -} - -# Flash an image to both A and B slot of partition. Abort on failure. -# Arguments: -flash_image_ab_or_abort() { - flash_image_or_abort "${1}" "${2}_a" "${3}" - flash_image_or_abort "${1}" "${2}_b" "${3}" -} - -# Operating system checks and variable definition -os_checks() { - case "$(uname -s 2> /dev/null)" in - Linux|GNU/Linux) - echo "INFO: You are using a Linux distribution." - FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot" - ;; - msys|MINGW*) - echo "INFO: You are using MinGW on Windows" - FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe" - ;; - *) - echo "ERROR: Unsupported operating system (${OSTYPE})." - echo "ERROR: Only GNU/Linux, and MinGW on Windows are currently supported." - abort_now - ;; - esac -} - -# Control the reboot sequence -reboot_device() { - echo "-----------" - echo "" - echo "INFO: Done. The device will reboot now." - "${FASTBOOT_BIN}" -s "${sn}" reboot - echo "" - echo "INFO: You can unplug the USB cable now." - echo "" -} - -echo "" -echo "*** ${PRODUCT} flashing script ***" -echo "" -echo "INFO: The procedure will start soon. Please wait..." -echo "Note that this will detect and flash only on ${PRODUCT} device." -sleep 2 +# Target Flashing Images info +FLASH_AB_FW_IMGS="bluetooth devcfg dsp modem xbl tz hyp keymaster abl aop featenabler imagefv multiimgoem qupfw uefisecapp xbl_config cpucp shrm" +FLASH_AB_IMGS="boot dtbo vendor_boot vbmeta vbmeta_system" +FLASH_A_IMGS="super" +ERASE_IMGS="userdata metadata" -# Begin with some OS checks and variable definition -os_checks +# Target flash process behavior +CLEAN_FLASH=true +VIRTUAL_AB=true -# Call function to look for device(s) -# If only one device is found $sn will store its serial number -find_device +source factory.common -# Flash the device -flash_device -# Reboot device -reboot_device +# Common flashing function +flash_factory diff --git a/flash/axolotl/flash_axolotl_factory.sh b/flash/axolotl/flash_axolotl_factory.sh index dd40d2b8aedd4a37d07c535aa3e4e1926d750379..93da3250b47fa8f1ecea53276aa1dc5c551b4c79 100755 --- a/flash/axolotl/flash_axolotl_factory.sh +++ b/flash/axolotl/flash_axolotl_factory.sh @@ -1,226 +1,20 @@ #!/usr/bin/env bash -########## -# This script is created and maintained by -# Bharath(@teamb58).org -# Feel free to connect for any queries or suggestions. -########## - -########## -# This script flashes a software release and completely wipes the device. -# -########## - -set -e -set -u - -CLEAN_FLASH="true" # Control data wipe behavior. Default is "true". - # Target device info PRODUCT="SHIFT6mq" -# Bootloader identifies as generic "sdm845" instead of "axolotl" while Fastbootd identifies as "axolotl" PRODUCT_ID="sdm845" -# Paths/files -ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -IMAGES_DIR="${ROOT_DIR}" - -# Abort the script (and wait for a key to be pressed). -abort_now() { - echo "" - read -rp "ERROR: Aborting now (press Enter to terminate)." a - exit 1 -} - -# Check for connected phone -find_device() { - echo "INFO: Looking for connected device(s)..." - DEVICE_FOUND="false" - while [ ${DEVICE_FOUND} = "false" ] - do - serial_numbers= - - for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+') - do - # Checking the product ID - PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1) - # Add serial, if product matches - if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]] - then - serial_numbers="${serial_numbers} $sn" - fi - done - - case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in - 0) - echo "" - echo "WARNING: No ${PRODUCT} found in fastboot mode." - echo "WARNING: Make sure that a ${PRODUCT} is connected." - ;; - 1) - echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." - - DEVICE_FOUND="true" - break - ;; - *) - echo "" - echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected." - echo "WARNING: Please connect only one ${PRODUCT}." - ;; - esac - - echo "" - while true - do - read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a - if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ] - then - break - elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ] - then - exit 0 - fi - done - done -} - -# Flash (or manipulate) relevant partitions -flash_device() { - - flash_image_ab_or_abort "${sn}" ImageFv "${IMAGES_DIR}/ImageFv.img" - flash_image_ab_or_abort "${sn}" aop "${IMAGES_DIR}/aop.img" - flash_image_ab_or_abort "${sn}" bluetooth "${IMAGES_DIR}/bluetooth.img" - flash_image_ab_or_abort "${sn}" cmnlib "${IMAGES_DIR}/cmnlib.img" - flash_image_ab_or_abort "${sn}" cmnlib64 "${IMAGES_DIR}/cmnlib64.img" - flash_image_ab_or_abort "${sn}" devcfg "${IMAGES_DIR}/devcfg.img" - flash_image_ab_or_abort "${sn}" dsp "${IMAGES_DIR}/dsp.img" - flash_image_ab_or_abort "${sn}" hyp "${IMAGES_DIR}/hyp.img" - flash_image_ab_or_abort "${sn}" keymaster "${IMAGES_DIR}/keymaster.img" - flash_image_ab_or_abort "${sn}" modem "${IMAGES_DIR}/modem.img" - flash_image_ab_or_abort "${sn}" qupfw "${IMAGES_DIR}/qupfw.img" - flash_image_ab_or_abort "${sn}" storsec "${IMAGES_DIR}/storsec.img" - flash_image_ab_or_abort "${sn}" tz "${IMAGES_DIR}/tz.img" - flash_image_ab_or_abort "${sn}" xbl "${IMAGES_DIR}/xbl.img" - flash_image_ab_or_abort "${sn}" xbl_config "${IMAGES_DIR}/xbl_config.img" - - flash_image_ab_or_abort "${sn}" boot "${IMAGES_DIR}/boot.img" - flash_image_ab_or_abort "${sn}" dtbo "${IMAGES_DIR}/dtbo.img" - flash_image_ab_or_abort "${sn}" recovery "${IMAGES_DIR}/recovery.img" - flash_image_or_abort "${sn}" super super.img - flash_image_ab_or_abort "${sn}" vbmeta "${IMAGES_DIR}/vbmeta.img" - flash_image_ab_or_abort "${sn}" vbmeta_system "${IMAGES_DIR}/vbmeta_system.img" - flash_image_ab_or_abort "${sn}" vbmeta_vendor "${IMAGES_DIR}/vbmeta_vendor.img" - - if [ "${CLEAN_FLASH}" = "true" ] - then - flash_image_or_abort "${sn}" userdata "${IMAGES_DIR}/userdata.img" - "$FASTBOOT_BIN" -s "${sn}" erase metadata - fi - - "$FASTBOOT_BIN" -s "${sn}" --set-active=a -} - -# Flash an image to a partition. Abort on failure. -# Arguments: -flash_image_or_abort() { - local retval=0 - "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${3}" || retval=$? - - if [ "${retval}" -ne 0 ] - then - echo "" - echo "ERROR: Could not flash the ${2} partition on device ${1}." - echo "" - echo "ERROR: Please unplug the phone, take the battery out, boot the device into" - echo "ERROR: fastboot mode, and start this script again." - echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" - echo "ERROR: (cable until the fastboot menu appears.)" - abort_now - fi -} - -# Flash an image to both A and B slot of partition. Abort on failure. -# Arguments: -flash_image_ab_or_abort() { - flash_image_or_abort "${1}" "${2}_a" "${3}" - flash_image_or_abort "${1}" "${2}_b" "${3}" -} - -# Operating system checks and variable definition -os_checks() { - case "$(uname -s 2> /dev/null)" in - Linux|GNU/Linux) - echo "INFO: You are using a Linux distribution." - FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot" - ;; - msys|MINGW*) - echo "INFO: You are using MinGW on Windows" - FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe" - ;; - *) - echo "ERROR: Unsupported operating system (${OSTYPE})." - echo "ERROR: Only GNU/Linux, and MinGW on Windows are currently supported." - abort_now - ;; - esac -} - -# Control the reboot sequence -reboot_device() { - echo "-----------" - echo "" - echo "INFO: Done. The device will reboot now." - "${FASTBOOT_BIN}" -s "${sn}" reboot - echo "" - echo "INFO: You can unplug the USB cable now." - echo "" -} - -# Warn about data wipe, and ask for confirmation -data_wipe_check() { - if [ "${CLEAN_FLASH}" = "true" ] - then - echo "" - echo "WARNING: Flashing this image wipes all user data and settings on the phone." - echo " Are you sure you want to wipe data and continue?" - echo "" - # Read user's input - read -rp " Type \"Yes\" (case sensitive) and press enter to wipe data and continue. Else, just press enter: " a - echo "" - if [ "_${a:-"No"}" != '_Yes' ] - # NOTE: $a is being set by the read command above, - # so the check for a to be set is mostly redundant - then - echo "WARNING: You DID NOT type \"Yes\", proceeding without data wipe." - echo "" - CLEAN_FLASH="false" - else - echo "WARNING: You typed \"Yes\", proceeding with data wipe." - CLEAN_FLASH="true" - fi - fi -} - -echo "" -echo "*** ${PRODUCT} flashing script ***" -echo "" -echo "INFO: The procedure will start soon. Please wait..." -echo "Note that this will detect and flash only on ${PRODUCT} device." -sleep 2 - -# Begin with some OS checks and variable definition -os_checks - -# Call function to look for device(s) -# If only one device is found $sn will store its serial number -find_device +# Target Flashing Images info +FLASH_AB_FW_IMGS="ImageFv aop bluetooth cmnlib cmnlib64 devcfg dsp hyp keymaster modem qupfw storsec tz xbl xbl_config" +FLASH_AB_IMGS="boot dtbo recovery vbmeta vbmeta_system vbmeta_vendor" +FLASH_A_IMGS="super userdata" +ERASE_IMGS="metadata" -# Call function to look for data wipe check -data_wipe_check +# Target flash process behavior +CLEAN_FLASH=true +VIRTUAL_AB=true -# Flash the device -flash_device +source factory.common -# Reboot device -reboot_device +# Common flashing function +flash_factory diff --git a/flash/factory.common b/flash/factory.common new file mode 100755 index 0000000000000000000000000000000000000000..db87d38b7e45403746dd58afb5ae8fc1ad63bafe --- /dev/null +++ b/flash/factory.common @@ -0,0 +1,252 @@ +#!/usr/bin/env bash + +set -e + +# Paths/files +ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +IMAGES_DIR="${ROOT_DIR}" + +# Abort the script (and wait for a key to be pressed). +abort_now() { + echo "" + read -rp "ERROR: Aborting now (press Enter to terminate)." a + exit 1 +} + +# Erase a list of partitions. Abort on failure. +# Arguments: +erase_images_or_abort() { +if [ -n "${2}" ] +then + for PARTITION in $2; + do + local retval=0 + "${FASTBOOT_BIN}" -s "${1}" erase "${PARTITION}" || retval=$? + if [ "${retval}" -ne 0 ] + then + echo "" + echo "ERROR: Could not erase the ${PARTITION} partition on device ${1}." + echo "" + echo "ERROR: Please unplug the phone, take the battery out, boot the device into" + echo "ERROR: fastboot mode, and start this script again." + echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" + echo "ERROR: (cable until the fastboot menu appears.)" + abort_now + fi + done +fi +} + +# Check for connected phone +find_device() { + echo "INFO: Looking for connected device(s)..." + DEVICE_FOUND="false" + while [ ${DEVICE_FOUND} = "false" ] + do + serial_numbers= + + for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+') + do + # Checking the product ID + PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1) + # Add serial, if product matches + if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]] + then + serial_numbers="${serial_numbers} $sn" + fi + done + + case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in + 0) + echo "" + echo "WARNING: No ${PRODUCT} found in fastboot mode." + echo "WARNING: Make sure that a ${PRODUCT} is connected." + ;; + 1) + echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." + + DEVICE_FOUND="true" + break + ;; + *) + echo "" + echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected." + echo "WARNING: Please connect only one ${PRODUCT}." + ;; + esac + + echo "" + while true + do + read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a + if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ] + then + break + elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ] + then + exit 0 + fi + done + done +} + +# Flash (or manipulate) relevant partitions +flash_device() { + flash_images_ab_or_abort "${sn}" "${FLASH_AB_FW_IMGS}" + flash_images_a_or_abort "${sn}" "${FLASH_A_FW_IMGS}" + +if [ "${FW_BL_RESTART}" = "true" ] +then + echo "INFO: Firmware images flashed. The device will reboot to bootloader again to continue." + "${FASTBOOT_BIN}" -s "${sn}" reboot bootloader +fi + + flash_images_ab_or_abort "${sn}" "${FLASH_AB_IMGS}" + flash_images_a_or_abort "${sn}" "${FLASH_A_IMGS}" + +if [ "${CLEAN_FLASH}" = "true" ] +then + erase_images_or_abort "${sn}" "${ERASE_IMGS}" + format_images_or_abort "${sn}" "${FORMAT_IMGS}" +fi + +if [ "${VIRTUAL_AB}" = "true" ] +then + "${FASTBOOT_BIN}" -s "${sn}" --set-active=a +fi +} + +# Common flash function to be called from device flash script +flash_factory() { + # Begin with some OS checks and variable definition + os_checks + + # Call function to look for device(s) + # If only one device is found $sn will store its serial number + find_device + + # Flash the device + flash_device + + # Reboot device + reboot_device +} + +# Flash an image to a partition. Abort on failure. +# Arguments: +flash_image_or_abort() { + local retval=0 + "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${3}" || retval=$? + + if [ "${retval}" -ne 0 ] + then + echo "" + echo "ERROR: Could not flash the ${2} partition on device ${1}." + echo "" + echo "ERROR: Please unplug the phone, take the battery out, boot the device into" + echo "ERROR: fastboot mode, and start this script again." + echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" + echo "ERROR: (cable until the fastboot menu appears.)" + abort_now + fi +} + +# Flash an image to both A and B slot of partition. Abort on failure. +# Arguments: +flash_image_ab_or_abort() { + flash_image_or_abort "${1}" "${2}_a" "${3}" + flash_image_or_abort "${1}" "${2}_b" "${3}" +} + +# Flash a list of images to partitions. Abort on failure. +# Arguments: +flash_images_a_or_abort() { +if [ -n "${2}" ] +then + for BLOB in $2; + do + PARTITION="${BLOB%%:*}" + IMAGE=$(echo $BLOB | cut -s -d : -f 2) + + if [[ "$PARTITION" = "userdata" && "${CLEAN_FLASH}" != "true" ]] + then + continue + fi + flash_image_or_abort "${1}" "${PARTITION}" "${IMAGES_DIR}/${IMAGE:-$PARTITION.img}" + done +fi +} + +# Flash a list of images to A and B slot of partitions. Abort on failure. +# Arguments: +flash_images_ab_or_abort() { +if [ -n "${2}" ] +then + for BLOB in $2; + do + PARTITION="${BLOB%%:*}" + IMAGE=$(echo $BLOB | cut -s -d : -f 2) + + flash_image_ab_or_abort "${1}" "${PARTITION}" "${IMAGES_DIR}/${IMAGE:-$PARTITION.img}" + done +fi +} + +# Erase a list of partitions. Abort on failure. +# Arguments: +format_images_or_abort() { +if [ -n "${2}" ] +then + for PARTITION in $2; + do + local retval=0 + "${FASTBOOT_BIN}" -s "${1}" format "${PARTITION}" || retval=$? + if [ "${retval}" -ne 0 ] + then + echo "" + echo "ERROR: Could not format the ${PARTITION} partition on device ${1}." + echo "" + echo "ERROR: Please unplug the phone, take the battery out, boot the device into" + echo "ERROR: fastboot mode, and start this script again." + echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" + echo "ERROR: (cable until the fastboot menu appears.)" + abort_now + fi + done +fi +} + +# Operating system checks and variable definition +os_checks() { + case "$(uname -s 2> /dev/null)" in + Linux|GNU/Linux) + echo "INFO: You are using a Linux distribution." + FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot" + ;; + msys|MINGW*) + echo "INFO: You are using MinGW on Windows." + FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe" + ;; + Darwin) + echo "INFO: You are using MacOS." + FASTBOOT_BIN="${ROOT_DIR}/bin-darwin/fastboot" + ;; + *) + echo "ERROR: Unsupported operating system (${OSTYPE})." + echo "ERROR: Only GNU/Linux, MacOS and MinGW on Windows are currently supported." + abort_now + ;; + esac +} + +# Control the reboot sequence +reboot_device() { + echo "-----------" + echo "" + echo "INFO: Done. The device will reboot now." + "${FASTBOOT_BIN}" -s "${sn}" reboot + echo "" + echo "INFO: You can unplug the USB cable now." + echo "" +} + diff --git a/flash/fastboot/bin-darwin/e2fsdroid b/flash/fastboot/bin-darwin/e2fsdroid new file mode 100755 index 0000000000000000000000000000000000000000..5213ef0a203f84bcfe2f8d6263bd4e8e692e9ef7 Binary files /dev/null and b/flash/fastboot/bin-darwin/e2fsdroid differ diff --git a/flash/fastboot/bin-darwin/fastboot b/flash/fastboot/bin-darwin/fastboot new file mode 100755 index 0000000000000000000000000000000000000000..ff1493f4a526f74a8f052bdb6842eb6ee5866aa9 Binary files /dev/null and b/flash/fastboot/bin-darwin/fastboot differ diff --git a/flash/fastboot/bin-darwin/lib64/libc++.dylib b/flash/fastboot/bin-darwin/lib64/libc++.dylib new file mode 100755 index 0000000000000000000000000000000000000000..ee2c001479a8b85cbe7a17eab8ff82024888bd7f Binary files /dev/null and b/flash/fastboot/bin-darwin/lib64/libc++.dylib differ diff --git a/flash/fastboot/bin-darwin/make_f2fs b/flash/fastboot/bin-darwin/make_f2fs new file mode 100755 index 0000000000000000000000000000000000000000..f307ac4feab6f29b44528d7daf9d84bef930ae21 Binary files /dev/null and b/flash/fastboot/bin-darwin/make_f2fs differ diff --git a/flash/fastboot/bin-darwin/make_f2fs_casefold b/flash/fastboot/bin-darwin/make_f2fs_casefold new file mode 100755 index 0000000000000000000000000000000000000000..6d09c526ebfc5cbc391d25e2a976dcc0e691891a Binary files /dev/null and b/flash/fastboot/bin-darwin/make_f2fs_casefold differ diff --git a/flash/fastboot/bin-darwin/mke2fs b/flash/fastboot/bin-darwin/mke2fs new file mode 100755 index 0000000000000000000000000000000000000000..2ca1b8d4775d0bfcd530f2d07ba460916db6d250 Binary files /dev/null and b/flash/fastboot/bin-darwin/mke2fs differ diff --git a/flash/fastboot/bin-darwin/mke2fs.conf b/flash/fastboot/bin-darwin/mke2fs.conf new file mode 100755 index 0000000000000000000000000000000000000000..8ea960da6f2ee25e2e6bb591ed12e61a432cd808 --- /dev/null +++ b/flash/fastboot/bin-darwin/mke2fs.conf @@ -0,0 +1,53 @@ +[defaults] + base_features = sparse_super,large_file,filetype,dir_index,ext_attr + default_mntopts = acl,user_xattr + enable_periodic_fsck = 0 + blocksize = 4096 + inode_size = 256 + inode_ratio = 16384 + reserved_ratio = 1.0 + +[fs_types] + ext3 = { + features = has_journal + } + ext4 = { + features = has_journal,extent,huge_file,dir_nlink,extra_isize,uninit_bg + inode_size = 256 + } + ext4dev = { + features = has_journal,extent,huge_file,flex_bg,inline_data,64bit,dir_nlink,extra_isize + inode_size = 256 + options = test_fs=1 + } + small = { + blocksize = 1024 + inode_size = 128 + inode_ratio = 4096 + } + floppy = { + blocksize = 1024 + inode_size = 128 + inode_ratio = 8192 + } + big = { + inode_ratio = 32768 + } + huge = { + inode_ratio = 65536 + } + news = { + inode_ratio = 4096 + } + largefile = { + inode_ratio = 1048576 + blocksize = -1 + } + largefile4 = { + inode_ratio = 4194304 + blocksize = -1 + } + hurd = { + blocksize = 4096 + inode_size = 128 + } diff --git a/flash/fastboot/bin-darwin/sload_f2fs b/flash/fastboot/bin-darwin/sload_f2fs new file mode 100755 index 0000000000000000000000000000000000000000..fe3cf743848094ed2eb519a5500597fd05ad98df Binary files /dev/null and b/flash/fastboot/bin-darwin/sload_f2fs differ diff --git a/flash/fastboot/bin-darwin/source.properties b/flash/fastboot/bin-darwin/source.properties new file mode 100755 index 0000000000000000000000000000000000000000..9eb2a8bfac2a22b20b8abc6f025cc8efd728f8a4 --- /dev/null +++ b/flash/fastboot/bin-darwin/source.properties @@ -0,0 +1,2 @@ +Pkg.UserSrc=false +Pkg.Revision=33.0.3 diff --git a/flash/otter/flash_otter_factory.sh b/flash/otter/flash_otter_factory.sh index 091dbd4d3f441164798569994d8814ef4c3da85c..7d03b35ab058fa06af24ff85f3bbc45de11519a4 100755 --- a/flash/otter/flash_otter_factory.sh +++ b/flash/otter/flash_otter_factory.sh @@ -1,197 +1,20 @@ #!/usr/bin/env bash -########## -# This script is created and maintained by -# Bharath(@teamb58).org -# Feel free to connect for any queries or suggestions. -########## - -########## -# This script flashes a software release and complete wipes the device. -# -########## - -set -e -set -u - # Target device info PRODUCT="SHIFTphone 8" PRODUCT_ID="otter" -# Paths/files -ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -IMAGES_DIR="${ROOT_DIR}" - -# Abort the script (and wait for a key to be pressed). -abort_now() { - echo "" - read -rp "ERROR: Aborting now (press Enter to terminate)." a - exit 1 -} - -# Check for connected phone -find_device() { - echo "INFO: Looking for connected device(s)..." - DEVICE_FOUND="false" - while [ ${DEVICE_FOUND} = "false" ] - do - serial_numbers= - - for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+') - do - # Checking the product ID - PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1) - # Add serial, if product matches - if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]] - then - serial_numbers="${serial_numbers} $sn" - fi - done - - case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in - 0) - echo "" - echo "WARNING: No ${PRODUCT} found in fastboot mode." - echo "WARNING: Make sure that a ${PRODUCT} is connected." - ;; - 1) - echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." - - DEVICE_FOUND="true" - break - ;; - *) - echo "" - echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected." - echo "WARNING: Please connect only one ${PRODUCT}." - ;; - esac - - echo "" - while true - do - read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a - if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ] - then - break - elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ] - then - exit 0 - fi - done - done -} - -# 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" - flash_image_ab_or_abort "${sn}" modem "${IMAGES_DIR}/modem.img" - flash_image_ab_or_abort "${sn}" xbl "${IMAGES_DIR}/xbl.img" - flash_image_ab_or_abort "${sn}" tz "${IMAGES_DIR}/tz.img" - flash_image_ab_or_abort "${sn}" hyp "${IMAGES_DIR}/hyp.img" - flash_image_ab_or_abort "${sn}" keymaster "${IMAGES_DIR}/keymaster.img" - - flash_image_ab_or_abort "${sn}" abl "${IMAGES_DIR}/abl.img" - flash_image_ab_or_abort "${sn}" boot "${IMAGES_DIR}/boot.img" - flash_image_ab_or_abort "${sn}" dtbo "${IMAGES_DIR}/dtbo.img" - flash_image_ab_or_abort "${sn}" vendor_boot "${IMAGES_DIR}/vendor_boot.img" - flash_image_ab_or_abort "${sn}" vbmeta_system "${IMAGES_DIR}/vbmeta_system.img" - flash_image_ab_or_abort "${sn}" vbmeta "${IMAGES_DIR}/vbmeta.img" - flash_image_or_abort "${sn}" super "${IMAGES_DIR}/super.img" - - flash_image_ab_or_abort "${sn}" aop "${IMAGES_DIR}/aop.img" - flash_image_ab_or_abort "${sn}" featenabler "${IMAGES_DIR}/featenabler.img" - flash_image_ab_or_abort "${sn}" imagefv "${IMAGES_DIR}/imagefv.img" - flash_image_ab_or_abort "${sn}" multiimgoem "${IMAGES_DIR}/multiimgoem.img" - flash_image_ab_or_abort "${sn}" qupfw "${IMAGES_DIR}/qupfw.img" - flash_image_ab_or_abort "${sn}" qweslicstore "${IMAGES_DIR}/qweslicstore.img" - flash_image_ab_or_abort "${sn}" uefisecapp "${IMAGES_DIR}/uefisecapp.img" - flash_image_ab_or_abort "${sn}" xbl_config "${IMAGES_DIR}/xbl_config.img" - - flash_image_ab_or_abort "${sn}" cpucp "${IMAGES_DIR}/cpucp.img" - flash_image_ab_or_abort "${sn}" shrm "${IMAGES_DIR}/shrm.img" - - "$FASTBOOT_BIN" -s "${sn}" erase userdata - "$FASTBOOT_BIN" -s "${sn}" erase metadata - - "$FASTBOOT_BIN" -s "${sn}" --set-active=a - -} - -# Flash an image to a partition. Abort on failure. -# Arguments: -flash_image_or_abort() { - local retval=0 - "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${3}" || retval=$? - - if [ "${retval}" -ne 0 ] - then - echo "" - echo "ERROR: Could not flash the ${2} partition on device ${1}." - echo "" - echo "ERROR: Please unplug the phone, take the battery out, boot the device into" - echo "ERROR: fastboot mode, and start this script again." - echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" - echo "ERROR: (cable until the fastboot menu appears.)" - abort_now - fi -} - -# Flash an image to both A and B slot of partition. Abort on failure. -# Arguments: -flash_image_ab_or_abort() { - flash_image_or_abort "${1}" "${2}_a" "${3}" - flash_image_or_abort "${1}" "${2}_b" "${3}" -} - -# Operating system checks and variable definition -os_checks() { - case "$(uname -s 2> /dev/null)" in - Linux|GNU/Linux) - echo "INFO: You are using a Linux distribution." - FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot" - ;; - msys|MINGW*) - echo "INFO: You are using MinGW on Windows" - FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe" - ;; - *) - echo "ERROR: Unsupported operating system (${OSTYPE})." - echo "ERROR: Only GNU/Linux, and MinGW on Windows are currently supported." - abort_now - ;; - esac -} - -# Control the reboot sequence -reboot_device() { - echo "-----------" - echo "" - echo "INFO: Done. The device will reboot now." - "${FASTBOOT_BIN}" -s "${sn}" reboot - echo "" - echo "INFO: You can unplug the USB cable now." - echo "" -} - -echo "" -echo "*** ${PRODUCT} flashing script ***" -echo "" -echo "INFO: The procedure will start soon. Please wait..." -echo "Note that this will detect and flash only on ${PRODUCT} device." -sleep 2 +# Target Flashing Images info +FLASH_AB_FW_IMGS="bluetooth devcfg dsp modem xbl tz hyp keymaster abl aop featenabler imagefv multiimgoem qupfw qweslicstore uefisecapp xbl_config cpucp shrm" +FLASH_AB_IMGS="boot dtbo vendor_boot vbmeta vbmeta_system" +FLASH_A_IMGS="super" +ERASE_IMGS="userdata metadata" -# Begin with some OS checks and variable definition -os_checks +# Target flash process behavior +CLEAN_FLASH=true +VIRTUAL_AB=true -# Call function to look for device(s) -# If only one device is found $sn will store its serial number -find_device +source factory.common -# Flash the device -flash_device -# Reboot device -reboot_device +# Common flashing function +flash_factory diff --git a/flash/shiba/flash_shiba_factory.sh b/flash/shiba/flash_shiba_factory.sh index a5ac8dda552593d96a9d74cbd684559677a3b732..cc1734ff7e4f904f66b82a16256e4b5a7739fdea 100755 --- a/flash/shiba/flash_shiba_factory.sh +++ b/flash/shiba/flash_shiba_factory.sh @@ -1,198 +1,21 @@ #!/usr/bin/env bash -########## -# This script is created and maintained by -# Bharath(@teamb58).org -# Feel free to connect for any queries or suggestions. -########## - -########## -# This script flashes a software release and complete wipes the device. -# -########## - -set -e -set -u - # Target device info PRODUCT="Pixel 8" PRODUCT_ID="shiba" -# Paths/files -ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -IMAGES_DIR="${ROOT_DIR}" - -# Abort the script (and wait for a key to be pressed). -abort_now() { - echo "" - read -rp "ERROR: Aborting now (press Enter to terminate)." a - exit 1 -} - -# Check for connected phone -find_device() { - echo "INFO: Looking for connected device(s)..." - DEVICE_FOUND="false" - while [ ${DEVICE_FOUND} = "false" ] - do - serial_numbers= - - for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+') - do - # Checking the product ID - PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1) - # Add serial, if product matches - if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]] - then - serial_numbers="${serial_numbers} $sn" - fi - done - - case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in - 0) - echo "" - echo "WARNING: No ${PRODUCT} found in fastboot mode." - echo "WARNING: Make sure that a ${PRODUCT} is connected." - ;; - 1) - echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." - - DEVICE_FOUND="true" - break - ;; - *) - echo "" - echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected." - echo "WARNING: Please connect only one ${PRODUCT}." - ;; - esac - - echo "" - while true - do - read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a - if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ] - then - break - elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ] - then - exit 0 - fi - done - done -} - -# Flash (or manipulate) relevant partitions -flash_fw() { - - flash_image_ab_or_abort "${sn}" abl "${IMAGES_DIR}/abl.img" - flash_image_ab_or_abort "${sn}" bl1 "${IMAGES_DIR}/bl1.img" - flash_image_ab_or_abort "${sn}" bl2 "${IMAGES_DIR}/bl2.img" - flash_image_ab_or_abort "${sn}" bl31 "${IMAGES_DIR}/bl31.img" - flash_image_ab_or_abort "${sn}" gcf "${IMAGES_DIR}/gcf.img" - flash_image_ab_or_abort "${sn}" gsa "${IMAGES_DIR}/gsa.img" - flash_image_ab_or_abort "${sn}" gsa_bl1 "${IMAGES_DIR}/gsa_bl1.img" - flash_image_ab_or_abort "${sn}" ldfw "${IMAGES_DIR}/ldfw.img" - flash_image_ab_or_abort "${sn}" modem "${IMAGES_DIR}/modem.img" - flash_image_ab_or_abort "${sn}" pbl "${IMAGES_DIR}/pbl.img" - flash_image_ab_or_abort "${sn}" tzsw "${IMAGES_DIR}/tzsw.img" - - "$FASTBOOT_BIN" -s "${sn}" reboot bootloader - -} - -flash_device() { - - flash_image_ab_or_abort "${sn}" boot "${IMAGES_DIR}/boot.img" - flash_image_ab_or_abort "${sn}" init_boot "${IMAGES_DIR}/init_boot.img" - flash_image_ab_or_abort "${sn}" dtbo "${IMAGES_DIR}/dtbo.img" - flash_image_ab_or_abort "${sn}" vendor_kernel_boot "${IMAGES_DIR}/vendor_kernel_boot.img" - flash_image_ab_or_abort "${sn}" vendor_boot "${IMAGES_DIR}/vendor_boot.img" - flash_image_ab_or_abort "${sn}" vbmeta_system "${IMAGES_DIR}/vbmeta_system.img" - flash_image_ab_or_abort "${sn}" vbmeta_vendor "${IMAGES_DIR}/vbmeta_vendor.img" - flash_image_ab_or_abort "${sn}" vbmeta "${IMAGES_DIR}/vbmeta.img" - flash_image_or_abort "${sn}" super "${IMAGES_DIR}/super.img" - - "$FASTBOOT_BIN" -s "${sn}" erase userdata - "$FASTBOOT_BIN" -s "${sn}" erase metadata - - "$FASTBOOT_BIN" -s "${sn}" --set-active=a - -} - -# Flash an image to a partition. Abort on failure. -# Arguments: -flash_image_or_abort() { - local retval=0 - "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${3}" || retval=$? - - if [ "${retval}" -ne 0 ] - then - echo "" - echo "ERROR: Could not flash the ${2} partition on device ${1}." - echo "" - echo "ERROR: Please unplug the phone, take the battery out, boot the device into" - echo "ERROR: fastboot mode, and start this script again." - echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" - echo "ERROR: (cable until the fastboot menu appears.)" - abort_now - fi -} - -# Flash an image to both A and B slot of partition. Abort on failure. -# Arguments: -flash_image_ab_or_abort() { - flash_image_or_abort "${1}" "${2}_a" "${3}" - flash_image_or_abort "${1}" "${2}_b" "${3}" -} - -# Operating system checks and variable definition -os_checks() { - case "$(uname -s 2> /dev/null)" in - Linux|GNU/Linux) - echo "INFO: You are using a Linux distribution." - FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot" - ;; - msys|MINGW*) - echo "INFO: You are using MinGW on Windows" - FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe" - ;; - *) - echo "ERROR: Unsupported operating system (${OSTYPE})." - echo "ERROR: Only GNU/Linux, and MinGW on Windows are currently supported." - abort_now - ;; - esac -} - -# Control the reboot sequence -reboot_device() { - echo "-----------" - echo "" - echo "INFO: Done. The device will reboot now." - "${FASTBOOT_BIN}" -s "${sn}" reboot - echo "" - echo "INFO: You can unplug the USB cable now." - echo "" -} - -echo "" -echo "*** ${PRODUCT} flashing script ***" -echo "" -echo "INFO: The procedure will start soon. Please wait..." -echo "Note that this will detect and flash only on ${PRODUCT} device." -sleep 2 +# Target Flashing Images info +FLASH_AB_FW_IMGS="abl bl1 bl2 bl31 gcf gsa gsa_bl1 ldfw modem pbl tzsw" +FLASH_AB_IMGS="boot init_boot dtbo vendor_kernel_boot vendor_boot vbmeta_system vbmeta_vendor vbmeta" +FLASH_A_IMGS="super" +ERASE_IMGS="userdata metadata" -# Begin with some OS checks and variable definition -os_checks +# Target flash process behavior +CLEAN_FLASH=true +FW_BL_RESTART=true +VIRTUAL_AB=true -# Call function to look for device(s) -# If only one device is found $sn will store its serial number -find_device +source factory.common -# Flash the fw -flash_fw -# Flash the device -flash_device -# Reboot device -reboot_device +# Common flashing function +flash_factory diff --git a/flash/tetris/flash_tetris_factory.sh b/flash/tetris/flash_tetris_factory.sh index 9ab077768c348ccbe0be1e7e73e1d0e0a61954cf..3c9da3444d599be89413b58be25a034fb3c404cf 100755 --- a/flash/tetris/flash_tetris_factory.sh +++ b/flash/tetris/flash_tetris_factory.sh @@ -1,230 +1,20 @@ #!/usr/bin/env bash -########## -# This script is created and maintained by -# Bharath(@teamb58).org -# Feel free to connect for any queries or suggestions. -########## - -########## -# This script flashes a software release and complete wipes the device. -# -########## - -set -e -set -u - -CLEAN_FLASH="true" # Control data wipe behavior. Default is "true". - # Target device info PRODUCT="CMF Phone 1" PRODUCT_ID="k6878v1_64" -# Paths/files -ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -IMAGES_DIR="${ROOT_DIR}" - -# Abort the script (and wait for a key to be pressed). -abort_now() { - echo "" - read -rp "ERROR: Aborting now (press Enter to terminate)." a - exit 1 -} - -# Check for connected phone -find_device() { - echo "INFO: Looking for connected device(s)..." - DEVICE_FOUND="false" - while [ ${DEVICE_FOUND} = "false" ] - do - serial_numbers= - - for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+') - do - # Checking the product ID - PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1) - # Add serial, if product matches - if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]] - then - serial_numbers="${serial_numbers} $sn" - fi - done - - case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in - 0) - echo "" - echo "WARNING: No ${PRODUCT} found in fastboot mode." - echo "WARNING: Make sure that a ${PRODUCT} is connected." - ;; - 1) - echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." - - DEVICE_FOUND="true" - break - ;; - *) - echo "" - echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected." - echo "WARNING: Please connect only one ${PRODUCT}." - ;; - esac - - echo "" - while true - do - read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a - if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ] - then - break - elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ] - then - exit 0 - fi - done - done -} - -# Flash (or manipulate) relevant partitions -flash_device() { - flash_image_ab_or_abort ${sn} apusys apusys.img - flash_image_ab_or_abort ${sn} boot boot.img - flash_image_ab_or_abort ${sn} ccu ccu.img - flash_image_ab_or_abort ${sn} connsys_bt connsys_bt.img - flash_image_ab_or_abort ${sn} connsys_gnss connsys_gnss.img - flash_image_ab_or_abort ${sn} connsys_wifi connsys_wifi.img - flash_image_ab_or_abort ${sn} dpm dpm.img - flash_image_ab_or_abort ${sn} dtbo dtbo.img - flash_image_ab_or_abort ${sn} gpueb gpueb.img - flash_image_ab_or_abort ${sn} gz gz.img - flash_image_ab_or_abort ${sn} init_boot init_boot.img - flash_image_ab_or_abort ${sn} lk lk.img - flash_image_ab_or_abort ${sn} logo logo.img - flash_image_ab_or_abort ${sn} mcf_ota mcf_ota.img - flash_image_ab_or_abort ${sn} mcupm mcupm.img - flash_image_ab_or_abort ${sn} modem modem.img - flash_image_ab_or_abort ${sn} pi_img pi_img.img - flash_image_ab_or_abort ${sn} preloader preloader_raw.img - flash_image_ab_or_abort ${sn} scp scp.img - flash_image_ab_or_abort ${sn} spmfw spmfw.img - flash_image_ab_or_abort ${sn} sspm sspm.img - flash_image_or_abort ${sn} super super.img - flash_image_ab_or_abort ${sn} tee tee.img - flash_image_ab_or_abort ${sn} vbmeta vbmeta.img - flash_image_ab_or_abort ${sn} vbmeta_system vbmeta_system.img - flash_image_ab_or_abort ${sn} vbmeta_vendor vbmeta_vendor.img - flash_image_ab_or_abort ${sn} vcp vcp.img - flash_image_ab_or_abort ${sn} vendor_boot vendor_boot.img - - if [ "${CLEAN_FLASH}" = "true" ] - then - "$FASTBOOT_BIN" -s "${sn}" erase userdata - "$FASTBOOT_BIN" -s "${sn}" erase metadata - fi - - "$FASTBOOT_BIN" -s "${sn}" --set-active=a - -} - -# Flash an image to a partition. Abort on failure. -# Arguments: -flash_image_or_abort() { - local retval=0 - "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${IMAGES_DIR}"/"${3}" || retval=$? - - if [ "${retval}" -ne 0 ] - then - echo "" - echo "ERROR: Could not flash the ${2} partition on device ${1}." - echo "" - echo "ERROR: Please unplug the phone and boot the device into" - echo "ERROR: fastboot mode, and start this script again." - echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" - echo "ERROR: (cable until the fastboot menu appears.)" - abort_now - fi -} - -# Flash an image to both A and B slot of partition. Abort on failure. -# Arguments: -flash_image_ab_or_abort() { - flash_image_or_abort "${1}" "${2}_a" "${3}" - flash_image_or_abort "${1}" "${2}_b" "${3}" -} - -# Operating system checks and variable definition -os_checks() { - case "$(uname -s 2> /dev/null)" in - Linux|GNU/Linux) - echo "INFO: You are using a Linux distribution." - FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot" - ;; - msys|MINGW*) - echo "INFO: You are using MinGW on Windows" - FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe" - ;; - *) - echo "ERROR: Unsupported operating system (${OSTYPE})." - echo "ERROR: Only GNU/Linux, and MinGW on Windows are currently supported." - abort_now - ;; - esac -} - -# Control the reboot sequence -reboot_device() { - echo "-----------" - echo "" - echo "INFO: Done. The device will reboot now." - "${FASTBOOT_BIN}" -s "${sn}" reboot - echo "" - echo "INFO: You can unplug the USB cable now." - echo "" -} - -# Warn about data wipe, and ask for confirmation -data_wipe_check() { - if [ "${CLEAN_FLASH}" = "true" ] - then - echo "" - echo "WARNING: Flashing this image wipes all user data and settings on the phone." - echo " Are you sure you want to wipe data and continue?" - echo "" - # Read user's input - read -rp " Type \"Yes\" (case sensitive) and press enter to wipe data and continue. Else, just press enter: " a - echo "" - if [ "_${a:-"No"}" != '_Yes' ] - # NOTE: $a is being set by the read command above, - # so the check for a to be set is mostly redundant - then - echo "WARNING: You DID NOT type \"Yes\", proceeding without data wipe." - echo "" - CLEAN_FLASH="false" - else - echo "WARNING: You typed \"Yes\", proceeding with data wipe." - CLEAN_FLASH="true" - fi - fi -} - -echo "" -echo "*** ${PRODUCT} flashing script ***" -echo "" -echo "INFO: The procedure will start soon. Please wait..." -echo "Note that this will detect and flash only on ${PRODUCT} device." -sleep 2 - -# Begin with some OS checks and variable definition -os_checks - -# Call function to look for device(s) -# If only one device is found $sn will store its serial number -find_device +# Target Flashing Images info +FLASH_AB_FW_IMGS="apusys ccu connsys_bt connsys_gnss connsys_wifi dpm gpueb gz lk logo mcf_ota mcupm modem pi_img preloader:preloader_raw.img scp spmfw sspm tee vcp" +FLASH_AB_IMGS="boot dtbo init_boot vbmeta vbmeta_system vbmeta_vendor vendor_boot" +FLASH_A_IMGS="super" +ERASE_IMGS="userdata metadata" -# Call function to look for data wipe check -data_wipe_check +# Target flash process behavior +CLEAN_FLASH=true +VIRTUAL_AB=true -# Flash the device -flash_device +source factory.common -# Reboot device -reboot_device +# Common flashing function +flash_factory diff --git a/flash/two/flash_two_factory.sh b/flash/two/flash_two_factory.sh index 8a1f902623ea066b0698e30f32f36edb69ee9127..24809620baf8dc29b0a9be31f39d88b9adc17772 100755 --- a/flash/two/flash_two_factory.sh +++ b/flash/two/flash_two_factory.sh @@ -1,218 +1,21 @@ #!/usr/bin/env bash -########## -# This script is created and maintained by -# Bharath(@teamb58).org -# Feel free to connect for any queries or suggestions. -########## - -########## -# This script flashes a software release and complete wipes the device. -# -########## - -set -e -set -u - -CLEAN_FLASH="true" # Control data wipe behavior. Default is "true". - # Target device info PRODUCT="Murena Two" PRODUCT_ID="k71v1_64_bsp" -# Paths/files -ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -IMAGES_DIR="${ROOT_DIR}" - -# Abort the script (and wait for a key to be pressed). -abort_now() { - echo "" - read -rp "ERROR: Aborting now (press Enter to terminate)." a - exit 1 -} - -# Check for connected phone -find_device() { - echo "INFO: Looking for connected device(s)..." - DEVICE_FOUND="false" - while [ ${DEVICE_FOUND} = "false" ] - do - serial_numbers= - - for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+') - do - # Checking the product ID - PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1) - # Add serial, if product matches - if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]] - then - serial_numbers="${serial_numbers} $sn" - fi - done - - case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in - 0) - echo "" - echo "WARNING: No ${PRODUCT} found in fastboot mode." - echo "WARNING: Make sure that a ${PRODUCT} is connected." - ;; - 1) - echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})." - - DEVICE_FOUND="true" - break - ;; - *) - echo "" - echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected." - echo "WARNING: Please connect only one ${PRODUCT}." - ;; - esac - - echo "" - while true - do - read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a - if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ] - then - break - elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ] - then - exit 0 - fi - done - done -} - -# Flash (or manipulate) relevant partitions -flash_device() { - flash_image_ab_or_abort "${sn}" boot boot.img - flash_image_ab_or_abort "${sn}" dtbo dtbo.img - flash_image_ab_or_abort "${sn}" cam_vpu1 cam_vpu1.img - flash_image_ab_or_abort "${sn}" cam_vpu2 cam_vpu2.img - flash_image_ab_or_abort "${sn}" cam_vpu3 cam_vpu3.img - flash_image_ab_or_abort "${sn}" dtbo dtbo.img - flash_image_ab_or_abort "${sn}" gz gz.img - flash_image_ab_or_abort "${sn}" lk lk.img - flash_image_or_abort "${sn}" logo logo.bin - flash_image_ab_or_abort "${sn}" md1img md1img.img - flash_image_ab_or_abort "${sn}" preloader preloader_k71v1_64_bsp.bin - flash_image_ab_or_abort "${sn}" scp scp.img - flash_image_ab_or_abort "${sn}" spmfw spmfw.img - flash_image_ab_or_abort "${sn}" sspm sspm.img - flash_image_or_abort "${sn}" super super.img - flash_image_ab_or_abort "${sn}" tee tee.img - flash_image_ab_or_abort "${sn}" vbmeta_vendor vbmeta_vendor.img - flash_image_ab_or_abort "${sn}" vbmeta_system vbmeta_system.img - flash_image_ab_or_abort "${sn}" vbmeta vbmeta.img - - if [ "${CLEAN_FLASH}" = "true" ] - then - "$FASTBOOT_BIN" -s "${sn}" erase userdata - "$FASTBOOT_BIN" -s "${sn}" format md_udc - fi -} - -# Flash an image to a partition. Abort on failure. -# Arguments: -flash_image_or_abort() { - local retval=0 - "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${IMAGES_DIR}"/"${3}" || retval=$? - - if [ "${retval}" -ne 0 ] - then - echo "" - echo "ERROR: Could not flash the ${2} partition on device ${1}." - echo "" - echo "ERROR: Please unplug the phone and boot the device into" - echo "ERROR: fastboot mode, and start this script again." - echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)" - echo "ERROR: (cable until the fastboot menu appears.)" - abort_now - fi -} - -# Flash an image to both A and B slot of partition. Abort on failure. -# Arguments: -flash_image_ab_or_abort() { - flash_image_or_abort "${1}" "${2}_a" "${3}" - flash_image_or_abort "${1}" "${2}_b" "${3}" -} - -# Operating system checks and variable definition -os_checks() { - case "$(uname -s 2> /dev/null)" in - Linux|GNU/Linux) - echo "INFO: You are using a Linux distribution." - FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot" - ;; - msys|MINGW*) - echo "INFO: You are using MinGW on Windows" - FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe" - ;; - *) - echo "ERROR: Unsupported operating system (${OSTYPE})." - echo "ERROR: Only GNU/Linux, and MinGW on Windows are currently supported." - abort_now - ;; - esac -} - -# Control the reboot sequence -reboot_device() { - echo "-----------" - echo "" - echo "INFO: Done. The device will reboot now." - "${FASTBOOT_BIN}" -s "${sn}" reboot - echo "" - echo "INFO: You can unplug the USB cable now." - echo "" -} - -# Warn about data wipe, and ask for confirmation -data_wipe_check() { - if [ "${CLEAN_FLASH}" = "true" ] - then - echo "" - echo "WARNING: Flashing this image wipes all user data and settings on the phone." - echo " Are you sure you want to wipe data and continue?" - echo "" - # Read user's input - read -rp " Type \"Yes\" (case sensitive) and press enter to wipe data and continue. Else, just press enter: " a - echo "" - if [ "_${a:-"No"}" != '_Yes' ] - # NOTE: $a is being set by the read command above, - # so the check for a to be set is mostly redundant - then - echo "WARNING: You DID NOT type \"Yes\", proceeding without data wipe." - echo "" - CLEAN_FLASH="false" - else - echo "WARNING: You typed \"Yes\", proceeding with data wipe." - CLEAN_FLASH="true" - fi - fi -} - -echo "" -echo "*** ${PRODUCT} flashing script ***" -echo "" -echo "INFO: The procedure will start soon. Please wait..." -echo "Note that this will detect and flash only on ${PRODUCT} device." -sleep 2 - -# Begin with some OS checks and variable definition -os_checks - -# Call function to look for device(s) -# If only one device is found $sn will store its serial number -find_device +# Target Flashing Images info +FLASH_AB_FW_IMGS="cam_vpu1 cam_vpu2 cam_vpu3 gz lk md1img preloader:preloader_k71v1_64_bsp.bin scp spmfw sspm tee" +FLASH_A_FW_IMGS="logo:logo.bin" +FLASH_AB_IMGS="boot dtbo vbmeta vbmeta_system vbmeta_vendor" +FLASH_A_IMGS="super" +ERASE_IMGS="userdata" +FORMAT_IMGS="md_udc" -# Call function to look for data wipe check -data_wipe_check +# Target flash process behavior +CLEAN_FLASH=true -# Flash the device -flash_device +source factory.common -# Reboot device -reboot_device +# Common flashing function +flash_factory