Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
moxiu6 committed Jan 12, 2025
1 parent bae76d2 commit 96b0fbe
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
67 changes: 67 additions & 0 deletions GSI_Flasher.bat
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions check_device.py
Original file line number Diff line number Diff line change
@@ -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.")

0 comments on commit 96b0fbe

Please sign in to comment.