-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_kernel_backup.sh
executable file
·261 lines (219 loc) · 5.79 KB
/
build_kernel_backup.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
#!/bin/bash
export PATH=/opt/toolchains/arm-cortex_a15-linux-gnueabihf_5.3/bin:$PATH
RDIR=$(pwd)
[ -z $VARIANT ] && \
# device variant/carrier, possible options:
# can = N900W8 (Canadian, same as T-Mobile)
# eur = N9005 (Snapdragon International / hltexx / Europe)
# spr = N900P (Sprint)
# tmo = N900T (T-Mobile, same as Canadian)
# kor = N900K/L/S (Unified Korean / KT Corporation, LG Telecom, South Korea Telecom)
# not currently possible options (missing cm12.1 support!):
# att = N900A (AT&T)
# usc = N900R4 (US Cellular)
# vzw = N900V (Verizon)
VARIANT=can
[ -z $VER ] && \
# version number
VER=MarkOne
# KERNEL_NAME should NOT contain any spaces
KERNEL_NAME=machinex
# kernel version string appended to 3.4.x-${KERNEL_NAME}-kernel-hlte-
# (shown in Settings -> About device)
KERNEL_VERSION=${KERNEL_NAME}-$VER-$VARIANT
# output directory of flashable kernel
OUT_DIR=$RDIR
# output filename of flashable kernel
OUT_NAME=${KERNEL_NAME}-$KERNEL_VERSION-hlte
# should we make a TWRP flashable zip? (1 = yes, 0 = no)
MAKE_ZIP=1
# should we make an Odin flashable tar.md5? (1 = yes, 0 = no)
MAKE_TAR=0
# amount of cpu threads to use in kernel make process
THREADS=6
############## SCARY NO-TOUCHY STUFF ###############
# Used as the prefix for the ramdisk and zip folders. Also used to prefix the defconfig files in arch/arm/configs/.
FILE_PREFIX=mx
KERNEL_AUTHOR=robcore
RAMDISK_FOLDER=${FILE_PREFIX}.ramdisk
ZIP_FOLDER=${FILE_PREFIX}.zip
DEFCONFIG=${FILE_PREFIX}config
VARIANT_DEFCONFIG=${FILE_PREFIX}config
export ARCH=arm
export CROSS_COMPILE=/opt/toolchains/arm-cortex_a15-linux-gnueabihf_5.3/bin/arm-cortex_a15-linux-gnueabihf-
export LOCALVERSION=$KERNEL_VERSION
env KCONFIG_NOTIMESTAMP=true
if [ ! -f $RDIR"/arch/arm/configs/${VARIANT_DEFCONFIG}" ] ; then
echo "Device variant/carrier $VARIANT not found in arm configs!"
exit -1
fi
if ! [ ! -d $RDIR/${RAMDISK_FOLDER}/variant/$VARIANT/ ] ; then
echo "Device variant/carrier $VARIANT not found in ${RAMDISK_FOLDER}/variant!"
exit -1
fi
KDIR=$RDIR/build/arch/arm/boot
CLEAN_BUILD()
{
echo "Cleaning build..."
# clean up leftover junk
find . -type f \( -iname \*.rej \
-o -iname \*.orig \
-o -iname \*.bkp \
-o -iname \*.ko \) \
| parallel rm -fv {};
cd $RDIR
rm -rf build
echo "Removing old boot.img..."
rm -f ${ZIP_FOLDER}/boot.img
echo "Removing old zip/tar.md5 files..."
rm -f $OUT_DIR/$OUT_NAME.zip
rm -f $OUT_DIR/$OUT_NAME.tar.md5
echo "Removing old scripts/mkqcdtbootimg/mkqcdtbootimg..."
make -C $RDIR/scripts/mkqcdtbootimg clean
rm -rf $RDIR/scripts/mkqcdtbootimg/mkqcdtbootimg 2>/dev/null
}
BUILD_KERNEL_CONFIG()
{
echo "Creating kernel config..."
cd $RDIR
mkdir -p build
make -C $RDIR O=build ${DEFCONFIG} \
VARIANT_DEFCONFIG=${VARIANT_DEFCONFIG}
}
BUILD_KERNEL()
{
echo "Starting build..."
make -C $RDIR O=build -j"$THREADS"
}
BUILD_RAMDISK()
{
echo "Building ramdisk structure..."
cd $RDIR
rm -rf build/ramdisk 2>/dev/null
mkdir -p build/ramdisk
cp -ar ${RAMDISK_FOLDER}/* build/ramdisk
echo "Building ramdisk.img..."
cd $RDIR/build/ramdisk
mkdir -pm 755 dev proc sys system
mkdir -pm 771 data
find | fakeroot cpio -o -H newc | gzip -9 > $KDIR/ramdisk.cpio.gz
cd $RDIR
}
BUILD_BOOT_IMG()
{
echo "Generating boot.img..."
if [ ! -f $RDIR/scripts/mkqcdtbootimg/mkqcdtbootimg ] ; then
make -C $RDIR/scripts/mkqcdtbootimg
fi
$RDIR/scripts/mkqcdtbootimg/mkqcdtbootimg --kernel $KDIR/zImage \
--ramdisk $KDIR/ramdisk.cpio.gz \
--dt_dir $KDIR \
--cmdline "console=null androidboot.hardware=qcom user_debug=23 msm_rtb.filter=0x37 ehci-hcd.park=3" \
--base 0x00000000 \
--pagesize 2048 \
--ramdisk_offset 0x02000000 \
--tags_offset 0x01e00000 \
--output $RDIR/${ZIP_FOLDER}/boot.img
}
CREATE_ZIP()
{
if [ $MAKE_ZIP != 1 ]; then return; fi
echo "Compressing to TWRP flashable zip file..."
cd $RDIR/${ZIP_FOLDER}
zip -r -9 - * > $OUT_DIR/$OUT_NAME.zip
cd $RDIR
}
CREATE_TAR()
{
if [ $MAKE_TAR != 1 ]; then return; fi
echo "Compressing to Odin flashable tar.md5 file..."
cd $RDIR/${ZIP_FOLDER}
tar -H ustar -c boot.img > $OUT_DIR/$OUT_NAME.tar
cd $OUT_DIR
md5sum -t $OUT_NAME.tar >> $OUT_NAME.tar
mv $OUT_NAME.tar $OUT_NAME.tar.md5
cd $RDIR
}
function SHOW_HELP()
{
SCRIPT_NAME=`basename "$0"`
cat << EOF
${KERNEL_NAME} by ${KERNEL_AUTHOR}. To configure this script for your build, edit the top of mx-build.sh before continuing.
usage: ./$SCRIPT_NAME [OPTION]
Common options:
-a|--all Do a complete build (starting at the beginning)
-c|--clean Remove everything this build script has done
-k|--kernel Try the build again starting at compiling the kernel
-r|--ramdisk Try the build again starting at the ramdisk
Other options that only complete 1 part of the build:
-ko|--kernel-only Recompile only the kernel
Build script by jcadduono, frequentc & robcore
EOF
exit -1
}
function BUILD_RAMDISK_CONTINUE()
{
BUILD_RAMDISK && BUILD_BOOT_IMG && CREATE_ZIP && CREATE_TAR
}
function BUILD_KERNEL_CONTINUE()
{
BUILD_KERNEL && BUILD_RAMDISK_CONTINUE
}
function BUILD_ALL()
{
CLEAN_BUILD && BUILD_KERNEL_CONFIG && BUILD_KERNEL_CONTINUE
}
if [ $# = 0 ] ; then
SHOW_HELP
fi
while [[ $# > 0 ]]
do
key="$1"
case $key in
-a|--all)
if ! BUILD_ALL; then
echo "Failed!"
exit -1
else
echo "Finished!"
fi
break
;;
-c|--clean)
CLEAN_BUILD
break
;;
-k|--kernel)
if ! BUILD_KERNEL_CONTINUE; then
echo "Failed!"
exit -1
else
echo "Finished!"
fi
break
;;
-ko|--kernel-only)
if ! BUILD_KERNEL; then
echo "Failed!"
exit -1
else
echo "Finished!"
fi
break
;;
-r|--ramdisk)
if ! BUILD_RAMDISK_CONTINUE; then
echo "Failed!"
exit -1
else
echo "Finished!"
fi
break
;;
*)
SHOW_HELP
break;
;;
esac
shift # past argument or value
done