summaryrefslogtreecommitdiff
path: root/BraswellPlatformPkg/Stitch/SEC/SEC_Stitching.bat
blob: b09934023cff5ab1cb4a7b4b13fc2b9f0c1a912e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
@echo off
SetLocal EnableDelayedExpansion EnableExtensions

:: Require 2 input parameters
if "%~2"==""  goto Usage

:: Assign initial values
set exitCode=0
set BIOS_Rom=%~f1
set SEC_Version=%~2
set Platform_Type=%~3
set IFWI_Name=%~4

if "%~3"=="" (
  REM remove the leading path if present, then save only 1st 4 chars of filename
  set Platform_Type=%~n1
  set Platform_Type=!Platform_Type:~0,4!
)

if "%~4"=="" (
  set hour=%time: =0%
  reg copy "HKCU\Control Panel\International" "HKCU\Control Panel\International_Temp" /f >nul
  reg add "HKCU\Control Panel\International" /v sShortDate /d "yyyy-MM-dd" /f >nul
  for /f "tokens=1" %%i in ("%date%") do set today=%%i
  reg copy "HKCU\Control Panel\International_Temp" "HKCU\Control Panel\International" /f >nul
  reg delete "HKCU\Control Panel\International_Temp" /f >nul
  set today=%today:-=_%
  set IFWI_Name=%~n1_SEC_%SEC_Version%_%today%_%hour:~0,2%%time:~3,2%
)

echo =========================================================================
echo Start Stitching SEC ...
echo BIOS_Rom = %BIOS_Rom%;
echo Platform_Type = %Platform_Type%;  SEC_Version = %SEC_Version%;
echo IFWI_Name = %IFWI_Name%;
echo.

if not exist %BIOS_Rom% (
  echo Error: BIOS %Bios_Rom% not found.
  goto TxeFail
)

if x%IFWI_Name:_SV_=%==x%IFWI_Name% (
  if /i "!Platform_Type!"=="CHTT" (
    goto SkipFTool
  )
  if /i "!Platform_Type!"=="BSW" (
    if not exist %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled_fitc.xml (
      echo Error: %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled_fitc.xml not found.
      goto ContinueWithFtool
    )
    goto SkipFTool
  )
)

:ContinueWithFtool

::
:: execute below cmds from Stitch/SEC/ directory
::
REM FTOOL usage -- For PO and SV use only.
if /i "!Platform_Type!"=="CHTT" (
  if exist %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled.xml (
    FTool\ftool.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled.xml^
      /b /o ..\%IFWI_Name%_SecEnabled.bin^
      /me  %Platform_Type%\%SEC_Version%\CHV_SEC_REGION.bin^
      /bios %BIOS_Rom%
  )
)

if /i "!Platform_Type!"=="BSW" (
  if exist %Platform_Type%\%SEC_Version%\Production_CHV_SEC_REGION.bin (
    if exist %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled.xml (
      FTool\ftool.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled.xml^
        /b /o ..\%IFWI_Name%_Production_SecEnabled.bin^
        /me  %Platform_Type%\%SEC_Version%\Production_CHV_SEC_REGION.bin^
        /bios %BIOS_Rom%
    )
  )
  if exist %Platform_Type%\%SEC_Version%\PreProduction_CHV_SEC_REGION.bin (
    if exist %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled.xml (
      FTool\ftool.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled.xml^
        /b /o ..\%IFWI_Name%_PreProduction_SecEnabled.bin^
        /me  %Platform_Type%\%SEC_Version%\PreProduction_CHV_SEC_REGION.bin^
        /bios %BIOS_Rom%
    )
  )
  if exist %Platform_Type%\%SEC_Version%\CHV_SEC_REGION.bin (
    if exist %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled.xml (
      FTool\ftool.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled.xml^
        /b /o ..\%IFWI_Name%_SecEnabled.bin^
        /me  %Platform_Type%\%SEC_Version%\CHV_SEC_REGION.bin^
        /bios %BIOS_Rom%
    )
  )
)

goto SkipFITC

:SkipFtool
:: Always generate the SecEnabled IFWI
if /i "!Platform_Type!"=="BSW" (
  if exist %Platform_Type%\%SEC_Version%\PreProduction_CHV_SEC_REGION.bin (
    %Platform_Type%\%SEC_Version%\FITC\fitc.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled_fitc.xml^
    /b /o ..\%IFWI_Name%_PreProduction_SecEnabled.bin^
    /txe  %Platform_Type%\%SEC_Version%\PreProduction_CHV_SEC_REGION.bin^
    /bios %BIOS_Rom%^
    /fpf  %Platform_Type%\%SEC_Version%\FpfMirrorNvarValues.txt
  )
  if exist %Platform_Type%\%SEC_Version%\Production_CHV_SEC_REGION.bin (
    %Platform_Type%\%SEC_Version%\FITC\fitc.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled_fitc.xml^
    /b /o ..\%IFWI_Name%_Production_SecEnabled.bin^
    /txe  %Platform_Type%\%SEC_Version%\Production_CHV_SEC_REGION.bin^
    /bios %BIOS_Rom%^
    /fpf  %Platform_Type%\%SEC_Version%\FpfMirrorNvarValues.txt
  )
  if exist %Platform_Type%\%SEC_Version%\CHV_SEC_REGION.bin (
    %Platform_Type%\%SEC_Version%\FITC\fitc.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled_fitc.xml^
    /b /o ..\%IFWI_Name%_SecEnabled.bin^
    /txe  %Platform_Type%\%SEC_Version%\CHV_SEC_REGION.bin^
    /bios %BIOS_Rom%^
    /fpf  %Platform_Type%\%SEC_Version%\FpfMirrorNvarValues.txt
  )
)
if /i "!Platform_Type!"=="CHTT" (
  FITC\fitc.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled_fitc.xml^
    /b /o ..\%IFWI_Name%_SecEnabled.bin^
    /txe  %Platform_Type%\%SEC_Version%\CHV_SEC_REGION.bin^
    /bios %BIOS_Rom%^
    /fpf  %Platform_Type%\%SEC_Version%\FpfMirrorNvarValues.txt

  FITC\fitc.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled_fitc_FFD.xml^
    /b /o ..\%IFWI_Name%_SecEnabled_FFD.bin^
    /txe  %Platform_Type%\%SEC_Version%\CHV_SEC_REGION.bin^
    /bios %BIOS_Rom%^
    /fpf  %Platform_Type%\%SEC_Version%\FpfMirrorNvarValues.txt

  FITC\fitc.exe  %Platform_Type%\%SEC_Version%\%Platform_Type%_8MB_SPI_SecEnabled_fitc_CR.xml^
    /b /o ..\%IFWI_Name%_SecEnabled_CR.bin^
    /txe  %Platform_Type%\%SEC_Version%\CHV_SEC_REGION.bin^
    /bios %BIOS_Rom%^
    /fpf  %Platform_Type%\%SEC_Version%\FpfMirrorNvarValues.txt

)

:SkipFITC

:: Remove the intermediate map files.
del /f/q ..\*.map >nul 2>&1
del /f/q ..\*MAP.txt >nul 2>&1

echo.
echo SEC Stitching Finished!
echo =========================================================================
goto Exit

:Usage
echo Script to stitch SEC FW with BIOS.
echo.
echo Usage: SEC_Stitching.bat ^<BIOS.ROM^> ^<SEC_Version^> [Platform_Type] [IFWI_Name]
echo.
echo        BIOS.ROM:       The BIOS rom file to use for the IFWI (path needs to be relative to this Script.)
echo        SEC_Version:    Version of the SeC FW binary and FITC tool to use (eg. 1.0.0.1027)
echo        Platform_Type:  CHTS, CHTT, or CHTM  (default: first 4 Char of BIOS.rom filename)
echo        IFWI_Name:      The name to use for the IFWI created by FITC. (default: BIOS.ver_SEC.ver_Date_Time)
echo                        Output will be "IFWI_Name"_SecEnabled.bin and "IFWI_Name"_SecDisabled.bin
echo                        Note: Must define [Platform_Type] when using this options
echo                        Eg. "SEC_Stitching.bat BIOS.rom SecVersion IFWI_Name"  is Not valid.
echo.

:TxeFail
set exitCode=1

:Exit
exit /b %exitCode%
EndLocal