fastboot %* getvar product 2>&1 | findstr /r /c:"^product: *kunzite" || echo Missmatching image and device
fastboot %* getvar product 2>&1 | findstr /r /c:"^product: *kunzite" || exit /B 1
::erase opcust and opconfig when cota enabled; Judge whether the partition exists before erase;
fastboot %* getvar partition-type:opcust 2>&1 | findstr /r /c:"^partition-type:opcust: raw"
if %errorlevel% equ 0 (
fastboot %* erase opcust || @echo "Erase opcust error" && exit /B 1
)
fastboot %* getvar partition-type:opconfig 2>&1 | findstr /r /c:"^partition-type:opconfig: raw"
if %errorlevel% equ 0 (
fastboot %* erase opconfig || @echo "Erase opconfig error" && 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
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_ab || @echo "Erase boot_ab error" && exit /B 1
fastboot %* flash abl_ab %~dp0images\abl.elf || @echo "Flash abl_ab error" && exit /B 1
fastboot %* flash xbl_ab %~dp0images\xbl_s.melf || @echo "Flash xbl_ab error" && exit /B 1
fastboot %* flash xbl_config_ab %~dp0images\xbl_config.elf || @echo "Flash xbl_config_ab error" && exit /B 1
fastboot %* flash shrm_ab %~dp0images\shrm.elf || @echo "Flash shrm_ab error" && exit /B 1
fastboot %* flash aop_ab %~dp0images\aop.mbn || @echo "Flash aop_ab error" && exit /B 1
fastboot %* flash aop_config_ab %~dp0images\aop_devcfg.mbn || @echo "Flash aop_config_ab error" && exit /B 1
fastboot %* flash tz_ab %~dp0images\tz.mbn || @echo "Flash tz_ab error" && exit /B 1
fastboot %* flash devcfg_ab %~dp0images\devcfg.mbn || @echo "Flash devcfg_ab error" && exit /B 1
fastboot %* flash featenabler_ab %~dp0images\featenabler.mbn || @echo "Flash featenabler_ab error" && exit /B 1
fastboot %* flash hyp_ab %~dp0images\hypvmperformance.mbn || @echo "Flash hyp_ab error" && exit /B 1
fastboot %* flash uefi_ab %~dp0images\uefi.elf || @echo "Flash uefi error" && exit /B 1
fastboot %* flash uefisecapp_ab %~dp0images\uefi_sec.mbn || @echo "Flash uefisecapp error" && exit /B 1
for /f "tokens=3" %%i in ('fastboot %* oem hwid 2^>^&1 ^| findstr "HwCountry"') do set "result=%%i"
if "%result%"=="GL" (
fastboot %* flash modem_ab %~dp0images\modem\global\NON-HLOS.bin || @echo "Flash modem error" && exit /B 1
) else if "%result%"=="CN" (
fastboot %* flash modem_ab %~dp0images\modem\cn\NON-HLOS.bin || @echo "Flash modem error" && exit /B 1
) else if "%result%"=="IN" (
fastboot %* flash modem_ab %~dp0images\modem\in\NON-HLOS.bin || @echo "Flash modem error" && exit /B 1
) else (
@echo HwCountry error!
exit /B 1
)
fastboot %* flash bluetooth_ab %~dp0images\BTFM.bin || @echo "Flash bluetooth error" && exit /B 1
fastboot %* flash dsp_ab %~dp0images\dspso.bin || @echo "Flash dsp error" && exit /B 1
fastboot %* flash keymaster_ab %~dp0images\keymint.mbn || @echo "Flash keymaster error" && exit /B 1
fastboot %* flash qupfw_ab %~dp0images\qupv3fw.elf || @echo "Flash qupfw error" && exit /B 1
::fastboot %* flash multiimgoem_ab %~dp0images\multi_image.mbn || @echo "Flash multiimgoem error" && exit /B 1
::fastboot %* flash multiimgqti_ab %~dp0images\multi_image_qti.mbn || @echo "Flash multiimgqti error" && exit /B 1
fastboot %* flash cpucp_ab %~dp0images\cpucp.elf || @echo "Flash cpucp error" && exit /B 1
fastboot %* flash rtice %~dp0images\rtice.mbn || @echo "Flash rtice error" && exit /B 1
fastboot %* flash logfs %~dp0images\logfs_ufs_8mb.bin || @echo "Flash logfs error" && exit /B 1
fastboot %* flash rescue %~dp0images\rescue.img || @echo "Flash rescue error" && exit /B 1
fastboot %* flash storsec %~dp0images\storsec.mbn || @echo "Flash storsec error" && exit /B 1
fastboot %* flash toolsfv %~dp0images\tools.fv || @echo "Flash toolsfv error" && exit /B 1
::fastboot %* flash qweslicstore_ab %~dp0images\qweslicstore.bin || @echo "Flash qweslicstore error" && exit /B 1
fastboot %* flash xbl_ramdump_ab %~dp0images\XblRamdump.elf || @echo "Flash xbl_ramdump error" && exit /B 1
fastboot %* flash xbl_sc_test_mode %~dp0images\xbl_sc_test_mode.bin || @echo "Flash xbl_sc_test_mode error" && exit /B 1
fastboot %* erase imagefv_ab || @echo "Erase imagefv error" && exit /B 1
fastboot %* flash imagefv_ab %~dp0images\imagefv.elf || @echo "Flash imagefv error" && exit /B 1
fastboot %* flash super %~dp0images\super.img || @echo "Flash super error" && exit /B 1
fastboot %* flash vendor_boot_ab %~dp0images\vendor_boot.img || @echo "Flash vendor_boot error" && exit /B 1
fastboot %* flash dtbo_ab %~dp0images\dtbo.img || @echo "Flash dtbo error" && exit /B 1
fastboot %* flash vbmeta_ab %~dp0images\vbmeta.img || @echo "Flash vbmeta error" && exit /B 1
fastboot %* flash vbmeta_system_ab %~dp0images\vbmeta_system.img || @echo "Flash vbmeta_system error" && exit /B 1
fastboot %* erase metadata || @echo "Erase metadata error" && exit /B 1
fastboot %* flash metadata %~dp0images\metadata.img || @echo "Flash metadata error" && exit /B 1
fastboot %* erase userdata || @echo "Erase userdata error" && exit /B 1
fastboot %* flash userdata %~dp0images\userdata.img || @echo "Flash userdata error" && exit /B 1
::fastboot %* flash cust %~dp0images\cust.img || @echo "Flash cust error" && exit /B 1
fastboot %* flash init_boot_ab %~dp0images\init_boot.img || @echo "Flash init_boot error" && exit /B 1
fastboot %* flash recovery_ab %~dp0images\recovery.img || @echo "Flash recovery error" && exit /B 1
fastboot %* flash pvmfw_ab %~dp0images\pvmfw.img || @echo "Flash pvmfw error" && exit /B 1
fastboot %* flash countrycode_ab %~dp0images\countrycode.img || @echo "Flash countrycode_ab error" && exit /B 1
fastboot %* flash boot_ab %~dp0images\boot.img || @echo "Flash boot error" && exit /B 1
fastboot %* flash misc %~dp0images\misc.img || @echo "Flash misc error" && exit /B 1
fastboot %* set_active a || @echo "Set active a error" && exit /B 1
fastboot %* oem erase-vb-index
fastboot %* getvar unlocked 2>&1 | findstr /r "yes" 2>&1 && fastboot %* oem lock || fastboot %* reboot