forked from gokhanmoral/siyahkernel3
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathbuild_kernel.sh
executable file
·245 lines (203 loc) · 8.07 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/bin/bash
###############################################################################
# To all DEV around the world :) #
# #
# 1.) use the "bash" #
# chsh -s /bin/bash `whoami` #
# #
# 2.) load the ".config" #
# ./load_config.sh #
# #
# 3.) clean the sources #
# ./clean_kernel.sh #
# #
# 4.) now you can build my kernel #
# ./build_kernel.sh #
# #
# Have fun and update me if something nice can be added to my source. #
###############################################################################
# location
if [ "${1}" != "" ]; then
export KERNELDIR=`readlink -f ${1}`;
else
export KERNELDIR=`readlink -f .`;
fi;
export PARENT_DIR=`readlink -f ${KERNELDIR}/..`;
export INITRAMFS_SOURCE=`readlink -f ${KERNELDIR}/../initramfs3`;
export INITRAMFS_TMP=/tmp/initramfs_source;
# kernel
export ARCH=arm;
export USE_SEC_FIPS_MODE=true;
export KERNEL_CONFIG=dorimanx_defconfig;
# build script
export USER=`whoami`;
export HOST=`uname -n`;
export TMPFILE=`mktemp -t`;
chmod -R 777 /tmp;
# system compiler
# gcc x.x.x
# export CROSS_COMPILE=$PARENT_DIR/toolchain/bin/arm-none-eabi-;
# gcc 4.8.3 (Linaro 2013.x)
export CROSS_COMPILE=$KERNELDIR/android-toolchain/bin/arm-eabi-;
# importing PATCH for GCC depend on GCC version
GCCVERSION=`./scripts/gcc-version.sh ${CROSS_COMPILE}gcc`;
# check xml-config for "STweaks"-app
XML2CHECK="${INITRAMFS_SOURCE}/res/customconfig/customconfig.xml";
xmllint --noout $XML2CHECK;
if [ $? == 1 ]; then
echo "xml-Error: $XML2CHECK";
exit 1;
fi;
# compiler detection
if [ "a$GCCVERSION" == "a0404" ]; then
cp $KERNELDIR/arch/arm/boot/compressed/Makefile_old_gcc $KERNELDIR/arch/arm/boot/compressed/Makefile;
echo "GCC 4.3.X Compiler Detected, building";
elif [ "a$GCCVERSION" == "a0404" ]; then
cp $KERNELDIR/arch/arm/boot/compressed/Makefile_old_gcc $KERNELDIR/arch/arm/boot/compressed/Makefile;
echo "GCC 4.4.X Compiler Detected, building";
elif [ "a$GCCVERSION" == "a0405" ]; then
cp $KERNELDIR/arch/arm/boot/compressed/Makefile_old_gcc $KERNELDIR/arch/arm/boot/compressed/Makefile;
echo "GCC 4.5.X Compiler Detected, building";
elif [ "a$GCCVERSION" == "a0406" ]; then
cp $KERNELDIR/arch/arm/boot/compressed/Makefile_linaro $KERNELDIR/arch/arm/boot/compressed/Makefile;
echo "GCC 4.6.X Compiler Detected, building";
elif [ "a$GCCVERSION" == "a0407" ]; then
cp $KERNELDIR/arch/arm/boot/compressed/Makefile_linaro $KERNELDIR/arch/arm/boot/compressed/Makefile;
echo "GCC 4.7.X Compiler Detected, building";
elif [ "a$GCCVERSION" == "a0408" ]; then
cp $KERNELDIR/arch/arm/boot/compressed/Makefile_linaro $KERNELDIR/arch/arm/boot/compressed/Makefile;
echo "GCC 4.8.X Compiler Detected, building";
else
echo "Compiler not recognized! please fix the 'build_kernel.sh'-script to match your compiler.";
exit 0;
fi;
# dorimanx detection ;)
if [ $HOST == "dorimanx-virtual-machine" ] || [ $HOST == "dorimanx" ]; then
NR_CPUS=16;
echo "Dori power detected!";
else
NR_CPUS=$(expr `grep processor /proc/cpuinfo | wc -l`);
if [ "$NR_CPUS" -lt 2 ]; then
(( NR_CPUS=2 ))
fi;
echo "not dorimanx system detected, setting $NR_CPUS build threads"
fi;
# copy config
if [ ! -f $KERNELDIR/.config ]; then
cp $KERNELDIR/arch/arm/configs/$KERNEL_CONFIG $KERNELDIR/.config;
fi;
# read config
. $KERNELDIR/.config;
# get version from config
GETVER=`grep 'Siyah-.*-V' .config |sed 's/Siyah-//g' | sed 's/.*".//g' | sed 's/-J.*//g'`;
# remove previous zImage files
if [ -e $KERNELDIR/zImage ]; then
rm $KERNELDIR/zImage;
fi;
if [ -e $KERNELDIR/arch/arm/boot/zImage ]; then
rm $KERNELDIR/arch/arm/boot/zImage;
fi;
# remove previous initramfs files
if [ -d $INITRAMFS_TMP ]; then
echo "removing old temp initramfs_source";
rm -rf $INITRAMFS_TMP;
fi;
# clean initramfs old compile data
rm -f $KERNELDIR/usr/initramfs_data.cpio;
rm -f $KERNELDIR/usr/initramfs_data.o;
# copy new config
cp $KERNELDIR/.config $KERNELDIR/arch/arm/configs/$KERNEL_CONFIG;
# remove all old modules before compile
for i in `find $KERNELDIR/ -name "*.ko"`; do
rm -f $i;
done;
# copy initramfs files to tmp directory
cp -dxPR $INITRAMFS_SOURCE $INITRAMFS_TMP;
# create new image with version & date
#read -t 3 -p "create new kernel Image LOGO with version & date, 3sec timeout (y/n)?";
echo "0" > $TMPFILE;
#if [ "$REPLY" == "y" ]; then
(
./mod_logo_build.sh;
)&
#else
# echo "1" > $TMPFILE;
#fi;
# make modules
mkdir -p $INITRAMFS_TMP/lib/modules;
make -j${NR_CPUS} KALLSYMS_EXTRA_PASS=1 modules || exit 1;
# clear git repository from tmp-initramfs
if [ -d $INITRAMFS_TMP/.git ]; then
rm -rf $INITRAMFS_TMP/.git;
fi;
# clear mercurial repository from tmp-initramfs
if [ -d $INITRAMFS_TMP/.hg ]; then
rm -rf $INITRAMFS_TMP/.hg;
fi;
# remove empty directory placeholders from tmp-initramfs
for i in `find $INITRAMFS_TMP -name EMPTY_DIRECTORY`; do
rm -f $i;
done;
# remove more from from tmp-initramfs ...
rm -f $INITRAMFS_TMP/compress-sql.sh;
rm -f $INITRAMFS_TMP/update*;
# copy modules into tmp-initramfs
mkdir -p $INITRAMFS_TMP/lib/modules;
for i in `find $KERNELDIR -name '*.ko'`; do
cp -av $i $INITRAMFS_TMP/lib/modules/;
done;
for i in `find $INITRAMFS_TMP/lib/modules/ -name '*.ko'`; do
${CROSS_COMPILE}strip --strip-unneeded $i;
done;
for i in `find $INITRAMFS_TMP/lib/modules/ -name '*.ko'`; do
${CROSS_COMPILE}strip --strip-debug $i;
done;
chmod 755 $INITRAMFS_TMP/lib/modules/*;
# compress modules to reduce initramfs size
#tar -C $INITRAMFS_TMP/lib -cvf - . | xz -9 -c > $INITRAMFS_TMP/modules.tar.xz;
#rm -rf $INITRAMFS_TMP/lib/*;
md5sum $INITRAMFS_TMP/res/misc/payload/STweaks.apk | awk '{print $1}' > $INITRAMFS_TMP/res/stweaks_md5;
chmod 644 $INITRAMFS_TMP/res/stweaks_md5;
# wait for the boot-image
while [ $(cat ${TMPFILE}) == 0 ]; do
sleep 2;
echo "wait for image ...";
done;
# to check section mismatch add to make this
# CONFIG_DEBUG_SECTION_MISMATCH=y
# make kernel!!!
time make -j $NR_CPUS KALLSYMS_EXTRA_PASS=1 zImage CONFIG_INITRAMFS_SOURCE="$INITRAMFS_TMP";
# restore clean arch/arm/boot/compressed/Makefile_clean till next time
cp $KERNELDIR/arch/arm/boot/compressed/Makefile_clean $KERNELDIR/arch/arm/boot/compressed/Makefile;
if [ -e $KERNELDIR/arch/arm/boot/zImage ]; then
cp $KERNELDIR/.config $KERNELDIR/arch/arm/configs/$KERNEL_CONFIG;
# echo "Kernel size before payload!";
# stat $KERNELDIR/arch/arm/boot/zImage || exit 1;
# $KERNELDIR/mkshbootimg.py $KERNELDIR/zImage $KERNELDIR/arch/arm/boot/zImage $KERNELDIR/payload.tar.xz $KERNELDIR/recovery.tar.xz;
cp $KERNELDIR/arch/arm/boot/zImage $KERNELDIR/;
# clean old files ...
rm $KERNELDIR/READY-JB/boot/zImage;
rm $KERNELDIR/READY-JB/Kernel_*;
# copy all needed to ready kernel folder
cp $KERNELDIR/.config $KERNELDIR/READY-JB/;
# echo "Kernel size after payload merge!";
stat $KERNELDIR/zImage || exit 1;
cp $KERNELDIR/zImage /$KERNELDIR/READY-JB/boot/;
# create zip-file
cd $KERNELDIR/READY-JB/ && zip -r Kernel_${GETVER}-`date +"[%H-%M]-[%d-%m]-JB-SGII-PWR-CORE"`.zip .;
# push to android
ADB_STATUS=`adb get-state`;
if [ "$ADB_STATUS" == "device" ]; then
read -t 3 -p "push kernel to android, 3sec timeout (y/n)?";
if [ "$REPLY" == "y" ]; then
adb push $KERNELDIR/READY-JB/Kernel_*JB*.zip /sdcard/;
read -t 3 -p "reboot to recovery, 3sec timeout (y/n)?";
if [ "$REPLY" == "y" ]; then
adb reboot recovery;
fi;
fi;
fi;
else
# with red-color
echo -e "\e[1;31mKernel STUCK in BUILD! no zImage exist\e[m"
fi;