summaryrefslogtreecommitdiffstats
path: root/quarkbuild.bat
blob: f0fc74f43bd8c04651dabae7f76a3ab8548611c1 (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
@REM
@REM Copyright (c) 2013 Intel Corporation.
@REM
@REM Redistribution and use in source and binary forms, with or without
@REM modification, are permitted provided that the following conditions
@REM are met:
@REM
@REM * Redistributions of source code must retain the above copyright
@REM notice, this list of conditions and the following disclaimer.
@REM * Redistributions in binary form must reproduce the above copyright
@REM notice, this list of conditions and the following disclaimer in
@REM the documentation and/or other materials provided with the
@REM distribution.
@REM * Neither the name of Intel Corporation nor the names of its
@REM contributors may be used to endorse or promote products derived
@REM from this software without specific prior written permission.
@REM
@REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@REM "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@REM LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@REM A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
@REM OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
@REM SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
@REM LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
@REM DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@REM THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
@REM (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
@REM OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@REM

@echo off

@REM Make sure you fully understand (the lack of) delayedexpansion
@REM in batch files before you try to use error reporting
set MY_ERROR_LVL=0


@if /I "%1"=="" goto Usage
@if /I "%1"=="-h" goto Usage
@if /I "%1"=="-clean" goto Clean
@if /I "%2"=="" goto Usage
@if /I "%3"=="" goto Usage

@REM
@REM Windows build environment traditionally has problems with long path names.
@REM most notably the MAX_PATH limit.
@REM Substitute the source code root to avoid these problems.
@REM
set CURRENTDIR=%~dp0
set CURRENTDIR=%CURRENTDIR:~0,-1%
set CURRENTDRIVE=%~d1
set SUBSTDRIVE=%2:

subst /d %SUBSTDRIVE%
subst %SUBSTDRIVE% %CURRENTDIR%
%SUBSTDRIVE%

@REM ###########################################################################
@REM ########################    PreSetup-processing      ######################
@REM ###########################################################################
if NOT exist %SUBSTDRIVE%\Conf (
  mkdir %SUBSTDRIVE%\Conf
)

if NOT exist %SUBSTDRIVE%\Conf\tools_def.txt (
  echo copying ... tools_def.template to %SUBSTDRIVE%\Conf\tools_def.txt
  copy /Y %SUBSTDRIVE%\QuarkPlatformPkg\Override\BaseTools\Conf\tools_def.template %SUBSTDRIVE%\Conf\tools_def.txt > nul
)
if NOT exist %SUBSTDRIVE%\Conf\build_rule.txt (
  echo copying ... build_rule.template to %SUBSTDRIVE%\Conf\build_rule.txt
  copy /Y %SUBSTDRIVE%QuarkPlatformPkg\Override\BaseTools\Conf\build_rule.template %SUBSTDRIVE%\Conf\build_rule.txt > nul
)  

@if not defined WORKSPACE (
  call %SUBSTDRIVE%\edksetup.bat
)

@echo off

if /I "%1"=="-r32" (
  set TARGET=RELEASE
  set DEBUG_PRINT_ERROR_LEVEL=-DDEBUG_PRINT_ERROR_LEVEL=0x80000000
  set DEBUG_PROPERTY_MASK=-DDEBUG_PROPERTY_MASK=0x23
  goto CheckParameter3
)

if /I "%1"=="-d32" (
  set TARGET=DEBUG
  set DEBUG_PRINT_ERROR_LEVEL=-DDEBUG_PRINT_ERROR_LEVEL=0x80000042
  set DEBUG_PROPERTY_MASK=-DDEBUG_PROPERTY_MASK=0x27
  goto CheckParameter3
) else (
  goto Usage
)

:CheckParameter3
  set PLATFORM=%3
  goto BuildAll

:Clean
echo Removing Build/Conf directories ... 
if exist Build rmdir Build /s /q
if exist Conf  rmdir Conf  /s /q
if exist *.log  del *.log /q /f
set WORKSPACE=
set EDK_TOOLS_PATH=
goto End

:BuildAll
@echo off

@REM Add all arguments after the 3rd to the EDK_PARAMS variable
@REM tokens=1-3 puts the 1st, 2nd and 3rd arguments in %%a, %%b and %%c
@REM All remaining arguments are in %%d


for /f "tokens=1-3*" %%a in ("%*") do (
    set EDK_PARAMS=%%d
)

if NOT exist %WORKSPACE%\BaseTools (
  echo Error: SVN directories missing - please run svn update to download
  goto End
)

if exist %WORKSPACE%\QuarkSocPkg\QuarkNorthCluster\Binary\QuarkMicrocode\RMU.bin  goto GotCMC
echo Trying to fetch Chipset Microcode...
%WORKSPACE%\fetchCMCBinary.py
if %ERRORLEVEL% NEQ 0 (
    set MY_ERROR_LVL=%ERRORLEVEL%
    echo Error: Chipset Microcode is missing
    goto End
)

:GotCMC

@REM ###########################################################################
@REM ########################   PreBuild-processing       ######################
@REM ###########################################################################
if NOT exist %WORKSPACE%\Conf (
  echo Error: Missing folder %WORKSPACE%\Conf\
  goto End
)

@if not exist Build\%PLATFORM%\%TARGET%_%VS_VERSION%%VS_X86%\IA32 (
  mkdir Build\%PLATFORM%\%TARGET%_%VS_VERSION%%VS_X86%\IA32
)

@REM ####################################################################################################################
@REM ######                                Perform the actual build                                         #############
@REM ######   Warning: parameters here are supposed to override any corresponding value in Conf/target.txt  #############
@REM ####################################################################################################################
build  -p %PLATFORM%Pkg\%PLATFORM%Pkg.dsc -b %TARGET% -a IA32 -n 4 -t %VS_VERSION%%VS_X86% -y Report.log %EDK_PARAMS% %DEBUG_PRINT_ERROR_LEVEL% %DEBUG_PROPERTY_MASK%
if %ERRORLEVEL% NEQ 0   ( set MY_ERROR_LVL=%ERRORLEVEL% & Goto End )

@REM ###############################################################################
@REM ########################       PostBuild-processing       #####################
@REM ###############################################################################
.\QuarkPlatformPkg\Tools\QuarkSpiFixup\QuarkSpiFixup.py %PLATFORM% %TARGET% %VS_VERSION%%VS_X86%

@REM ####################################################################################################################
@REM ######         Perform EDKII build again after QuarkSpiFixup so that output .fd file usable.           #############
@REM ######   Warning: parameters here are supposed to override any corresponding value in Conf/target.txt  #############
@REM ####################################################################################################################
build  -p %PLATFORM%Pkg\%PLATFORM%Pkg.dsc -b %TARGET% -a IA32 -n 4 -t %VS_VERSION%%VS_X86% -y Report.log %EDK_PARAMS% %DEBUG_PRINT_ERROR_LEVEL% %DEBUG_PROPERTY_MASK%
if %ERRORLEVEL% NEQ 0   ( set MY_ERROR_LVL=%ERRORLEVEL% & Goto End )

set OutputModulesDir=%WORKSPACE%\Build\%PLATFORM%\%TARGET%_%VS_VERSION%%VS_X86%\FV

@REM Copy build output .fd file int0 FlashModules directory.
@REM Use similar name to full Quark Spi Flash tools but emphasise only EDKII assets in bin file.
copy /Y %OutputModulesDir%\QUARK.fd %OutputModulesDir%\FlashModules\Flash-EDKII-missingPDAT.bin

@REM ###############################################################################
@REM ########################     Image signing stage           ####################
@REM ########################       (dummy signing)             ####################
@REM ###############################################################################
%WORKSPACE%\QuarkPlatformPkg\Tools\SignTool\DummySignTool.exe %OutputModulesDir%\FlashModules\EDKII_BOOT_STAGE1_IMAGE1.Fv %OutputModulesDir%\EDKII_BOOT_STAGE1_IMAGE1.Fv.signed
%WORKSPACE%\QuarkPlatformPkg\Tools\SignTool\DummySignTool.exe %OutputModulesDir%\FlashModules\EDKII_BOOT_STAGE1_IMAGE2.Fv %OutputModulesDir%\EDKII_BOOT_STAGE1_IMAGE2.Fv.signed
%WORKSPACE%\QuarkPlatformPkg\Tools\SignTool\DummySignTool.exe %OutputModulesDir%\FlashModules\EDKII_BOOT_STAGE2_RECOVERY.Fv %OutputModulesDir%\EDKII_BOOT_STAGE2_RECOVERY.Fv.signed
%WORKSPACE%\QuarkPlatformPkg\Tools\SignTool\DummySignTool.exe %OutputModulesDir%\FlashModules\EDKII_BOOT_STAGE2_COMPACT.Fv %OutputModulesDir%\EDKII_BOOT_STAGE2_COMPACT.Fv.signed
%WORKSPACE%\QuarkPlatformPkg\Tools\SignTool\DummySignTool.exe %OutputModulesDir%\FlashModules\EDKII_BOOT_STAGE2.Fv %OutputModulesDir%\EDKII_BOOT_STAGE2.Fv.signed
%WORKSPACE%\QuarkPlatformPkg\Tools\SignTool\DummySignTool.exe %OutputModulesDir%\FlashModules\EDKII_RECOVERY_IMAGE1.Fv %OutputModulesDir%\EDKII_RECOVERY_IMAGE1.Fv.signed

@REM ###############################################################################
@REM ####################         Capsule creation stage            ################
@REM ####################     (Recovery and Update capsules)        ################
@REM ###############################################################################
set CapsuleConfigFile=%WORKSPACE%\%PLATFORM%Pkg\Tools\CapsuleCreate\%PLATFORM%PkgCapsuleComponents.inf
set CapsuleOutputFileReset=%OutputModulesDir%\%PLATFORM%PkgReset.Cap
@REM CAPSULE_FLAGS_PERSIST_ACROSS_RESET          0x00010000
@REM CAPSULE_FLAGS_INITIATE_RESET                0x00040000
set CapsuleFlagsReset=0x00050000

%WORKSPACE%\QuarkPlatformPkg\Tools\CapsuleCreate\CapsuleCreate.exe %CapsuleConfigFile% %OutputModulesDir% %CapsuleOutputFileReset% %CapsuleFlagsReset%

%WORKSPACE%\QuarkPlatformPkg\Tools\SignTool\DummySignTool.exe %CapsuleOutputFileReset% %CapsuleOutputFileReset%.signed

copy /b /Y %OutputModulesDir%\EDKII_BOOT_STAGE2_RECOVERY.Fv.signed + %CapsuleOutputFileReset%.signed %OutputModulesDir%\FVMAIN.fv > nul

@REM ###############################################################################
@REM ################       Create useful output directories        ################
@REM ###############################################################################
@if not exist %OutputModulesDir%\RemediationModules (
  mkdir %OutputModulesDir%\RemediationModules
)

@REM Copy the 'Recovery Capsule' and 'Update Capsules' to the RemediationModules directory
@REM Use same/similar names in stand-alone builds compared to full Quark Spi Flash tools.
copy /Y %OutputModulesDir%\FVMAIN.fv %OutputModulesDir%\RemediationModules\.
copy /Y %CapsuleOutputFileReset%.signed %OutputModulesDir%\RemediationModules\Flash-EDKII.cap
copy /Y %WORKSPACE%\QuarkPlatformPkg\Applications\CapsuleApp.efi %OutputModulesDir%\RemediationModules\.

@if not exist %OutputModulesDir%\Tools (
  mkdir %OutputModulesDir%\Tools
)

@REM Copy the 'CapsuleCreate.exe' tool to the Tools directory
copy /Y %WORKSPACE%\QuarkPlatformPkg\Tools\CapsuleCreate\CapsuleCreate.exe %OutputModulesDir%\Tools\.

@if not exist %OutputModulesDir%\Applications (
  mkdir %OutputModulesDir%\Applications
)

@REM Copy the 'CapsuleApp.efi' application to the Applications directory
copy /Y %WORKSPACE%\QuarkPlatformPkg\Applications\CapsuleApp.efi %OutputModulesDir%\Applications\.

copy Report.log Build\%PLATFORM%\%TARGET%_%VS_VERSION%%VS_X86%\ > nul
if ERRORLEVEL 1 exit /b 1
goto End

:Usage
  echo.
  echo  Usage: "%0 [-h | -r32 | -d32 | -clean] [subst drive letter] [PlatformName] [-DSECURE_LD(optional)] [-DSECURE_BOOT(optional)]"
  echo.

:End
%CURRENTDRIVE%
subst /d %SUBSTDRIVE%
echo.
exit /b %MY_ERROR_LVL%