@ECHO OFF
REM Version: V06
REM Date: 20180725
REM ============== USAGE ==============
REM flashall_AFT.cmd [Format option] [SN number]
REM [Format option]: 1=enable, 0=disable. default=0
REM Format userdata/cache
REM [SN number]: device SN number
REM Support multiple download image
REM ============== setting ==============
SETLOCAL
IF "%selfWrapped%"=="" (
REM this is necessary so that we can use "exit" to terminate the batch file,
REM and all subroutines, but not the original cmd.exe
SET selfWrapped=true
%ComSpec% /s /c ""%~0" %*"
GOTO :EOF
)
REM ============== main() ==============
CLS
SET "dataerase=0"
SET "SSN="
SET "para="
SET "tempSysName=.system_tmp.img"
IF [%1] EQU [1] ( SET dataerase=1 )
IF NOT [%2] EQU [] ( SET para=-s )
IF NOT [%2] EQU [] (
SET SSN=%2
SET tempSysName=.system_tmp_%2.img
)
call:flash
EXIT 0
REM ============== flash() ==============
:flash
SET "RAW="
FOR /F "delims=" %%i IN ('dir "%~dp0" /B ^| findstr /I "raw"') DO ( SET RAW=%%i )
IF NOT EXIST "%RAW%" ECHO "FAILED, RAW NOT EXIST!" && EXIT 1
ECHO.
ECHO ##################################################################
ECHO ####################### FLASH RAW FILE ########################
ECHO ##################################################################
ECHO.
ECHO ## RAW: %RAW%
ECHO ## ERASE DATA: %dataerase%
ECHO ## SSN: %SSN%
ECHO.
ECHO ===================================================================
call:fastboot_tool flash all "%RAW%"
REM call:fastboot_tool reboot-bootloader
REM timeout /T 10
ping 127.0.0.1 -n 10 > null
IF %dataerase% EQU 1 (
call:fastboot_tool -w
call:fastboot_tool format asdf
call:fastboot_tool format ADF
)
set "errorlevel="
fastboot oem device-info 2>lock.txt && findstr /C:"(bootloader) Device unlocked: true" lock.txt
echo errorlevel=%errorlevel%
REM errorlevel == 0 => Device unlocked: true
REM if %errorlevel% ==0 goto lock
if %errorlevel% ==0 goto reboot
REM errorlevel == 1 => Device unlocked: false
if %errorlevel% ==1 goto reboot
REM ============== Lock ==================
:lock
echo fastboot.exe oem asus-csc_lk
call:fastboot_tool oem asus-csc_lk
REM echo fastboot.exe -w
REM call:fastboot_tool -w
REM ============== Reboot ================
:reboot
IF %dataerase% EQU 1 (
for /f "tokens=3,4" %%i in (lock.txt) do (
echo ## %%i %%j
if "%%i" == "authorized:" (
if "%%j" == "true" (
REM goto oemlock
goto adb_enable
)
if "%%j" == "false" (
goto adb_enable
)
)
)
REM fastboot oem device-info 2>dungle_lock.txt && findstr /C:"(bootloader) Device authorized: true" dungle_lock.txt
REM echo errorlevel=%errorlevel%
REM errorlevel == 0 => Device authorized: true
REM if %errorlevel% ==0 goto oemlock
REM errorlevel == 1 => Device authorized: false
REM if %errorlevel% ==1 goto adb_enable
emlock
REM oem lock
REM ============== oem lock ================
echo fastboot.exe oem reset-dev_info
call:fastboot_tool oem reset-dev_info
)
:adb_enable
echo call:fastboot_tool oem adb_enable
call:fastboot_tool oem adb_enable
IF EXIST %tempSysName% DEL %tempSysName%
ECHO.
ECHO ##################################################################
ECHO ################## FLASH COMPLETE. RESTART! ###################
ECHO ##################################################################
ECHO.
GOTO:EOF
REM ============== fastboot_tool() ==============
:fastboot_tool
ECHO [command] : fastboot.exe %~1 %~2 %~3 %~4 %para% %SSN%
fastboot.exe %~1 %~2 %~3 %~4 %para% %SSN%
IF NOT %ERRORLEVEL% == 0 (
ECHO "FAILED, fastboot.exe %~1 %~2 %~3 %~4 %para% %SSN% failure, EXIT!"
IF EXIST %tempSysName% DEL %tempSysName%
EXIT 1
)
ECHO ===================================================================
GOTO:EOF
:END