-
Notifications
You must be signed in to change notification settings - Fork 3
/
kramel.sh
248 lines (229 loc) · 6.55 KB
/
kramel.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
#!/usr/bin/env bash
# Copyright (c) 2021-2023, Tashfin Shakeer Rhythm <[email protected]>.
# Version: 10.1
# Revision: 29-06-2023
# shellcheck disable=SC1091
## Global variables
# Colors
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
CYAN="\033[0;36m"
# User details
USER='Tashar'
HOST='Endeavour'
TOKEN='ADD YOUR TOKEN HERE'
CHATID='ADD YOUR CHATID HERE'
BOT_MSG_URL="https://api.telegram.org/bot${TOKEN}/sendMessage"
BOT_BUILD_URL="https://api.telegram.org/bot${TOKEN}/sendDocument"
DEVICE='Mi A2 / 6X'
CODENAME='wayne'
CODENAME2='jasmine'
PROCS="$(nproc --all)"
# Paths
KERNEL_DIR="$(pwd)"
TOOLCHAIN="${KERNEL_DIR}/../toolchains"
GZIP_DIR="${TOOLCHAIN}/neutron-gzip"
COREUTILS_DIR="${TOOLCHAIN}/neutron-coreutils"
ZIP_DIR="${KERNEL_DIR}/../4.19-ak3"
## Go to kernel directory
cd "${KERNEL_DIR}" || exit 1
## Functions
# A function to showcase the help section of the script
help() {
echo -e "${CYAN}
Usage ./kramel.sh [ARG]
Arguments:
--clang sets clang as the compiler
--gcc sets gcc as the compiler
--newcam sets newcam as the camera library
--oldcam sets oldcam as the camera library
--osscam sets osscam as the camera library
--qpnp sets qpnp as the haptics driver
--qti sets qti as the haptics driver
--dynamic sets retrofit dynamic partition
--non-dynamic sets regular partition type
--thin-lto enables thin LTO
--full-lto enables full LTO
--non-lto disables LTO
--help shows this menu
"
}
# A function to send message(s) via Telegram's BOT api
tg_post_msg() {
curl -s -X POST "${BOT_MSG_URL}" \
-d chat_id="${CHATID}" \
-d "disable_web_page_preview=true" \
-d "parse_mode=html" \
-d text="$1"
}
# A function to send file(s) via Telegram's BOT api
tg_post_build() {
#Post MD5Checksum alongwith for easeness
MD5CHECK=$(md5sum "$1" | cut -d' ' -f1)
#Show the Checksum alongwith caption
curl --progress-bar -F document=@"$1" "${BOT_BUILD_URL}" \
-F chat_id="${CHATID}" \
-F "disable_web_page_preview=true" \
-F "parse_mode=html" \
-F caption="$2 | <b>MD5 Checksum : </b><code>${MD5CHECK}</code>"
}
set_config() {
./scripts/config --file "${KERNEL_DIR}/arch/arm64/configs/${DFCF}" -e "$1"
}
unset_config() {
./scripts/config --file "${KERNEL_DIR}/arch/arm64/configs/${DFCF}" -d "$1"
}
## Argument list
for args in "${@}"; do
case "${args}" in
"--clang")
C_PATH="${TOOLCHAIN}/Neutron-Clang-BOLT"
KBUILD_COMPILER_STRING="$("${C_PATH}"/bin/clang -v 2>&1 | head -n 1 | sed 's/(https..*//' | sed 's/ version//')"
MAKE+=(
O=work
CC='ccache clang'
LLVM=1
LLVM_IAS=1
CROSS_COMPILE=aarch64-linux-gnu-
CROSS_COMPILE_COMPAT=arm-linux-gnueabi-
)
;;
"--gcc")
C_PATH="${TOOLCHAIN}/gcc64/bin:${TOOLCHAIN}/gcc32"
KBUILD_COMPILER_STRING="$("${TOOLCHAIN}"/gcc64/bin/aarch64-elf-gcc --version | head -n 1)"
MAKE+=(
O=work
CC=aarch64-elf-gcc
LD="${TOOLCHAIN}/gcc64/bin/aarch64-elf-ld.lld"
LD_LIBRARY_PATH="${C_PATH}"/lib:"${LD_LIBRARY_PART}"
AR=llvm-ar
NM=llvm-nm
OBJCOPY=llvm-objcopy
OBJDUMP=llvm-objdump
OBJCOPY=llvm-objcopy
OBJSIZE=llvm-size
STRIP=llvm-strip
CROSS_COMPILE=aarch64-elf-
CROSS_COMPILE_COMPAT=arm-eabi-
CC_COMPAT=arm-eabi-gcc
)
;;
"--newcam")
DFCF="vendor/${CODENAME}-perf_defconfig"
CAM='NEWCAM'
;;
"--oldcam")
DFCF="vendor/${CODENAME}-old-perf_defconfig"
CAM='OLDCAM'
;;
"--osscam")
DFCF="vendor/${CODENAME}-oss-perf_defconfig"
CAM='OSSCAM'
;;
"--qpnp")
HAPTIC='QPNP'
;;
"--qti")
HAPTIC='QTI'
;;
"--dynamic")
PARTITION='DYNAMIC'
;;
"--non-dynamic")
PARTITION='NON-DYNAMIC'
;;
"--thin-lto")
LTO_VARIANT='THIN_LTO'
set_config 'CONFIG_LTO_CLANG_THIN'
;&
"--full-lto")
LTO_VARIANT='FULL_LTO'
unset_config 'CONFIG_LTO_NONE'
set_config 'CONFIG_LTO_CLANG_FULL'
;;
"--non-lto")
LTO_VARIANT='NON_LTO'
unset_config 'CONFIG_LTO_CLANG_THIN'
unset_config 'CONFIG_LTO_CLANG_FULL'
set_config 'CONFIG_LTO_NONE'
;;
"--help")
help
exit 0
;;
*)
echo -e "${YELLOW}Invaild argument(s) '${*}'. Run './kramel.sh --help'"
sleep 1
exit 1
;;
esac
done
## Export environment variables
export KBUILD_BUILD_USER="${USER}"
export KBUILD_BUILD_HOST="${HOST}"
export PATH="${COREUTILS_DIR}/bin:${GZIP_DIR}/bin:${C_PATH}/bin:${PATH}"
export ARCH='arm64'
export PYTHON='python3'
## Start compilation
rm -rf "${KERNEL_DIR}/work" "${KERNEL_DIR}/log.txt"
if [[ ! -d "${KERNEL_DIR}/out" ]]; then
mkdir "${KERNEL_DIR}/out"
fi
BUILD_START="$(date +"%s")"
make -j"${PROCS}" "${DFCF}" "${MAKE[@]}"
echo -e "\n${CYAN} Build started..."
echo -e "${GREEN}"
time make -j"${PROCS}" "${MAKE[@]}" 2>&1 | tee log.txt
git restore "${KERNEL_DIR}/arch/arm64/configs/${DFCF}"
echo -e "\n${CYAN} Build finished. Zipping...\n"
BUILD_END="$(date +"%s")"
DIFF="$((BUILD_END - BUILD_START))"
## Start zipping and posting
if [[ -f "${KERNEL_DIR}/work/arch/arm64/boot/Image.gz-dtb" ]]; then
tg_post_build "log.txt" "Compiled kernel successfully!!"
source "${KERNEL_DIR}/work/.config"
KNAME="$(echo "${CONFIG_LOCALVERSION}" | cut -c 2-)"
KV="$(cat <"${KERNEL_DIR}/work/include/generated/utsrelease.h" | cut -c 21- | tr -d '"')"
DATE="$(date +"%Y-%m-%d %H:%M")"
COMMIT_NAME="$(git show -s --format=%s)"
COMMIT_HASH="$(git rev-parse --short HEAD)"
if [[ $PARTITION == NON-DYNAMIC ]]; then
ZIP_NAME="${KNAME}-${CAM}-${HAPTIC}-${CODENAME2^^}-${CODENAME^^}-$(date +"%H%M")"
else
ZIP_NAME="${KNAME}-${CAM}-${HAPTIC}-${PARTITION}-${CODENAME2^^}-${CODENAME^^}-$(date +"%H%M")"
fi
FINAL_ZIP="${ZIP_NAME}-signed.zip"
cp "${KERNEL_DIR}/work/arch/arm64/boot/Image.gz-dtb" "${ZIP_DIR}"
cd "${ZIP_DIR}" || exit 1
zip -r9 "${ZIP_NAME}.zip" ./* -x README.md LICENSE FUNDING.yml zipsigner*
java -jar zipsigner* "${ZIP_NAME}.zip" "${FINAL_ZIP}"
echo -e "\n${CYAN} Pushing kernel zip...\n"
if [[ $PARTITION == NON-DYNAMIC ]]; then
tg_post_build "${FINAL_ZIP}" "${CAM}+${HAPTIC}"
else
tg_post_build "${FINAL_ZIP}" "${CAM}+${HAPTIC}+${PARTITION}"
fi
cp "${FINAL_ZIP}" "${KERNEL_DIR}/out"
rm -rf ./*.zip Image.gz-dtb
cd "${KERNEL_DIR}" || exit 1
# Print the build information
tg_post_msg "
=========Scarlet-X Kernel=========
Compiler: <code>${KBUILD_COMPILER_STRING}</code>
Linux Version: <code>${KV}</code>
Maintainer: <code>${USER}</code>
Device: <code>${DEVICE}</code>
Codename: <code>${CODENAME}</code>
Zipname: <code>${FINAL_ZIP}</code>
LTO Variant: <code>${LTO_VARIANT}</code>
Build Date: <code>${DATE}</code>
Build Duration: <code>$((DIFF / 60)).$((DIFF % 60)) mins</code>
Last Commit Name: <code>${COMMIT_NAME}</code>
Last Commit Hash: <code>${COMMIT_HASH}</code>
"
else
tg_post_build "log.txt" "Build failed!!"
echo -e "\n${RED} Kernel image not found"
exit 1
fi