echo off
cls
set all_dimm=%*
set first_dimm=%1
set pwd=%CD%
set option=
:start
	echo Enter the number of the update option according to the following followed by Enter:
	echo 1. Update BIOS, BMC, ME, FRUSDR,DCPMM DIMMs - DCPMM DIMM ID must be passed as an arguement
	echo 2. Update BIOS, BMC, ME, FRUSDR only
	echo 3. Update DCPMM DIMMs only - DCPMM DIMM ID must be passed as an arguement

	SET /P option=[ENTER 1/2/3]:
	if /I '%option%'=='' echo '%option%' is invalid please try again
	if /I '%option%'=='1' GOTO Selection1
	if /I '%option%'=='2' GOTO Selection2
	if /I '%option%'=='3' GOTO Selection3
echo 
goto start

:Selection1
	CALL chdir "C:\Program Files\Intel\OFU_V14_1_Build19_AllOS\Win_x64"
	CALL flashupdt -u %pwd%/flashupdt.cfg
	CALL chdir %pwd%
	CALL echo Updates for Apache Pass starting
	if not exist "C:\Progra~1\Intel\DCPM Software\" (
		   echo "Apache Pass Software is not installed. Kindly install it before proceeding."
	       goto end )    
	
    if exist "C:\Progra~1\Intel\DCPM Software\" (
	set ipmctl_path="C:\Progra~1\Intel\DCPM Software\"
	%ipmctl_path%ipmctl show -d SubsystemRevisionID -dimm %first_dimm% | find "SubsystemRevisionID" > version.txt
	set /p cmd=<version.txt
	echo %cmd%
	pushd "%~dp0"
	if "%cmd%" == "   SubsystemRevisionID=0x0000" ( echo "EKV Controller Rev Code is A0. No binary available to update the firmware. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0010" ( echo "EKV Controller Rev Code is S0. No binary available to update the firmware. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0011" (
		echo "EKV Controller Rev Code is S1. No binary available to update the firmware. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0012" (
		echo "EKV Controller Rev Code is S1b rev 46. No binary available to update the firmware. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0013" (
		echo "EKV Controller Rev Code is S1 rev89. No binary available to update the firmware. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0014" (
		echo "EKV Controller Rev Code is S1b IOPSS Bin2. No binary available to update the firmware. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0015" (
		echo "EKV Controller Rev Code is S1b IOPSS Bin1. No binary available to update the firmware. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0016" (
		echo "EKV Controller Rev Code is B0: PO, VIS."
		%ipmctl_path%ipmctl load -f -source %pwd%\fw_ekvb0_1.2.0.5346_encrypt_signed_strip.bin -dimm %all_dimm%
	echo "Updates completed. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0017" (
		echo "EKV Controller Rev Code is B0:preQS."
		%ipmctl_path%ipmctl load -f -source %pwd%\fw_ekvb0_1.2.0.5346_encrypt_signed_strip.bin -dimm %all_dimm%
		echo "Updates completed. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0018" (
		echo "EKV Controller Rev Code is B0: QS."
		%ipmctl_path%ipmctl load -f -source %pwd%\fw_ekvb0_1.2.0.5346_encrypt_signed_strip.bin -dimm %all_dimm%
		echo "Updates completed. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0019" (
		echo "EKV Controller Rev Code is B0: HVM."
		%ipmctl_path%ipmctl load -f -source %pwd%\fw_ekvb0_1.2.0.5346_encrypt_signed_strip.bin -dimm %all_dimm%
		echo "Updates completed. Please close the CMD prompt before executing another command.")
)
 
goto end

:Selection2

	CALL chdir "C:\Program Files\Intel\OFU_V14_1_Build19_AllOS\Win_x64"
	CALL flashupdt -u %pwd%/flashupdt.cfg
	CALL chdir %pwd%

goto end

:Selection3

	if not exist "C:\Progra~1\Intel\DCPM Software\" (
		   echo "DCPMM Software is not installed. Kindly install it before proceeding."
	       goto end )    
	
    if exist "C:\Progra~1\Intel\DCPM Software\" (
		set ipmctl_path="C:\Progra~1\Intel\DCPM Software\"
		%ipmctl_path%ipmctl show -d SubsystemRevisionID -dimm %first_dimm% | find "SubsystemRevisionID" > version.txt
		set /p cmd=<version.txt
		echo %cmd%
		pushd "%~dp0"
	if "%cmd%" == "   SubsystemRevisionID=0x0000" ( echo "EKV Controller Rev Code is A0.")
	if "%cmd%" == "   SubsystemRevisionID=0x0010" ( echo "EKV Controller Rev Code is S0.")
	if "%cmd%" == "   SubsystemRevisionID=0x0011" (
		echo "EKV Controller Rev Code is S1. No binary available to update the firmware.")
	if "%cmd%" == "   SubsystemRevisionID=0x0012" (
		echo "EKV Controller Rev Code is S1b rev 46. No binary available to update the firmware.")
	if "%cmd%" == "   SubsystemRevisionID=0x0013" (
		echo "EKV Controller Rev Code is S1 rev89. No binary available to update the firmware.")
	if "%cmd%" == "   SubsystemRevisionID=0x0014" (
		echo "EKV Controller Rev Code is S1b IOPSS Bin2. No binary available to update the firmware.")
	if "%cmd%" == "   SubsystemRevisionID=0x0015" (
		echo "EKV Controller Rev Code is S1b IOPSS Bin1. No binary available to update the firmware.")
	if "%cmd%" == "   SubsystemRevisionID=0x0016" (
		echo "EKV Controller Rev Code is B0: PO, VIS."
		%ipmctl_path%ipmctl load -f -source %pwd%\fw_ekvb0_1.2.0.5346_encrypt_signed_strip.bin -dimm %all_dimm%
		echo "Updates completed. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0017" (
		echo "EKV Controller Rev Code is B0:preQS."
		%ipmctl_path%ipmctl load -f -source %pwd%\fw_ekvb0_1.2.0.5346_encrypt_signed_strip.bin -dimm %all_dimm%
		echo "Updates completed. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0018" (
		echo "EKV Controller Rev Code is B0: QS."
		%ipmctl_path%ipmctl load -f -source %pwd%\fw_ekvb0_1.2.0.5346_encrypt_signed_strip.bin -dimm %all_dimm%
		echo "Updates completed. Please close the CMD prompt before executing another command.")
	if "%cmd%" == "   SubsystemRevisionID=0x0019" (
		echo "EKV Controller Rev Code is B0: HVM."
		%ipmctl_path%ipmctl load -f -source %pwd%\fw_ekvb0_1.2.0.5346_encrypt_signed_strip.bin -dimm %all_dimm%
		echo "Updates completed. Please close the CMD prompt before executing another command.")
) 
goto end

:end
pause