forked from raystef66/InfiniR_kernel_alioth
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbuild_kernel
executable file
·317 lines (260 loc) · 12.1 KB
/
build_kernel
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
#!/usr/bin/env bash
# shellcheck disable=SC2199
# shellcheck source=/dev/null
#
# Copyright (C) 2020-22 UtsavBalar1231 <utsavbalar1231@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Start cleanup of previous build
if [[ -d anykernel ]]; then
rm -fr anykernel/
fi
if [[ -f ${out_dir}/arch/arm64/boot/dtb ]]; then
rm -fr ${out_dir}/arch/arm64/boot/dtb
fi
if [[ -f ${out_dir}/arch/arm64/boot/Image.gz ]]; then
rm -fr ${out_dir}/arch/arm64/boot/Image.gz
fi
if [[ -f ${out_dir}/arch/arm64/boot/Image ]]; then
rm -fr ${out_dir}/arch/arm64/boot/Image
fi
if [[ -f ${out_dir}/arch/arm64/boot/dtbo.img ]]; then
rm -fr ${out_dir}/arch/arm64/boot/dtbo.img
fi
KBUILD_COMPILER_STRING=$(${HOME}/clang/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')
KBUILD_LINKER_STRING=$(${HOME}/clang/bin/ld.lld --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//' | sed 's/(compatible with [^)]*)//')
export KBUILD_COMPILER_STRING
export KBUILD_LINKER_STRING
cp -r $HOME/anykernel ./
#
# Enviromental Variables
#
date=$(date +"%Y-%m-%d-%H%M")
device="alioth"
# Set our directory
out_dir=out/
# Select LTO or non LTO builds
if [[ "$@" =~ "lto"* ]]; then
VERSION="IMMENSITY-X-${device^^}-LTO-${date}"
else
VERSION="IMMENSITY-X-${device^^}-${date}"
fi
# Export Zip name
export zipname="${VERSION}.zip"
# How much kebabs we need? Kanged from @raphielscape :)
if [[ -z "${jobs}" ]]; then
count="$(grep -c '^processor' /proc/cpuinfo)"
export jobs="$((count + 2))"
fi
args="ARCH=arm64 \
O=${out_dir} \
LLVM=1 \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_COMPAT=arm-linux-gnueabi- \
-j${jobs}"
dts_source=arch/arm64/boot/dts/vendor/qcom
# Correct panel dimensions on MIUI builds
function miui_fix_dimens() {
sed -i 's/<154>/<1537>/g' ${dts_source}/dsi-panel-j1s*
sed -i 's/<154>/<1537>/g' ${dts_source}/dsi-panel-j2*
sed -i 's/<155>/<1544>/g' ${dts_source}/dsi-panel-j3s-37-02-0a-dsc-video.dtsi
sed -i 's/<155>/<1545>/g' ${dts_source}/dsi-panel-j11-38-08-0a-fhd-cmd.dtsi
sed -i 's/<155>/<1546>/g' ${dts_source}/dsi-panel-k11a-38-08-0a-dsc-cmd.dtsi
sed -i 's/<155>/<1546>/g' ${dts_source}/dsi-panel-l11r-38-08-0a-dsc-cmd.dtsi
sed -i 's/<70>/<695>/g' ${dts_source}/dsi-panel-j11-38-08-0a-fhd-cmd.dtsi
sed -i 's/<70>/<695>/g' ${dts_source}/dsi-panel-j3s-37-02-0a-dsc-video.dtsi
sed -i 's/<70>/<695>/g' ${dts_source}/dsi-panel-k11a-38-08-0a-dsc-cmd.dtsi
sed -i 's/<70>/<695>/g' ${dts_source}/dsi-panel-l11r-38-08-0a-dsc-cmd.dtsi
sed -i 's/<71>/<710>/g' ${dts_source}/dsi-panel-j1s*
sed -i 's/<71>/<710>/g' ${dts_source}/dsi-panel-j2*
}
# Enable back mi smartfps while disabling qsync min refresh-rate
function miui_fix_fps() {
sed -i 's/\/\/ mi,mdss-dsi-pan-enable-smart-fps/mi,mdss-dsi-pan-enable-smart-fps/g' ${dts_source}/dsi-panel*
sed -i 's/\/\/ mi,mdss-dsi-smart-fps-max_framerate/mi,mdss-dsi-smart-fps-max_framerate/g' ${dts_source}/dsi-panel*
sed -i 's/\/\/ qcom,mdss-dsi-pan-enable-smart-fps/qcom,mdss-dsi-pan-enable-smart-fps/g' ${dts_source}/dsi-panel*
sed -i 's/qcom,mdss-dsi-qsync-min-refresh-rate/\/\/qcom,mdss-dsi-qsync-min-refresh-rate/g' ${dts_source}/dsi-panel*
}
# Enable back refresh rates supported on MIUI
function miui_fix_dfps() {
sed -i 's/120 90 60/120 90 60 50 30/g' ${dts_source}/dsi-panel-g7a-36-02-0c-dsc-video.dtsi
sed -i 's/120 90 60/120 90 60 50 30/g' ${dts_source}/dsi-panel-g7a-37-02-0a-dsc-video.dtsi
sed -i 's/120 90 60/120 90 60 50 30/g' ${dts_source}/dsi-panel-g7a-37-02-0b-dsc-video.dtsi
sed -i 's/144 120 90 60/144 120 90 60 50 48 30/g' ${dts_source}/dsi-panel-j3s-37-02-0a-dsc-video.dtsi
}
# Enable back brightness control from dtsi
function miui_fix_fod() {
sed -i 's/\/\/39 00 00 00 00 00 03 51 03 FF/39 00 00 00 00 00 03 51 03 FF/g' ${dts_source}/dsi-panel-j9-38-0a-0a-fhd-video.dtsi
sed -i 's/\/\/39 00 00 00 00 00 03 51 0D FF/39 00 00 00 00 00 03 51 0D FF/g' ${dts_source}/dsi-panel-j2-p2-1-38-0c-0a-dsc-cmd.dtsi
sed -i 's/\/\/39 00 00 00 00 00 05 51 0F 8F 00 00/39 00 00 00 00 00 05 51 0F 8F 00 00/g' ${dts_source}/dsi-panel-j1s-42-02-0a-dsc-cmd.dtsi
sed -i 's/\/\/39 00 00 00 00 00 05 51 0F 8F 00 00/39 00 00 00 00 00 05 51 0F 8F 00 00/g' ${dts_source}/dsi-panel-j1s-42-02-0a-mp-dsc-cmd.dtsi
sed -i 's/\/\/39 00 00 00 00 00 05 51 0F 8F 00 00/39 00 00 00 00 00 05 51 0F 8F 00 00/g' ${dts_source}/dsi-panel-j2-mp-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 00 00 00 00 00 05 51 0F 8F 00 00/39 00 00 00 00 00 05 51 0F 8F 00 00/g' ${dts_source}/dsi-panel-j2-p2-1-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 00 00 00 00 00 05 51 0F 8F 00 00/39 00 00 00 00 00 05 51 0F 8F 00 00/g' ${dts_source}/dsi-panel-j2s-mp-42-02-0a-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 00 00/39 01 00 00 00 00 03 51 00 00/g' ${dts_source}/dsi-panel-j2-38-0c-0a-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 00 00/39 01 00 00 00 00 03 51 00 00/g' ${dts_source}/dsi-panel-j2-38-0c-0a-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 03 FF/39 01 00 00 00 00 03 51 03 FF/g' ${dts_source}/dsi-panel-j11-38-08-0a-fhd-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 03 FF/39 01 00 00 00 00 03 51 03 FF/g' ${dts_source}/dsi-panel-j9-38-0a-0a-fhd-video.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 07 FF/39 01 00 00 00 00 03 51 07 FF/g' ${dts_source}/dsi-panel-j1u-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 07 FF/39 01 00 00 00 00 03 51 07 FF/g' ${dts_source}/dsi-panel-j2-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 07 FF/39 01 00 00 00 00 03 51 07 FF/g' ${dts_source}/dsi-panel-j2-p1-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 0F FF/39 01 00 00 00 00 03 51 0F FF/g' ${dts_source}/dsi-panel-j1u-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 0F FF/39 01 00 00 00 00 03 51 0F FF/g' ${dts_source}/dsi-panel-j2-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 03 51 0F FF/39 01 00 00 00 00 03 51 0F FF/g' ${dts_source}/dsi-panel-j2-p1-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 05 51 07 FF 00 00/39 01 00 00 00 00 05 51 07 FF 00 00/g' ${dts_source}/dsi-panel-j1s-42-02-0a-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 05 51 07 FF 00 00/39 01 00 00 00 00 05 51 07 FF 00 00/g' ${dts_source}/dsi-panel-j1s-42-02-0a-mp-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 05 51 07 FF 00 00/39 01 00 00 00 00 05 51 07 FF 00 00/g' ${dts_source}/dsi-panel-j2-mp-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 05 51 07 FF 00 00/39 01 00 00 00 00 05 51 07 FF 00 00/g' ${dts_source}/dsi-panel-j2-p2-1-42-02-0b-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 00 00 05 51 07 FF 00 00/39 01 00 00 00 00 05 51 07 FF 00 00/g' ${dts_source}/dsi-panel-j2s-mp-42-02-0a-dsc-cmd.dtsi
sed -i 's/\/\/39 01 00 00 01 00 03 51 03 FF/39 01 00 00 01 00 03 51 03 FF/g' ${dts_source}/dsi-panel-j11-38-08-0a-fhd-cmd.dtsi
sed -i 's/\/\/39 01 00 00 11 00 03 51 03 FF/39 01 00 00 11 00 03 51 03 FF/g' ${dts_source}/dsi-panel-j2-p2-1-38-0c-0a-dsc-cmd.dtsi
}
function tg_post_error() {
curl -s -X POST https://api.telegram.org/bot"${bot_api_key}"/sendMessage -d text="Error in ${device}: $1 build!!" -d chat_id="${ci_channel_id}"
curl -F chat_id="${ci_channel_id}" -F document=@"$(pwd)/build.log" https://api.telegram.org/bot"${bot_api_key}"/sendDocument
exit 1
}
function enable_lto() {
scripts/config --file ${out_dir}/.config \
-e LTO_CLANG
# Make olddefconfig
cd ${out_dir} || exit
make -j${jobs} ${args} olddefconfig
cd ../ || exit
}
function disable_lto() {
scripts/config --file ${out_dir}/.config \
-d LTO_CLANG
# Make olddefconfig
cd ${out_dir} || exit
make -j${jobs} ${args} olddefconfig
cd ../ || exit
}
function pack_image_build() {
mkdir -p anykernel/kernels/$1
# Check if the kernel is built
if [[ -f ${out_dir}/System.map ]]; then
if [[ -f ${out_dir}/arch/arm64/boot/Image.gz ]]; then
cp ${out_dir}/arch/arm64/boot/Image.gz anykernel/kernels/$1
elif [[ -f ${out_dir}/arch/arm64/boot/Image ]]; then
cp ${out_dir}/arch/arm64/boot/Image anykernel/kernels/$1
else
tg_post_error $1
fi
else
tg_post_error $1
fi
cp ${out_dir}/arch/arm64/boot/dtb anykernel/kernels/$1
cp ${out_dir}/arch/arm64/boot/dtbo.img anykernel/kernels/$1
}
start=$(date +"%s")
# Set compiler Path
PATH=${HOME}/gas:${HOME}/clang/bin/:$PATH
export LD_LIBRARY_PATH=${HOME}/clang/lib64:$LD_LIBRARY_PATH
# # AOSP Build
# echo "------ Stating AOSP Build ------"
# Make defconfig
# make -j${jobs} ${args} "${device}"_defconfig
# # Enable LTO
# if [[ "$@" =~ "lto"* ]]; then
# enable_lto
# fi
# os=aosp
# make -j${jobs} ${args} 2>&1 | tee build.log
# find ${out_dir}/${dts_source} -name '*.dtb' -exec cat {} + > ${out_dir}/arch/arm64/boot/dtb
# pack_image_build ${os}
# echo "------ Finishing AOSP Build ------"
# MIUI Build
echo "------ Starting MIUI Build ------"
os=miui
# Make defconfig
make -j${jobs} ${args} "${device}"_defconfig
scripts/config --file ${out_dir}/.config \
-d LOCALVERSION_AUTO \
-d TOUCHSCREEN_COMMON \
--set-str STATIC_USERMODEHELPER_PATH /system/bin/micd \
-e BOOT_INFO \
-e BINDER_OPT \
-e IPC_LOGGING \
-e KPERFEVENTS \
-e MIGT \
-e MIGT_ENERGY_MODEL \
-e MIHW \
-e MILLET \
-e MI_DRM_OPT \
-e MIUI_ZRAM_MEMORY_TRACKING \
-e MI_RECLAIM \
-d OSSFOD \
-e PACKAGE_RUNTIME_INFO \
-e PERF_HUMANTASK \
-e PERF_CRITICAL_RT_TASK \
-e SF_BINDER \
-e TASK_DELAY_ACCT
# FIXME: disable LTO on MIUI
if [[ "$@" =~ "lto"* ]]; then
disable_lto
fi
# Make olddefconfig
cd ${out_dir} || exit
make -j${jobs} ${args} CC="ccache clang" HOSTCC="ccache gcc" HOSTCXX="ccache g++" olddefconfig
cd ../ || exit
miui_fix_dimens
miui_fix_fps
miui_fix_dfps
miui_fix_fod
make -j${jobs} ${args} CC="ccache clang" HOSTCC="ccache gcc" HOSTCXX="ccache g++" 2>&1 | tee build.log
find ${out_dir}/${dts_source} -name '*.dtb' -exec cat {} + >${out_dir}/arch/arm64/boot/dtb
pack_image_build ${os}
git checkout arch/arm64/boot/dts/vendor &>/dev/null
echo "------ Finishing MIUI Build ------"
# # AOSPA Build
# echo "------ Starting AOSPA Build ------"
# os=aospa
# # Make defconfig
# make -j${jobs} ${args} "${device}"_defconfig
# scripts/config --file ${out_dir}/.config \
# -d SDCARD_FS \
# -e UNICODE
# # Enable LTO
# if [[ "$@" =~ "lto"* ]]; then
# enable_lto
# fi
# # Make olddefconfig
# cd ${out_dir} || exit
# make -j${jobs} ${args} olddefconfig
# cd ../ || exit
# make -j${jobs} ${args} 2>&1 | tee build.log
# find ${out_dir}/${dts_source} -name '*.dtb' -exec cat {} + > ${out_dir}/arch/arm64/boot/dtb
# pack_image_build ${os}
# echo "------ Finishing AOSPA Build ------"
end=$(date +"%s")
diff=$((end - start))
cd anykernel || exit
zip -r9 "${zipname}" ./* -x .git .gitignore ./*.zip
# FILE=$(gdrive upload --share $zipname)
# file_id=$(echo $FILE | awk '{print $7}')
# echo "File upload to gdrive"
# echo ${file_id}
checker=$(find ./ -maxdepth 1 -type f -name ${zipname} -printf "%s\n")
if (($((checker / 1048576)) > 5)); then
curl -s -X POST https://api.telegram.org/bot"${bot_api_key}"/sendMessage -d text="✅ Kernel compiled successfully in $((diff / 60)) minute(s) and $((diff % 60)) seconds for ${device}" -d chat_id="${ci_channel_id}" -d parse_mode=HTML
# curl -s -X POST https://api.telegram.org/bot"${bot_api_key}"/sendMessage -d text="Kernel build link: ${file_id}" -d chat_id="${ci_channel_id}" -d parse_mode=HTML
curl -F chat_id="${ci_channel_id}" -F document=@"$(pwd)/${zipname}" https://api.telegram.org/bot"${bot_api_key}"/sendDocument
else
tg_post_error
fi
cd $(pwd) || exit
echo ""
echo -e ${zipname} " is ready!"
echo ""