-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake-koffee.sh
executable file
·302 lines (271 loc) · 8.34 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
#!/bin/bash
VERSION=0.9
DEFCONFIG=lineageos_a6010_defconfig
TOOLCHAIN=../../../prebuilts/gcc/linux-x86/arm/arm-eabi/bin/arm-none-eabi-
KCONFIG=false
CUST_CONF=no
BUILD_NUMBER=1
DEVICE=a6010
KCONF_REPLACE=false
KERNEL_NAME="Eclipse"
SKIP_MODULES=true
DONTPACK=false
USER=$USER
DATE=`date`
BUILD_HOST=`hostname`
BUILD_PATH=`pwd`
CLEAN=false
VERBOSE=0
INDTB=-dtb
usage() {
echo "$KERNEL_NAME build script v$VERSION"
echo `date`
echo "Written by acroreiser <acroreiser@gmail.com>"
echo ""
echo "Usage:"
echo ""
echo "make-koffee.sh [-d/-D/-O <file>] [-K] [-U <user>] [-N <BUILD_NUMBER>] [-k] [-R] [-V] -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 (a6000 for Lenovo a6000/a6010, m0 for i9300 or t03g for n7100)"
echo " -O <file> external/other defconfig."
echo " -t <toolchain_prefix> toolchain prefix for custom toolchain (default GCC 4.7)"
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 " -H <hostname> set build host"
echo " -N <release_number> set release number"
echo " -V verbose output"
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 KBUILD_BUILD_HOST=$BUILD_HOST CROSS_COMPILE=$TOOLCHAIN V=$VERBOSE zImage$INDTB
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 KBUILD_BUILD_HOST=$BUILD_HOST CROSS_COMPILE=$TOOLCHAIN V=$VERBOSE modules
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
}
build_dtbs()
{
make ARCH=arm KBUILD_BUILD_VERSION=$BUILD_NUMBER $JOBS KBUILD_BUILD_USER=$USER KBUILD_BUILD_HOST=$BUILD_HOST CROSS_COMPILE=$TOOLCHAIN V=$VERBOSE dtbs
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
}
make_flashable()
{
# copy anykernel template over
if [ "$DEVICE" == "a6010" ] || [ "$DEVICE" == "a6000" ]; then
cp -R $BUILD_PATH/anykernel_a6000/* $REPACK_PATH
echo "--------------------------------------" > $REPACK_PATH/info.txt
echo "| Build date: $DATE" >> $REPACK_PATH/info.txt
echo "| Configuration file: $DEFCONFIG" >> $REPACK_PATH/info.txt
echo "| Release: $BVERN" >> $REPACK_PATH/info.txt
echo "| Building for: $DEVICE" >> $REPACK_PATH/info.txt
echo "| Build user: $USER" >> $REPACK_PATH/info.txt
echo "| Build host: $BUILD_HOST" >> $REPACK_PATH/info.txt
echo "| Build toolchain: $TVERSION" >> $REPACK_PATH/info.txt
echo "| Kernel security patch level: $(cat patchlevel.txt)" >> $REPACK_PATH/info.txt
else
echo "Attempt to create flashable for an unknown device. Aborting..."
exit 1
fi
cd $REPACK_PATH
# delete placeholder files
find . -name placeholder -delete
# copy kernel image
cp $BUILD_PATH/arch/arm/boot/zImage$INDTB $REPACK_PATH/zImage$INDTB
# replace variables in anykernel script
cd $REPACK_PATH
KERNELNAME="Flashing $KERNEL_NAME"
sed -i "s;###kernelname###;${KERNELNAME};" META-INF/com/google/android/update-binary;
COPYRIGHT=$(echo '(c) acroreiser, 2022')
sed -i "s;###copyright###;${COPYRIGHT};" META-INF/com/google/android/update-binary;
BUILDINFO="Release ${BUILD_NUMBER}, $DATE"
sed -i "s;###buildinfo###;${BUILDINFO};" META-INF/com/google/android/update-binary;
# create zip file
zip -r9 ${KERNEL_NAME}-r${BUILD_NUMBER}.zip * -x ${KERNEL_NAME}-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}-r${BUILD_NUMBER}.zip ${KERNEL_NAME}-r${BUILD_NUMBER}-signed.zip
cp ${KERNEL_NAME}-r${BUILD_NUMBER}-signed.zip $BUILD_PATH/${KERNEL_NAME}-r${BUILD_NUMBER}-${DEVICE}-signed.zip
md5sum $BUILD_PATH/${KERNEL_NAME}-r${BUILD_NUMBER}-${DEVICE}-signed.zip > $BUILD_PATH/${KERNEL_NAME}-r${BUILD_NUMBER}-${DEVICE}-signed.zip.md5
else
cp ${KERNEL_NAME}-r${BUILD_NUMBER}.zip $BUILD_PATH/${KERNEL_NAME}-r${BUILD_NUMBER}-${DEVICE}.zip
md5sum $BUILD_PATH/${KERNEL_NAME}-r${BUILD_NUMBER}-${DEVICE}.zip > $BUILD_PATH/${KERNEL_NAME}-r${BUILD_NUMBER}-${DEVICE}.zip.md5
fi
cd $BUILD_PATH
return 0
}
# Pre
while getopts "hvO:j:Kd:kB:S:N:CU:H:t:V" 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;;
H) BUILD_HOST=$OPTARG;;
V) VERBOSE=1;;
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
THREADS=$(nproc --all)
fi
JOBS="-j$THREADS"
if [ -d "`pwd`/.tmpzip" ]; then
rm -fr "`pwd`/.tmpzip"
fi
REPACK_PATH=`pwd`/.tmpzip
mkdir -p $REPACK_PATH
# 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 [ -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 "| Configuration file: $DEFCONFIG"
echo "| Release: $BVERN"
echo "| Building for: $DEVICE"
echo "| Build user: $USER"
echo "| Build host: $BUILD_HOST"
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
#echo "---- Stage 2: Building the Device Tree ----"
# make the kernel backward-compatible Oreo and Pie
# build_dtbs
if [ "$SKIP_MODULES" = "false" ]; then
echo "---- Stage 3: Building modules ----"
build_modules
if [ $? -eq 0 ]; then
echo "*** Modules is ready! ***"
else
echo "*** MODULE BUILD FAILED ***"
exit 1
fi
else
echo "---- Stage 3(skipped): Building modules ----"
fi
if [ "$DONTPACK" = "false" ]; then
echo "---- Stage 4: Packing all stuff ----"
make_flashable
if [ $? -eq 0 ]; then
echo "--------------------------------------"
cat $REPACK_PATH/info.txt
echo "> Flashable ZIP: $(ls | grep ${KERNEL_NAME}-r${BUILD_NUMBER}-${DEVICE} | grep .zip | head -n 1)"
echo "> MD5sum: $(ls | grep ${KERNEL_NAME}-r${BUILD_NUMBER}-${DEVICE} | grep .md5)"
echo "--------------------------------------"
echo "*** $KERNEL_NAME is ready! ***"
else
echo "*** KOFFEE ZIP BUILD FAILED ***"
exit 1
fi
rm -fr .tmpzip
else
echo "---- Stage 3(skipped): Packing all stuff ----"
echo "--------------------------------------"
echo "--------------------------------------"
echo "| Build date: $DATE"
echo "| Configuration file: $DEFCONFIG"
echo "| Release: $BVERN"
echo "| Building for: $DEVICE"
echo "| Build user: $USER"
echo "| Build host: $BUILD_HOST"
echo "| Build toolchain: $TVERSION"
echo "| Number of threads: $THREADS"
echo "> zImage: arch/arm/boot/zImage"
echo "--------------------------------------"
echo "*** $KERNEL_NAME is ready! ***"
fi