forked from minealex2244/Aldeon-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_kernel.sh
executable file
·226 lines (174 loc) · 7.11 KB
/
build_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
#!/bin/bash
###############################################################################
# To all DEV around the world :) #
# to build this kernel you need to be ROOT and to have bash as script loader #
# do this: #
# cd /bin #
# rm -f sh #
# ln -s bash sh #
# #
# Now you can build my kernel. #
# using bash will make your life easy. so it's best that way. #
# Have fun and update me if something nice can be added to my source. #
# #
# Original scripts by halaszk & various sources throughout gitHub #
# modified by UpInTheAir for SkyHigh kernels #
# very very slightly modified by The Sickness for his Twisted S6 kernel #
# #
###############################################################################
############################################ SETUP ############################################
# Time of build startup
res1=$(date +%s.%N)
echo
echo "${bldcya}***** Setting up Environment *****${txtrst}";
echo
. ./env_setup.sh ${1} || exit 1;
if [ ! -f $KERNELDIR/.config ]; then
echo
echo "${bldcya}***** Writing Config *****${txtrst}";
cp $KERNELDIR/arch/arm64/configs/$KERNEL_CONFIG .config;
make ARCH=arm64 $KERNEL_CONFIG;
fi;
. $KERNELDIR/.config
########################################### CLEAN UP ##########################################
echo
echo "${bldcya}***** Clean up first *****${txtrst}"
find . -type f -name "*~" -exec rm -f {} \;
find . -type f -name "*orig" -exec rm -f {} \;
find . -type f -name "*rej" -exec rm -f {} \;
# cleanup previous Image files
if [ -e $KERNELDIR/dt.img ]; then
rm $KERNELDIR/dt.img;
fi;
if [ -e $KERNELDIR/arch/arm64/boot/Image ]; then
rm $KERNELDIR/arch/arm64/boot/Image;
fi;
if [ -e $KERNELDIR/arch/arm64/boot/dt.img ]; then
rm $KERNELDIR/arch/arm64/boot/dt.img;
fi;
# cleanup variant ramdisk files
find . -type f -name "EMPTY_DIRECTORY" -exec rm -f {} \;
if [ -e $BK/$TARGET/boot.img ]; then
rm -rf $BK/$TARGET/boot.img
fi;
if [ -e $BK/$TARGET/Image ]; then
rm -rf $BK/$TARGET/Image
fi;
if [ -e $BK/$TARGET/ramdisk.gz ]; then
rm -rf $BK/$TARGET/ramdisk.gz
fi;
if [ -e $BK/$TARGET/ramdisk/lib/modules/ ]; then
cd ${KERNELDIR}/$BK/$TARGET
find . -type f -name "*.ko" -exec rm -f {} \;
cd ${KERNELDIR}
fi;
if [ -e $BK/system/lib/modules/ ]; then
cd ${KERNELDIR}/$BK/system
find . -type f -name "*.ko" -exec rm -f {} \;
fi;
cd ${KERNELDIR}
# cleanup old output files
rm -rf ${KERNELDIR}/output/$TARGET/*
# cleanup old dtb files
rm -rf $KERNELDIR/arch/arm64/boot/dts/*.dtb;
echo "Done"
####################################### COMPILE IMAGES #######################################
echo
echo "${bldcya}***** Compiling kernel *****${txtrst}"
if [ $USER != "root" ]; then
make CONFIG_DEBUG_SECTION_MISMATCH=y -j10 Image ARCH=arm64
else
make -j10 Image ARCH=arm64
fi;
if [ -e $KERNELDIR/arch/arm64/boot/Image ]; then
echo
echo "${bldcya}***** Final Touch for Kernel *****${txtrst}"
stat $KERNELDIR/arch/arm64/boot/Image || exit 1;
mv ./arch/arm64/boot/Image ./$BK/$TARGET
echo
echo "--- Creating custom dt.img ---"
./utilities/dtbtool -o dt.img -s 2048 -p ./scripts/dtc/dtc ./arch/arm64/boot/dts/
else
echo "${bldred}Kernel STUCK in BUILD!${txtrst}"
exit 0;
fi;
echo
echo "Done"
###################################### RAMDISK GENERATION #####################################
echo
echo "${bldcya}***** Make ramdisk *****${txtrst}"
# make modules
make -j10 modules ARCH=arm64 || exit 1;
# find modules
for i in $(find "$KERNELDIR" -name '*.ko'); do
cp -av "$i" ./$BK/system/lib/modules/;
done;
if [ -f "./$BK/system/lib/modules/*" ]; then
chmod 0755 ./$BK/system/lib/modules/*
${CROSS_COMPILE}strip --strip-debug ./$BK/system/lib/modules/*.ko
${CROSS_COMPILE}strip --strip-unneeded ./$BK/system/lib/modules/*
fi;
# fix ramdisk permissions
cd ${KERNELDIR}/$BK
cp ./ramdisk_fix_permissions.sh ./$TARGET/ramdisk/ramdisk_fix_permissions.sh
cd ${KERNELDIR}/$BK/$TARGET/ramdisk
chmod 0777 ramdisk_fix_permissions.sh
./ramdisk_fix_permissions.sh 2>/dev/null
rm -f ramdisk_fix_permissions.sh
# make ramdisk
cd ${KERNELDIR}/$BK
./mkbootfs ./$TARGET/ramdisk | gzip > ./$TARGET/ramdisk.gz
echo
echo "Done"
##################################### BOOT.IMG GENERATION #####################################
echo
echo "${bldcya}***** Make boot.img *****${txtrst}"
read -p "Do you want to use a stock (s) or custom generated (c) dt.img? (s/c) > " dt
echo
if [ "$dt" = "c" -o "$dt" = "C" ]; then
./mkbootimg --kernel ./$TARGET/Image --dt ${KERNELDIR}/dt.img --ramdisk ./$TARGET/ramdisk.gz --base 0x10000000 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 --tags_offset 0x00000100 --pagesize 2048 -o ./$TARGET/boot.img
fi
if [ "$dt" = "s" -o "$dt" = "S" ]; then
./mkbootimg --kernel ./$TARGET/Image --dt ./$TARGET/dt.img --ramdisk ./$TARGET/ramdisk.gz --base 0x10000000 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 --tags_offset 0x00000100 --pagesize 2048 -o ./$TARGET/boot.img
fi
echo -n "SEANDROIDENFORCE" >> ./$TARGET/boot.img
echo "Done"
###################################### ARCHIVE GENERATION #####################################
echo
echo "${bldcya}***** Make archives *****${txtrst}"
cp -R ./sickness ${KERNELDIR}/output/$TARGET/
cp -R ./supersu ${KERNELDIR}/output/$TARGET/
cp -R ./busybox ${KERNELDIR}/output/$TARGET/
cp ./$TARGET/boot.img ${KERNELDIR}/output/$TARGET/sickness
cp -R ./system ${KERNELDIR}/output/$TARGET/
cp -R ./META-INF ${KERNELDIR}/output/$TARGET/
cd ${KERNELDIR}/output/$TARGET
GETVER=`grep 'S6_MM_*v' ${KERNELDIR}/.config | sed 's/.*".//g' | sed 's/-S.*//g'`
# Without Clearwater audio mod
AUDIO=`grep '# CONFIG_SND_SOC_ARIZONA_CONTROL*' ${KERNELDIR}/.config | sed 's/.*".//g' | sed 's/-S.*//g'`
if [ "$AUDIO" == "# CONFIG_SND_SOC_ARIZONA_CONTROL is not set" ]; then
AUDIO="no-audio"
else
AUDIO=""
fi
zip -r SM-$TARGET-$AUDIO-kernel-${GETVER}-`date +[%d-%m-%y]`.zip .
tar -H ustar -c ${KERNELDIR}/output/$TARGET/sickness/boot.img > SM-$TARGET-$AUDIO-kernel-${GETVER}-`date +[%d-%m-%y]`.tar
md5sum -t SM-$TARGET-$AUDIO-kernel-${GETVER}-`date +[%d-%m-%y]`.tar >> SM-$TARGET-$AUDIO-kernel-${GETVER}-`date +[%d-%m-%y]`.tar
mv SM-$TARGET-$AUDIO-kernel-${GETVER}-`date +[%d-%m-%y]`.tar SM-$TARGET-$AUDIO-kernel-${GETVER}-`date +[%d-%m-%y]`.tar.md5
echo
echo "Done"
#################################### OPTIONAL SOURCE CLEAN ####################################
echo
echo "${bldcya}***** Clean source *****${txtrst}"
cd ${KERNELDIR}
read -p "Do you want to Clean the source? (y/n) > " mc
if [ "$mc" = "Y" -o "$mc" = "y" ]; then
xterm -e make clean
xterm -e make mrproper
fi
echo
echo "Build completed"
echo
echo "${txtbld}***** Flashable zip found in output directory *****${txtrst}"
echo
# build script ends