-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
build_oc.tool
executable file
·404 lines (359 loc) · 10.8 KB
/
build_oc.tool
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#!/bin/bash
abort() {
echo "ERROR: $1!"
exit 1
}
buildutil() {
UTILS=(
"AppleEfiSignTool"
"ACPIe"
"EfiResTool"
"ext4read"
"LogoutHook"
"acdtinfo"
"disklabel"
"icnspack"
"macserial"
"ocpasswordgen"
"ocvalidate"
"TestBmf"
"TestCpuFrequency"
"TestDiskImage"
"TestHelloWorld"
"TestImg4"
"TestKextInject"
"TestMacho"
"TestMp3"
"TestExt4Dxe"
"TestFatDxe"
"TestNtfsDxe"
"TestPeCoff"
"TestProcessKernel"
"TestRsaPreprocess"
"TestSmbios"
)
if [ "$HAS_OPENSSL_BUILD" = "1" ]; then
UTILS+=("RsaTool")
fi
local cores
cores=$(getconf _NPROCESSORS_ONLN)
pushd "${selfdir}/Utilities" || exit 1
for util in "${UTILS[@]}"; do
cd "$util" || exit 1
echo "Building ${util}..."
make clean || exit 1
make -j "$cores" || exit 1
#
# FIXME: Do not build RsaTool for Win32 without OpenSSL.
#
if [ "$util" = "RsaTool" ] && [ "$HAS_OPENSSL_W32BUILD" != "1" ]; then
continue
fi
if [ "$(which i686-w64-mingw32-gcc)" != "" ]; then
echo "Building ${util} for Windows..."
UDK_ARCH=Ia32 CC=i686-w64-mingw32-gcc STRIP=i686-w64-mingw32-strip DIST=Windows make clean || exit 1
UDK_ARCH=Ia32 CC=i686-w64-mingw32-gcc STRIP=i686-w64-mingw32-strip DIST=Windows make -j "$cores" || exit 1
fi
if [ "$(which x86_64-linux-musl-gcc)" != "" ]; then
echo "Building ${util} for Linux..."
STATIC=1 SUFFIX=.linux UDK_ARCH=X64 CC=x86_64-linux-musl-gcc STRIP=x86_64-linux-musl-strip DIST=Linux make clean || exit 1
STATIC=1 SUFFIX=.linux UDK_ARCH=X64 CC=x86_64-linux-musl-gcc STRIP=x86_64-linux-musl-strip DIST=Linux make -j "$cores" || exit 1
fi
cd - || exit 1
done
popd || exit
}
get_inf_version() {
VER="VERSION_STRING"
if [ ! -f "${1}" ]; then
echo "Missing .inf file ${1}" > /dev/stderr
exit 1
fi
ver_line=$(grep -E "${VER} *=" "${1}")
if [ "${ver_line}" = "" ] ; then
echo "Missing ${VER} in ${1}" > /dev/stderr
exit 1
fi
read -ra ver_array <<<"${ver_line}"
if [ "${ver_array[0]}" != "${VER}" ] ||
[ "${ver_array[1]}" != "=" ] ||
[ "${ver_array[2]}" = "" ] ; then
echo "Malformed ${VER} line in ${1}" > /dev/stderr
exit 1
fi
echo "${ver_array[2]}"
}
package() {
if [ ! -d "$1" ]; then
echo "Missing package directory $1"
exit 1
fi
local ver
ver=$(grep OPEN_CORE_VERSION ./Include/Acidanthera/Library/OcMainLib.h | sed 's/.*"\(.*\)".*/\1/' | grep -E '^[0-9.]+$')
if [ "$ver" = "" ]; then
echo "Invalid version $ver"
ver="UNKNOWN"
fi
selfdir=$(pwd)
pushd "$1" || exit 1
rm -rf tmp || exit 1
dirs=(
"tmp/Docs/AcpiSamples"
"tmp/Utilities"
)
for dir in "${dirs[@]}"; do
mkdir -p "${dir}" || exit 1
done
efidirs=(
"EFI/BOOT"
"EFI/OC/ACPI"
"EFI/OC/Drivers"
"EFI/OC/Kexts"
"EFI/OC/Tools"
"EFI/OC/Resources/Audio"
"EFI/OC/Resources/Font"
"EFI/OC/Resources/Image"
"EFI/OC/Resources/Label"
)
# Switch to parent architecture directory (i.e. Build/X64 -> Build).
local dstdir
dstdir="$(pwd)/tmp"
pushd .. || exit 1
for arch in "${ARCHS[@]}"; do
for dir in "${efidirs[@]}"; do
mkdir -p "${dstdir}/${arch}/${dir}" || exit 1
done
# copy OpenCore main program.
cp "${arch}/OpenCore.efi" "${dstdir}/${arch}/EFI/OC" || exit 1
printf "%s" "OpenCore" > "${dstdir}/${arch}/EFI/OC/.contentFlavour" || exit 1
printf "%s" "Disabled" > "${dstdir}/${arch}/EFI/OC/.contentVisibility" || exit 1
local suffix="${arch}"
if [ "${suffix}" = "X64" ]; then
suffix="x64"
fi
cp "${arch}/Bootstrap.efi" "${dstdir}/${arch}/EFI/BOOT/BOOT${suffix}.efi" || exit 1
printf "%s" "OpenCore" > "${dstdir}/${arch}/EFI/BOOT/.contentFlavour" || exit 1
printf "%s" "Disabled" > "${dstdir}/${arch}/EFI/BOOT/.contentVisibility" || exit 1
efiTools=(
"BootKicker.efi"
"ChipTune.efi"
"CleanNvram.efi"
"CsrUtil.efi"
"FontTester.efi"
"GopStop.efi"
"KeyTester.efi"
"ListPartitions.efi"
"MmapDump.efi"
"ResetSystem.efi"
"RtcRw.efi"
"TpmInfo.efi"
"OpenControl.efi"
"ControlMsrE2.efi"
)
for efiTool in "${efiTools[@]}"; do
cp "${arch}/${efiTool}" "${dstdir}/${arch}/EFI/OC/Tools"/ || exit 1
done
# Special case: OpenShell.efi
cp "${arch}/Shell.efi" "${dstdir}/${arch}/EFI/OC/Tools/OpenShell.efi" || exit 1
efiDrivers=(
"ArpDxe.efi"
"AudioDxe.efi"
"BiosVideo.efi"
"CrScreenshotDxe.efi"
"Dhcp4Dxe.efi"
"DnsDxe.efi"
"DpcDxe.efi"
"Ext4Dxe.efi"
"FirmwareSettingsEntry.efi"
"HiiDatabase.efi"
"HttpBootDxe.efi"
"HttpDxe.efi"
"HttpUtilitiesDxe.efi"
"Ip4Dxe.efi"
"MnpDxe.efi"
"NvmExpressDxe.efi"
"OpenCanopy.efi"
"OpenHfsPlus.efi"
"OpenLegacyBoot.efi"
"OpenLinuxBoot.efi"
"OpenNtfsDxe.efi"
"OpenPartitionDxe.efi"
"OpenRuntime.efi"
"OpenUsbKbDxe.efi"
"OpenVariableRuntimeDxe.efi"
"Ps2KeyboardDxe.efi"
"Ps2MouseDxe.efi"
"ResetNvramEntry.efi"
"SnpDxe.efi"
"TcpDxe.efi"
"ToggleSipEntry.efi"
"Udp4Dxe.efi"
"UsbMouseDxe.efi"
"XhciDxe.efi"
)
for efiDriver in "${efiDrivers[@]}"; do
cp "${arch}/${efiDriver}" "${dstdir}/${arch}/EFI/OC/Drivers"/ || exit 1
done
done
docs=(
"Configuration.pdf"
"Differences/Differences.pdf"
"Sample.plist"
"SampleCustom.plist"
)
for doc in "${docs[@]}"; do
cp "${selfdir}/Docs/${doc}" "${dstdir}/Docs"/ || exit 1
done
cp "${selfdir}/Changelog.md" "${dstdir}/Docs"/ || exit 1
cp -r "${selfdir}/Docs/AcpiSamples/"* "${dstdir}/Docs/AcpiSamples"/ || exit 1
mkdir -p "${dstdir}/Docs/AcpiSamples/Binaries" || exit 1
cd "${dstdir}/Docs/AcpiSamples/Source" || exit 1
for i in *.dsl ; do
iasl "$i" || exit 1
done
mv ./*.aml "${dstdir}/Docs/AcpiSamples/Binaries" || exit 1
cd - || exit 1
utilScpts=(
"LegacyBoot"
"CreateVault"
"FindSerialPort"
"macrecovery"
"kpdescribe"
"ShimUtils"
)
for utilScpt in "${utilScpts[@]}"; do
cp -r "${selfdir}/Utilities/${utilScpt}" "${dstdir}/Utilities"/ || exit 1
done
buildutil || exit 1
# Copy LogoutHook.
mkdir -p "${dstdir}/Utilities/LogoutHook" || exit 1
logoutFiles=(
"Launchd.command"
"Launchd.command.plist"
"README.md"
"Legacy/nvramdump"
)
for file in "${logoutFiles[@]}"; do
cp "${selfdir}/Utilities/LogoutHook/${file}" "${dstdir}/Utilities/LogoutHook"/ || exit 1
done
# Copy OpenDuetPkg booter.
for arch in "${ARCHS[@]}"; do
local tgt
local booter
local booter_blockio
tgt="$(basename "$(pwd)")"
booter="$(pwd)/../../OpenDuetPkg/${tgt}/${arch}/boot"
booter_blockio="$(pwd)/../../OpenDuetPkg/${tgt}/${arch}/boot-blockio"
if [ -f "${booter}" ]; then
echo "Copying OpenDuetPkg boot file from ${booter}..."
cp "${booter}" "${dstdir}/Utilities/LegacyBoot/boot${arch}" || exit 1
else
echo "Failed to find OpenDuetPkg at ${booter}!"
fi
if [ -f "${booter_blockio}" ]; then
echo "Copying OpenDuetPkg BlockIO boot file from ${booter_blockio}..."
cp "${booter_blockio}" "${dstdir}/Utilities/LegacyBoot/boot${arch}-blockio" || exit 1
else
echo "Failed to find OpenDuetPkg BlockIO at ${booter_blockio}!"
fi
done
# Copy EFI-era Mac GOP firmware driver.
eg_ver=$(get_inf_version "${selfdir}/Staging/EnableGop/EnableGop.inf") || exit 1
egdirect_ver=$(get_inf_version "${selfdir}/Staging/EnableGop/EnableGopDirect.inf") || exit 1
if [ "${eg_ver}" != "${egdirect_ver}" ] ; then
echo "Mismatched EnableGop versions (${eg_ver} and ${egdirect_ver})!"
exit 1
fi
mkdir -p "${dstdir}/Utilities/EnableGop/Pre-release" || exit 1
ENABLE_GOP_GUID="3FBA58B1-F8C0-41BC-ACD8-253043A3A17F"
ffsNames=(
"EnableGop"
"EnableGopDirect"
)
for ffsName in "${ffsNames[@]}"; do
cp "FV/Ffs/${ENABLE_GOP_GUID}${ffsName}/${ENABLE_GOP_GUID}.ffs" "${dstdir}/Utilities/EnableGop/Pre-release/${ffsName}_${eg_ver}.ffs" || exit 1
done
gopDrivers=(
"EnableGop"
"EnableGopDirect"
)
for file in "${gopDrivers[@]}"; do
cp "X64/${file}.efi" "${dstdir}/Utilities/EnableGop/Pre-release/${file}_${eg_ver}.efi" || exit 1
done
helpFiles=(
"README.md"
"UEFITool_Inserted_Screenshot.png"
"vBiosInsert.sh"
)
for file in "${helpFiles[@]}"; do
cp "${selfdir}/Staging/EnableGop/${file}" "${dstdir}/Utilities/EnableGop"/ || exit 1
done
cp "${selfdir}/Staging/EnableGop/Release/"* "${dstdir}/Utilities/EnableGop"/ || exit 1
# Provide EDK-II BaseTools.
mkdir "${dstdir}/Utilities/BaseTools" || exit 1
if [ "$(unamer)" = "Windows" ]; then
cp "${selfdir}/UDK/BaseTools/Bin/Win32/EfiRom.exe" "${dstdir}/Utilities/BaseTools" || exit 1
cp "${selfdir}/UDK/BaseTools/Bin/Win32/GenFfs.exe" "${dstdir}/Utilities/BaseTools" || exit 1
else
cp "${selfdir}/UDK/BaseTools/Source/C/bin/EfiRom" "${dstdir}/Utilities/BaseTools" || exit 1
cp "${selfdir}/UDK/BaseTools/Source/C/bin/GenFfs" "${dstdir}/Utilities/BaseTools" || exit 1
fi
utils=(
"ACPIe"
"acdtinfo"
"macserial"
"ocpasswordgen"
"ocvalidate"
"disklabel"
"icnspack"
)
for util in "${utils[@]}"; do
dest="${dstdir}/Utilities/${util}"
mkdir -p "${dest}" || exit 1
bin="${selfdir}/Utilities/${util}/${util}"
cp "${bin}" "${dest}" || exit 1
if [ -f "${bin}.exe" ]; then
cp "${bin}.exe" "${dest}" || exit 1
fi
if [ -f "${bin}.linux" ]; then
cp "${bin}.linux" "${dest}" || exit 1
fi
done
# additional docs for macserial.
cp "${selfdir}/Utilities/macserial/FORMAT.md" "${dstdir}/Utilities/macserial"/ || exit 1
cp "${selfdir}/Utilities/macserial/README.md" "${dstdir}/Utilities/macserial"/ || exit 1
# additional docs for ocvalidate.
cp "${selfdir}/Utilities/ocvalidate/README.md" "${dstdir}/Utilities/ocvalidate"/ || exit 1
pushd "${dstdir}" || exit 1
zip -qr -FS ../"OpenCore-${ver}-${2}.zip" ./* || exit 1
popd || exit 1
rm -rf "${dstdir}" || exit 1
popd || exit 1
popd || exit 1
}
cd "$(dirname "$0")" || exit 1
if [ "$ARCHS" = "" ]; then
ARCHS=(X64 IA32)
export ARCHS
fi
SELFPKG=OpenCorePkg
NO_ARCHIVES=0
DISCARD_SUBMODULES=OpenCorePkg
export SELFPKG
export NO_ARCHIVES
export DISCARD_SUBMODULES
src=$(curl -LfsS https://raw.githubusercontent.com/acidanthera/ocbuild/master/efibuild.sh) && eval "$src" || exit 1
cd Utilities/ocvalidate || exit 1
ocv_tool=""
if [ -x ./ocvalidate ]; then
ocv_tool=./ocvalidate
elif [ -x ./ocvalidate.exe ]; then
ocv_tool=./ocvalidate.exe
fi
if [ -x "$ocv_tool" ]; then
"$ocv_tool" ../../Docs/Sample.plist || abort "Wrong Sample.plist"
"$ocv_tool" ../../Docs/SampleCustom.plist || abort "Wrong SampleCustom.plist"
fi
cd ../..
cd Library/OcConfigurationLib || exit 1
./CheckSchema.py OcConfigurationLib.c || abort "Wrong OcConfigurationLib.c"