rem ASMB9 Firmware Update
rem (1)YafuKCS version 6.79.
rem (2)Image Filename version : 2.3.3
@echo off

CLS
ASMC8 -release_date
if errorlevel 1 goto failed

echo Check fw version...Please wait.

Yaflash.exe -kcs bridge.ima -info -vyes >FW_INFO.txt

::major version
type FW_INFO.txt | xgrep "7." | vstr /f "e" 2 | vstr /I | vstr /s "  " " " | vstr /s "   ""|" | vstr /f "|" 2 | vstr /f "." 1 >romver1.txt
::miner version
type FW_INFO.txt | xgrep "7." | vstr /f "e" 2 | vstr /I | vstr /s "  " " " | vstr /s "   ""|" | vstr /f "|" 2 | vstr /f "." 2 >romver2.txt


xgrep "2" romver1.txt > nul
IF ERRORLEVEL 1 goto findromver2
IF ERRORLEVEL 0 goto findromver3

:findromver2
xgrep "14" romver2.txt > nul
IF ERRORLEVEL 1 goto Note115
IF ERRORLEVEL 0 goto Note114

:findromver3
xgrep "0" romver2.txt > nul
IF ERRORLEVEL 1 goto RebootBMC
IF ERRORLEVEL 0 goto Note118

:Note114
echo FW Version is 1.14.x. Please use flash3.bat
goto update

:Note115
echo FW Version is 1.15.x. Please use flash3.bat
goto update

:Note118
echo FW Version is 2.0.x. Please use flash3.bat
goto update

:RebootBMC
echo -------Reboot BMC-------
ASMC8.exe -kcs 18 02 
ASMB_MAC -delay 10

:CheckLoop
echo Please wait for BMC reboot...
ASMC8.exe -kcs c0 0c 04
if errorlevel 0 goto :UpdateLTS12
goto :CheckLoop

:UpdateLTS12
ASMB_MAC -delay 180
echo -------BMC reboot is complete-------
echo Update to LTS12 fw
if exist FW_INFO.txt del FW_INFO.txt
if exist romver1.txt del romver1.txt
if exist romver2.txt del romver2.txt  
ASMC8.exe -kcs c0 02 00
Yaflash.exe -kcs KRA16233.ima -preserve-config
goto end

:update
if exist FW_INFO.txt del FW_INFO.txt
if exist romver1.txt del romver1.txt
if exist romver2.txt del romver2.txt  
goto end1

:failed
CLS
echo Please update the last version of BIOS
goto update

:end
echo Please wait for 70 seconds to initialize firmware
if exist FW_INFO.txt del FW_INFO.txt
if exist romver1.txt del romver1.txt
if exist romver2.txt del romver2.txt 
ASMB_MAC -delay 70

:end1
PAUSE





