-
Notifications
You must be signed in to change notification settings - Fork 36
/
kernel_update.sh
485 lines (403 loc) · 15.7 KB
/
kernel_update.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#!/bin/bash
# Kernel update constants.
KTMP="/tmp/kupdate"
# Boot.Scr's
BOOT_SCR_UBUNTU="http://builder.mdrjr.net/tools/boot.scr_ubuntu.tar"
BOOT_SCR_UBUNTU_XU="http://builder.mdrjr.net/tools/boot.scr_ubuntu_xu.tar"
BOOT_SCR_FEDORA20="http://builder.mdrjr.net/tools/boot.scr_fedora20.tar"
BOOT_SCR_FEDORA20_XU="http://builder.mdrjr.net/tools/boot.scr_fedora20_xu.tar"
BOOT_SCR_UBUNTU_XU3="http://builder.mdrjr.net/tools/odroidxu3.boot.ini"
GOVERNOR_XU3="https://raw.githubusercontent.com/mdrjr/5422_bootini/master/ondemand"
# Firmware
FIRMWARE_URL="http://builder.mdrjr.net/tools/firmware.tar.xz"
# Kernel builds
export K_PKG_URL="http://builder.mdrjr.net/kernel-3.8/00-LATEST"
export XU_K_PKG_URL="http://builder.mdrjr.net/kernel-3.4/00-LATEST"
export XU3_K_PKG_URL="http://builder.mdrjr.net/kernel-3.10/00-LATEST"
export C_K_PKG_URL="http://builder.mdrjr.net/kernel-3.10-c/00-LATEST"
kernel_update() {
get_board
while true; do
KO=$(whiptail --backtitle "Hardkernel ODROID Utility v$_REV" --menu "Kernel Update/Configuration" 0 0 0 \
"1" "Update Kernel" \
"2" "Install firmware files to /lib/firmware" \
"3" "Update boot scripts" \
"4" "Update udev rules for ODROID subdevices (mali, cec..)" \
"5" "Update the bootloader" \
"6" "Exit" \
3>&1 1>&2 2>&3)
KR=$?
if [ $KR -eq 1 ]; then
return 0
else
case "$KO" in
"1") do_kernel_update ;;
"2") do_firmware_update ;;
"3") do_bootscript_update ;;
"4") do_udev_update ;;
"5") do_bootloader_update ;;
"6") break;;
*) msgbox "KERNEL-UPDATE: Error. You shouldn't be here. Value $KO please report this on the forums" ;;
esac
fi
done
}
do_kernel_download() {
rm -fr $KTMP
mkdir -p $KTMP
cd $KTMP
if [ "$BOARD" = "odroidxu" ]; then
dlf_fast $XU_K_PKG_URL/$BOARD.tar.xz "Downloading ODROID-XU Kernel. Please wait." $KTMP/$BOARD.tar.xz
dlf_fast $XU_K_PKG_URL/$BOARD.tar.xz.md5sum "Downloading ODROID-XU Kernel MD5SUM. Please wait." $KTMP/$BOARD.tar.xz.md5sum
elif [ "$BOARD" = "odroidxu3" ]; then
dlf_fast $XU3_K_PKG_URL/$BOARD.tar.xz "Downloading ODROID-XU3 Kernel. Please wait." $KTMP/$BOARD.tar.xz
dlf_fast $XU3_K_PKG_URL/$BOARD.tar.xz.md5sum "Downloading ODROID-XU3 Kernel MD5SUM. Please wait." $KTMP/$BOARD.tar.xz.md5sum
elif [ "$BOARD" = "odroidc" ]; then
dlf_fast $C_K_PKG_URL/odroidc.tar.xz "Downloading ODROID-C1 kernel. Please wait." $KTMP/odroidc.tar.xz
dlf_fast $C_K_PKG_URL/odroidc.tar.xz.md5sum "Downloading ODROID-C1 Kernel MD5SUM. Please Wait." $KTMP/odroidc.tar.xz.md5sum
else
dlf_fast $K_PKG_URL/$BOARD.tar.xz "Downloading $BOARD Kernel. Please Wait." $KTMP/$BOARD.tar.xz
dlf_fast $K_PKG_URL/$BOARD.tar.xz.md5sum "Downloading $BOARD Kernel MD5SUM. Please Wait." $KTMP/$BOARD.tar.xz.md5sum
fi
VALID=`cat $KTMP/$BOARD.tar.xz.md5sum | awk '{printf $1}'`
CURRENT=`md5sum $KTMP/$BOARD.tar.xz | awk '{printf $1}'`
if [ "$VALID" != "$CURRENT" ]; then
msgbox "There was a issue downloading the kernel. Application will exit."
exit
fi
}
do_kernel_update() {
if [ "$BOARD" = "odroidc" ]; then
if [ ! -f /etc/apt/sources.list.d/odroid.list ]; then
if ! whiptail --yesno "It looks like you are running image 1.0 or 1.1 for -C1. I can upgrade this to 1.2 for you. I need 500MB of disk space to do that. Are you ok with it ?" 0 0; then
return
else
curl -s deb.odroid.in/v1.1_to_v1.2.sh | bash
return
fi
else
apt-get -y update
apt-get -y dist-upgrade
apt-get -y install linux-image-c1
msgbox "Your system is now up to date."
return
fi
fi
do_5422_1504_apt_update
do_kernel_download
case "$DISTRO" in
"ubuntu")
do_ubuntu_kernel_update ;;
"debian")
do_debian_kernel_update ;;
*) msgbox "KERNEL-UPDATE: Distro not found. Shouldn't be here. Please report on the forums" ;;
esac
}
do_firmware_update() {
do_5422_1504_apt_update
if [ "$BOARD" = "odroidc" ]; then
apt-get -y update
apt-get -y install linux-firmware
msgbox "linux-firmware package install or updated."
return
fi
rm -rf $KTMP
mkdir -p $KTMP
cd $KTMP
dlf_fast $FIRMWARE_URL "Downloading Linux Firmware files (/lib/firmware)" $KTMP/firmware.tar.xz
echo "Updating the firmware"
xz -d firmware.tar.xz
(cd /lib/firmware && tar xf $KTMP/firmware.tar)
msgbox "KERNEL-UPDATE: Done. Firmware updated"
rm -fr $KTMP
}
do_bootscript_update() {
rm -fr $KTMP
mkdir -p $KTMP
cd $KTMP
do_5422_1504_apt_update
if [ "$BOARD" = "odroidc" ]; then
msgbox "Please use apt-get update && apt-get dist-upgrade to upgrade your board."
return
fi
case "$DISTRO" in
"ubuntu")
if [ "$BOARD" = "odroidxu" ]; then
dlf $BOOT_SCR_UBUNTU_XU "Download boot.ini for ODROID-XU" $KTMP/bscrxu.tar
tar xf bscrxu.tar
cp $KTMP/xu/* /media/boot
elif [ "$BOARD" = "odroidx2" ] || [ "$BOARD" = "odroidu2" ]; then
dlf $BOOT_SCR_UBUNTU "Downloading boot.scr's for $BOARD" $KTMP/prime.tar
tar xf prime.tar
cp $KTMP/x2u2/*.scr /media/boot
elif [ "$BOARD" = "odroidx" ]; then
dlf $BOOT_SCR_UBUNTU "Downloading boot.scr's for ODROID-X" $KTMP/reg.tar
tar xf reg.tar
cp $KTMP/x/*.scr /media/boot
elif [ "$BOARD" = "odroidxu3" ]; then
dlf $BOOT_SCR_UBUNTU_XU3 "Updating boot.ini for ODROID-XU3" /media/boot/boot.ini
dlf $GOVERNOR_XU3 "Upading governor setup for ODROID-XU3" /etc/init.d/ondemand
fi
;;
"debian")
if [ "$BOARD" = "odroidxu" ]; then
dlf $BOOT_SCR_UBUNTU_XU "Download boot.ini for ODROID-XU" $KTMP/bscrxu.tar
tar xf bscrxu.tar
cp $KTMP/xu/* /boot
elif [ "$BOARD" = "odroidx2" ] || [ "$BOARD" = "odroidu2" ]; then
dlf $BOOT_SCR_UBUNTU "Downloading boot.scr's for $BOARD" $KTMP/prime.tar
tar xf prime.tar
cp $KTMP/x2u2/*.scr /boot
elif [ "$BOARD" = "odroidx" ]; then
dlf $BOOT_SCR_UBUNTU "Downloading boot.scr's for ODROID-X" $KTMP/reg.tar
tar xf reg.tar
cp $KTMP/x/*.scr /boot
elif [ "$BOARD" = "odroidxu3" ]; then
dlf $BOOT_SCR_UBUNTU_XU3 "Updating boot.ini for ODROID-XU3" /media/boot/boot.ini
fi
;;
*)
msgbox "KERNEL-UPDATE: bootscript: Distro not supported"
;;
esac
msgbox "KERNEL-UPDATE: boostscript: Boot scripts updated"
}
do_udev_update() {
do_5422_1504_apt_update
if [ "$DISTRO" = "ubuntu" ] || [ "$DISTRO" = "debian" ]; then
echo "KERNEL==\"mali\",SUBSYSTEM==\"misc\",MODE=\"0777\"" > /etc/udev/rules.d/10-odroid.rules
echo "KERNEL==\"mali0\",SUBSYSTEM==\"misc\",MODE=\"0777\"" >> /etc/udev/rules.d/10-odroid.rules
echo "KERNEL==\"ump\",SUBSYSTEM==\"ump\",MODE=\"0777\"" >> /etc/udev/rules.d/10-odroid.rules
echo "KERNEL==\"ttySAC0\", SYMLINK+=\"ttyACM99\"" >> /etc/udev/rules.d/10-odroid.rules
echo "KERNEL==\"event*\", SUBSYSTEM==\"input\", MODE=\"0777\"" >> /etc/udev/rules.d/10-odroid.rules
echo "KERNEL==\"CEC\", MODE=\"0777\"" >> /etc/udev/rules.d/10-odroid.rules
echo "KERNEL==\"amvideo\", MODE=\"0666\"" >> /etc/udev/rules.d/10-odroid.rules
echo "KERNEL==\"amstream*\", MODE=\"0666\"" >> /etc/udev/rules.d/10-odroid.rules
fi
msgbox "KERNEL-UPDATE: UDEV: udev rules for ODROID Installed"
}
do_bootloader_update() {
do_5422_1504_apt_update
if [ "$BOARD" = "odroidc" ]; then
msgbox "Please use apt-get update && apt-get dist-upgrade to upgrade your board."
return
fi
device=/dev/mmcblk0
D="SDCard"
if [ -f /sys/block/mmcblk0boot0/force_ro ]; then
emmc=1
D="eMMC"
device=/dev/mmcblk0boot0
if ! echo 0 > /sys/block/mmcblk0boot0/force_ro; then
msgbox "I've found a running eMMC but I couldn't get it to accept the new bootloaders."
return
fi
fi
if [ -n "$emmc" ]; then
# Going eMMC Mode
if [ "$BOARD" = "odroidx" ] || [ "$BOARD" = "odroidx2" ] || [ "$BOARD" = "odroidu2" ]; then
# 4412 eMMC Positions
signed_bl1_position=0
bl2_position=30
uboot_position=62
tzsw_position=2110
elif [ "$BOARD" = "odroidxu3" ]; then
# 5422 eMMC Positions
signed_bl1_position=0
bl2_position=30
uboot_position=62
tzsw_position=718
fi
else
if [ "$BOARD" = "odroidx" ] || [ "$BOARD" = "odroidx2" ] || [ "$BOARD" = "odroidu2" ]; then
# 4412 SD Positions
signed_bl1_position=1
bl2_position=31
uboot_position=63
tzsw_position=2111
elif [ "$BOARD" = "odroidxu3" ]; then
# 5422 SD Positions
signed_bl1_position=1
bl2_position=31
uboot_position=63
tzsw_position=719
else
msgbox "Your board isn't supported"
fi
fi
BLTEMP=/tmp/blTemp
rm -fr $BLTEMP
mkdir $BLTEMP
if ! whiptail --yesno "I found that you booted from a $D. If that's correct say Yes and I'll download and update your bootloaders. Otherwise please say NO" 0 0; then
msgbox "Understood! Aborting!"
return
fi
if [ "$BOARD" = "odroidxu3" ]; then
# 5422 Update
# bl1
echo "*** Downloading Bootloaders for ODROID-XU3"
if ! curl -s https://raw.githubusercontent.com/hardkernel/u-boot/odroidxu3-v2012.07/sd_fuse/hardkernel/bl1.bin.hardkernel > $BLTEMP/bl1.bin; then
msgbox "Something wrong with the Download. Will now quit"
break
fi
# bl2
if ! curl -s https://raw.githubusercontent.com/hardkernel/u-boot/odroidxu3-v2012.07/sd_fuse/hardkernel/bl2.bin.hardkernel > $BLTEMP/bl2.bin; then
msgbox "Something wrong with the Download. Will now quit"
break
fi
# u-boot
if ! curl -s https://raw.githubusercontent.com/hardkernel/u-boot/odroidxu3-v2012.07/sd_fuse/hardkernel/u-boot.bin.hardkernel > $BLTEMP/uboot.bin; then
msgbox "Something wrong with the Download. Will now quit"
break
fi
#tzsw
if ! curl -s https://raw.githubusercontent.com/hardkernel/u-boot/odroidxu3-v2012.07/sd_fuse/hardkernel/tzsw.bin.hardkernel > $BLTEMP/tzsw.bin; then
msgbox "Something wrong with the Download. Will now quit"
break
fi
elif [ "$BOARD" = "odroidx" ] || [ "$BOARD" = "odroidx2" ] || [ "$BOARD" = "odroidu2" ]; then
# 4412 Update
# bl1
echo "*** Downloading Bootloaders for ODROID-X/X2/U2/U3"
if ! curl -s https://raw.githubusercontent.com/hardkernel/u-boot/odroid-v2010.12/sd_fuse/bl1.HardKernel > $BLTEMP/bl1.bin; then
msgbox "Something wrong with the Download. Will now quit"
break
fi
# bl2
if ! curl -s https://raw.githubusercontent.com/hardkernel/u-boot/odroid-v2010.12/sd_fuse/bl2.HardKernel > $BLTEMP/bl2.bin; then
msgbox "Something wrong with the Download. Will now quit"
break
fi
# u-boot
if ! curl -s https://raw.githubusercontent.com/hardkernel/u-boot/odroid-v2010.12/sd_fuse/u-boot.bin.HardKernel > $BLTEMP/uboot.bin; then
msgbox "Something wrong with the Download. Will now quit"
break
fi
#tzsw
if ! curl -s https://raw.githubusercontent.com/hardkernel/u-boot/odroid-v2010.12/sd_fuse/tzsw.HardKernel > $BLTEMP/tzsw.bin; then
msgbox "Something wrong with the Download. Will now quit"
break
fi
else
msgbox "Your board: $BOARD isn't supported yet"
return
fi
echo "*** Updating bl1"
dd iflag=dsync oflag=dsync if=$BLTEMP/bl1.bin of=$device seek=$signed_bl1_position
echo "*** Updating bl2"
dd iflag=dsync oflag=dsync if=$BLTEMP/bl2.bin of=$device seek=$bl2_position
echo "*** Updating U-Boot"
dd iflag=dsync oflag=dsync if=$BLTEMP/uboot.bin of=$device seek=$uboot_position
echo "*** Update tzsw"
dd iflag=dsync oflag=dsync if=$BLTEMP/tzsw.bin of=$device seek=$tzsw_position
msgbox "Bootloader Update complete"
}
do_ubuntu_kernel_update() {
cd $KTMP
echo "*** Installing new kernel. Please wait. A backup and log will be saved on /root"
export klog=/root/kernel_update-log-$DATE.txt
tar -Jcf /root/kernel-backup-$DATE.tar.xz /lib/modules /media/boot &>> $klog
xz -d $BOARD.tar.xz &>> $klog
tar xf $BOARD.tar &>> $klog
rm -fr /media/boot/exynos5422-odroidxu3.dtb /media/boot/meson8b_odroidc.dtb /media/boot/zImage* /media/boot/uImage* /media/boot/uInitrd* /lib/modules/3.10* /lib/modules/3.8.13* /lib/modules/3.4* &>> $klog
if [ "$BOARD" = "odroidc" ]; then
cp -aRP boot/uImage /media/boot/uImage &>> $klog
cp -aRP boot/meson8b_odroidc.dtb /media/boot/meson8b_odroidc.dtb &>> $klog
else
cp -aRP boot/zImage /media/boot/zImage &>> $klog
fi
if [ "$BOARD" = "odroidxu3" ]; then
cp -aRP boot/exynos5422-odroidxu3.dtb /media/boot/exynos5422-odroidxu3.dtb &>> $klog
fi
cp -aRP lib/modules/* /lib/modules &>> $klog
if [ -f /etc/initramfs-tools/initramfs.conf ]; then
cat /etc/initramfs-tools/initramfs.conf | sed s/"MODULES=most"/"MODULES=dep"/g > /tmp/a.conf
mv /tmp/a.conf /etc/initramfs-tools/initramfs.conf
fi
export K_VERSION=`ls $KTMP/boot/config-* | sed s/"-"/" "/g | awk '{printf $2}'`
cp $KTMP/boot/config-* /boot
update-initramfs -c -k $K_VERSION &>> $klog
mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n "uInitrd $K_VERSION" -d /boot/initrd.img-$K_VERSION /boot/uInitrd-$K_VERSION &>> $klog
cp /boot/uInitrd-$K_VERSION /media/boot/uInitrd
if [ "$BOARD" = "odroidxu" ]; then
axel -o $KTMP/hwc.tar -n 2 -q http://builder.mdrjr.net/tools/xubuntu_hwcomposer.tar &>> $klog
(cd /usr && tar xf $KTMP/hwc.tar) &>> $klog
fi
if [ -f /etc/initramfs/post-update.d/flash-kernel ]; then
echo '#!/bin/bash' > /etc/initramfs/post-update.d/flash-kernel
echo "exit 0" >> /etc/initramfs/post-update.d/flash-kernel
chmod +x /etc/initramfs/post-update.d/flash-kernel
fi
if [ "$BOARD" != "odroidxu" ]; then
update_hwclock
fi
if [ "$BOARD" = "odroidx" ] || [ "$BOARD" = "odroidx2" ]; then
cp $KTMP/boot/zImage.lcdkit /media/boot
fi
msgbox "KERNEL-UPDATE: Done. Your kernel should be updated now.
Check /root for the backup and log files.
BACKUP: /root/kernel-backup-$DATE.tar.xz
LOG: $klog"
rm -fr $KTMP
}
do_debian_kernel_update() {
cd $KTMP
echo "*** Installing new kernel. Please way. A backup and log will be saved on /root"
export klog=/root/kernel_update-log-$DATE.txt
tar -Jcf /root/kernel-backup-$DATE.tar.xz /lib/modules /boot &>> $klog
xz -d $BOARD.tar.xz &>> $klog
tar xf $BOARD.tar &>> $klog
rm -fr /boot/exynos5422-odroidxu3.dtb /boot/zImage* /boot/uImage* /boot/uInitrd* /lib/modules/3.8.13* /lib/modules/3.4* &>> $klog
cp -aRP boot/zImage /boot/zImage &>> $klog
if [ "$BOARD" = "odroidxu3" ]; then
cp -aRP boot/exynos5422-odroidxu3.dtb /boot/exynos5422-odroidxu3.dtb &>> $klog
fi
cp -aRP lib/modules/* /lib/modules &>> $klog
if [ -f /etc/initramfs-tools/initramfs.conf ]; then
cat /etc/initramfs-tools/initramfs.conf | sed s/"MODULES=most"/"MODULES=dep"/g > /tmp/a.conf
mv /tmp/a.conf /etc/initramfs-tools/initramfs.conf
fi
export K_VERSION=`ls $KTMP/boot/config-* | sed s/"-"/" "/g | awk '{printf $2}'`
cp $KTMP/boot/config-* /boot
update-initramfs -c -k $K_VERSION &>> $klog
mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n "uInitrd $K_VERSION" -d /boot/initrd.img-$K_VERSION /boot/uInitrd-$K_VERSION &>> $klog
cp /boot/uInitrd-$K_VERSION /boot/uInitrd
if [ "$BOARD" = "odroidxu" ]; then
axel -o $KTMP/hwc.tar -n 2 -q http://builder.mdrjr.net/tools/xubuntu_hwcomposer.tar &>> $klog
(cd /usr && tar xf $KTMP/hwc.tar) &>> $klog
fi
if [ "$BOARD" != "odroidxu" ]; then
update_hwclock
fi
if [ "$BOARD" = "odroidx" ] || [ "$BOARD" = "odroidx2" ]; then
cp $KTMP/boot/zImage.lcdkit /boot
fi
msgbox "KERNEL-UPDATE: Done. Your kernel should be updated now.
Check /root for the backup and log files.
BACKUP: /root/kernel-backup-$DATE.tar.xz
LOG: $klog"
rm -fr $KTMP
}
update_hwclock() {
do_5422_1504_apt_update
mv /sbin/hwclock /sbin/hwclock.orig
axel -o /sbin/hwclock -q http://builder.mdrjr.net/tools/hwclock &>> $klog
chmod 0755 /sbin/hwclock
}
install_headers() {
do_5422_1504_apt_update
if [ "$BOARD" = "odroidxu3" ]; then
if [ "$DISTRO_VERSION" = "15.04" ] || [ "$DISTRO_VERSION" = "15.10" ]; then
apt-get -y install linux-headers-xu3
return
fi
fi
if [ "$BOARD" = "odroidc" ]; then
msgbox "Please use apt-get update && apt-get dist-upgrade to upgrade your board."
return
fi
rm -rf /usr/src/linux-*
mv $KTMP/usr/src/linux* /usr/src
rm -fr /lib/modules/$K_VERSION/build
ln -s /usr/src/linux-$K_VERSION /lib/modules/$K_VERSION/build
}