@echo off
cls
REM # B057 update script
REM # Update.bat $
REM #
REM # Check for arguments
if [%1] == [] (GOTO NOARG)
REM # Pass in device name from arg
set dn=%~1
set mf="B010"

REM # Print device name to screen
REM #echo.
REM #echo "%dn%"
REM storcli -adpsetprop exposeEnclDevicesEnbl 1 -aall > NULL
storcli /c0 set backplane expose=on > NULL
ping localhost > null
REM # Check minimum firmware level is on expander
sg_inq "%dn%" | findstr %mf% >NUL

if %errorlevel% equ 0 (
	echo.
	echo "The expander doesn't meet the minimum firmware version required."
	echo "Flash the expander firmware up to B011 before updating any further"
	goto :eof
)

REM # Update firmware
echo Updating expander firmware...
echo.
call fw_tool2.bat --fw_update ..\..\binary\firmware_image.bin "%dn%"
TIMEOUT 10 /NOBREAK
REM # call sg_ses.exe --page=0x04 --control --data=02,02 "%dn%" 
echo.
echo.
echo "POWER CYCLE THE EXPANDER OR JBOD !"
:eof
REM storcli -adpsetprop exposeEnclDevicesEnbl 0 -aall > NULL
storcli /c0 set backplane expose=off > NULL
ping localhost > null
goto END
:NOARG
echo no arguments provided, please read the Windows_Firmware_Update_README file for instructions.
:END