From 96b0fbe83fe7337b8c1810732b6b19c3ee4aa76f Mon Sep 17 00:00:00 2001 From: Moxiu <194266748+moxiu6@users.noreply.github.com> Date: Sun, 12 Jan 2025 14:26:10 +0100 Subject: [PATCH] initial commit --- GSI_Flasher.bat | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ check_device.py | 20 +++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 GSI_Flasher.bat create mode 100644 check_device.py diff --git a/GSI_Flasher.bat b/GSI_Flasher.bat new file mode 100644 index 0000000..43bae3e --- /dev/null +++ b/GSI_Flasher.bat @@ -0,0 +1,67 @@ +@echo off +setlocal enabledelayedexpansion + +:: Check if ADB is in the environment variables +where adb >nul 2>nul +if %errorlevel% neq 0 ( + echo ADB is not found in the environment variables. + set /p ADB_PATH="Please enter the full path to adb (e.g., C:\path\to\adb): " +) else ( + set ADB_PATH=adb + echo ADB is found in the environment variables. +) + +:: Check if Fastboot is in the environment variables +where fastboot >nul 2>nul +if %errorlevel% neq 0 ( + echo Fastboot is not found in the environment variables. + set /p FASTBOOT_PATH="Please enter the full path to fastboot (e.g., C:\path\to\fastboot): " +) else ( + set FASTBOOT_PATH=fastboot + echo Fastboot is found in the environment variables. +) + +:: Run Python script to check if device is connected +echo Running device check... +python check_device.py + +:: Prompt user to select the GSI image using File Explorer, filtering for .img files +echo Please select the GSI image file to flash (only .img files are supported)... +for /f "delims=" %%i in ('powershell -command "(New-Object -ComObject Shell.Application).BrowseForFolder(0, 'Select GSI Image', 0, 0).Items() | Where-Object { $_.Name -like '*.img' } | Select-Object -First 1 | ForEach-Object { $_.Path }"') do set GSI_IMAGE=%%i + +:: Check if a GSI image was selected +if not defined GSI_IMAGE ( + echo No GSI image selected. Exiting... + exit /b +) + +:: Show selected GSI image +echo You selected: "%GSI_IMAGE%" + +:: Check if ADB is working +echo Checking if ADB can detect your device... +"%ADB_PATH%" devices + +:: Reboot to fastboot mode +echo Rebooting to fastboot mode... +"%ADB_PATH%" reboot bootloader + +:: Wait for the device to be in fastboot mode +echo Waiting for device to enter fastboot mode... +timeout /t 5 + +:: Flash the GSI image +echo Flashing the GSI image... +"%FASTBOOT_PATH%" flash system "%GSI_IMAGE%" + +:: Wait for the flashing process to complete +echo Waiting for the flashing process to complete... +timeout /t 5 + +:: Reboot the device +echo Rebooting the device... +"%FASTBOOT_PATH%" reboot + +echo Flashing complete! Your device should reboot into the new system image. + +pause \ No newline at end of file diff --git a/check_device.py b/check_device.py new file mode 100644 index 0000000..91df34f --- /dev/null +++ b/check_device.py @@ -0,0 +1,20 @@ +import subprocess +import sys + +def check_device(): + # Run adb devices command + result = subprocess.run(['adb', 'devices'], capture_output=True, text=True) + + # Check if device is listed + if 'device' in result.stdout: + print("Device detected.") + return True + else: + print("No devices found.") + return False + +if __name__ == "__main__": + if not check_device(): + sys.exit("Exiting... No device detected.") + else: + print("Device is ready for flashing.")