forked from crimeofheart/UK-PRO5
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_kernel.sh
executable file
·183 lines (152 loc) · 6.19 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
#!/bin/bash +x
###############################################################################
# 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 go back to kernel folder and run: #
# #
# sh clean_kernel.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. #
###############################################################################
# set variables
FIT=custom_defconfig
P=custom_defconfig_P
DTS=arch/arm/boot/dts
IMG=arch/arm/boot
DC=arch/arm/configs
BK=build_kernel
OUT=output
DT=exynos5433-tre_eur_open_16.dtb
# Time of build startup
res1=$(date +%s.%N)
echo "${bldcya}***** Setting up Environment *****${txtrst}";
. ./env_setup.sh ${1} || exit 1;
# Generate Ramdisk
echo "${bldcya}***** Generating Ramdisk *****${txtrst}"
echo "0" > $TMPFILE;
(
# remove previous initramfs files
if [ -d $INITRAMFS_TMP ]; then
echo "${bldcya}***** Removing old temp initramfs_source *****${txtrst}";
rm -rf $INITRAMFS_TMP;
fi;
mkdir -p $INITRAMFS_TMP;
cp -ax $INITRAMFS_SOURCE/* $INITRAMFS_TMP;
# 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
find $INITRAMFS_TMP -name EMPTY_DIRECTORY | parallel rm -rf {};
# remove more from from tmp-initramfs ...
rm -f $INITRAMFS_TMP/update* >> /dev/null;
./utilities/mkbootfs $INITRAMFS_TMP | gzip > ramdisk.gz
echo "1" > $TMPFILE;
echo "${bldcya}***** Ramdisk Generation Completed Successfully *****${txtrst}"
)&
if [ ! -f $KERNELDIR/.config ]; then
echo "${bldcya}***** Writing Config *****${txtrst}";
cp $KERNELDIR/arch/arm/configs/$KERNEL_CONFIG .config;
make $KERNEL_CONFIG;
fi;
. $KERNELDIR/.config
# remove previous zImage files
if [ -e $KERNELDIR/zImage ]; then
rm $KERNELDIR/zImage;
rm $KERNELDIR/boot.img;
fi;
if [ -e $KERNELDIR/arch/arm/boot/zImage ]; then
rm $KERNELDIR/arch/arm/boot/zImage;
fi;
# force regeneration of .dtb and zImage files for every compile
rm -f arch/arm/boot/*.dtb
rm -f arch/arm/boot/*.cmd
rm -f arch/arm/boot/zImage
rm -f arch/arm/boot/Image
# remove previous initramfs files
rm -rf $KERNELDIR/out/system/lib/modules >> /dev/null;
rm -rf $KERNELDIR/out/tmp_modules >> /dev/null;
rm -rf $KERNELDIR/out/temp >> /dev/null;
# clean initramfs old compile data
rm -f $KERNELDIR/usr/initramfs_data.cpio >> /dev/null;
rm -f $KERNELDIR/usr/initramfs_data.o >> /dev/null;
# remove all old modules before compile
find $KERNELDIR -name "*.ko" | parallel rm -rf {};
# wait for the successful ramdisk generation
while [ $(cat ${TMPFILE}) == 0 ]; do
sleep 2;
echo "${bldblu}Waiting for Ramdisk generation completion.${txtrst}";
done;
# make zImage
echo "${bldcya}***** Compiling kernel *****${txtrst}"
if [ $USER != "root" ]; then
# make CONFIG_NO_ERROR_ON_MISMATCH=y -j5 zImage
make CONFIG_DEBUG_SECTION_MISMATCH=y -j5 zImage
else
nice -n -15 make -j5 zImage
fi;
###################################### DT.IMG GENERATION #####################################
echo -n "Build dt.img......................................."
./tools/dtbtool -o $BK/dt.img -s 2048 -p ./scripts/dtc/ $DTS/ | sleep 1
# get rid of the temps in dts directory
rm -rf $DTS/.*.tmp
rm -rf $DTS/.*.cmd
rm -rf $DTS/*.dtb
# Calculate DTS size for all images and display on terminal output
du -k "$BK/dt.img" | cut -f1 >sizT
sizT=$(head -n 1 sizT)
rm -rf sizT
echo "$sizT Kb"
if [ -e $KERNELDIR/arch/arm/boot/zImage ]; then
echo "${bldcya}***** Final Touch for Kernel *****${txtrst}"
cp $KERNELDIR/arch/arm/boot/zImage $KERNELDIR/zImage;
stat $KERNELDIR/zImage || exit 1;
echo "--- Creating boot.img ---"
# copy all needed to out kernel folder
./utilities/mkbootimg --kernel zImage --dt $BK/dt.img --ramdisk ramdisk.gz --cmdline "" --board SYSMAGIC000K --base 0x10000000 --kernel_offset 0x00008000 --ramdisk_offset 0x01000000 --tags_offset 0x00000100 --pagesize 2048 -o boot.img
rm $KERNELDIR/out/boot.img >> /dev/null;
rm $KERNELDIR/out/Kernel_* >> /dev/null;
GETVER=`grep 'Ultimate_Kernel_v.*' arch/arm/configs/${KERNEL_CONFIG} | sed 's/.*_.//g' | sed 's/".*//g'`
cp $KERNELDIR/boot.img /$KERNELDIR/out/
cd $KERNELDIR/out/
zip -r Ultimate_Kernel_v${GETVER}.zip .
echo "${bldcya}***** Ready *****${txtrst}";
# finished? get elapsed time
res2=$(date +%s.%N)
echo "${bldgrn}Total time elapsed: ${txtrst}${grn}$(echo "($res2 - $res1) / 60"|bc ) minutes ($(echo "$res2 - $res1"|bc ) seconds) ${txtrst}";
while [ "$push_ok" != "y" ] && [ "$push_ok" != "n" ] && [ "$push_ok" != "Y" ] && [ "$push_ok" != "N" ]
do
read -p "${bldblu}Do you want to push the kernel to the sdcard of your device?${txtrst}${blu} (y/n)${txtrst}" push_ok;
sleep 1;
done
if [ "$push_ok" == "y" ] || [ "$push_ok" == "Y" ]; then
STATUS=`adb get-state` >> /dev/null;
while [ "$ADB_STATUS" != "device" ]
do
sleep 1;
ADB_STATUS=`adb get-state` >> /dev/null;
done
adb push $KERNELDIR/out/Ultimate_Kernel_v*.zip /sdcard/
while [ "$reboot_recovery" != "y" ] && [ "$reboot_recovery" != "n" ] && [ "$reboot_recovery" != "Y" ] && [ "$reboot_recovery" != "N" ]
do
read -p "${bldblu}Reboot to recovery?${txtrst}${blu} (y/n)${txtrst}" reboot_recovery;
sleep 1;
done
if [ "$reboot_recovery" == "y" ] || [ "$reboot_recovery" == "Y" ]; then
adb reboot recovery;
fi;
fi;
exit 0;
else
echo "${bldred}Kernel STUCK in BUILD!${txtrst}"
fi;