diff --git a/flash/Android.mk b/flash/Android.mk new file mode 100644 index 0000000000000000000000000000000000000000..f6e471191cc671cb350d61867d5a188c6dc0b91d --- /dev/null +++ b/flash/Android.mk @@ -0,0 +1,39 @@ +LOCAL_PATH := $(call my-dir) + +IMG_PACKAGE_TARGET_CONFIG := $(LOCAL_PATH)/$(TARGET_DEVICE)/config.mk + +ifneq (,$(wildcard $(IMG_PACKAGE_TARGET_CONFIG))) +IMAGE_PACKAGE_NAME := IMG-e-$(LINEAGE_VERSION) +INSTALLED_IMG_PACKAGE_TARGET := $(PRODUCT_OUT)/$(IMAGE_PACKAGE_NAME).zip +MD5 := prebuilts/build-tools/path/$(HOST_PREBUILT_TAG)/md5sum +SHA256 := prebuilts/build-tools/path/$(HOST_PREBUILT_TAG)/sha256sum +$(INSTALLED_IMG_PACKAGE_TARGET): intermediates := $(call intermediates-dir-for,PACKAGING,IMG_PACKAGE) +$(INSTALLED_IMG_PACKAGE_TARGET): zip_root := $(intermediates)/$(IMAGE_PACKAGE_NAME) + +# Following variables can be defined through the config on a per device basis +HLOS_IMAGES_TARGET := +INCLUDE_IN_IMG_PACKAGE := +include $(IMG_PACKAGE_TARGET_CONFIG) + +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)/$(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 +endif + +$(INSTALLED_IMG_PACKAGE_TARGET): $(INCLUDE_IN_IMG_PACKAGE) $(INSTALLED_RADIOIMAGE_TARGET) $(SOONG_ZIP) + @echo "Package IMG package: $@" + $(hide) rm -rf $@ $(zip_root) + $(hide) mkdir -p $(zip_root) + $(hide) $(foreach t,$(INCLUDE_IN_IMG_PACKAGE) $(INSTALLED_RADIOIMAGE_TARGET), \ + cp -r $(t) $(zip_root)/$(notdir $(t));) + $(hide) find $(zip_root) | sort > $(zip_root).zip.list + $(hide) $(SOONG_ZIP) -d -o $@ -C $(zip_root) -l $(zip_root).zip.list + $(hide) $(MD5) $@ | sed "s|$(PRODUCT_OUT)/||" > $@.md5sum + $(hide) $(SHA256) $@ | sed "s|$(PRODUCT_OUT)/||" > $@.sha256sum + +bacon: $(INSTALLED_IMG_PACKAGE_TARGET) +endif diff --git a/flash/FP2/config.mk b/flash/FP2/config.mk new file mode 100644 index 0000000000000000000000000000000000000000..31c6415011f72fbde6b0a2a55cff1878260bc97d --- /dev/null +++ b/flash/FP2/config.mk @@ -0,0 +1,5 @@ +HLOS_IMAGES_TARGET := boot.img \ + cache.img \ + recovery.img \ + system.img \ + userdata.img diff --git a/flash/FP2/flash_FP2_factory.sh b/flash/FP2/flash_FP2_factory.sh new file mode 100755 index 0000000000000000000000000000000000000000..1226c45ae39adb9735f38c300d5e8d8b60c3d551 --- /dev/null +++ b/flash/FP2/flash_FP2_factory.sh @@ -0,0 +1,211 @@ +#!/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 2" +PRODUCT_ID="FP2" + +# 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_or_abort "${sn}" rpm "${IMAGES_DIR}/rpm.img" + flash_image_or_abort "${sn}" sbl1 "${IMAGES_DIR}/sbl1.img" + flash_image_or_abort "${sn}" tz "${IMAGES_DIR}/tz.img" + flash_image_or_abort "${sn}" modem "${IMAGES_DIR}/modem.img" + flash_image_or_abort "${sn}" splash "${IMAGES_DIR}/splash.img" + flash_image_or_abort "${sn}" aboot "${IMAGES_DIR}/aboot.img" + flash_image_or_abort "${sn}" boot "${IMAGES_DIR}/boot.img" + flash_image_or_abort "${sn}" recovery "${IMAGES_DIR}/recovery.img" + flash_image_or_abort "${sn}" system "${IMAGES_DIR}/system.img" + + if [ "${CLEAN_FLASH}" = "true" ] + then + flash_image_or_abort "${sn}" userdata "${IMAGES_DIR}/userdata.img" + flash_image_or_abort "${sn}" cache "${IMAGES_DIR}/cache.img" + fi +} + +# 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)" + 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 +} + +# 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 + +# 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 + +# Call function to look for data wipe check +data_wipe_check + +# Flash the device +flash_device + +# Reboot device +reboot_device diff --git a/flash/fastboot/bin-linux-x86/fastboot b/flash/fastboot/bin-linux-x86/fastboot new file mode 100755 index 0000000000000000000000000000000000000000..1141b12acb92a5de0646c3ced04beee5cde32966 Binary files /dev/null and b/flash/fastboot/bin-linux-x86/fastboot differ diff --git a/flash/fastboot/bin-msys/AdbWinApi.dll b/flash/fastboot/bin-msys/AdbWinApi.dll new file mode 100644 index 0000000000000000000000000000000000000000..7abe26cf1d2ab67f0107b19c5fe5a9c4543f90c0 Binary files /dev/null and b/flash/fastboot/bin-msys/AdbWinApi.dll differ diff --git a/flash/fastboot/bin-msys/AdbWinUsbApi.dll b/flash/fastboot/bin-msys/AdbWinUsbApi.dll new file mode 100644 index 0000000000000000000000000000000000000000..e7a6de1208910df2577ef86bbe536fb23fa5f015 Binary files /dev/null and b/flash/fastboot/bin-msys/AdbWinUsbApi.dll differ diff --git a/flash/fastboot/bin-msys/adb.exe b/flash/fastboot/bin-msys/adb.exe new file mode 100644 index 0000000000000000000000000000000000000000..dd233d84d4af0fcbd7933b7bc93c02ac75f103ce Binary files /dev/null and b/flash/fastboot/bin-msys/adb.exe differ diff --git a/flash/fastboot/bin-msys/fastboot.exe b/flash/fastboot/bin-msys/fastboot.exe new file mode 100644 index 0000000000000000000000000000000000000000..51d620dee8a3fe51dc5ce4dae18b2ae138466cde Binary files /dev/null and b/flash/fastboot/bin-msys/fastboot.exe differ