echo " fastboot flash tools"
fastboot %* getvar product 2>&1 | findstr /r /c:"^product: *" || echo Missmatching image and device
fastboot %* getvar product 2>&1 | findstr /r /c:"^product: *" || exit /B 1
::check anti_version
if exist %~dp0images\anti_version.txt (for /f "delims==" %%a in (%~dp0images\anti_version.txt) do (set CURRENT_ANTI_VER=%%a))
if [%CURRENT_ANTI_VER%] EQU [] set CURRENT_ANTI_VER=0
for /f "tokens=2 delims=: " %%i in ('fastboot %* getvar anti 2^>^&1 ^| findstr /r /c:"anti:"') do (set version=%%i)
if [%version%] EQU [] set version=0
set anticheck="antirollback check pass"
if %version% GTR %CURRENT_ANTI_VER% set anticheck="Current device antirollback version is greater than this pakcage"
echo %anticheck% | findstr /r /c:"pass" || @echo "Antirollback check error" && exit /B 1
:: crc check
fastboot %* getvar crc 2>&1 | findstr /r /c:"^crc: 1" && if %errorlevel% equ 0 (
fastboot %* flash crclist %~dp0images\crclist.txt || @echo "Flash crclist error" && exit /B 1
fastboot %* flash sparsecrclist %~dp0images\sparsecrclist.txt || @echo "Flash sparsecrclist error" && exit /B 1
)
fastboot %* erase boot_a || @echo "Erase boot_a error" && exit /B 1
fastboot %* erase boot_b || @echo "Erase boot_b error" && exit /B 1
fastboot %* erase metadata || @echo "Erase metadata error" && exit /B 1
fastboot %* flash super "%~dp0images\super.img" || @echo "Flash super error" && goto error
fastboot %* flash vbmeta_a "%~dp0images\vbmeta.img" || @echo "Flash vbmeta_a error" && goto error
fastboot %* flash vbmeta_b "%~dp0images\vbmeta.img" || @echo "Flash vbmeta_b error" && goto error
fastboot %* flash vbmeta_system_a "%~dp0images\vbmeta_system.img" || @echo "Flash vbmeta_system_a error" && goto error
fastboot %* flash vbmeta_system_b "%~dp0images\vbmeta_system.img" || @echo "Flash vbmeta_system_b error" && goto error
fastboot %* flash userdata "%~dp0images\userdata.img" || @echo "Flash userdata error" && goto error
fastboot %* flash tz_a "%~dp0images\tz.mbn" || @echo "Flash tz_a error" && goto error
fastboot %* flash tz_b "%~dp0images\tz.mbn" || @echo "Flash tz_b error" && goto error
fastboot %* flash xbl_a "%~dp0images\xbl.elf" || @echo "Flash xbl_a error" && goto error
fastboot %* flash xbl_b "%~dp0images\xbl.elf" || @echo "Flash xbl_b error" && goto error
fastboot %* flash xbl_config_a "%~dp0images\xbl_config.elf" || @echo "Flash xbl_config_a error" && goto error
fastboot %* flash xbl_config_b "%~dp0images\xbl_config.elf" || @echo "Flash xbl_config_b error" && goto error
fastboot %* flash rpm_a "%~dp0images\rpm.mbn" || @echo "Flash rpm_a error" && goto error
fastboot %* flash rpm_b "%~dp0images\rpm.mbn" || @echo "Flash rpm_b error" && goto error
fastboot %* flash abl_a "%~dp0images\abl.elf" || @echo "Flash abl_a error" && goto error
fastboot %* flash abl_b "%~dp0images\abl.elf" || @echo "Flash abl_b error" && goto error
fastboot %* flash devcfg_a "%~dp0images\devcfg.mbn" || @echo "Flash devcfg_a error" && goto error
fastboot %* flash devcfg_b "%~dp0images\devcfg.mbn" || @echo "Flash devcfg_b error" && goto error
fastboot %* flash hyp_a "%~dp0images\hyp.mbn" || @echo "Flash hyp_a error" && goto error
fastboot %* flash hyp_b "%~dp0images\hyp.mbn" || @echo "Flash hyp_b error" && goto error
fastboot %* flash keymaster_a "%~dp0images\km41.mbn" || @echo "Flash keymaster_a error" && goto error
fastboot %* flash keymaster_b "%~dp0images\km41.mbn" || @echo "Flash keymaster_b error" && goto error
fastboot %* flash featenabler_a "%~dp0images\featenabler.mbn" || @echo "Flash featenabler_a error" && goto error
fastboot %* flash featenabler_b "%~dp0images\featenabler.mbn" || @echo "Flash featenabler_b error" && goto error
fastboot %* flash qupfw_a "%~dp0images\qupv3fw.elf" || @echo "Flash qupfw_a error" && goto error
fastboot %* flash qupfw_b "%~dp0images\qupv3fw.elf" || @echo "Flash qupfw_b error" && goto error
fastboot %* flash imagefv_a "%~dp0images\imagefv.elf" || @echo "Flash imagefv_a error" && goto error
fastboot %* flash imagefv_b "%~dp0images\imagefv.elf" || @echo "Flash imagefv_b error" && goto error
fastboot %* flash bluetooth_a "%~dp0images\BTFM.bin" || @echo "Flash bluetooth_a error" && goto error
fastboot %* flash bluetooth_b "%~dp0images\BTFM.bin" || @echo "Flash bluetooth_b error" && goto error
fastboot %* flash uefisecapp_a "%~dp0images\uefi_sec.mbn" || @echo "Flash uefisecapp_a error" && goto error
fastboot %* flash uefisecapp_b "%~dp0images\uefi_sec.mbn" || @echo "Flash uefisecapp_b error" && goto error
fastboot %* flash storsec "%~dp0images\storsec.mbn" || @echo "Flash storsec error" && goto error
fastboot %* flash logfs "%~dp0images\logfs_ufs_8mb.bin" || @echo "Flash logfs error" && goto error
fastboot %* flash dsp_a "%~dp0images\dspso.bin" || @echo "Flash dsp_a error" && goto error
fastboot %* flash dsp_b "%~dp0images\dspso.bin" || @echo "Flash dsp_b error" && goto error
fastboot %* flash vendor_boot_a "%~dp0images\vendor_boot.img" || @echo "Flash vendor_boot_a error" && goto error
fastboot %* flash vendor_boot_b "%~dp0images\vendor_boot.img" || @echo "Flash vendor_boot_b error" && goto error
fastboot %* flash modem_a "%~dp0images\NON-HLOS.bin" || @echo "Flash modem_a error" && goto error
fastboot %* flash modem_b "%~dp0images\NON-HLOS.bin" || @echo "Flash modem_b error" && goto error
fastboot %* flash core_nhlos_a "%~dp0images\Core_NON-HLOS.bin" || @echo "Flash core_nhlos_a error" && goto error
fastboot %* flash core_nhlos_b "%~dp0images\Core_NON-HLOS.bin" || @echo "Flash core_nhlos_b error" && goto error
fastboot %* flash dtbo_a "%~dp0images\dtbo.img" || @echo "Flash dtbo_a error" && goto error
fastboot %* flash dtbo_b "%~dp0images\dtbo.img" || @echo "Flash dtbo_b error" && goto error
fastboot %* flash cust "%~dp0images\cust.img" || @echo "Flash cust error" && goto error
fastboot %* flash boot_a "%~dp0images\boot.img" || @echo "Flash boot_a error" && goto error
fastboot %* flash boot_b "%~dp0images\boot.img" || @echo "Flash boot_b error" && goto error
fastboot %* set_active a || @echo "Set active a error" && exit 1
fastboot %* reboot || @echo "Reboot error" && exit 1
:error
exit 1