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