@rem Copyright ? Huawei Technologies Co., Ltd. 2010-2020. All rights reserved.
@rem Description: mbb burn script

@echo off
fastboot -i 0x12d1 getvar chip_version>chip_version.txt 2>&1
	type chip_version.txt| findstr /e "0.9"
	if !errorlevel! NEQ 0 (
		type chip_version.txt| findstr /e "95000110"
			if !errorlevel! NEQ 0 (
				@echo "您未使用正确的版本烧写，镜像版本与单板版本不匹配！" >>burn_log.txt
				goto error
			)
	)

fastboot -i 0x12d1 getvar pagesize>pagesize.txt 2>&1
	if %errorlevel% NEQ 0 goto error

type pagesize.txt| findstr /e "800"
	@if %errorlevel%==0 (
		set system_img=system_2k.img
		set modem_fw_img=balong_modem_fw_2k.img
::		set multica_img=multica_2k.img
::		set upgrade_img=balong_upgrade_2k.img
	)
type pagesize.txt| findstr /e "1000"
	@if %errorlevel%==0 (
		set system_img=system_4k.img
		set modem_fw_img=balong_modem_fw_4k.img
::		set multica_img=multica_4k.img
::		set upgrade_img=balong_upgrade_4k.img
	)
::if not exist %system_img% (
::	goto error
::)
::if not exist %modem_fw_img% (
::	goto error
::)

set system_img=system.ubi
set online_img=online.ubi
set recoveryfs_img=recoveryfs.ubi
@echo " %date% %time% ">>burn_log.txt
@echo %system_img% >> burn_log.txt 2>&1
@echo %recoveryfs_img% >> burn_log.txt 2>&1
::@echo %modem_fw_img% >> burn_log.txt 2>&1
::@echo %upgrade_img% >> burn_log.txt 2>&1

fastboot -i 0x12d1 erase m3boot >> burn_log.txt 2>&1

fastboot -i 0x12d1 erase ptable >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error
fastboot -i 0x12d1 flash ptable ptable.bin >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 erase s_version >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error 
fastboot -i 0x12d1 flash hiboot hiboot.img >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

if exist dtcust.img (
fastboot -i 0x12d1 flash dtcust dtcust.img >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error
fastboot -i 0x12d1 flash modem_dtcust modem_dtcust.img >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error
)
if exist dt.img (
fastboot -i 0x12d1 flash dt dt.img >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error
fastboot -i 0x12d1 flash modem_dt modem_dt.img >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error
)

fastboot -i 0x12d1 flash m3image lpmcu.bin >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 flash kernel boot.img >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 flash recovery boot.img >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 erase system  >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error
fastboot -i 0x12d1 flash system %system_img% >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 erase online >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error
fastboot -i 0x12d1 flash online %online_img% >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 erase recoveryfs  >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error
fastboot -i 0x12d1 flash recoveryfs %recoveryfs_img% >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

if exist hifi.bin (
fastboot -i 0x12d1 flash hifi hifi.bin >> burn_log.txt 2>&1
    )
    @if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 flash nvdload nv_modem.bin >> burn_log.txt 2>&1
	@if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 flash nvcust nv_cust.bin >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

::if exist %multica_img% (
::fastboot -i 0x12d1 erase multica >> burn_log.txt 2>&1
::    @if %errorlevel% NEQ 0 goto error

::fastboot -i 0x12d1 flash multica %multica_img% >> burn_log.txt 2>&1
::    @if %errorlevel% NEQ 0 goto error
::)

::if exist %upgrade_img% (
::fastboot -i 0x12d1 erase online >> burn_log.txt 2>&1
::    @if %errorlevel% NEQ 0 goto error
::fastboot -i 0x12d1 flash online %upgrade_img% >> burn_log.txt 2>&1
::    @if %errorlevel% NEQ 0 goto error
::)

if exist trustedcore.img (
fastboot -i 0x12d1 flash teeos trustedcore.img >> burn_log.txt 2>&1
	)
    @if %errorlevel% NEQ 0 goto error
if exist bl31.bin (
fastboot -i 0x12d1 flash trusted_fw bl31.bin >> burn_log.txt 2>&1
)
    @if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 flash m3boot xloader.bin >> burn_log.txt 2>&1
    @if %errorlevel% NEQ 0 goto error

fastboot -i 0x12d1 reboot-bootloader >> burn_log.txt 2>&1

@del chip_version.txt
@del pagesize.txt
@echo success>>burn_ret.txt
@echo on
EXIT /b  0

:error
@echo fail>>burn_ret.txt
@echo on
EXIT /b  1
