forked from edk2-porting/edk2-msm
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·291 lines (267 loc) · 10.2 KB
/
build.sh
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
#!/bin/bash
function _help(){
echo "Usage: build.sh --device DEV"
echo
echo "Build edk2 for Qualcomm Snapdragon platforms."
echo
echo "Options: "
echo " --device DEV, -d DEV: build for DEV."
echo " --all, -a: build all devices."
echo " --chinese, -c: use hub.nuaa.cf for submodule cloning."
echo " --release MODE, -r MODE: Release mode for building, default is 'RELEASE', 'DEBUG' alternatively."
echo " --toolchain TOOLCHAIN: Set toolchain, default is 'CLANG38'."
echo " --uart, -u: compile with UART support, print debug messages to uart debug port."
echo " --no-exception-disp: do not display exception information in DEBUG builds"
echo " --acpi, -A: compile DSDT using MS asl with wine"
echo " --clean, -C: clean workspace and output."
echo " --distclean, -D: clean up all files that are not in repo."
echo " --outputdir, -O: output folder."
echo " --boot, -b: fastboot boot image."
echo " --fixclang, -f: fix build using Clang by suppressing -Os flag."
echo " --help, -h: show this help."
echo
echo "MainPage: https://github.com/edk2-porting/edk2-msm"
exit "${1}"
}
function _error(){ echo "${@}" >&2;exit 1; }
function _call_hook(){
local NAME="${1}"
shift
if declare -F "${NAME}" &>/dev/null
then eval "${NAME}" "${@}"||return 1
fi
return 0
}
function _load_platform_hooks(){
if [ -f "${ROOTDIR}/${1}" ]
then source "${ROOTDIR}/${1}"
fi
}
function _build(){
local DEVICE="${1}"
shift
source "${_EDK2}/edksetup.sh"
[ -d "${WORKSPACE}" ]||mkdir "${WORKSPACE}"
set -x
make -C "${_EDK2}/BaseTools"||exit "$?"
SPLIT_DSDT=false
EXT=""
if [ -f "configs/devices/${DEVICE}.conf" ]
then source "configs/devices/${DEVICE}.conf"
else _error "Device configuration not found"
fi
typeset -l SOC_PLATFORM_L="$SOC_PLATFORM"
if [ -f "configs/${SOC_PLATFORM_L}.conf" ]
then source "configs/${SOC_PLATFORM_L}.conf"
else _error "SoC configuration not found"
fi
# for overriding config
source "configs/devices/${DEVICE}.conf"
_load_platform_hooks Platform/platform.sh.inc
_load_platform_hooks Silicon/platform.sh.inc
_load_platform_hooks "Silicon/${SOC_VENDOR}/platform.sh.inc"
_load_platform_hooks "Platform/${VENDOR_NAME}/platform.sh.inc"
_load_platform_hooks "Silicon/${SOC_VENDOR}/${SOC_PLATFORM_L}/platform.sh.inc"
_load_platform_hooks "Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/platform.sh.inc"
_load_platform_hooks "Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/${PLATFORM_NAME}.sh.inc"
_load_platform_hooks "Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/${DEVICE}.sh.inc"
_call_hook platform_pre_acpi||return "$?"
if "${GEN_ACPI}"
then
if "${SPLIT_DSDT}"
then
rm -rf "${WORKSPACE}/Build/${DEVICE}/ACPI"
mkdir -p "${WORKSPACE}/Build/${DEVICE}/ACPI"
pushd "${WORKSPACE}/Build/${DEVICE}/ACPI"
cp "${ROOTDIR}/Silicon/${SOC_VENDOR}/${SOC_PLATFORM_L}/AcpiTables"/* ./
if compgen -G "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/*.asl" > /dev/null; then
cp "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/"*.asl ./
fi
cp "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/${DEVICE}/"* ./
if [ "${USE_IASL}" == "true" ]
then iasl -ve Dsdt.asl ||_error "iasl failed"
else wine "${ROOTDIR}/tools/asl-x64.exe" Dsdt.asl ||_error "asl.exe failed"
fi
test -e DSDT.aml && cp DSDT.aml "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/${DEVICE}/DSDT.aml"
test -e DSDT.AML && cp DSDT.AML "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/AcpiTables/${DEVICE}/DSDT.aml"
popd
else
_error "Building DSDT is unsupported for this device"
fi
fi
# based on the instructions from edk2-platform
rm -f "${OUTDIR}/boot-${DEVICE}${EXT}.img" "${OUTDIR}/uefi-${DEVICE}"*
case "${MODE}" in
RELEASE) _MODE=RELEASE;;
*) _MODE=DEBUG;;
esac
echo "Building BootShim"
pushd "${ROOTDIR}/tools/BootShim"
rm -f BootShim.bin BootShim.elf BootShim.Dualboot.bin BootShim.Dualboot.elf
make UEFI_BASE=${FD_BASE} UEFI_SIZE=${FD_SIZE}
popd
_call_hook platform_pre_build||return "$?"
mkdir -p "${ROOTDIR}/Common/edk2/Conf"
cp "${ROOTDIR}/tools/"{build_rule.txt,tools_def.txt} "${ROOTDIR}/Common/edk2/Conf/"
build \
-s \
-n 0 \
-a AARCH64 \
-t "${TOOLCHAIN}" \
-p "${ROOTDIR}/Platform/${VENDOR_NAME}/${SOC_PLATFORM_L}/${PLATFORM_NAME}.dsc" \
-b "${_MODE}" \
-D FIRMWARE_VER="${GITCOMMIT}" \
-D USE_UART="${USE_UART}" \
-D FIX_CLANG="${FIX_CLANG}" \
-D NO_EXCEPTION_DISPLAY="${NO_EXCEPTION_DISPLAY}" \
-D FD_BASE="${FD_BASE}" -D FD_SIZE="${FD_SIZE}" \
||return "$?"
_call_hook platform_build_kernel||return "$?"
_call_hook platform_build_bootimg||return "$?"
echo "Build done: ${OUTDIR}/boot-${DEVICE}${EXT}.img"
set +x
}
function _clean(){ rm --one-file-system --recursive --force "${WORKSPACE}"./workspace "${OUTDIR}"/boot-*.img "${OUTDIR}"/uefi-*.img*; }
function _distclean(){ if [ -d .git ];then git clean -xdf;else _clean;fi; }
OUTDIR="${PWD}"
ROOTDIR="$(realpath "$(dirname "$0")")"
cd "${ROOTDIR}"||exit 1
typeset -l DEVICE
typeset -u MODE
DEVICE=""
MODE=RELEASE
CHINESE=false
CLEAN=false
DISTCLEAN=false
TOOLCHAIN=CLANG38
export FIX_CLANG=0
SOC_VENDOR=Qualcomm
USE_UART=0
NO_EXCEPTION_DISPLAY=0
export ROOTDIR OUTDIR SOC_VENDOR
export GEN_ACPI=false
export GEN_ROOTFS=true
export FASTBOOT=false
OPTS="$(getopt -o t:d:hfabczACDO:r:u -l toolchain:,device:,help,fixclang,all,boot,chinese,acpi,skip-rootfs-gen,no-exception-disp,uart,clean,distclean,outputdir:,release: -n 'build.sh' -- "$@")"||exit 1
eval set -- "${OPTS}"
while true
do case "${1}" in
-d|--device) DEVICE="${2}";shift 2;;
-a|--all) DEVICE=all;shift;;
-b|--boot) FASTBOOT=true;shift;;
-c|--chinese) CHINESE=true;shift;;
-A|--acpi) GEN_ACPI=true;shift;;
-C|--clean) CLEAN=true;shift;;
-D|--distclean) DISTCLEAN=true;shift;;
-O|--outputdir) OUTDIR="${2}";shift 2;;
--skip-rootfs-gen) GEN_ROOTFS=false;shift;;
--no-exception-disp) NO_EXCEPTION_DISPLAY=1;shift;;
-r|--release) MODE="${2}";shift 2;;
-t|--toolchain) TOOLCHAIN="${2}";shift 2;;
-u|--uart) USE_UART=1;shift;;
-f|--fixclang) FIX_CLANG=1;shift;;
-h|--help) _help 0;shift;;
--) shift;break;;
*) _help 1;;
esac
done
if "${DISTCLEAN}";then _distclean;exit "$?";fi
if "${CLEAN}";then _clean;exit "$?";fi
[ -z "${DEVICE}" ]&&_help 1
if ! [ -f Common/edk2/edksetup.sh ] && ! [ -f ../edk2/edksetup.sh ]
then
set -e
echo "Updating submodules"
if "${CHINESE}"
then
git submodule set-url GPLDrivers/Library/droidboot https://hub.nuaa.cf/Android-Boot-Manager/droidboot_gui.git
pushd GPLDrivers/Library/droidboot
git submodule set-url lib/ext4 https://hub.nuaa.cf/Android-Boot-Manager/droidboot_ext4
git submodule set-url lib/lvgl https://hub.nuaa.cf/Android-Boot-Manager/droidboot_lvgl
git submodule set-url lib/droidboot_platforms https://hub.nuaa.cf/Android-Boot-Manager/droidboot_platforms
git submodule set-url lib/libudft https://hub.nuaa.cf/Android-Boot-Manager/libufdt
git submodule set-url lib/minigz https://hub.nuaa.cf/Android-Boot-Manager/droidboot_minigz
popd
git submodule set-url Common/edk2 https://hub.nuaa.cf/tianocore/edk2.git
git submodule set-url Common/edk2-platforms https://hub.nuaa.cf/tianocore/edk2-platforms.git
git submodule set-url Platform/EFI_Binaries https://hub.nuaa.cf/edk2-porting/edk2-sdm845-binary.git
git submodule init;git submodule update --depth 1
pushd Common/edk2
git submodule set-url ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3 https://hub.nuaa.cf/ucb-bar/berkeley-softfloat-3.git
git submodule set-url CryptoPkg/Library/OpensslLib/openssl https://hub.nuaa.cf/openssl/openssl.git
git submodule set-url BaseTools/Source/C/BrotliCompress/brotli https://hub.nuaa.cf/google/brotli.git
git submodule set-url UnitTestFrameworkPkg/Library/CmockaLib/cmocka https://hub.nuaa.cf/tianocore/edk2-cmocka.git
git submodule set-url ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3 https://hub.nuaa.cf/ucb-bar/berkeley-softfloat-3.git
git submodule set-url MdeModulePkg/Library/BrotliCustomDecompressLib/brotli https://hub.nuaa.cf/google/brotli.git
git submodule set-url MdeModulePkg/Universal/RegularExpressionDxe/oniguruma https://hub.nuaa.cf/kkos/oniguruma.git
git submodule set-url RedfishPkg/Library/JsonLib/jansson https://hub.nuaa.cf/akheron/jansson.git
git submodule init;git submodule update
git checkout .gitmodules
popd
git checkout .gitmodules
else
git submodule init;git submodule update --depth 1
pushd Common/edk2
git submodule init;git submodule update
popd
pushd GPLDrivers/Library/droidboot
git submodule init;git submodule update
popd
fi
set +e
fi
for i in "${EDK2}" ./Common/edk2 ../edk2
do
if [ -n "${i}" ]&&[ -f "${i}/edksetup.sh" ]
then
_EDK2="$(realpath "${i}")"
break
fi
done
for i in "${EDK2_PLATFORMS}" ./Common/edk2-platforms ../edk2-platforms
do
if [ -n "${i}" ]&&[ -d "${i}/Platform" ]
then
_EDK2_PLATFORMS="$(realpath "${i}")"
break
fi
done
for i in "${DROIDBOOT}" GPLDrivers/Library/droidboot ./droidboot ../droidboot
do
if [ -n "${i}" ]&&[ -f "${i}/droidboot.inc" ]
then
_DROIDBOOT="$(realpath "${i}")"
break
fi
done
[ -n "${_EDK2}" ]||_error "EDK2 not found, please see README.md"
[ -n "${_EDK2_PLATFORMS}" ]||_error "EDK2 Platforms not found, please see README.md"
[ -f "configs/devices/${DEVICE}.conf" ]||_error "Device configuration not found"
echo "EDK2 Path: ${_EDK2}"
echo "EDK2_PLATFORMS Path: ${_EDK2_PLATFORMS}"
export CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
export GCC5_AARCH64_PREFIX="${CROSS_COMPILE}"
export CLANG38_AARCH64_PREFIX="${CROSS_COMPILE}"
export PACKAGES_PATH="$_EDK2:$_EDK2_PLATFORMS:$_DROIDBOOT:$PWD:$PWD/GPLDrivers"
export WORKSPACE="${OUTDIR}/workspace"
GITCOMMIT="$(git describe --tags --always)"||GITCOMMIT="unknown"
export GITCOMMIT
echo > ramdisk
set -e
if [ "${DEVICE}" == "all" ]
then
E=0
for i in configs/*.conf
do
DEV="$(basename "$i" .conf)"
echo "Building ${DEV}"
_build "${DEV}"||E="$?"
done
exit "${E}"
else
_build "${DEVICE}"
fi
if "${FASTBOOT}"
then
fastboot boot ${OUTDIR}/boot-${DEVICE}${EXT}.img
fi