forked from chips-project/msm-4.14
-
Notifications
You must be signed in to change notification settings - Fork 9
/
kernel.sh
executable file
·296 lines (239 loc) · 7.89 KB
/
kernel.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
#! /bin/bash
# Script For Building Android arm64 Kernel
#
# Copyright (c) 2018-2020 Panchajanya1999 <[email protected]>
#
# 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.
#
#Kernel building script
# Function to show an informational message
msg() {
echo -e "\e[1;32m$*\e[0m"
}
err() {
echo -e "\e[1;41m$*\e[0m"
exit 1
}
##------------------------------------------------------##
##----------Basic Informations, COMPULSORY--------------##
# The defult directory where the kernel should be placed
KERNEL_DIR=/home/sleepy/Documents/msm-4.14
# The name of the Kernel, to name the ZIP
ZIPNAME="Team-420"
# The name of the device for which the kernel is built
MODEL="Redmi Note 8"
# The codename of the device
DEVICE="Ginkgo"
# The defconfig which should be used. Get it from config.gz from
# your device or check source
DEFCONFIG=vendor/nethunter_defconfig
# Specify compiler.
# 'clang' or 'gcc'
COMPILER=clang
# Clean source prior building. 1 is NO(default) | 0 is YES
INCREMENTAL=1
# Generate a full DEFCONFIG prior building. 1 is YES | 0 is NO(default)
DEF_REG=0
# Build dtbo.img (select this only if your source has support to building dtbo.img)
# 1 is YES | 0 is NO(default)
BUILD_DTBO=0
# Sign the zipfile
# 1 is YES | 0 is NO
SIGN=0
# Silence the compilation
# 1 is YES(default) | 0 is NO
SILENCE=0
# Debug purpose. Send logs on every successfull builds
# 1 is YES | 0 is NO(default)
LOG_DEBUG=0
##------------------------------------------------------##
##---------Do Not Touch Anything Beyond This------------##
# Check if we are using a dedicated CI ( Continuous Integration ), and
# set KBUILD_BUILD_VERSION and KBUILD_BUILD_HOST and CI_BRANCH
## Set defaults first
DISTRO=$(cat /etc/*-release | head -n 1 | cut -b 7- | sed s/.$//)
KBUILD_BUILD_HOST=$(uname -a | awk '{print $2}')
CI_BRANCH=$(git rev-parse --abbrev-ref HEAD)
export KBUILD_BUILD_HOST CI_BRANCH
## Check for CI
if [ -n "$CI" ]
then
if [ -n "$CIRCLECI" ]
then
export KBUILD_BUILD_VERSION=$CIRCLE_BUILD_NUM
export KBUILD_BUILD_HOST="Kali"
export CI_BRANCH=$CIRCLE_BRANCH
fi
if [ -n "$DRONE" ]
then
export KBUILD_BUILD_VERSION=$DRONE_BUILD_NUMBER
export KBUILD_BUILD_HOST=$DRONE_SYSTEM_HOST
export CI_BRANCH=$DRONE_BRANCH
else
echo "Not presetting Build Version"
fi
fi
#Check Kernel Version
KERVER=$(make kernelversion)
# Set a commit head
COMMIT_HEAD=$(git log --oneline -1)
# Set Date
DATE=$(TZ=Asia/Kolkata date +"%Y%m%d-%T")
#Now Its time for other stuffs like cloning, exporting, etc
clone() {
echo " "
if [ $COMPILER = "clang" ]
then
msg "|| Cloning Clang-11 ||"
git clone --depth=1 https://github.com/Panchajanya1999/azure-clang.git clang-llvm
# Toolchain Directory defaults to clang-llvm
TC_DIR=$KERNEL_DIR/clang-llvm
elif [ $COMPILER = "gcc" ]
then
msg "|| Cloning GCC 9.3.0 baremetal ||"
git clone --depth=1 https://github.com/arter97/arm64-gcc.git gcc64
git clone --depth=1 https://github.com/arter97/arm32-gcc.git gcc32
GCC64_DIR=$KERNEL_DIR/gcc64
GCC32_DIR=$KERNEL_DIR/gcc32
fi
msg "|| Cloning libufdt ||"
git clone https://android.googlesource.com/platform/system/libufdt "$KERNEL_DIR"/scripts/ufdt/libufdt
}
##------------------------------------------------------##
exports() {
export KBUILD_BUILD_USER="S133PY"
export ARCH=arm64
export SUBARCH=arm64
if [ $COMPILER = "clang" ]
then
KBUILD_COMPILER_STRING=$("$TC_DIR"/bin/clang --version | head -n 1 | perl -pe 's/\(http.*?\)//gs' | sed -e 's/ */ /g' -e 's/[[:space:]]*$//')
PATH=$TC_DIR/bin/:$PATH
elif [ $COMPILER = "gcc" ]
then
KBUILD_COMPILER_STRING=$("$GCC64_DIR"/bin/aarch64-elf-gcc --version | head -n 1)
PATH=$GCC64_DIR/bin/:$GCC32_DIR/bin/:/usr/bin:$PATH
fi
export PATH KBUILD_COMPILER_STRING
export BOT_MSG_URL="https://api.telegram.org/bot$token/sendMessage"
export BOT_BUILD_URL="https://api.telegram.org/bot$token/sendDocument"
PROCS=$(nproc --all)
export PROCS
}
##----------------------------------------------------------##
build_kernel() {
if [ $INCREMENTAL = 0 ]
then
msg "|| Cleaning Sources ||"
make clean && make mrproper && rm -rf out
fi
if [ "$PTTG" = 1 ]
then
tg_post_msg "<b>$KBUILD_BUILD_VERSION CI Build Triggered</b>%0A<b>Docker OS: </b><code>$DISTRO</code>%0A<b>Kernel Version : </b><code>$KERVER</code>%0A<b>Date : </b><code>$(TZ=Asia/Kolkata date)</code>%0A<b>Device : </b><code>$MODEL [$DEVICE]</code>%0A<b>Pipeline Host : </b><code>$KBUILD_BUILD_HOST</code>%0A<b>Host Core Count : </b><code>$PROCS</code>%0A<b>Compiler Used : </b><code>$KBUILD_COMPILER_STRING</code>%0a<b>Branch : </b><code>$CI_BRANCH</code>%0A<b>Top Commit : </b><code>$COMMIT_HEAD</code>%0A<b>Status : </b>#Nightly" "$CHATID"
fi
make O=out $DEFCONFIG
if [ $DEF_REG = 1 ]
then
cp .config arch/arm64/configs/$DEFCONFIG
git add arch/arm64/configs/$DEFCONFIG
git commit -m "$DEFCONFIG: Regenerate
This is an auto-generated commit"
fi
BUILD_START=$(date +"%s")
if [ $COMPILER = "clang" ]
then
MAKE+=(
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi- \
CC=clang \
AR=llvm-ar \
OBJDUMP=llvm-objdump \
STRIP=llvm-strip
)
elif [ $COMPILER = "gcc" ]
then
MAKE+=(
CROSS_COMPILE_ARM32=arm-eabi- \
CROSS_COMPILE=aarch64-elf- \
AR=aarch64-elf-ar \
OBJDUMP=aarch64-elf-objdump \
STRIP=aarch64-elf-strip
)
fi
if [ $SILENCE = "1" ]
then
MAKE+=( -s )
fi
msg "|| Started Compilation ||"
make -j"$PROCS" O=out \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
LD=ld.lld "${MAKE[@]}" 2>&1 | tee error.log
BUILD_END=$(date +"%s")
DIFF=$((BUILD_END - BUILD_START))
if [ -f "$KERNEL_DIR"/out/arch/arm64/boot/Image.gz-dtb ]
then
msg "|| Kernel successfully compiled ||"
if [ $BUILD_DTBO = 1 ]
then
msg "|| Building DTBO ||"
tg_post_msg "<code>Building DTBO..</code>" "$CHATID"
python2 "$KERNEL_DIR/scripts/ufdt/libufdt/utils/src/mkdtboimg.py" \
create "$KERNEL_DIR/out/arch/arm64/boot/dtbo.img" --page_size=4096 "$KERNEL_DIR/out/arch/arm64/boot/dts/qcom/sm6150-idp-overlay.dtbo"
fi
gen_zip
else
if [ "$PTTG" = 1 ]
then
tg_post_build "error.log" "$CHATID" "<b>Build failed to compile after $((DIFF / 60)) minute(s) and $((DIFF % 60)) seconds</b>"
fi
fi
}
##--------------------------------------------------------------##
gen_zip() {
msg "|| Zipping into a flashable zip ||"
mv "$KERNEL_DIR"/out/arch/arm64/boot/Image.gz-dtb AnyKernel/Image.gz-dtb
if [ $BUILD_DTBO = 1 ]
then
mv "$KERNEL_DIR"/out/arch/arm64/boot/dtbo.img AnyKernel/dtbo.img
fi
cd AnyKernel || exit
find ${KERNEL_DIR}/out -name "*.ko" -exec cp {} modules/vendor/lib/modules \;
zip -r9 $ZIPNAME-$DEVICE-"$DATE" * -x .git README.md
## Prepare a final zip variable
ZIP_FINAL="$ZIPNAME-$DEVICE-$DATE.zip"
if [ $SIGN = 1 ]
then
## Sign the zip before sending it to telegram
if [ "$PTTG" = 1 ]
then
msg "|| Signing Zip ||"
tg_post_msg "<code>Signing Zip file with AOSP keys..</code>" "$CHATID"
fi
curl -sLo zipsigner-3.0.jar https://raw.githubusercontent.com/baalajimaestro/AnyKernel/master/zipsigner-3.0.jar
java -jar zipsigner-3.0.jar $ZIPNAME-$DEVICE-"$DATE".zip "$ZIP_FINAL"-signed.zip
ZIP_FINAL="$ZIP_FINAL-signed.zip"
fi
if [ "$PTTG" = 1 ]
then
tg_post_build "$ZIP_FINAL" "$CHATID" "Build took : $((DIFF / 60)) minute(s) and $((DIFF % 60)) second(s)"
fi
cd ..
}
clone
exports
build_kernel
if [ $LOG_DEBUG = "1" ]
then
tg_post_build "error.log" "$CHATID" "Debug Mode Logs"
fi
##----------------*****-----------------------------##