octeon: sysupgrade: rename old kernel after mounting /boot
[openwrt.git] / target / linux / octeon / base-files / lib / upgrade / platform.sh
1 #
2 # Copyright (C) 2014 OpenWrt.org
3 #
4
5 . /lib/functions/octeon.sh
6
7 platform_get_rootfs() {
8         local rootfsdev
9
10         if read cmdline < /proc/cmdline; then
11                 case "$cmdline" in
12                         *block2mtd=*)
13                                 rootfsdev="${cmdline##*block2mtd=}"
14                                 rootfsdev="${rootfsdev%%,*}"
15                         ;;
16                         *root=*)
17                                 rootfsdev="${cmdline##*root=}"
18                                 rootfsdev="${rootfsdev%% *}"
19                         ;;
20                 esac
21
22                 echo "${rootfsdev}"
23         fi
24 }
25
26 platform_copy_config() {
27         local board="$(octeon_board_name)"
28         local rootfs="$(platform_get_rootfs)"
29
30         mount -t ext4 -o rw,noatime "${rootfs}" /mnt
31         cp -af "$CONF_TAR" /mnt/
32         umount /mnt
33 }
34
35 platform_do_upgrade() {
36         local board=$(octeon_board_name)
37         local rootfs="$(platform_get_rootfs)"
38
39         [ -b "${rootfs}" ] || return 1
40
41         case "$board" in
42         erlite)
43                 local tar_file="$1"
44                 local kernel_length=`(tar xf $tar_file sysupgrade-erlite/kernel -O | wc -c) 2> /dev/null`
45                 local rootfs_length=`(tar xf $tar_file sysupgrade-erlite/root -O | wc -c) 2> /dev/null`
46
47                 mkdir -p /boot
48                 mount -t vfat /dev/sda1 /boot
49
50                 [ -f /boot/vmlinux.64 -a ! -L /boot/vmlinux.64 ] && {
51                         mv /boot/vmlinux.64 /boot/vmlinux.64.previous
52                         mv /boot/vmlinux.64.md5 /boot/vmlinux.64.md5.previous
53                 }
54
55                 tar xf $tar_file sysupgrade-erlite/kernel -O > /boot/vmlinux.64
56                 md5sum /boot/vmlinux.64 | cut -f1 -d " " > /boot/vmlinux.64.md5
57                 tar xf $tar_file sysupgrade-erlite/root -O | dd of="${rootfs}" bs=4096
58                 sync
59                 umount /boot
60                 return 0
61                 ;;
62         esac
63
64         return 1
65         
66 }
67
68 platform_check_image() {
69         local board=$(octeon_board_name)
70
71         case "$board" in
72         erlite)
73                 local tar_file="$1"
74                 local kernel_length=`(tar xf $tar_file sysupgrade-erlite/kernel -O | wc -c) 2> /dev/null`
75                 local rootfs_length=`(tar xf $tar_file sysupgrade-erlite/root -O | wc -c) 2> /dev/null`
76                 [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
77                         echo "The upgarde image is corrupt."
78                         return 1
79                 }
80                 return 0
81                 ;;
82         esac
83
84         echo "Sysupgrade is not yet supported on $board."
85         return 1
86 }