-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdKernel.sh
executable file
·331 lines (273 loc) · 10.6 KB
/
updKernel.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
323
324
325
326
327
328
329
330
331
#!/bin/bash
# This file is part of horOpenVario
# Copyright (C) 2017-2021 Kai Horstmann <horstmannkai@hotmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# set -x
export LANG=C.UTF-8
cleanup_and_exit_error () {
echo "Unmount the SD card image"
sync
sudo umount sdcard/sys
sudo umount sdcard/proc
sudo umount sdcard/dev/pts
sudo umount sdcard/dev
sudo umount sdcard/boot
sudo umount sdcard
sudo losetup -d /dev/loop5
exit 1
}
# Architecture of the target system
# Can be something like armhf, amd64, i386, arm64, s390 (haha)
# Must conform with existing Unbuntu architectures
if [ y$TARGETARCH = y ]
then
TARGETARCH=armhf
fi
# According to the architecture I may need the emulator to be able to chroot into the
# new root.
case $TARGETARCH in
armhf)
EMULATOR=qemu-arm-static
ARCH=arm
BUILDDIR=build
;;
i386)
EMULATOR=qemu-i386-static
ARCH=x86
BUILDDIR=build.i386
;;
arm64)
EMULATOR=qemu-aarch64-static
ARCH=arm64
BUILDDIR=build.arm64
;;
s390)
EMULATOR=qemu-s390x-static
ARCH=s390
BUILDDIR=build.s390
;;
*)
echo "Error: \$TARGETARCH is undefined or invalid. \$TARGETARCH = \"$TARGETARCH\""
exit 1
;;
esac
no_pause=0
if test x"$1" = "x--no-pause"
then
no_pause=1
fi
BASEDIR=`dirname $0`
BASEDIR="`(cd \"$BASEDIR\" ; BASEDIR=\`pwd\`; echo \"$BASEDIR\")`"
echo " BASEDIR = $BASEDIR"
export BASEDIR
cd $BASEDIR
./mountSDImage.sh
(
echo "Rebuild the kernel"
# Make sure that there is no stale modules directory left.
# I will derive the linux version from the modules directory name
rm -rf $BUILDDIR/kernel/debian/*
echo "Delete previous build artifacts"
rm $BUILDDIR/* 2>/dev/null
#echo "Clean the kernel"
# $BUILDDIR/kernel/build.sh clean
if [ $TARGETARCH = armhf ]
then
$BUILDDIR/kernel/build.sh dtbs || exit 1
echo "Copy the dtb"
sudo cp -v $BUILDDIR/kernel/arch/arm/boot/dts/sun7i-a20-cubieboard2.dtb sdcard/boot
fi # if [ $TARGETARCH = armhf ]
echo "Build Debian kernel package"
$BUILDDIR/kernel/build.sh -j8 bindeb-pkg || exit 1
) || cleanup_and_exit_error
if [ -d build/kernel/debian/tmp/lib/modules ]
then
LINUX_VERSION=`basename $BUILDDIR/kernel/debian/tmp/lib/modules/*`
else
LINUX_VERSION=`basename $BUILDDIR/kernel/debian/linux-image/lib/modules/*`
fi
echo "LINUX_VERSION = $LINUX_VERSION"
if test $no_pause = 0
then
echo "Hit enter to continue"
read x
fi
if [ $TARGETARCH = armhf ]
then
(
echo "Build the Mali kernel module"
cd src/sunxi-mali
# Clean the structure and prepare for a new build in case of a previous failure
CROSS_COMPILE=arm-linux-gnueabihf- KDIR=$BASEDIR/$BUILDDIR/kernel ./build.sh -r r8p1 -c >/dev/null 2>&1
CROSS_COMPILE=arm-linux-gnueabihf- KDIR=$BASEDIR/$BUILDDIR/kernel ./build.sh -r r8p1 -b || exit 1
) || cleanup_and_exit_error
if test $no_pause = 0
then
echo "Hit enter to continue"
read x
fi
(
echo "Install the Mali kernel module in the kernel DEB image"
cd src/sunxi-mali
if [ -d $BASEDIR/$BUILDDIR/kernel/debian/tmp ]
then
CROSS_COMPILE=arm-linux-gnueabihf- KDIR=$BASEDIR/$BUILDDIR/kernel INSTALL_MOD_PATH=$BASEDIR/$BUILDDIR/kernel/debian/tmp ./build.sh -r r8p1 -i || exit 1
else
CROSS_COMPILE=arm-linux-gnueabihf- KDIR=$BASEDIR/$BUILDDIR/kernel INSTALL_MOD_PATH=$BASEDIR/$BUILDDIR/kernel/debian/linux-image ./build.sh -r r8p1 -i || exit 1
fi
# undo the patches. Otherwise the next build will fail because applying the patches is part of the build option of build.sh
CROSS_COMPILE=arm-linux-gnueabihf- KDIR=$BASEDIR/$BUILDDIR/kernel ./build.sh -r r8p1 -u
exit 0
) || cleanup_and_exit_error
if test $no_pause = 0
then
echo "Hit enter to continue"
read x
fi
echo " "
echo "make boot script images"
( cd sdcard/boot ;
echo "# setenv bootm_boot_mode sec
setenv bootargs console=tty0 root=/dev/mmcblk0p2 rootwait consoleblank=0 panic=10 drm_kms_helper.drm_leak_fbdev_smem=1
ext2load mmc 0 0x43000000 sun7i-a20-cubieboard2.dtb
# Building the initrd is broken. The kernel boots without initrd just fine.
# ext2load mmc 0 0x44000000 initrd.img-$LINUX_VERSION
ext2load mmc 0 0x41000000 vmlinuz-$LINUX_VERSION
# Skip the initrd in the boot command.
# bootz 0x41000000 0x44000000 0x43000000
bootz 0x41000000 - 0x43000000" |sudo tee boot.cmd > /dev/null || cleanup_and_exit_error
echo " "
echo "Make boot script boot.scr from boot.cmd"
sudo mkimage -A arm -T script -C none -d boot.cmd boot.scr || cleanup_and_exit_error
) || cleanup_and_exit_error
echo " "
echo "Add boot script and device tree to the debian installer image"
if [ -d $BASEDIR/$BUILDDIR/kernel/debian/tmp ]
then
sudo cp -v sdcard/boot/boot.cmd sdcard/boot/boot.scr $BUILDDIR/kernel/debian/tmp/boot
sudo cp -v $BUILDDIR/kernel/arch/arm/boot/dts/sun7i-a20-cubieboard2.dtb $BUILDDIR/kernel/debian/tmp/boot
else
sudo cp -v sdcard/boot/boot.cmd sdcard/boot/boot.scr $BUILDDIR/kernel/debian/linux-image/boot
sudo cp -v $BUILDDIR/kernel/arch/arm/boot/dts/sun7i-a20-cubieboard2.dtb $BUILDDIR/kernel/debian/linux-image/boot
fi
if test $no_pause = 0
then
echo "Hit enter to continue"
read x
fi
(
echo "Re-build the linux image package including MALI"
cd $BASEDIR/$BUILDDIR/kernel
if [ -d $BASEDIR/$BUILDDIR/kernel/debian/tmp ]
then
dpkg-deb --root-owner-group --build "debian/tmp" .. || exit 1
else
dpkg-deb --root-owner-group --build "debian/linux-image" .. || exit 1
fi
)
if test $no_pause = 0
then
echo "Hit enter to continue"
read x
fi
fi # if [ $TARGETARCH = armhf ]
(
echo "Install kernel and modules and headers"
# uninstall and delete the debug kernel images when they exist
sudo chroot sdcard bin/bash -c "apt-get remove -y \"linux-image*\""
sudo chroot sdcard bin/bash -c "apt-get remove -y \"linux-headers*\""
#sudo chroot sdcard bin/bash -c "apt-get remove -y \"linux-libc-dev*\""
sudo rm -v sdcard/linux*.deb
# Clean the boot scripts and device tree. They are now supposed to come with the Debian installer
sudo rm -vf sdcard/boot/boot.cmd sdcard/boot/boot.scr sdcard/boot/sun7i-a20-cubieboard2.dtb
rm -fv $BUILDDIR/linux-image-$LINUX_VERSION-dbg*.deb
sudo cp -v $BUILDDIR/linux-*$LINUX_VERSION*.deb sdcard
sudo chroot sdcard bin/bash -c "dpkg -i linux-image-$LINUX_VERSION*.deb linux-headers-$LINUX_VERSION*.deb linux-libc-dev_$LINUX_VERSION*.deb" || exit 1
#sudo chroot sdcard bin/bash -c "dpkg -i linux-headers-$LINUX_VERSION*.deb" || exit 1
#sudo chroot sdcard bin/bash -c "dpkg -i linux-libc-dev_$LINUX_VERSION*.deb" || exit 1
#sudo rm -f sdcard/linux-*$LINUX_VERSION*.deb
) || cleanup_and_exit_error
if test $no_pause = 0
then
echo "Hit enter to continue"
read x
fi
echo "Build the Debian installer for the Mali R6P2 blob and includes"
sudo rm -rf build/mali-deb/* || cleanup_and_exit_error
mkdir build/mali-deb/DEBIAN || cleanup_and_exit_error
echo "Package: arm-mali-400-fbdev-blob
Version: 6.2
Section: custom
Priority: optional
Architecture: armhf
Essential: no
Installed-Size: 1060
Maintainer: https://github.com/hor63/horOpenVario
Description: MALI R6P2 userspace blob for fbdev device" > build/mali-deb/DEBIAN/control
mkdir build/mali-deb/usr || cleanup_and_exit_error
mkdir build/mali-deb/usr/include || cleanup_and_exit_error
mkdir build/mali-deb/usr/lib || cleanup_and_exit_error
mkdir build/mali-deb/usr/lib/arm-linux-gnueabihf || cleanup_and_exit_error
cp -Rpv src/mali-blobs/include/fbdev/* build/mali-deb/usr/include/ || cleanup_and_exit_error
cp -Rpv src/mali-blobs/r6p2/arm/fbdev/lib* build/mali-deb/usr/lib/arm-linux-gnueabihf/ || cleanup_and_exit_error
find build/mali-deb/usr/ -type d |xargs chmod -v 755
find build/mali-deb/usr/include -type f |xargs chmod -v 644
find build/mali-deb/usr/lib -type f |xargs chmod -v 755
dpkg-deb --root-owner-group --build build/mali-deb || cleanup_and_exit_error
sudo mv -v build/mali-deb.deb sdcard/mali-deb-R6P2.deb || cleanup_and_exit_error
sudo chroot sdcard bin/bash -c "dpkg -i mali-deb-R6P2.deb" || cleanup_and_exit_error
echo "Build the Debian installer for the Mali R8P1 blob and includes"
sudo rm -rf build/mali-deb/* || cleanup_and_exit_error
mkdir build/mali-deb/DEBIAN || cleanup_and_exit_error
echo "Package: arm-mali-400-fbdev-blob
Version: 8.1
Section: custom
Priority: optional
Architecture: armhf
Essential: no
Installed-Size: 1060
Maintainer: https://github.com/hor63/horOpenVario
Description: MALI R8P1 userspace blob for fbdev device" > build/mali-deb/DEBIAN/control
mkdir build/mali-deb/usr || cleanup_and_exit_error
mkdir build/mali-deb/usr/include || cleanup_and_exit_error
mkdir build/mali-deb/usr/lib || cleanup_and_exit_error
mkdir build/mali-deb/usr/lib/arm-linux-gnueabihf || cleanup_and_exit_error
cp -Rpv src/mali-blobs/include/fbdev/* build/mali-deb/usr/include/ || cleanup_and_exit_error
cp -Rpv src/mali-blobs/r8p1/arm/fbdev/lib* build/mali-deb/usr/lib/arm-linux-gnueabihf/ || cleanup_and_exit_error
find build/mali-deb/usr/ -type d |xargs chmod -v 755
find build/mali-deb/usr/include -type f |xargs chmod -v 644
find build/mali-deb/usr/lib -type f |xargs chmod -v 755
dpkg-deb --root-owner-group --build build/mali-deb || cleanup_and_exit_error
sudo mv -v build/mali-deb.deb sdcard/mali-deb-R8P1.deb || cleanup_and_exit_error
# sudo chroot sdcard bin/bash -c "dpkg -i mali-deb-R8P1.deb" || cleanup_and_exit_error
if test $no_pause = 0
then
echo "-------------- Almost done --------------------"
echo "Hit enter to continue"
read x
fi
echo "Unmount the SD card image"
sync
sudo umount sdcard/sys
sudo umount sdcard/proc
sudo umount sdcard/dev/pts
sudo umount sdcard/dev
sudo umount sdcard/boot
sudo umount sdcard
sudo losetup -d /dev/loop5
#exit 0
echo "Copy the SD card image \"sd.img\" to the SD card raw device"
echo " ----------------- Done -------------------------"