@ECHO OFF

ECHO Please, carefully check the list of SSDs and select desired Intel P3700/P3600 SSD to update. 
ECHO PLEASE DO NOT INTERRUPT ANY TIMEOUTS IN THIS SCRIPT. THEY ARE REQUIRED FOR SUCCESFULL OPERATION
timeout 3
iSSDCM_win64.exe -drive_list

SET /P drv_index=Please enter drive number: 
IF "%drv_index%"=="" GOTO Error

iSSDCM_win64.exe -drive_index %drv_index% > DrvIndx
IF EXIST "FWver" del /F "FWver"
IF EXIST "Status" del /F "Status"
find "Firmware" < DrvIndx > FWver
find "Status" < DrvIndx > Status

SET /P assert_=<Status
SET assert=%assert_:~22,7%

IF "%assert%"=="Healthy" GOTO FW_version_check
IF NOT "%assert%"=="Healthy" GOTO EraseAssert

:EraseAssert

ECHO SSD you selected is in the ASSERTED state, please Clear the Assert or Low Level Format the drive
timeout 3
NCAT130.exe -drive_index %drv_index% -erase_assert
timeout 5
NCAT130.exe -drive_index %drv_index% -lowlevelformat 
timeout 5
NCAT130.exe -drive_index %drv_index%

SET /P update=Do you want to update FW now? Y/N: 
IF "%update%"=="y" GOTO FW_version_check
IF "%update%"=="Y" GOTO FW_version_check
IF "%update%"=="n" GOTO Exit
IF "%update%"=="N" GOTO Exit

GOTO Error1

ECHO Doing FW version check
:FW_version_check
SET /p FWversion_=< FWver
SET FWversion=%FWversion_:~22,8%
ECHO FW version recognized as %FWVersion%
timeout 2

IF "%FWversion%"=="8DV10036" GOTO UpdateFrom36
IF "%FWversion%"=="8DV10E41" GOTO UpdateFrom41
IF "%FWversion%"=="8DV10043" GOTO UpdateFrom43
IF "%FWversion%"=="8DV10049" ECHO Selected SSD already updated to QS Firmware & GOTO VPD

GOTO Error2

:UpdateFrom36
ECHO Starting FW update...
timeout 3
iSSDCM_win64.exe -drive_index %drv_index% -firmware_update 8DV10043_signed.bin <y
timeout 5
NCAT120.exe -drive_index %drv_index% -bootloader_update 8B1B0128.bin <y
timeout 5
NCAT120.exe -drive_index %drv_index% -lowlevelformat <y
timeout 5
NCAT120.exe -drive_index %drv_index% -update_config <y
ECHO -----------------------
ECHO DO NOT INTERRUPT, TIMEOUT REQUIRED
ECHO -----------------------
timeout 7
NCAT130.exe -drive_index %drv_index% -lowlevelformat <y
timeout 5
iSSDCM_win64.exe -drive_index %drv_index% -firmware_update 8DV10049_signed.bin <y
ECHO DO NOT INTERRUPT, TIMEOUT REQUIRED
ECHO -----------------------
timeout 7
NCAT130.exe -drive_index %drv_index% -update_config <y
timeout 5
NCAT130.exe -drive_index %drv_index%
ECHO End of FW update. 
GOTO VPD


:UpdateFrom41
ECHO Starting FW update...
timeout 3
iSSDCM_win64.exe -drive_index %drv_index% -firmware_update 8DV10043_signed.bin <y
timeout 5
NCAT120.exe -drive_index %drv_index% -bootloader_update 8B1B0128.bin <y
timeout 5
NCAT120.exe -drive_index %drv_index% -update_config <y
ECHO -----------------------
ECHO DO NOT INTERRUPT, TIMEOUT REQUIRED
timeout 7
NCAT130.exe -drive_index %drv_index% -lowlevelformat <y
timeout 5
iSSDCM_win64.exe -drive_index %drv_index% -firmware_update 8DV10049_signed.bin <y
timeout 5
NCAT130.exe -drive_index %drv_index% -update_config <y
timeout 5
NCAT130.exe -drive_index %drv_index%
ECHO End of FW update. 
GOTO VPD

:UpdateFrom43
iSSDCM_win64.exe -drive_index %drv_index% -firmware_update 8DV10049_signed.bin <y
timeout 5
NCAT130.exe -drive_index %drv_index% -bootloader_update 8B1B0128.bin <y
timeout 5
NCAT130.exe -drive_index %drv_index% -update_config <y
ECHO -----------------------
ECHO DO NOT PRESS ANY BUTTON IF CONFIG WAS UPDATED (timeout required)

timeout 3
ECHO End of FW update. 
GOTO VPD

:VPD
ECHO FOR VPD CONTENTS UPDATE IT IS REQUIRED FOR NVMe DRIVE TO BE THE ONLY PCIE DRIVE IN THE SYSTEM! 
ECHO PLEASE REFER TO "QS UPDATE PACKAGE.PPT" FOR MORE INFORMATION
SET /P VPD=Do you want to update VPD contents? Y/N 
IF "%VPD%"=="y" GOTO VPD
IF "%VPD%"=="Y" GOTO VPD
IF "%VPD%"=="n" GOTO Exit
IF "%VPD%"=="N" GOTO Exit
timeout 3

:VPD
VPDBinary.exe -drive_index %drv_index% -create_vpdbinary vpd.bin
RW.exe /Command="LOAD vpd.bin SMBUS Byte 0xA6 0 255; RwExit" /Min

:Exit
ECHO End of script. The tool will exit now
Timeout 3
GOTO End

:Error 
ECHO Wrong Drive Index!
GOTO End

:Error1
ECHO Wrong Response!
GOTO End

:Error2
ECHO Incorrect FW Revision. Execution aborted.
Timeout 4
GOTO End

:End
IF EXIST "FWver" del /F "FWver"
IF EXIST "Status" del /F "Status"