@echo off
adb reboot bootloader
for /f "tokens=2 delims=: " %%a in ('fastboot.exe getvar build_id 2^>^&1 ^| findstr build_id') do set build_id=%%a
if "%build_id%"=="" (goto :Old_Way) else (goto :Check_Device)
:Check_Device
set expected=RADITZ
for /f "tokens=2 delims=: " %%a in ('fastboot.exe getvar device 2^>^&1 ^| findstr device') do set device=%%a
if "%device%"=="%expected%" (goto :Flash) else (goto :Error)
:Old_Way
set expected=MSM8937
for /f "tokens=2 delims=: " %%a in ('fastboot.exe getvar product 2^>^&1 ^| findstr product') do set product=%%a
if "%product%"=="%expected%" (goto :Flash) else (goto :Error)
:Flash
echo for not erase modemst1 and modemst2
rem fastboot flash partition gpt_both0.bin
fastboot flash tz tz.mbn
fastboot flash sbl1 sbl1.mbn
fastboot flash rpm rpm.mbn
fastboot flash aboot emmc_appsboot.mbn
fastboot flash devcfg devcfg.mbn
fastboot flash lksecapp lksecapp.mbn
fastboot flash keymaster keymaster.mbn
fastboot flash cmnlib cmnlib.mbn
fastboot flash cmnlib64 cmnlib64.mbn
fastboot flash tzbak tz.mbn
fastboot flash sbl1bak sbl1.mbn
fastboot flash rpmbak rpm.mbn
fastboot flash abootbak emmc_appsboot.mbn
fastboot flash devcfgbak devcfg.mbn
fastboot flash lksecappbak lksecapp.mbn
fastboot flash keymasterbak keymaster.mbn
fastboot flash cmnlibbak cmnlib.mbn
fastboot flash cmnlib64bak cmnlib64.mbn
rem fastboot flash fsg fs_image.tar.gz.mbn.img
rem fastboot flash modemst1 dummy.bin
rem fastboot flash modemst2 dummy.bin
rem fastboot flash persist persist.img
fastboot erase misc
fastboot erase boot
fastboot flash modem NON-HLOS.bin
fastboot flash system system.img
fastboot flash cache cache.img
fastboot flash userdata userdata.img
fastboot flash recovery recovery.img
rem fastboot flash sec sec.dat
fastboot flash dsp adspso.bin
fastboot flash mdtp mdtp.img
fastboot erase splash
fastboot flash splash splash.img
fastboot erase DDR
fastboot flash boot boot.img
fastboot reboot
pause
exit
:Error
echo Device does not match RADITZ and cannot be flashed. Check the FW.
pause
exit