forked from PixelExperience-Devices/kernel_xiaomi_sm6250
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·444 lines (409 loc) · 9.79 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
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#!/usr/bin/env bash
# Written by: cyberknight777
# YAKB v2.0
# Copyright (c) 2022-2023 Cyber Knight <cyberknight755@gmail.com>
#
# GNU GENERAL PUBLIC LICENSE
# Version 3, 29 June 2007
#
# Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
# Everyone is permitted to copy and distribute verbatim copies
# of this license document, but changing it is not allowed.
# Some Placeholders: [!] [*] [✓] [✗]
# Default defconfig to use for builds.
export CONFIG=vendor/xiaomi/miatoll_defconfig
# Default directory where kernel is located in.
KDIR=$(pwd)
export KDIR
# Default linker to use for builds.
export LINKER="ld"
# Device name.
export DEVICE="Xiaomi SD720G Family"
# Date of build.
DATE=$(date +"%Y-%m-%d")
export DATE
# Device codename.
export CODENAME="miatoll"
# Builder name.
export BUILDER="LeddaZ"
# Kernel repository URL.
export REPO_URL="https://github.com/LeddaZ/android_kernel_xiaomi_sm7125"
# Commit hash of HEAD.
COMMIT_HASH=$(git rev-parse --short HEAD)
export COMMIT_HASH
# Number of jobs to run.
PROCS=$(nproc --all)
export PROCS
# Compiler to use for builds.
export COMPILER=gcc
# Requirements
if [[ "${COMPILER}" = gcc ]]; then
if [ ! -d "${KDIR}/gcc64" ]; then
echo "Downloading arm64 gcc..."
curl -s https://api.github.com/repos/mvaisakh/gcc-build/releases/latest | grep "eva-gcc-arm64-" | cut -d : -f 2,3 | tr -d \" | wget -O gcc-arm64.xz -qi -
tar -xf gcc-arm64.xz
rm gcc-arm64.xz
mv "${KDIR}"/gcc-arm64 "${KDIR}"/gcc64
fi
if [ ! -d "${KDIR}/gcc32" ]; then
echo "Downloading arm gcc..."
curl -s https://api.github.com/repos/mvaisakh/gcc-build/releases/latest | grep "eva-gcc-arm-" | cut -d : -f 2,3 | tr -d \" | wget -O gcc-arm.xz -qi -
tar -xf gcc-arm.xz
rm gcc-arm.xz
mv "${KDIR}"/gcc-arm "${KDIR}"/gcc32
fi
KBUILD_COMPILER_STRING=$("${KDIR}"/gcc64/bin/aarch64-elf-gcc --version | head -n 1)
export KBUILD_COMPILER_STRING
export PATH="${KDIR}"/gcc32/bin:"${KDIR}"/gcc64/bin:/usr/bin/:${PATH}
MAKE+=(
ARCH=arm64
O=out
CROSS_COMPILE=aarch64-elf-
CROSS_COMPILE_ARM32=arm-eabi-
LD="${KDIR}"/gcc64/bin/aarch64-elf-"${LINKER}"
AR=llvm-ar
NM=llvm-nm
OBJDUMP=llvm-objdump
OBJCOPY=llvm-objcopy
OBJSIZE=llvm-objsize
STRIP=llvm-strip
HOSTAR=llvm-ar
HOSTCC=gcc
HOSTCXX=aarch64-elf-g++
CC=aarch64-elf-gcc
)
elif [[ ${COMPILER} == clang ]]; then
if [ ! -f "${KDIR}/neutron-clang/bin/clang" ]; then
rm -rf "${KDIR}"/neutron-clang
mkdir "${KDIR}"/neutron-clang
cd "${KDIR}"/neutron-clang || exit 1
bash <(curl -s "https://raw.githubusercontent.com/Neutron-Toolchains/antman/main/antman") -S
cd "${KDIR}" || exit 1
fi
KBUILD_COMPILER_STRING=$("${KDIR}"/neutron-clang/bin/clang -v 2>&1 | head -n 1 | sed 's/(https..*//' | sed 's/ version//')
export KBUILD_COMPILER_STRING
export PATH=$KDIR/neutron-clang/bin/:/usr/bin/:${PATH}
MAKE+=(
O=out
LLVM=1
)
fi
if [ ! -d "${KDIR}/AnyKernel3/" ]; then
git clone https://github.com/LeddaZ/AnyKernel3 -b miatoll
fi
export KBUILD_BUILD_USER="leddaz"
export KBUILD_BUILD_HOST="stargazer"
zipn="Nitro-miatoll-$(date '+%Y%m%d-%H%M').zip"
if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
head=$(git rev-parse --verify HEAD 2>/dev/null); then
zipn="${zipn::-4}-$(echo $head | cut -c1-8).zip"
fi
# A function to exit on SIGINT.
exit_on_signal_SIGINT() {
echo -e "\n\n\e[1;31m[✗] Received INTR call - Exiting...\e[0m"
exit 0
}
trap exit_on_signal_SIGINT SIGINT
# A function to clean kernel source prior building.
clean() {
echo -e "\n\e[1;93m[*] Cleaning source and out/ directory! \e[0m"
make clean && make mrproper && rm -rf "${KDIR}"/out
echo -e "\n\e[1;32m[✓] Source cleaned and out/ removed! \e[0m"
}
# A function to regenerate defconfig.
rgn() {
echo -e "\n\e[1;93m[*] Regenerating defconfig! \e[0m"
make "${MAKE[@]}" $CONFIG
cp -rf "${KDIR}"/out/.config "${KDIR}"/arch/arm64/configs/$CONFIG
echo -e "\n\e[1;32m[✓] Defconfig regenerated! \e[0m"
}
# A function to open menuconfig to update current config.
mcfg() {
rgn
echo -e "\n\e[1;93m[*] Making Menuconfig! \e[0m"
make "${MAKE[@]}" menuconfig
cp -rf "${KDIR}"/out/.config "${KDIR}"/arch/arm64/configs/$CONFIG
echo -e "\n\e[1;32m[✓] Saved Modifications! \e[0m"
}
# A function to open nconfig to update current config.
ncfg() {
rgn
echo -e "\n\e[1;93m[*] Making Nconfig! \e[0m"
make "${MAKE[@]}" nconfig
cp -rf "${KDIR}"/out/.config "${KDIR}"/arch/arm64/configs/$CONFIG
echo -e "\n\e[1;32m[✓] Saved Modifications! \e[0m"
}
# A function to build the kernel.
img() {
rgn
echo -e "\n\e[1;93m[*] Building Kernel! \e[0m"
BUILD_START=$(date +"%s")
time make -j"$PROCS" "${MAKE[@]}" Image dtbo.img dtb.img 2>&1 | tee log.txt
BUILD_END=$(date +"%s")
DIFF=$((BUILD_END - BUILD_START))
if [ -f "${KDIR}/out/arch/arm64/boot/Image" ]; then
echo -e "\n\e[1;32m[✓] Kernel built after $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)! \e[0m"
else
echo -e "\n\e[1;31m[✗] Build Failed! \e[0m"
exit 1
fi
}
# A function to build DTBs.
dtb() {
rgn
echo -e "\n\e[1;93m[*] Building DTBS! \e[0m"
time make -j"$PROCS" "${MAKE[@]}" dtbs dtbo.img dtb.img
echo -e "\n\e[1;32m[✓] Built DTBS! \e[0m"
}
# A function to build out-of-tree modules.
mod() {
if [[ ${TGI} == "1" ]]; then
tg "*Building Modules!*"
fi
rgn
echo -e "\n\e[1;93m[*] Building Modules! \e[0m"
mkdir -p "${KDIR}"/out/modules
make "${MAKE[@]}" modules_prepare
make -j"$PROCS" "${MAKE[@]}" modules INSTALL_MOD_PATH="${KDIR}"/out/modules
make "${MAKE[@]}" modules_install INSTALL_MOD_PATH="${KDIR}"/out/modules
find "${KDIR}"/out/modules -type f -iname '*.ko' -exec cp {} "${KDIR}"/AnyKernel3/modules/system/lib/modules/ \;
echo -e "\n\e[1;32m[✓] Built Modules! \e[0m"
}
# A function to build an AnyKernel3 zip.
mkzip() {
if [[ ${TGI} == "1" ]]; then
tg "*Building zip!*"
fi
echo -e "\n\e[1;93m[*] Building zip! \e[0m"
mkdir -p "${KDIR}"/AnyKernel3/dtbs
mv "${KDIR}"/out/arch/arm64/boot/dtbo.img "${KDIR}"/AnyKernel3
mv "${KDIR}"/out/arch/arm64/boot/dtb.img "${KDIR}"/AnyKernel3
mv "${KDIR}"/out/arch/arm64/boot/Image "${KDIR}"/AnyKernel3
cd "${KDIR}"/AnyKernel3 || exit 1
zip -r9 "$zipn" . -x ".git*" -x "README.md" -x "LICENSE" -x "*.zip"
echo -e "\n\e[1;32m[✓] Built zip! \e[0m"
}
# A function to build specific objects.
obj() {
rgn
echo -e "\n\e[1;93m[*] Building ${1}! \e[0m"
time make -j"$PROCS" "${MAKE[@]}" "$1"
echo -e "\n\e[1;32m[✓] Built ${1}! \e[0m"
}
# A function to showcase the options provided for args-based usage.
helpmenu() {
echo -e "\n\e[1m
usage: bash $0 <arg>
example: bash $0 mcfg
example: bash $0 mcfg img
example: bash $0 mcfg img mkzip
example: bash $0 --obj=drivers/android/binder.o
example: bash $0 --obj=kernel/sched/
example: bash $0 --upr=r16
mcfg Runs make menuconfig
ncfg Runs make nconfig
img Builds Kernel
dtb Builds dtb(o).img
mod Builds out-of-tree modules
mkzip Builds anykernel3 zip
--obj Builds specific driver/subsystem
rgn Regenerates defconfig
\e[0m"
}
# A function to setup menu-based usage.
ndialog() {
HEIGHT=16
WIDTH=40
CHOICE_HEIGHT=30
BACKTITLE="Yet Another Kernel Builder"
TITLE="YAKB v2.0"
MENU="Choose one of the following options: "
OPTIONS=(1 "Build kernel"
2 "Build DTBs"
3 "Build modules"
4 "Open menuconfig"
5 "Open nconfig"
6 "Regenerate defconfig"
7 "Build AnyKernel3 zip"
8 "Build a specific object"
9 "Clean"
10 "Exit"
)
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case "$CHOICE" in
1)
clear
img
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
2)
clear
dtb
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
3)
clear
mod
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
4)
clear
mcfg
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
5)
clear
ncfg
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
6)
clear
rgn
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
7)
mkzip
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
8)
dialog --inputbox --stdout "Enter object path: " 15 50 | tee .f
ob=$(cat .f)
if [ -z "$ob" ]; then
dialog --inputbox --stdout "Enter object path: " 15 50 | tee .f
fi
clear
obj "$ob"
rm .f
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
9)
clear
clean
img
echo -ne "\e[1mPress enter to continue or 0 to exit! \e[0m"
read -r a1
if [ "$a1" == "0" ]; then
exit 0
else
clear
ndialog
fi
;;
10)
echo -e "\n\e[1m Exiting YAKB...\e[0m"
sleep 3
exit 0
;;
esac
}
if [[ -z $* ]]; then
ndialog
fi
for arg in "$@"; do
case "${arg}" in
"mcfg")
mcfg
;;
"ncfg")
ncfg
;;
"img")
img
;;
"dtb")
dtb
;;
"mod")
mod
;;
"mkzip")
mkzip
;;
"--obj="*)
object="${arg#*=}"
if [[ -z $object ]]; then
echo "Use --obj=filename.o"
exit 1
else
obj "$object"
fi
;;
"rgn")
rgn
;;
"clean")
clean
;;
"help")
helpmenu
exit 1
;;
*)
helpmenu
exit 1
;;
esac
done