forked from HuTao77-Studio/android_kernel_xiaomi_elish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
311 lines (231 loc) · 11.9 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
#!/bin/bash
# Some logics of this script are copied from [scripts/build_kernel]. Thanks to UtsavBalar1231.
# Ensure the script exits on error
set -e
# 到home目录下载clang
# git clone https://github.com/LineageOS/android_prebuilts_clang_kernel_linux-x86_clang-r416183b --depth=1
# git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9 -b android-10.0.0_r47 --depth=1
# git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9 -b android-10.0.0_r47 --depth=1
# git clone https://github.com/radcolor/arm-linux-gnueabi --depth=1
# 参考内核编译教程 小米8 编译 MIUI 和LineageOs 教程 https://lyxot.github.io/blog/2023/08/09/%E7%BB%99%E5%B0%8F%E7%B1%B38SE(Sirius)%E7%BC%96%E8%AF%91%E5%86%85%E6%A0%B8/
TOOLCHAIN_PATH=$HOME/android_prebuilts_clang_kernel_linux-x86_clang-r416183b/bin
GIT_COMMIT_ID=$(git rev-parse --short=8 HEAD)
TARGET_DEVICE=$1
if [ -z "$1" ]; then
echo "Error: No argument provided, please specific a target device."
echo "If you need KernelSU, please add [ksu] as the second arg."
echo "Examples:"
echo "Build for lmi(K30 Pro/POCO F2 Pro) without KernelSU:"
echo " bash build.sh lmi"
echo "Build for umi(Mi10) with KernelSU:"
echo " bash build.sh umi ksu"
exit 1
fi
if [ ! -d $TOOLCHAIN_PATH ]; then
echo "TOOLCHAIN_PATH [$TOOLCHAIN_PATH] does not exist."
echo "Please ensure the toolchain is there, or change TOOLCHAIN_PATH in the script to your toolchain path."
exit 1
fi
echo "TOOLCHAIN_PATH: [$TOOLCHAIN_PATH]"
TOOLCHAIN_PATH=$TOOLCHAIN_PATH:$HOME/aarch64-linux-android-4.9/bin:$HOME/arm-linux-androideabi-4.9/bin:$HOME/aarch64-linux-gnu/bin:$HOME/arm-linux-gnueabi/bin
export PATH="$TOOLCHAIN_PATH:$PATH"
if ! command -v aarch64-linux-gnu-ld >/dev/null 2>&1; then
echo "[aarch64-linux-gnu-ld] does not exist, please check your environment."
exit 1
fi
if ! command -v arm-linux-gnueabi-ld >/dev/null 2>&1; then
echo "[arm-linux-gnueabi-ld] does not exist, please check your environment."
exit 1
fi
if ! command -v clang >/dev/null 2>&1; then
echo "[clang] does not exist, please check your environment."
exit 1
fi
# Enable ccache for speed up compiling
export CCACHE_DIR="$HOME/.cache/ccache_mikernel"
export CC="ccache gcc"
export CXX="ccache g++"
export PATH="/usr/lib/ccache:$PATH"
echo "CCACHE_DIR: [$CCACHE_DIR]"
# CROSS_COMPILE_ARM32=arm-linux-gnueabi-
MAKE_ARGS="ARCH=arm64 SUBARCH=arm64 O=out CC=clang CROSS_COMPILE=aarch64-linux-gnu- CROSS_COMPILE_ARM32=arm-linux-gnueabi- CROSS_COMPILE_COMPAT=arm-linux-gnueabi- CLANG_TRIPLE=aarch64-linux-gnu- "
if [ "$1" == "j1" ]; then
make $MAKE_ARGS -j1
exit
fi
if [ "$1" == "continue" ]; then
make $MAKE_ARGS -j$(nproc)
exit
fi
if [ ! -f "arch/arm64/configs/${TARGET_DEVICE}_defconfig" ]; then
echo "No target device [${TARGET_DEVICE}] found."
echo "Avaliable defconfigs, please choose one target from below down:"
ls arch/arm64/configs/*_defconfig
exit 1
fi
# Check clang is existing.
echo "[clang --version]:"
clang --version
KSU_ZIP_STR=NoKernelSU
if [ "$2" == "ksu" ]; then
KSU_ENABLE=1
KSU_ZIP_STR=KernelSU
else
KSU_ENABLE=0
fi
echo "TARGET_DEVICE: $TARGET_DEVICE"
if [ $KSU_ENABLE -eq 1 ]; then
echo "KSU is enabled"
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s v0.9.5
else
echo "KSU is disabled"
fi
echo "Cleaning..."
rm -rf out/
if [ ! -d "anykernel/" ];then
echo "Clone AnyKernel3 for packing kernel (repo: https://github.com/liyafe1997/AnyKernel3)"
git clone https://github.com/liyafe1997/AnyKernel3 -b kona --single-branch --depth=1 anykernel
else
echo "文件夹已经存在"
# rm -rf anykernel/ 存在了就不要去删除了
fi
# ------------- Building for AOSP -------------
echo "Building for AOSP......"
make $MAKE_ARGS ${TARGET_DEVICE}_defconfig
exit 1
if [ $KSU_ENABLE -eq 1 ]; then
scripts/config --file out/.config -e KSU
else
scripts/config --file out/.config -d KSU
fi
make $MAKE_ARGS -j$(nproc)
if [ -f "out/arch/arm64/boot/Image" ]; then
echo "The file [out/arch/arm64/boot/Image] exists. AOSP Build successfully."
else
echo "The file [out/arch/arm64/boot/Image] does not exist. Seems AOSP build failed."
exit 1
fi
echo "Generating [out/arch/arm64/boot/dtb]......"
find out/arch/arm64/boot/dts -name '*.dtb' -exec cat {} + >out/arch/arm64/boot/dtb
rm -rf anykernel/kernels/
mkdir -p anykernel/kernels/
cp out/arch/arm64/boot/Image anykernel/kernels/
cp out/arch/arm64/boot/dtb anykernel/kernels/
cd anykernel
ZIP_FILENAME=Kernel_AOSP_${TARGET_DEVICE}_${KSU_ZIP_STR}_$(date +'%Y%m%d_%H%M%S')_anykernel3_${GIT_COMMIT_ID}.zip
zip -r9 $ZIP_FILENAME ./* -x .git .gitignore out/ ./*.zip
mv $ZIP_FILENAME ../
cd ..
echo "Build for AOSP finished."
###
# ------------- End of Building for AOSP -------------
# If you don't need AOSP you can comment out the above block [Building for AOSP]
# ------------- Building for MIUI -------------
echo "Clearning [out/] and build for MIUI....."
rm -rf out/
dts_source=arch/arm64/boot/dts/vendor/qcom
# Backup dts
cp -a ${dts_source} .dts.bak
# Correct panel dimensions on MIUI builds
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
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
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
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
make $MAKE_ARGS ${TARGET_DEVICE}_defconfig
if [ $KSU_ENABLE -eq 1 ]; then
scripts/config --file out/.config -e KSU
else
scripts/config --file out/.config -d KSU
fi
scripts/config --file out/.config \
--set-str STATIC_USERMODEHELPER_PATH /system/bin/micd \
-e PERF_CRITICAL_RT_TASK \
-e SF_BINDER \
-e OVERLAY_FS \
-d DEBUG_FS \
-e MIGT \
-e MIGT_ENERGY_MODEL \
-e MIHW \
-e PACKAGE_RUNTIME_INFO \
-e BINDER_OPT \
-e KPERFEVENTS \
-e MILLET \
-e PERF_HUMANTASK \
-d LTO_CLANG \
-d LOCALVERSION_AUTO \
-e SF_BINDER \
-e XIAOMI_MIUI \
-d MI_MEMORY_SYSFS \
-e TASK_DELAY_ACCT \
-e MIUI_ZRAM_MEMORY_TRACKING \
-d CONFIG_MODULE_SIG_SHA512 \
-d CONFIG_MODULE_SIG_HASH \
-e MI_FRAGMENTION \
make $MAKE_ARGS -j$(nproc)
if [ -f "out/arch/arm64/boot/Image" ]; then
echo "The file [out/arch/arm64/boot/Image] exists. MIUI Build successfully."
else
echo "The file [out/arch/arm64/boot/Image] does not exist. Seems MIUI build failed."
exit 1
fi
echo "Generating [out/arch/arm64/boot/dtb]......"
find out/arch/arm64/boot/dts -name '*.dtb' -exec cat {} + >out/arch/arm64/boot/dtb
# Restore modified dts
rm -rf ${dts_source}
mv .dts.bak ${dts_source}
rm -rf anykernel/kernels/
mkdir -p anykernel/kernels/
cp out/arch/arm64/boot/Image anykernel/kernels/
cp out/arch/arm64/boot/dtb anykernel/kernels/
echo "Build for MIUI finished."
# ------------- End of Building for MIUI -------------
# If you don't need MIUI you can comment out the above block [Building for MIUI]
cd anykernel
ZIP_FILENAME=Kernel_MIUI_${TARGET_DEVICE}_${KSU_ZIP_STR}_$(date +'%Y%m%d_%H%M%S')_anykernel3_${GIT_COMMIT_ID}.zip
zip -r9 $ZIP_FILENAME ./* -x .git .gitignore out/ ./*.zip
mv $ZIP_FILENAME ../
cd ..
echo "Done. The flashable zip is: [./$ZIP_FILENAME]"