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