forked from LineageOS/android_kernel_samsung_smdk4412
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmake-koffee.sh
executable file
·322 lines (282 loc) · 8.47 KB
/
make-koffee.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
#!/bin/bash
VERSION=0.5
DEFCONFIG=
TOOLCHAIN=
KCONFIG=false
CUST_CONF=no
BUILD_NUMBER=
DEVICE=UNKNOWN
KCONF_REPLACE=false
KERNEL_NAME="ubuntu"
BOEFFLA_VERSION="-"
SKIP_MODULES=true
DONTPACK=false
USER=$USER
DATE=`date`
BUILD_PATH=`pwd`
CLEAN=false
usage() {
echo "Koffee build script v$VERSION"
echo `date`
echo "Written by A\$teroid <[email protected]>"
echo ""
echo "Usage:"
echo ""
echo "make-koffee.sh [-d/-D/-O <file>] [-K] [-U <user>] [-N <BUILD_NUMBER>] [-k] [-R] -t <toolchain_prefix> -d <defconfig>"
echo ""
echo "Main options:"
echo " -K call Kconfig (use only with ready config!)"
echo " -d defconfig for the kernel. Will try to use already generated .config if not specified"
echo " -S set device codename (m0 for i9300 or t03g for n7100)"
echo " -O <file> external/other defconfig."
echo " -t <toolchain_prefix> toolchain prefix"
echo ""
echo "Extra options:"
echo " -j <number_of_cpus> set number of CPUs to use"
echo " -k make only zImage, do not pack into zip"
echo " -C cleanup before building"
echo " -R save your arguments to reuse (just run make-koffee.sh on next builds)"
echo " -U <username> set build user"
echo " -N <release_number> set release number"
echo " -v show build script version"
echo " -h show this help"
}
prepare()
{
make -j4 clean
}
make_config()
{
if [ "$CUST_CONF" != "no" ]; then
cp $CUST_CONF `pwd`/.config
echo "Using custom configuration from $CUST_CONF"
DEFCONFIG=custom
else
if [ ! -f "`pwd`/.config" ] || [ "$KCONF_REPLACE" = true ]; then
make ARCH=arm $JOBS $DEFCONFIG &>/dev/null
fi
fi
if [ "$KCONFIG" = "true" ]; then
make ARCH=arm $JOBS menuconfig
fi
}
build_kernel()
{
make ARCH=arm KBUILD_BUILD_VERSION=$BUILD_NUMBER $JOBS KBUILD_BUILD_USER=$USER CROSS_COMPILE=$TOOLCHAIN zImage
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
}
build_modules()
{
make ARCH=arm KBUILD_BUILD_VERSION=$BUILD_NUMBER $JOBS KBUILD_BUILD_USER=$USER CROSS_COMPILE=$TOOLCHAIN modules
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
}
make_flashable()
{
mkdir -p $REPACK_PATH
# copy anykernel template over
if [ "$DEVICE" == "m0" ]; then
cp -R $BUILD_PATH/anykernel_boeffla-i9300/* $REPACK_PATH
else
if [ "$DEVICE" == "t03g" ]; then
cp -R $BUILD_PATH/anykernel_boeffla-n7100/* $REPACK_PATH
else
echo "Attempt to create zip for unknown device. Aborting..."
exit 0
fi
fi
cd $REPACK_PATH
# delete placeholder files
find . -name placeholder -delete
# copy kernel image
cp $BUILD_PATH/arch/arm/boot/zImage $REPACK_PATH/zImage
if [ "$SKIP_MODULES" = "false" ]; then
{
# copy modules to either modules folder (CM and derivates) or directly in ramdisk (Samsung stock)
MODULES_PATH=$REPACK_PATH/modules
mkdir -p $MODULES_PATH
# copy generated modules
find $BUILD_PATH -name '*.ko' -exec cp -av {} $MODULES_PATH \;
# set module permissions
chmod 0644 $MODULES_PATH/*
# strip modules
${TOOLCHAIN}strip --strip-unneeded $MODULES_PATH/*
} 2>/dev/null
fi
# replace variables in anykernel script
cd $REPACK_PATH
KERNELNAME="GNU/Linux 3.18 kernel for i9300"
sed -i "s;###kernelname###;'${KERNELNAME}';" META-INF/com/google/android/update-binary;
COPYRIGHT=$(echo '(c) A\$teroid, ChronoMonochrome, 2020')
sed -i "s;###copyright###;${COPYRIGHT};" META-INF/com/google/android/update-binary;
BUILDINFO="Release 3.18 (${BUILD_NUMBER}), $DATE"
sed -i "s;###buildinfo###;${BUILDINFO};" META-INF/com/google/android/update-binary;
SOURCECODE="NOT COMPATIBLE WITH ANDROID!"
sed -i "s;###sourcecode###;${SOURCECODE};" META-INF/com/google/android/update-binary;
# create zip file
zip -r9 ${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}.zip * -x ${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}.zip
# sign recovery zip if there are keys available
if [ -f "$BUILD_PATH/tools_boeffla/testkey.x509.pem" ]; then
java -jar $BUILD_PATH/tools_boeffla/signapk.jar -w $BUILD_PATH/tools_boeffla/testkey.x509.pem $BUILD_PATH/tools_boeffla/testkey.pk8 ${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}.zip ${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-signed.zip
cp ${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-signed.zip $BUILD_PATH/${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-${DEVICE}-signed.zip
md5sum $BUILD_PATH/${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-${DEVICE}-signed.zip > $BUILD_PATH/${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-${DEVICE}-signed.zip.md5
else
cp ${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}.zip $BUILD_PATH/${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-${DEVICE}.zip
md5sum $BUILD_PATH/${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-${DEVICE}.zip > $BUILD_PATH/${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-${DEVICE}.zip.md5
fi
cd $BUILD_PATH
rm -fr .tmpzip
return 0
}
# Pre
while getopts "hvO:j:Kd:kB:S:N:CU:t:" opt
do
case $opt in
h) usage; exit 0;;
v) echo $VERSION; exit 0;;
t) TOOLCHAIN=$OPTARG;;
j) THREADS=$OPTARG;;
O) CUST_CONF=$OPTARG; DEFCONFIG=custom; KCONF_REPLACE=true;;
C) CLEAN=true;;
N) BUILD_NUMBER=$OPTARG;;
S) DEVICE=$OPTARG;;
K) KCONFIG=true;;
k) DONTPACK=true;;
d) DEFCONFIG="$OPTARG"; KCONF_REPLACE=true;;
U) USER=$OPTARG;;
*) usage; exit 0;;
esac
done
if [ -z $THREADS ]; then
JOBS="-j1"
THREADS=1
else
JOBS="-j$THREADS"
fi
if [ -d "`pwd`/.tmpzip" ]; then
rm -fr "`pwd`/.tmpzip"
fi
REPACK_PATH=`pwd`/.tmpzip
# ENTRY POINT
echo "Koffee build script v$VERSION"
echo $DATE
if [ "$DEFCONFIG" == "" ];
then
if [ ! -f "$BUILD_PATH/.config" ]; then
echo "FATAL: No config specified!"
echo "*** BUILD FAILED ***"
exit 1
fi
DEFCONFIG=".config"
fi
if [ "$DEFCONFIG" == "ubuntu_i9300_defconfig" ]; then
DEVICE="m0"
fi
if [ "$DEFCONFIG" == "lineageos_n7100_defconfig" ]; then
DEVICE="t03g"
fi
if [ -z $TOOLCHAIN ]; then
echo "FATAL: No toolchain prefix specified!"
echo "*** BUILD FAILED ***"
exit 1
fi
if [ "$CLEAN" = "true" ]; then
prepare &>/dev/null
fi
if [ "$DEFCONFIG" != ".config" ] || [ "$KCONFIG" == "true" ]; then
make_config
fi
TVERSION=$(${TOOLCHAIN}gcc --version | grep gcc)
if [ -z $BUILD_NUMBER ]; then
if [ -f "`pwd`/.version" ]; then
BVERN=$(cat `pwd`/.version)
else
BVERN=1
fi
else
BVERN=$BUILD_NUMBER
fi
if [ $? -eq 0 ]; then
echo "--------------------------------------"
echo "| Build date: $DATE"
echo "| Version: $BOEFFLA_VERSION"
echo "| Configuration file: $DEFCONFIG"
echo "| Release: $BVERN"
echo "| Building for: $DEVICE"
echo "| Build user: $USER"
echo "| Build host: `hostname`"
echo "| Build toolchain: $TVERSION"
echo "| Number of threads: $THREADS"
echo "--------------------------------------"
else
echo "*** CONFIGURATION FAILED ***"
exit 1
fi
echo "*** NOW WE GO! ***"
echo "---- Stage 1: Building the kernel ----"
build_kernel
if [ $? -eq 0 ]; then
echo "*** Kernel is ready! ***"
else
echo "*** zImage BUILD FAILED ***"
exit 1
fi
if [ "$SKIP_MODULES" = "false" ]; then
echo "---- Stage 2: Building modules ----"
build_modules
if [ $? -eq 0 ]; then
echo "*** Modules is ready! ***"
else
echo "*** MODULE BUILD FAILED ***"
exit 1
fi
else
echo "---- Stage 2(skipped): Building modules ----"
fi
if [ "$DONTPACK" = "false" ]; then
echo "---- Stage 3: Packing all stuff ----"
make_flashable
if [ $? -eq 0 ]; then
echo "--------------------------------------"
echo "--------------------------------------"
echo "| Build date: $DATE"
echo "| Version: $BOEFFLA_VERSION"
echo "| Configuration file: $DEFCONFIG"
echo "| Release: $BVERN"
echo "| Building for: $DEVICE"
echo "| Build user: $USER"
echo "| Build host: `hostname`"
echo "| Build toolchain: $TVERSION"
echo "| Number of threads: $THREADS"
echo "> Flashable ZIP: $(ls | grep ${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-${DEVICE} | grep .zip | head -n 1)"
echo "> MD5sum: $(ls | grep ${KERNEL_NAME}${BOEFFLA_VERSION}r${BUILD_NUMBER}-${DEVICE} | grep .md5)"
echo "--------------------------------------"
echo "*** Koffee is ready! ***"
else
echo "*** KOFFEE ZIP BUILD FAILED ***"
exit 1
fi
else
echo "---- Stage 3(skipped): Packing all stuff ----"
echo "--------------------------------------"
echo "--------------------------------------"
echo "| Build date: $DATE"
echo "| Version: $BOEFFLA_VERSION"
echo "| Configuration file: $DEFCONFIG"
echo "| Release: $BVERN"
echo "| Building for: $DEVICE"
echo "| Build user: $USER"
echo "| Build host: `hostname`"
echo "| Build toolchain: $TVERSION"
echo "| Number of threads: $THREADS"
echo "> zImage: arch/arm/boot/zImage"
echo "--------------------------------------"
echo "*** Koffee is ready! ***"
fi