Skip to content

Instantly share code, notes, and snippets.

@Sakata-MC
Last active January 7, 2021 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sakata-MC/7ec1d0d361e694a3dac99d2d28b17b8d to your computer and use it in GitHub Desktop.
Save Sakata-MC/7ec1d0d361e694a3dac99d2d28b17b8d to your computer and use it in GitHub Desktop.
@echo off
color 07
cls
::Firmware file to update to:
set "fw_file=me.bin"
::=======================================
::Disclaimer
echo Disclaimer:
echo This script is provided to you "As Is, Where Is", without any
echo support or warranty of any kind, express or implied.
echo Running the script implies acceptance of these terms.
echo.
echo You will see this twice if you did not run as administrator.
echo.
pause
cls
::Self-Elevation from:
::https://stackoverflow.com/a/12264592/1016343
:init
setlocal DisableDelayedExpansion
set cmdInvoke=1
set winSysFolder=System32
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
echo Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
echo args = "ELEV " >> "%vbsGetPrivileges%"
echo For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
echo args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
echo Next >> "%vbsGetPrivileges%"
if '%cmdInvoke%'=='1' goto InvokeCmd
echo UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
goto ExecElevation
:InvokeCmd
echo args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
echo UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"
:ExecElevation
"%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
exit /B
:gotPrivileges
setlocal & cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
:: Finally, the *actual* start of the script
:Start
:: cd /d "%~dp0"
pushd "%~dp0"
echo :::::::::::::::::::::::: :::::::::::::::::::::::: ::::::::::::::::::::::::
echo.
echo Current Intel ME Firmware:
for /f "tokens=*" %%f in ('call FWUpdLcl64.exe -FWVER') do set curr_ver=%%f
echo %curr_ver%
echo.
echo Version of ME Firmware in update:
for /f "tokens=*" %%f in ('call FWUpdLcl64.exe -FWVER "%fw_file%"') do set file_ver=%%f
echo %file_ver%
echo.
:: Should probably warn user is versions are the same...
if "%curr_ver%"=="%file_ver%" (
echo You already have the same version of the base firmware.
echo It is possible that PMC, PCHC, PHY or other blocks have been
echo updated, without updating the base firmware version.
echo.
echo Are you *sure* that you need to update?
echo.
)
echo :::::::::::::::::::::::: :::::::::::::::::::::::: ::::::::::::::::::::::::
echo.
::get date and time in usable form for filename
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set datetime=%datetime:~0,8%-%datetime:~8,6%
echo Backing up current firmware to file...
echo Backing up current firmware to file... >>log.txt
FWUpdLcl64.exe -save ME-FW-backup_%datetime%.bin >>log.txt
set "el=%errorlevel%"
if %el% NEQ 0 (
echo Possible error in backup, errorlevel returned: %el% >>log.txt
echo =======================================
echo  WARNING, POSSIBLE ERROR SAVING BACKUP
echo  Answer "No", and check "log.txt"
echo  PROCEED WITH CAUTION
echo =======================================
echo.
)
echo Before updating, save and close all other files and programs.
echo.
echo The system will reboot to UEFI firmware screen for validation.
echo.
choice /C YN /M "Are you sure you want to update?"
set answer=%errorlevel%
if !answer! EQU 1 (
echo.
FWUpdLcl64.exe -allowsv -f "%fw_file%"
set "el=!errorlevel!"
echo.
if !el! EQU 0 (
echo Flash successful, returned errorlevel 0 >>log.txt
echo Flash has completed. To ensure system stability, we must reboot IMMEDIATELY
::Sneakily leave ourselves a way to abort with shutdown /a
shutdown.exe /f /r /fw /t 30 /d P:1:1 /c "Flash has completed. To ensure system stability, we must reboot. 30s until reboot."
color
exit /b 0
) else (
echo Error Detected. Errorlevel returned: !el! >>log.txt
echo ERROR DETECTED.
echo Please READ the above error, and
echo take a screenshot BEFORE seeking help.
echo Errorlevel: !el!
pause
color
exit /b 1
)
)
echo Exiting.
color
exit /b 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment