-
Notifications
You must be signed in to change notification settings - Fork 21
/
twrp.sh
executable file
·330 lines (318 loc) · 9.84 KB
/
twrp.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/bin/bash
#
# Cronos Build Script V4.1
# For Exynos8890
# Coded by AnanJaser1211 @2019
# 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.
# Main Dir
CR_DIR=$(pwd)
# Define toolchan path
CR_TC=~/Android/Toolchains/linaro-4.9.4-aarch64-linux/bin/aarch64-linux-gnu-
# Define proper arch and dir for dts files
CR_DTS=arch/arm64/boot/dts
CR_DTS_TREBLE=arch/arm64/boot/exynos8890_Treble.dtsi
CR_DTS_ONEUI=arch/arm64/boot/exynos8890_Oneui.dtsi
# Define boot.img out dir
CR_OUT=$CR_DIR/Cronos/Out
CR_PRODUCT=$CR_DIR/Cronos/Product
# Presistant A.I.K Location
CR_AIK=$CR_DIR/Cronos/A.I.K
# Main Ramdisk Location
CR_RAMDISK=$CR_DIR/Cronos/Ramdisk
CR_RAMDISK_TREBLE=$CR_DIR/Cronos/Treble
CR_RAMDISK_Q=$CR_DIR/Cronos/Q
# Compiled image name and location (Image/zImage)
CR_KERNEL=$CR_DIR/arch/arm64/boot/Image
# Compiled dtb by dtbtool
CR_DTB=$CR_DIR/boot.img-dtb
# Kernel Name and Version
CR_VERSION=TWRP
CR_NAME=CronosKernel
# Thread count
CR_JOBS=$(nproc --all)
# Target Android version
CR_ANDROID=p
CR_PLATFORM=9.0.0
# Target ARCH
CR_ARCH=arm64
# Current Date
CR_DATE=$(date +%Y%m%d)
# Init build
export CROSS_COMPILE=$CR_TC
# General init
export ANDROID_MAJOR_VERSION=$CR_ANDROID
export PLATFORM_VERSION=$CR_PLATFORM
export $CR_ARCH
##########################################
# Device specific Variables [SM-G930X]
CR_DTSFILES_G930="exynos8890-herolte_eur_open_08.dtb exynos8890-herolte_eur_open_09.dtb exynos8890-herolte_eur_open_10.dtb"
CR_CONFIG_G930=hero_defconfig
CR_VARIANT_G930=G930X
# Device specific Variables [SM-G935X]
CR_DTSFILES_G935="exynos8890-hero2lte_eur_open_00.dtb exynos8890-hero2lte_eur_open_01.dtb exynos8890-hero2lte_eur_open_03.dtb exynos8890-hero2lte_eur_open_04.dtb exynos8890-hero2lte_eur_open_08.dtb"
CR_CONFIG_G935=hero2_defconfig
CR_VARIANT_G935=G935X
# Device specific Variables [SM-N935X]
CR_DTSFILES_N935="exynos8890-gracelte_eur_open_00.dtb exynos8890-gracelte_eur_open_01.dtb exynos8890-gracelte_eur_open_02.dtb exynos8890-gracelte_eur_open_03.dtb exynos8890-gracelte_eur_open_05.dtb exynos8890-gracelte_eur_open_07.dtb exynos8890-gracelte_eur_open_09.dtb exynos8890-gracelte_eur_open_11.dtb"
CR_CONFIG_N935=gracer_defconfig
CR_VARIANT_N935=N935X
# Common configs
CR_CONFIG_TREBLE=treble_defconfig
CR_CONFIG_ONEUI=oneui_defconfig
CR_CONFIG_8890=exynos8890_defconfig
CR_CONFIG_SPLIT=NULL
CR_CONFIG_CRONOS=cronos_defconfig
CR_ROOT="0"
CR_PERMISSIVE="0"
CR_HALLIC="0"
#####################################################
# Script functions
read -p "Clean source (y/n) > " yn
if [ "$yn" = "Y" -o "$yn" = "y" ]; then
echo "Clean Build"
CR_CLEAN="1"
else
echo "Dirty Build"
CR_CLEAN="0"
fi
echo "Build TWRP Variant"
CR_MODE="1"
CR_PERMISSIVE="1"
CR_HALLIC="0"
# Got Root?
#read -p "Kernel SU? (y/n) > " yn
#if [ "$yn" = "Y" -o "$yn" = "y" ]; then
# echo " WARNING : KernelSU Enabled!"
# export CONFIG_ASSISTED_SUPERUSER=y
# CR_ROOT="1"
#fi
BUILD_CLEAN()
{
if [ $CR_CLEAN = 1 ]; then
echo " "
echo " Cleaning build dir"
make clean && make mrproper
rm -r -f $CR_DTB
rm -rf $CR_DTS/.*.tmp
rm -rf $CR_DTS/.*.cmd
rm -rf $CR_DTS/*.dtb
rm -rf $CR_DIR/.config
rm -rf $CR_DTS/exynos8890.dtsi
rm -rf $CR_OUT/*.img
rm -rf $CR_OUT/*.zip
fi
if [ $CR_CLEAN = 0 ]; then
echo " "
echo " Skip Full cleaning"
rm -r -f $CR_DTB
rm -rf $CR_DTS/.*.tmp
rm -rf $CR_DTS/.*.cmd
rm -rf $CR_DTS/*.dtb
rm -rf $CR_DIR/.config
rm -rf $CR_DTS/exynos8890.dtsi
fi
}
BUILD_ROOT()
{
if [ $CR_ROOT = 1 ]; then
echo " "
echo " WARNING : KernelSU Enabled!"
mv $CR_PRODUCT/$CR_IMAGE_NAME.img $CR_PRODUCT/$CR_IMAGE_NAME-KernelSU.img
CR_IMAGE_NAME=$CR_IMAGE_NAME-KernelSU
fi
}
BUILD_IMAGE_NAME()
{
CR_IMAGE_NAME=$CR_NAME-$CR_VERSION-$CR_VARIANT-$CR_DATE
}
BUILD_GENERATE_CONFIG()
{
# Only use for devices that are unified with 2 or more configs
echo "----------------------------------------------"
echo " "
echo "Building defconfig for $CR_VARIANT"
echo " "
# Respect CLEAN build rules
BUILD_CLEAN
if [ -e $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig ]; then
echo " cleanup old configs "
rm -rf $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
fi
echo " Copy $CR_CONFIG "
cp -f $CR_DIR/arch/$CR_ARCH/configs/$CR_CONFIG $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
if [ $CR_CONFIG_SPLIT = NULL ]; then
echo " No split config support! "
else
echo " Copy $CR_CONFIG_SPLIT "
cat $CR_DIR/arch/$CR_ARCH/configs/$CR_CONFIG_SPLIT >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
fi
if [ $CR_MODE != "NULL" ]; then
echo " Copy $CR_CONFIG_TYPE "
cat $CR_DIR/arch/$CR_ARCH/configs/$CR_CONFIG_TYPE >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
fi
if [ $CR_PERMISSIVE = "1" ]; then
echo " Building Permissive Kernel"
echo "CONFIG_ALWAYS_PERMISSIVE=y" >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
fi
echo " Disable S-PEN"
echo "# CONFIG_INPUT_WACOM is not set" >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
echo "# CONFIG_EPEN_WACOM_W9018 is not set" >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
echo " Configure TWRP"
echo "CONFIG_RD_LZMA=y" >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
echo "CONFIG_DECOMPRESS_LZMA=y" >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
echo "CONFIG_CC_OPTIMIZE_FOR_SIZE=y" >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
echo "CONFIG_F2FS_FS=y" >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
echo "CONFIG_F2FS_FS_SECURITY=y" >> $CR_DIR/arch/$CR_ARCH/configs/tmp_defconfig
echo " Set $CR_VARIANT to generated config "
CR_CONFIG=tmp_defconfig
}
BUILD_OUT()
{
echo " "
echo "----------------------------------------------"
echo "$CR_VARIANT kernel build finished."
echo "Compiled DTB Size = $sizdT Kb"
echo "Kernel Image Size = $sizT Kb"
echo "Press Any key to end the script"
echo "----------------------------------------------"
}
BUILD_ZIMAGE()
{
echo "----------------------------------------------"
echo " "
echo "Building zImage for $CR_VARIANT"
export LOCALVERSION=-$CR_IMAGE_NAME
cp $CR_DTB_MOUNT $CR_DTS/exynos8890.dtsi
echo "Make $CR_CONFIG"
make $CR_CONFIG
make -j$CR_JOBS
if [ ! -e $CR_KERNEL ]; then
exit 0;
echo "Image Failed to Compile"
echo " Abort "
fi
du -k "$CR_KERNEL" | cut -f1 >sizT
sizT=$(head -n 1 sizT)
rm -rf sizT
echo " "
echo "----------------------------------------------"
}
BUILD_DTB()
{
echo "----------------------------------------------"
echo " "
echo "Building DTB for $CR_VARIANT"
# Use the DTS list provided in the build script.
# This source does not compile dtbs while doing Image
make $CR_DTSFILES
./tools/dtbTool/dtbTool -o $CR_DTB -d $CR_DTS/ -s 2048
if [ ! -e $CR_DTB ]; then
exit 0;
echo "DTB Failed to Compile"
echo " Abort "
fi
rm -rf $CR_DTS/.*.tmp
rm -rf $CR_DTS/.*.cmd
rm -rf $CR_DTS/*.dtb
rm -rf $CR_DTS/exynos8890.dtsi
du -k "$CR_DTB" | cut -f1 >sizdT
sizdT=$(head -n 1 sizdT)
rm -rf sizdT
echo " "
echo "----------------------------------------------"
}
PACK_BOOT_IMG()
{
echo "----------------------------------------------"
echo " "
echo "Building TWRP for $CR_VARIANT"
# Move Compiled kernel and dtb to Cronos Folder
mv $CR_KERNEL $CR_PRODUCT/kernel-$CR_VARIANT
mv $CR_DTB $CR_PRODUCT/dt.img-$CR_VARIANT
echo " "
# Respect CLEAN build rules
BUILD_CLEAN
}
# Main Menu
clear
echo "----------------------------------------------"
echo "$CR_NAME $CR_VERSION Build Script"
echo "----------------------------------------------"
PS3='Please select your option (1-4): '
menuvar=("SM-G930X" "SM-G935X" "SM-N935X" "Exit")
select menuvar in "${menuvar[@]}"
do
case $menuvar in
"SM-G930X")
clear
echo "Starting $CR_VARIANT_G930 kernel build..."
echo " Building TWRP variant "
CR_CONFIG_TYPE=$CR_CONFIG_TREBLE
CR_VARIANT=$CR_VARIANT_G930
CR_DTB_MOUNT=$CR_DTS_ONEUI
CR_CONFIG=$CR_CONFIG_8890
CR_CONFIG_SPLIT=$CR_CONFIG_G930
CR_DTSFILES=$CR_DTSFILES_G930
BUILD_IMAGE_NAME
BUILD_GENERATE_CONFIG
BUILD_ZIMAGE
BUILD_DTB
PACK_BOOT_IMG
BUILD_OUT
read -n1 -r key
break
;;
"SM-G935X")
clear
echo "Starting $CR_VARIANT_G935 kernel build..."
echo " Building TWRP variant "
CR_CONFIG_TYPE=$CR_CONFIG_TREBLE
CR_VARIANT=$CR_VARIANT_G935
CR_DTB_MOUNT=$CR_DTS_ONEUI
CR_CONFIG=$CR_CONFIG_8890
CR_CONFIG_SPLIT=$CR_CONFIG_G935
CR_DTSFILES=$CR_DTSFILES_G935
BUILD_IMAGE_NAME
BUILD_GENERATE_CONFIG
BUILD_ZIMAGE
BUILD_DTB
PACK_BOOT_IMG
BUILD_OUT
read -n1 -r key
break
;;
"SM-N935X")
clear
echo "Starting $CR_VARIANT_N935 kernel build..."
echo " Building TWRP variant "
CR_CONFIG_TYPE=$CR_CONFIG_TREBLE
CR_VARIANT=$CR_VARIANT_N935
CR_DTB_MOUNT=$CR_DTS_ONEUI
CR_CONFIG=$CR_CONFIG_8890
CR_CONFIG_SPLIT=$CR_CONFIG_N935
CR_DTSFILES=$CR_DTSFILES_N935
BUILD_IMAGE_NAME
BUILD_GENERATE_CONFIG
BUILD_ZIMAGE
BUILD_DTB
PACK_BOOT_IMG
BUILD_OUT
read -n1 -r key
break
;;
"Exit")
break
;;
*) echo Invalid option.;;
esac
done