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


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 :findromver1
goto :CheckLoop

:findromver1
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 UpdateLTS12
IF ERRORLEVEL 0 goto Update115

:findromver3
xgrep "0" romver2.txt > nul
IF ERRORLEVEL 1 goto UpdateLTS12N
IF ERRORLEVEL 0 goto UpdateLTS12

:Update115
echo FW Version is 1.14.x Update 1.15 fw first 
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
oyafu.exe -kcs bridge.ima -force-boot -vyes
ASMB_MAC -delay 200
echo UpdateLTS12
goto UpdateLTS12


:UpdateLTS12
ASMB_MAC -delay 180
echo -------BMC reboot is complete-------
echo FW Version is 1.15.x or 2.0.x 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
oyafu.exe -kcs KRA16233.ima -force-boot -vyes
goto end


:UpdateLTS12N
ASMB_MAC -delay 180
echo -------BMC reboot is complete-------
echo FW Version is 2.x.x 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 -force-boot -vyes
goto end


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

: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

: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




