• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1@REM @file
2@REM   Windows batch file to build BIOS ROM
3@REM
4@REM Copyright (c) 2006   - 2014, Intel Corporation. All rights reserved.<BR>
5@REM
6@REM   This program and the accompanying materials are licensed and made available under
7@REM   the terms and conditions of the BSD License that accompanies this distribution.
8@REM   The full text of the license may be found at
9@REM   http://opensource.org/licenses/bsd-license.php.
10@REM
11@REM   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12@REM   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13@REM
14
15@echo off
16SetLocal EnableDelayedExpansion EnableExtensions
17
18:: Set script defaults
19set exitCode=0
20set BackupRom=1
21set UpdateVBios=1
22set SpiLock=0
23set Stitch_Config=Stitch_Config.txt
24copy /y nul Stitching.log >nul
25
26:: Set default Suffix as:  YYYY_MM_DD_HHMM
27set hour=%time: =0%
28reg copy "HKCU\Control Panel\International" "HKCU\Control Panel\International_Temp" /f >nul
29reg add "HKCU\Control Panel\International" /v sShortDate /d "yyyy_MM_dd" /f >nul
30for /f "tokens=1" %%i in ("%date%") do set today=%%i
31reg copy "HKCU\Control Panel\International_Temp" "HKCU\Control Panel\International" /f >nul
32reg delete "HKCU\Control Panel\International_Temp" /f >nul
33set IFWI_Suffix=%today%_%hour:~0,2%%time:~3,2%
34
35:: Process input arguments
36if "%~1"=="?"       goto Usage
37if "%~1"=="/?"      goto Usage
38if /i "%~1"=="Help" goto Usage
39
40:OptLoop
41if /i "%~1"=="/nV" (
42    set UpdateVBios=0
43    shift
44    goto OptLoop
45)
46if /i "%~1"=="/nB" (
47    set BackupRom=0
48    shift
49    goto OptLoop
50)
51if /i "%~1"=="/yL" (
52    set SpiLock=1
53    shift
54    goto OptLoop
55)
56
57if /i "%~1"=="/B" (
58    if "%~2"==""  goto Usage
59    if not exist %~2 echo BIOS not found. & goto Usage
60    set BIOS_Names=%~2
61    set BIOS_File_Name=%~n2
62    shift & shift
63    goto OptLoop
64)
65if /i "%~1"=="/C" (
66    if "%~2"==""  goto Usage
67    if not exist %~2 echo ConfigFile not found. & goto Usage
68    set Stitch_Config=%~2
69    shift & shift
70    goto OptLoop
71)
72if /i "%~1"=="/S" (
73    if "%~2"==""  goto Usage
74    set IFWI_Suffix=%~2
75    shift & shift
76    goto OptLoop
77)
78
79if "%BIOS_File_Name:~0,4%"=="MNW2" (
80   set Stitch_Config= MNW2_Stitch_Config.txt
81)
82if "%BIOS_File_Name:~3,4%"=="MNW2" (
83   set Stitch_Config= MNW2_Stitch_Config.txt
84)
85
86:: if no rom specified by user, search in ./ for ROM files
87if "%BIOS_Names%"=="" (
88    set "BIOS_Names= "
89    for /f "tokens=*" %%i in ('dir /b *.rom') do set BIOS_Names=!BIOS_Names! %%i
90    if "!BIOS_Names!"==" " (
91        echo NO .ROM files found !!!
92        goto Usage
93    )
94)
95
96:: Parse the Stitch_Config File
97if not exist %Stitch_Config% (
98    echo Stitch Configuration File %Stitch_Config% not found.
99    goto ScriptFail
100)
101for /f "delims== tokens=1,2" %%i in (%Stitch_Config%) do (
102    if /i "%%i"=="HEADER"      set IFWI_HEADER=%%j
103    if /i "%%i"=="SEC_VERSION" set SEC_VERSION=%%j
104    if /i "%%i"=="Source" (
105        if /i "%%j"=="ALPHA" set Source_Prefix=A_
106        if /i "%%j"=="BF" set Source_Prefix=BF_
107        if /i "%%j"=="BE" set Source_Prefix=BE_
108        if /i "%%j"=="PV" set Source_Prefix=PV_
109        if /i "%%j"=="PR1" set Source_Prefix=PR1_
110    )
111)
112
113if %SpiLock% EQU 1 (
114  set IFWI_HEADER_FILE=IFWIHeader\!IFWI_HEADER!_SPILOCK.bin
115) else (
116  set IFWI_HEADER_FILE=IFWIHeader\!IFWI_HEADER!.bin
117)
118
119:: **********************************************************************
120:: The Main Stitching Loop
121:: **********************************************************************
122echo %date%  %time% >>Stitching.log 2>&1
123echo %date%  %time%
124echo.
125for %%i in (%BIOS_Names%) do (
126
127    REM  ----- Do NOT use :: for comments Inside of code blocks() -------
128    set BIOS_Rom=%%i
129    set BIOS_Name=%%~ni
130    set BIOS_Version=!BIOS_Name:~-7,7!
131
132    REM extract PlatformType from BIOS filename
133    set Platform_Type=!BIOS_Name:~0,4!
134
135    REM Special treat for BayLake FFD8
136    set Temp_Name=!BIOS_Name:~0,7!
137
138
139    REM Capitalize and validate the Platform_Type
140    if /i "!Platform_Type!"=="MNW2" (
141        set Platform_Type=MNW2
142    ) else (
143        echo Error - Unsupported PlatformType: !Platform_Type!
144        goto Usage
145    )
146
147
148    REM search BIOS_Name for Arch substring:  either IA32 or X64
149    if not "!BIOS_Name!"=="!BIOS_Name:_IA32_=!" (
150        set Arch=IA32
151    ) else if not "!BIOS_Name!"=="!BIOS_Name:_X64_=!" (
152        set Arch=X64
153    ) else (
154        echo Error:  Could not determine Architecture for !BIOS_Rom!
155        goto Usage
156    )
157    set IFWI_Prefix=!Platform_Type!_IFWI_%Source_Prefix%!Arch!_!!BIOS_Version!
158
159    REM search BIOS_Name for Build_Target substring: either R or D
160    if not "!BIOS_Name!"=="!BIOS_Name:_R_=!" (
161        set Build_Target=Release
162        set IFWI_Prefix=!IFWI_Prefix!_R
163    ) else if not "!BIOS_Name!"=="!BIOS_Name:_D_=!" (
164        set Build_Target=Debug
165        set IFWI_Prefix=!IFWI_Prefix!_D
166    ) else (
167        echo Error:  Could not determine Build Target for !BIOS_Rom!
168        goto Usage
169    )
170
171    REM Create a BIOS backup before Stitching
172    if %BackupRom% EQU 1 (
173        echo Creating backup of original BIOS rom.
174        copy /y !BIOS_Rom! !BIOS_Rom!.orig >nul
175    )
176
177    echo.  >>Stitching.log
178    echo ********** Stitching !BIOS_Rom! **********  >>Stitching.log
179    echo.  >>Stitching.log
180    echo.
181    echo Stitching IFWI for !BIOS_Rom! ...
182    echo ---------------------------------------------------------------------------
183    echo IFWI  Header: !IFWI_HEADER_FILE!,   SEC version: !SEC_VERSION!,
184    echo BIOS Version: !BIOS_Version!
185
186    echo Platform Type: !Platform_Type!,     IFWI Prefix: %BIOS_ID%
187    echo ---------------------------------------------------------------------------
188
189    echo -----------------------------
190    echo.
191    echo Generating IFWI... %BIOS_ID%.bin
192    echo.
193
194    copy /b/y !IFWI_HEADER_FILE! + ..\..\Vlv2MiscBinariesPkg\SEC\!SEC_VERSION!\VLV_SEC_REGION.bin + ..\..\Vlv2MiscBinariesPkg\SEC\!SEC_VERSION!\Vacant.bin + !BIOS_Rom! %BIOS_ID%.bin
195    echo.
196    echo ===========================================================================
197)
198@echo off
199
200::**********************************************************************
201:: end of main loop
202::**********************************************************************
203
204echo.
205echo  -- All specified ROM files Stitched. --
206echo.
207goto Exit
208
209:Usage
210echo.
211echo **************************************************************************************************
212echo This Script is used to Stitch together BIOS, GOP Driver, Microcode Patch and TXE FW
213echo into a single Integrated Firmware Image (IFWI).
214echo.
215echo Usage: IFWIStitch.bat [flags] [/B BIOS.ROM] [/C Stitch_Config] [/S IFWI_Suffix]
216echo.
217echo    This script has NO Required arguments, so that the user can just double click from the GUI.
218echo    However, this requires that the BIOS.ROM file name is formatted correctly.
219echo.
220echo    /nG             Do NOT update the GOP driver.  (applies to all ROM files for this run)
221echo    /nV             Do NOT update the VBIOS.       (applies to all ROM files for this run)
222echo    /nM             Do NOT update the Microcode.   (applies to all ROM files for this run)
223echo    /nB             Do NOT backup BIOS.ROMs. (Default will backup to BIOS.ROM.Orig)
224echo.
225echo    BIOS.ROM:       A single BIOS ROM file to use for stitching
226echo                    (DEFAULT: ALL .ROM files inside the current directory)
227echo    Stitch_Config:  Text file containing version info of each FW component
228echo                    (DEFAULT: Stitch_Config.txt)
229echo    IFWI_Suffix:    Suffix to append to the end of the IFWI filename
230echo                    (DEFAULT: YYYY_MM_DD_HHMM)
231echo.
232echo Examples:
233echo    IFIWStitch.bat                                      : Stitch all ROMs with defaults
234echo    IFIWStitch.bat /B C:/MyRoms/testBIOS.rom            : Stitch single ROM with defaults
235echo    IFIWStitch.bat /B ../testBIOS.rom /S test123        : Stitch single ROM and add custom suffix
236echo    IFIWStitch.bat /nM /nB /B testBIOS.rom /S test456   : Stitch single ROM, keep uCode from .rom,
237echo                                                          don't create backup, and add custom suffix.
238echo ****************************************************************************************************
239pause
240exit /b 1
241
242:ScriptFail
243set exitCode=1
244
245:Exit
246echo  -- See Stitching.log for more info. --
247echo.
248echo %date%  %time%
249echo.
250if "%Platform_Type%"=="MNW2" (
251  echo .
252) else (
253  echo only support MNW2 for this project!
254pause
255)
256exit /b %exitCode%
257EndLocal
258