-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.sh
executable file
·239 lines (231 loc) · 7.93 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
#!/bin/bash
##### Change this to add device #####
DEVICES=(
dipper
enchilada
enchilada-8g
fajita
fajita-8g
polaris
polaris-8g
beryllium
perseus
nx616j
m1882
m1892
skr-a0
judyln
star2qltechn
dipper-old
pafm00
trident
olympic
draco
pd1821
odin-base
akershus
equuleus
)
#####################################
function _help(){
echo "Usage: build.sh --device DEV"
echo
echo "Build edk2 for Qualcomm SDM845 platform."
echo
echo "Options: "
echo " --device DEV, -d DEV: build for DEV. (${DEVICES[*]})"
echo " --all, -a: build all devices."
echo " --chinese, -c: use Fastgit for submodule cloning."
echo " --release MODE, -r MODE: Release mode for building, default is 'RELEASE', 'DEBUG' alternatively."
echo " --acpi, -A: compile acpi. (not implemented yet)"
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 " --help, -h: show this help."
echo
echo "MainPage: https://github.com/edk2-porting/edk2-sdm845"
exit "${1}"
}
function _error(){ echo "${@}" >&2;exit 1; }
function _build(){
local DEVICE="${1}"
shift
source "${_EDK2}/edksetup.sh"
[ -d "${WORKSPACE}" ]||mkdir "${WORKSPACE}"
set -x
make -C "${_EDK2}/BaseTools"||exit "$?"
if "${GEN_ACPI}" && ! iasl -ve "sdm845Pkg/AcpiTables/${DEVICE}/Dsdt.asl"
then echo "iasl failed with ${?}" >&2;return 1
fi
# based on the instructions from edk2-platform
rm -f "${OUTDIR}/boot-${DEVICE}.img" uefi_img "uefi-${DEVICE}.img.gz" "uefi-${DEVICE}.img.gz-dtb"
case "${MODE}" in
RELEASE)_MODE=RELEASE;;
*)_MODE=DEBUG;;
esac
build \
-s \
-n 0 \
-a AARCH64 \
-t GCC5 \
-p "sdm845Pkg/Devices/${DEVICE}.dsc" \
-b "${_MODE}" \
-D FIRMWARE_VER="${GITCOMMIT}" \
||return "$?"
gzip -c \
< "workspace/Build/sdm845Pkg/${_MODE}_GCC5/FV/SDM845PKG_UEFI.fd" \
> "workspace/uefi-${DEVICE}.img.gz" \
||return "$?"
cat \
"workspace/uefi-${DEVICE}.img.gz" \
"device_specific/${DEVICE}.dtb" \
> "workspace/uefi-${DEVICE}.img.gz-dtb" \
||return "$?"
abootimg \
--create "${OUTDIR}/boot-${DEVICE}.img" \
-k "workspace/uefi-${DEVICE}.img.gz-dtb" \
-r ramdisk \
||return "$?"
echo "Build done: ${OUTDIR}/boot-${DEVICE}.img"
set +x
}
function _clean(){ rm --one-file-system --recursive --force ./workspace boot-*.img uefi-*.img*; }
function _distclean(){ if [ -d .git ];then git clean -xdf;else _clean;fi; }
cd "$(dirname "$0")"||exit 1
[ -f sdm845Pkg/sdm845Pkg.dsc ]||_error "cannot find sdm845Pkg/sdm845Pkg.dsc"
typeset -l DEVICE
typeset -u MODE
DEVICE=""
MODE=RELEASE
CHINESE=false
CLEAN=false
DISTCLEAN=false
export OUTDIR="${PWD}"
export GEN_ACPI=false
OPTS="$(getopt -o d:hacACDO:r: -l device:,help,all,chinese,acpi,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;;
-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;;
-r|--release)MODE="${2}";shift 2;;
-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 edk2/edksetup.sh ] || ! [ -f ../edk2/edksetup.sh ]
then set -e
echo "Updating submodules"
[ -e sdm845Pkg/AcpiTables/.git ]||git clone https://git.renegade-project.org/edk2-sdm845-acpi.git sdm845Pkg/AcpiTables
if "${CHINESE}"
then git submodule set-url edk2 https://hub.fastgit.org/tianocore/edk2.git
git submodule set-url edk2-platforms https://hub.fastgit.org/tianocore/edk2-platforms.git
git submodule set-url sdm845Pkg/Binary https://hub.fastgit.org/edk2-porting/edk2-sdm845-binary.git
git submodule set-url sdm845Pkg/Library/StdLib https://hub.fastgit.org/tianocore/edk2-libc.git
git submodule set-url sdm845Pkg/Library/SimpleInit https://hub.fastgit.org/BigfootACA/simple-init.git
git submodule init;git submodule update --depth 1
pushd edk2
git submodule set-url ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3 https://hub.fastgit.org/ucb-bar/berkeley-softfloat-3.git
git submodule set-url CryptoPkg/Library/OpensslLib/openssl https://hub.fastgit.org/openssl/openssl.git
git submodule set-url BaseTools/Source/C/BrotliCompress/brotli https://hub.fastgit.org/google/brotli.git
git submodule set-url UnitTestFrameworkPkg/Library/CmockaLib/cmocka https://git.cryptomilk.org/projects/cmocka.git
git submodule set-url ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3 https://hub.fastgit.org/ucb-bar/berkeley-softfloat-3.git
git submodule set-url MdeModulePkg/Library/BrotliCustomDecompressLib/brotli https://hub.fastgit.org/google/brotli.git
git submodule set-url MdeModulePkg/Universal/RegularExpressionDxe/oniguruma https://hub.fastgit.org/kkos/oniguruma.git
git submodule set-url RedfishPkg/Library/JsonLib/jansson https://hub.fastgit.org/akheron/jansson.git
git submodule init;git submodule update
git checkout .gitmodules
popd
pushd sdm845Pkg/Library/SimpleInit
git submodule set-url libs/lvgl https://hub.fastgit.org/lvgl/lvgl.git
git submodule set-url libs/lodepng https://hub.fastgit.org/lvandeve/lodepng.git
git submodule set-url libs/freetype https://hub.fastgit.org/freetype/freetype.git
git submodule init;git submodule update
popd
git checkout .gitmodules
else git submodule init;git submodule update --depth 1
pushd edk2
git submodule init;git submodule update
popd
pushd sdm845Pkg/Library/SimpleInit
git submodule init;git submodule update
popd
fi
set +e
fi
for i in "${EDK2}" ./edk2 ../edk2
do if [ -n "${i}" ]&&[ -f "${i}/edksetup.sh" ]
then _EDK2="$(realpath "${i}")"
break
fi
done
for i in "${EDK2_LIBC}" sdm845Pkg/Library/StdLib ./edk2-libc ../edk2-libc
do if [ -n "${i}" ]&&[ -d "${i}/StdLib" ]
then _EDK2_LIBC="$(realpath "${i}")"
break
fi
done
for i in "${EDK2_PLATFORMS}" ./edk2-platforms ../edk2-platforms
do if [ -n "${i}" ]&&[ -d "${i}/Platform" ]
then _EDK2_PLATFORMS="$(realpath "${i}")"
break
fi
done
for i in "${SIMPLE_INIT}" sdm845Pkg/Library/SimpleInit ./simple-init ../simple-init
do if [ -n "${i}" ]&&[ -f "${i}/SimpleInit.inc" ]
then _SIMPLE_INIT="$(realpath "${i}")"
break
fi
done
[ -n "${_EDK2}" ]||_error "EDK2 not found, please see README.md"
[ -n "${_EDK2_LIBC}" ]||_error "EDK2-LibC not found, please see README.md"
[ -n "${_EDK2_PLATFORMS}" ]||_error "EDK2 Platforms not found, please see README.md"
[ -n "${_SIMPLE_INIT}" ]||_error "SimpleInit not found, please see README.md"
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 PACKAGES_PATH="$_EDK2:$_EDK2_PLATFORMS:$_EDK2_LIBC:$_SIMPLE_INIT:$PWD"
export WORKSPACE="${PWD}/workspace"
GITCOMMIT="$(git describe --tags --always)"||GITCOMMIT="unknown"
export GITCOMMIT
echo > ramdisk
set -e
python3 assets/generate-logo.py "${GITCOMMIT}"
mkdir -p "${_SIMPLE_INIT}/build" "${_SIMPLE_INIT}/root/usr/share/locale"
for i in "${_SIMPLE_INIT}/po/"*.po
do [ -f "${i}" ]||continue
_name="$(basename "$i" .po)"
_path="${_SIMPLE_INIT}/root/usr/share/locale/${_name}/LC_MESSAGES"
mkdir -p "${_path}"
msgfmt -o "${_path}/simple-init.mo" "${i}"
done
bash "${_SIMPLE_INIT}/scripts/gen-rootfs-source.sh" \
"${_SIMPLE_INIT}" \
"${_SIMPLE_INIT}/build"
if [ "${DEVICE}" == "all" ]
then E=0
for i in "${DEVICES[@]}"
do echo "Building ${i}"
rm --recursive --force --one-file-system ./workspace||true
_build "${i}"||E="$?"
done
exit "${E}"
else HAS=false
for i in "${DEVICES[@]}"
do [ "${i}" == "${DEVICE}" ]||continue
HAS=true
break
done
[ "${HAS}" == "true" ]||_error "build.sh: unknown build target device ${DEVICE}."
_build "${DEVICE}"
fi