@ECHO OFF
:; Clear the screen
CLS 

:; Clear any previous variables set 
SET SASID=
SET Ver=

:; Expose Enclosure Devices Enable
CmdTool2 -adpsetprop ExposeEnclDevicesEnbl 1 -a0
TIMEOUT /T 1

:; Get SAS Address 
FOR /F "skip=14 tokens=4 delims= " %%i IN ('xflash -i get avail') do Call :ProgramExpander %%i

	:; Expose Enclosure Devices Disable
	CmdTool2 -adpsetprop ExposeEnclDevicesEnbl 0 -a0

	:; Print message and exit
	ECHO System power cycle is required to complete expander firmware udpate process
	GOTO :EOF

:; Program Expander(s) with new firmware
:ProgramExpander
	SET SASID=%1
	SET SASID=%SASID::=%
	SET SASID=%SASID:(=%
	SET SASID=%SASID:)=%
	
	:; Print SAS Address to program
	ECHO %SASID%

	:; Program Expander
	xflash -i %SASID% down fw sas2xfwBasic.fw 0 -y

:EOF
