@echo off
setlocal enabledelayedexpansion
set app=%~n0
set ANDROID_PRODUCT_OUT=.
if not exist "fastboot.exe" ( echo Error: cannot find fastboot at fastboot.exe & exit /b 1 )
.fastboot –version
echo.
goto :main
:help
echo %app% -h
echo Show this help
echo %app%
echo Flash a phone when only one phone is connnected
echo %app% -s ^<serial_number^>
echo Flash a phone when multiple phones are connnected
echo %app% -e
echo Erase userdata and metadata
echo %app% -n
echo Not reboot after flash
echo %app% -u
echo Update partition and flash a phone.
echo Note: Please use with CAUTION if necessary.
echo %app% -d
echo Debug purpose: not flash super.img
echo.
exit /b 0
goto :EOF
:fastboot
echo fastboot -s "%sn%" %*
..fastboot -s "%sn%" %*
if errorlevel 1 (
echo.
echo =========================
echo Error: fastboot failed!!!
echo =========================
pause
exit /b 1
)
echo.
goto :EOF
:main
echo Parse args…
set sn=
set erase_userdata=0
set not_reboot=0
set update_part=0
set debug=0
:args
if a%1==a goto :end_args
if a%1==a-h goto :help
if a%1==a-s if a%2==a ( echo Error: missing serial_number& exit /b 1) else (set sn=%2& shift ) & shift & goto :args
if a%1==a-e set erase_userdata=1 & shift & goto :args
if a%1==a-n set not_reboot=1 & shift & goto :args
if a%1==a-u set update_part=1 & shift & goto :args
if a%1==a-d set debug=1 & shift & goto :args
echo Error: unknown arg: %1
exit /b 1
:end_args
echo sn=%sn%
echo erase_userdata=%erase_userdata%
echo not_reboot=%not_reboot%
echo update_part=%update_part%
echo debug=%debug%
echo.
echo Find pac file…
set n=0
for %%i in (*.pac) do set /a n=n+1 & echo %%i & set pac=%%i
echo.
if %n% gtr 1 ( echo Error: only support one pac file, please remove unsed pac file & exit /b 1 )
if not exist "%pac%" ( echo Error: not found pac file %pac% & exit /b 1 )
echo.
echo Folder of extracted files…
set unp=%pac:~0,-4%
echo %unp%
if exist "%unp%unpac.ok" goto :end_unp
rd /s/q "%unp%" 2>nul
echo.
echo ======================================================
echo Note: it will take few minutes to extract pac file …
echo ======================================================
.fastboot parse-pac %pac%
if not exist "%unp%unpac.ok" ( echo Error: extract %pac% failed & exit /b 1 )
:end_unp
cd "%unp%" || ( echo Error: extract %pac% failed & exit /b 1 )
echo.
echo =========================================================
echo Note: please manually boot your phone to fastboot mode…
echo =========================================================
echo.
if not a%sn%==a goto :end_sn
echo Wait for a fastboot device…
..fastboot getvar serialno
echo.
echo List fastboot device…
set n=0
for /f "tokens=1,2" %%i in ('..fastboot devices ^| findstr fastboot') do set /a n=n+1 & set sn=%%i& echo %%i
echo.
if %n% gtr 1 ( echo Error: more than one device connected, please remove unsed device & exit /b 1 )
if a%sn%==a ( echo Error: no device connected & exit /b 1 )
:end_sn
echo.
echo Wait for %sn% in fastboot mode…
call :fastboot getvar serialno || goto :EOF
echo.
echo Set backup nv flag…
call :fastboot oem backupnv || goto :EOF
echo.
echo Flash NV…
call :fastboot flash nr_fixnv1_a QogirN6Pro_PS_SECU_Customer_nvitem.bin || goto :EOF
echo.
REM call :fastboot flash prodnv prodnv.img || goto :EOF
REM echo.
if %update_part%==0 goto :end_update
echo.
echo Copy gpt image …
copy /y/z ..Gpt_entry_* . || ( echo Error: copy Gpt failed & exit /b 1)
if not exist ..backup.%sn% mkdir ..backup.%sn%
echo.
echo Backup gpt …
call :fastboot oem pull partition ..backup.%sn%gpt-old.img || goto :EOF
echo.
echo Backup paritions…
call :fastboot oem pull factory ..backup.%sn%factory.img || goto :EOF
call :fastboot oem pull nr_fixnv1_a ..backup.%sn%nr_fixnv1_a.img || goto :EOF
call :fastboot oem pull miscdata ..backup.%sn%miscdata.img || goto :EOF
call :fastboot oem pull prodnv ..backup.%sn%prodnv.img || goto :EOF
echo.
::echo Erase all …
::call :fastboot erase erase_all || goto :EOF
echo.
echo Flash parition table…
call :fastboot flash gpt Gpt_entry_ufs-sign.bin || goto :EOF
echo.
echo Restore paritions…
call :fastboot flash factory ..backup.%sn%factory.img || goto :EOF
call :fastboot flash nr_fixnv1_a ..backup.%sn%nr_fixnv1_a.img || goto :EOF
call :fastboot flash miscdata ..backup.%sn%miscdata.img || goto :EOF
call :fastboot flash prodnv ..backup.%sn%prodnv.img || goto :EOF
:end_update
echo.
echo Flash key images…
call :fastboot flash splloader u-boot-spl-16k-ufs-sign.bin || goto :EOF
call :fastboot flash uboot_a lk-sign.bin || goto :EOF
call :fastboot flash sml_a sml-sign.bin || goto :EOF
call :fastboot flash teecfg_a teecfg-sign.bin || goto :EOF
call :fastboot flash trustos_a tos-sign.bin || goto :EOF
echo.
echo Flash other images…
call :fastboot flash blackbox blackbox.img || goto :EOF
if exist boot.img (
call :fastboot flash boot_a boot.img || goto :EOF
) else (
call :fastboot flash boot_a boot-gki.img || goto :EOF
)
call :fastboot flash cache cache.img || goto :EOF
call :fastboot flash ch_sys_a QogirN6Pro_CH.bin || goto :EOF
call :fastboot erase misc
call :fastboot reboot bootloader
TIMEOUT /T 5 /NOBREAK
call :fastboot flash vbmeta_a vbmeta-sign.img || goto :EOF
call :fastboot flash vbmeta_odm_a vbmeta_odm.img || goto :EOF
call :fastboot flash vbmeta_product_a vbmeta_product.img || goto :EOF
call :fastboot flash vbmeta_system_a vbmeta_system.img || goto :EOF
call :fastboot flash vbmeta_system_ext_a vbmeta_system_ext.img || goto :EOF
call :fastboot flash vbmeta_vendor_a vbmeta_vendor.img || goto :EOF
call :fastboot flash vendor_boot_a vendor_boot.img || goto :EOF
if a%debug%==a0 call :fastboot flash super super.img || goto :EOF
call :fastboot flash dtbo_a dtbo.img || goto :EOF
call :fastboot flash elabel elabel.img || goto :EOF
call :fastboot flash fbootlogo logo.bin || goto :EOF
call :fastboot flash init_boot_a init_boot.img || goto :EOF
call :fastboot flash l_agdsp_a QogirN6Pro_AUDCP_DSP_lit_dm.bin || goto :EOF
call :fastboot flash logo logo.bin || goto :EOF
call :fastboot flash nr_deltanv_a QogirN6Pro_PS_SECU_Customer_deltanv.bin || goto :EOF
call :fastboot flash nr_modem_a SC9600_QogirN6Pro_PS_SECU_Customer_modem.bin || goto :EOF
call :fastboot flash nr_phy_a SC9600_QogirN6Pro_PHY_SECU_modem.bin || goto :EOF
call :fastboot flash persist persist.img || goto :EOF
call :fastboot flash pm_sys_a QogirN6Pro_SP.bin || goto :EOF
if a%erase_userdata%==a1 call :fastboot flash userdata userdata.img || goto :EOF
echo.
echo Erase runtime partitions…
call :fastboot erase misc
call :fastboot erase nr_runtimenv1
call :fastboot erase sysdumpdb
::call :fastboot erase uboot_log
if a%erase_userdata%==a1 call :fastboot erase metadata
echo.
if a%not_reboot%==a0 (echo Reboot phone…&call :fastboot reboot || goto :EOF)
if a%erase_userdata%==a1 goto :EOF
echo.
echo =====================================================================================================================
echo NOTE: not erase userdata^^! If you find any abnormal boot or dump, please manually run these commands in fastboot mode:
echo =====================================================================================================================
echo fastboot -w
echo fastboot reboot
echo.
echo Try below 2 commands if above comands have problem
echo fastboot erase userdata
echo fastboot erase metadata
echo fastboot reboot
pause