@echo off

SET BIOS_NAME=X370SNx
SET PLATFORM_NAME=RAPTORLAKES

@if exist %BIOS_NAME%.BIN goto ChkFdm
@echo %BIOS_NAME%.BIN not found !!!
goto END

:ChkFdm
@if exist %PLATFORM_NAME%.fdm goto DoPatch
@echo %PLATFORM_NAME%.fdm not found !!!
goto END

:DoPatch
@if exist Tool\%PLATFORM_NAME%.fd del /f /q Tool\%PLATFORM_NAME%.fd
@if exist Tool\%PLATFORM_NAME%.fdm del /f /q Tool\%PLATFORM_NAME%.fdm
@if exist Tool\%PLATFORM_NAME%_FIT.fd del /f /q Tool\%PLATFORM_NAME%_FIT.fd
@if exist Tool\BiosGuard_BIOS.fd del /f /q Tool\BiosGuard_BIOS.fd
@if exist Tool\SIGN_BIOS\BiosGuard_BIOS.fd del /f /q Tool\SIGN_BIOS\BiosGuard_BIOS.fd
@if exist Tool\SIGN_BIOS\isflash.bin del /f /q Tool\SIGN_BIOS\isflash.bin
@if exist Tool\Pack_Tool\isflash.bin del /f /q Tool\Pack_Tool\isflash.bin
@copy /b %BIOS_NAME%.BIN Tool\%PLATFORM_NAME%_FIT.fd
@copy /b %PLATFORM_NAME%.fdm Tool\%PLATFORM_NAME%.fdm
@cd Tool
@del /f /q *.pem
@BootGuardKey.exe
@PatchFdmHash.exe %PLATFORM_NAME%_FIT.fd %PLATFORM_NAME%.fdm
@BpmGen2\BpmGen2.exe KMGEN -KEY pubkey.pem BPM -KM KeyManifest.bin -SIGNKEY keyprivkey.pem -SIGNPUBKEY keypubkey.pem -SIGHASHALG SHA384 -SCHEME RSAPSS -KMKHASH SHA384 -KMID 0x01 -SVN 1 -d:2 >bpmgen2_km.txt
@BpmGen2\BpmGen2.exe GEN %PLATFORM_NAME%_FIT.fd bpmgen2.params -BPM Manifest.bin -U %PLATFORM_NAME%.fd -KM KeyManifest.bin -d:2 >bpmgen2_bpm.txt
@copy /b %PLATFORM_NAME%.fd ..\%BIOS_NAME%.ROM
@SIGN_BIOS\Fitc\Fitc\BinAdd.exe SIGN_BIOS\Fitc\Fitc\input\%BIOS_NAME%(32M).BIN ..\%BIOS_NAME%.ROM ..\%BIOS_NAME%_SPI_32M.bin
@GenBiosGuardHdr.exe -i BiosGuardSetting.ini
@copy /b %PLATFORM_NAME%.fd + /b InsydeBiosGuardHeader.bin BiosGuard_BIOS.fd
@copy /b BiosGuard_BIOS.fd SIGN_BIOS\BiosGuard_BIOS.fd
@BootGuardKey.exe
@cd SIGN_BIOS
@iEFIFlashSigner.exe sign -n "Secure Certificate" -bios BiosGuard_BIOS.fd -ini platform.ini
@copy /b isflash.bin ..\Pack_Tool\isflash.bin
@copy /b isflash.bin ..\..\isflash.bin
@cd ..\Pack_Tool
@call pack.bat
@echo %CD%
@move /Y BIOS\%BIOS_NAME%.efi ..\..
@move /Y BIOS\%BIOS_NAME%.exe ..\..
@cd ..
@del /f /q %PLATFORM_NAME%_FIT.fd
@del /f /q %PLATFORM_NAME%.fdm
@cd ..

:END
@echo on