forked from xxmustafacooTR/exynos-linux-stable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.sh
executable file
·285 lines (231 loc) · 11.4 KB
/
variables.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
#!/bin/bash
####################
# Global variables #
####################
# Directories
CUR_DIR=$PWD
ANDROID_DIR="$CUR_DIR/android"
BOOT_DIR="$ANDROID_DIR/boot"
BUILD_DIR="$ANDROID_DIR/build"
MOD_DIR="$ANDROID_DIR/modules"
ZIP_DIR="$ANDROID_DIR/zip"
OUT_DIR="$ANDROID_DIR/out"
KERNEL_NAME="Kernel"
DTB_NAME="Dtb"
ZIP_NAME='REDxxTR'
# Set Kali Nethunter features off by default
NETHUNTER=false
#########################
# Environment variables #
#########################
# PATH and toolchain variables
export PATH=$CUR_DIR/toolchain/clang/bin:$CUR_DIR/toolchain/clang/lib:$ANDROID_DIR/tools/AIK/bin:${PATH}
export CLANG_TRIPLE=$CUR_DIR/toolchain/clang/bin/aarch64-linux-gnu-
export CROSS_COMPILE=$CUR_DIR/toolchain/clang/bin/aarch64-linux-gnu-
export CROSS_COMPILE_ARM32=$CUR_DIR/toolchain/clang/bin/arm-linux-gnueabi-
export CC=$CUR_DIR/toolchain/clang/bin/clang
export REAL_CC=$CUR_DIR/toolchain/clang/bin/clang
export LD=$CUR_DIR/toolchain/clang/bin/ld.lld
export AR=$CUR_DIR/toolchain/clang/bin/llvm-ar
export NM=$CUR_DIR/toolchain/clang/bin/llvm-nm
export OBJCOPY=$CUR_DIR/toolchain/clang/bin/llvm-objcopy
export OBJDUMP=$CUR_DIR/toolchain/clang/bin/llvm-objdump
export READELF=$CUR_DIR/toolchain/clang/bin/llvm-readelf
export STRIP=$CUR_DIR/toolchain/clang/bin/llvm-strip
export LLVM=1 && export LLVM_IAS=1
export KALLSYMS_EXTRA_PASS=1
export ARCH=arm64 && export SUBARCH=arm64
###########################################################
# Functions (called by buildN9.sh/buildS9.sh/buildS9+.sh) #
###########################################################
# Help screen
show_help() {
echo
echo "Build script for exynos-linux-stable (N9/S9/S9+)"
echo
echo "Options:"
echo
echo " -h Show this screen."
echo
echo " -k <option> Kernel type. Available options:"
echo " aosp Builds AOSP kernel."
echo " stock Builds stock kernel."
echo
echo " -d <option> DTB (device tree blob) filesystem. Available options:"
echo " erofs Uses the EROFS filesystem."
echo " ext4 Uses the Ext4 filesystem."
echo
echo " -r <option> Root method. Available options:"
echo " kernelsu Enables KernelSU support."
echo " magisk Disables KernelSU support."
echo
echo " -n Enable Kali Nethunter support."
echo
}
# Toolchain setup
tc_setup() {
if [ ! -d $CUR_DIR/toolchain/clang ]; then
mkdir -p mkdir $CUR_DIR/toolchain/clang
fi
if [ ! -f $CUR_DIR/toolchain/clang/bin/clang ]; then
printf "Fetching clang...\n"
curl https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/main/clang-r547379.tar.gz --output $CUR_DIR/toolchain/clang/clang.tar.gz
cd $CUR_DIR/toolchain/clang && tar xzvf clang.tar.gz && rm clang.tar.gz && cd $CUR_DIR
fi
if [ ! -d $CUR_DIR/toolchain/clang/aarch64-linux-gnu ]; then
printf "Copying binutils...\n"
cp -r $CUR_DIR/toolchain/binutils/* $CUR_DIR/toolchain/clang
fi
if [ -f $CUR_DIR/toolchain/clang/bin/clang ] && [ -d $CUR_DIR/toolchain/clang/aarch64-linux-gnu ]; then
printf "Toolchain is ready at: $CUR_DIR/toolchain/clang\n"
printf "Clang version: 19.0.1\n"
printf "Binutils version: 2.43\n"
else
printf "ERROR: Toolchain: Something went wrong.\n"
exit 1
fi
}
# Enable Ext4 for device tree blob
dts_ext4() {
printf "Config: Enabling Ext4 DTB\n"
sed -i 's|erofs|ext4|g' "$CUR_DIR"/arch/arm64/boot/dts/exynos/exynos9810-starlte_common.dtsi
sed -i 's|erofs|ext4|g' "$CUR_DIR"/arch/arm64/boot/dts/exynos/exynos9810-star2lte_common.dtsi
sed -i 's|erofs|ext4|g' "$CUR_DIR"/arch/arm64/boot/dts/exynos/exynos9810-crownlte_common.dtsi
DTB_NAME="Dtb"
}
# Enable EROFS for device tree blob
dts_erofs() {
printf "Config: Enabling EROFS DTB\n"
sed -i 's|ext4|erofs|g' "$CUR_DIR"/arch/arm64/boot/dts/exynos/exynos9810-starlte_common.dtsi
sed -i 's|ext4|erofs|g' "$CUR_DIR"/arch/arm64/boot/dts/exynos/exynos9810-star2lte_common.dtsi
sed -i 's|ext4|erofs|g' "$CUR_DIR"/arch/arm64/boot/dts/exynos/exynos9810-crownlte_common.dtsi
DTB_NAME="Dtb-erofs"
}
# Enable KernelSU configurations
enable_kernelsu() {
printf "Config: Enabling KernelSU\n"
KSU_KCONFIG="$CUR_DIR/drivers/Kconfig"
KSU_MAKEFILE="$CUR_DIR/drivers/Makefile"
if grep -q kernelsu "$KSU_KCONFIG"; then
printf " KernelSU: drivers/Kconfig: No action needed\n"
else
sed -i 's|endmenu|source "drivers/kernelsu/Kconfig"\n\nendmenu\n|g' "$CUR_DIR"/drivers/Kconfig
fi
if grep -q kernelsu "$KSU_MAKEFILE"; then
printf " KernelSU: drivers/Makefile: No action needed\n"
else
sed -i 's|#TZIC|obj-$(CONFIG_KSU) += kernelsu/\n\n#TZIC|g' "$CUR_DIR"/drivers/Makefile
fi
sed -i 's|# CONFIG_KSU is not set|CONFIG_KSU=y|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
KERNEL_NAME="$KERNEL_NAME-ksu"
}
# Disable KernelSU configurations
disable_kernelsu() {
printf "Config: Disabling KernelSU\n"
sed -i 's|CONFIG_KSU=y|# CONFIG_KSU is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
KERNEL_NAME="$KERNEL_NAME"
}
# Enable Kali Nethunter configurations
#
# Alternatively can use arch/arm64/configs/nethunter_defconfig:
#
#enable_nethunter() {
# printf "Enabling Kali Nethunter support\n"
# cat $CUR_DIR/arch/arm64/configs/nethunter_defconfig >> $CUR_DIR/arch/arm64/configs/exynos9810_temp_defconfig
# KERNEL_NAME="$KERNEL_NAME"
#}
enable_nethunter() {
printf "Config: Enabling Kali Nethunter support\n"
echo "CONFIG_NETHUNTER_SUPPORT=y" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
echo "CONFIG_NETHUNTER_ETHERNET_SUPPORT=y" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
echo "CONFIG_NETHUNTER_SDR_SUPPORT=y" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
echo "CONFIG_NETHUNTER_HID_SUPPORT=y" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
echo "CONFIG_NETHUNTER_USB_SUPPORT=y" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
echo "CONFIG_NETHUNTER_WIFI_DRIVERS_SUPPORT=y" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
cat $CUR_DIR/arch/arm64/configs/nethunter_defconfig >> $CUR_DIR/arch/arm64/configs/exynos9810_temp_defconfig
cat $CUR_DIR/arch/arm64/configs/custom_defconfig >> $CUR_DIR/arch/arm64/configs/exynos9810_temp_defconfig
KERNEL_NAME="$KERNEL_NAME"
}
# Disable Kali Nethunter configurations
disable_nethunter() {
printf "Config: Disabling Kali Nethunter support\n"
KERNEL_NAME="$KERNEL_NAME"
}
patch_wireguard() {
sed -i 's|#define priv_destructor destructor|#define priv_destructor priv_destructor|g' "$CUR_DIR"/net/wireguard/compat/compat.h
}
# Patch WiFi drivers for stock ROMs
patch_wifi() {
printf "Config: Patching Wifi to Old Driver\n"
"$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|# CONFIG_BCMDHD_100_15 is not set|CONFIG_BCMDHD_100_15=y|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
KERNEL_NAME="Kernel-a11"
}
# Enable stock ROM configurations
enable_stock() {
printf "Config: Patching Cached Defconfig For Stock Rom\n"
sed -i 's|CONFIG_SECURITY_SELINUX_NEVER_ENFORCE=y|# CONFIG_SECURITY_SELINUX_NEVER_ENFORCE is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_HALL_NEW_NODE=y|# CONFIG_HALL_NEW_NODE is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_NETFILTER_XT_MATCH_OWNER=y|# CONFIG_NETFILTER_XT_MATCH_OWNER is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_NETFILTER_XT_MATCH_L2TP=y|# CONFIG_NETFILTER_XT_MATCH_L2TP is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_L2TP=y|# CONFIG_L2TP is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|# CONFIG_NET_SCH_NETEM is not set|CONFIG_NET_SCH_NETEM=y|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|# CONFIG_NET_CLS_CGROUP is not set|CONFIG_NET_CLS_CGROUP=y|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_NET_CLS_BPF=y|# CONFIG_NET_CLS_BPF is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_VSOCKETS=y|# CONFIG_VSOCKETS is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|# CONFIG_CGROUP_NET_CLASSID is not set|CONFIG_CGROUP_NET_CLASSID=y|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_CUSTOM_FORCETOUCH=y|# CONFIG_CUSTOM_FORCETOUCH is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|# CONFIG_NETFILTER_XT_MATCH_ONESHOT is not set|CONFIG_NETFILTER_XT_MATCH_ONESHOT=y|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_SEC_VIB_NOTIFIER=y|# CONFIG_SEC_VIB_NOTIFIER is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_SEC_VIBRATOR=y|# CONFIG_SEC_VIBRATOR is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_MAX77705_VIBRATOR=y|# CONFIG_MAX77705_VIBRATOR is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|# CONFIG_SEC_HAPTIC is not set|CONFIG_SEC_HAPTIC=y|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|# CONFIG_MOTOR_DRV_MAX77705 is not set|CONFIG_MOTOR_DRV_MAX77705=y|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|# CONFIG_MOTOR_DRV_MAX77865 is not set|CONFIG_MOTOR_DRV_MAX77865=y|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
patch_wifi
echo "" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
echo "CONFIG_TCP_CONG_LIA=y" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
echo "CONFIG_TCP_CONG_OLIA=y" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
echo "CONFIG_NETFILTER_XT_MATCH_QTAGUID=y" >> "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
KERNEL_NAME="Kernel-stock"
}
# Enable AOSP ROM configurations
enable_aosp() {
printf "Config: Patching Cached Defconfig For AOSP Base\n"
sed -i 's|CONFIG_USB_ANDROID_SAMSUNG_MTP=y|# CONFIG_USB_ANDROID_SAMSUNG_MTP is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_EXYNOS_DECON_MDNIE_LITE_TUNE_RESTRICTIONS=y|# CONFIG_EXYNOS_DECON_MDNIE_LITE_TUNE_RESTRICTIONS is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_ZRAM_LRU_WRITEBACK=y|# CONFIG_ZRAM_LRU_WRITEBACK is not set|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
sed -i 's|CONFIG_ZRAM_LRU_WRITEBACK_LIMIT=5120|CONFIG_ZRAM_LRU_WRITEBACK_LIMIT=1024|g' "$CUR_DIR"/arch/arm64/configs/exynos9810_temp_defconfig
KERNEL_NAME="Kernel-aosp"
}
###########################################
# Cleaning functions (called by clean.sh) #
###########################################
clean_external() {
cd $CUR_DIR
rm -rf .*-fetch-lock drivers/kernelsu/.check net/wireguard/.check
}
clean_temp() {
cd $CUR_DIR
rm -rf vmlinux.* drivers/gator_5.27/gator_src_md5.h scripts/dtbtool_exynos/dtbtool arch/arm64/boot/dtb.img arch/arm64/boot/dts/exynos/*dtb* arch/arm64/configs/exynos9810_temp_defconfig
}
clean_prebuilt() {
cd $CUR_DIR
rm -rf $BUILD_DIR
}
clean_kernelsu() {
cd $CUR_DIR
rm -rf drivers/kernelsu
git checkout --ours drivers/Kconfig
git checkout --ours drivers/Makefile
git checkout --ours arch/arm64/boot/dts/exynos/exynos9810-crownlte_common.dtsi
git checkout --ours arch/arm64/boot/dts/exynos/exynos9810-star2lte_common.dtsi
git checkout --ours arch/arm64/boot/dts/exynos/exynos9810-starlte_common.dtsi
}
clean() {
cd $CUR_DIR
clean_temp
clean_external
make -j$(nproc) clean
make -j$(nproc) mrproper
}