@echo off
REM #     flashbios-s3.cmd  - script to Flash BIOS
REM #

set fwdir=%DeployPath%\update
set flashdir=%DeployPath%\win32\iFlash
set logfile=%DeploymentStore%\flashbios.log
REM set flashdir=X:\deploy\win32\iFlash
REM set logfile=\flashbios.log
set ADDLOG=call addLogRecord
REM set ADDLOG=echo
set RET=0

if Not Exist "%fwdir%\%fwfile%" call %DeployPath%\doc\prepareResources.cmd
call :setFilename
echo fwfile=%fwfile%
call addLogRecord FLASH INFO  "%0: fwfile=%fwfile%"
call addLogRecord FLASH INFO  "%0: logfile=%logfile%"


pushd %flashdir%
REM # copy the BIOS image to the current directory
copy /y %fwdir%\%fwfile%
REM # install the flashud.sys driver
rem win2kinstall %flashdir%\flashud.inf *INT0800
REM # get the BIOS, Firmware, FRUSDR versions
iflash32 /i     >%logfile%
if errorlevel 1 goto flasherror

REM # flash the BIOS
echo iflash32 /ni /u %fwfile% >>%logfile%
iflash32 /ni /u %fwfile% >>%logfile%
if errorlevel 1 goto flasherror
 %ADDLOG% FLASH INFO "%0: Success: iflash32 with %fwfile%"
 goto flashdone
:flasherror
 set RET=%ERRORLEVEL%
 %ADDLOG% FLASH ERROR "%0: Error: iflash32 with %fwfile% failed"
 goto :flashdone

:setFilename
    call varSet CFGLINE "findstr  /I iFlash32  %fwdir%\autoexec.bat"
    call :getFilename  %CFGLINE%
    goto :EOF

:getFilename
    set fwfile=%~2
    goto :EOF


:flashdone
rem win2kuninstall *INT0800
popd
echo iflash32 with %fwfile% done, ret=%RET%
exit /B %RET%
