11399a2629ec09b8d11742c8261caf7f03696f85
[openwrt/svn-archive/archive.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_do_upgrade() {
27 local board=$(octeon_board_name)
28 local rootfs="$(platform_get_rootfs)"
29
30 [ -d "${rootfs}" ] || return 1
31
32 case "$board" in
33 erlite)
34 local tar_file="$1"
35 local kernel_length=`(tar xf $tar_file sysupgrade-erlite/kernel -O | wc -c) 2> /dev/null`
36 local rootfs_length=`(tar xf $tar_file sysupgrade-erlite/root -O | wc -c) 2> /dev/null`
37
38 [ -f /boot/vmlinux.64 -a ! -L /boot/vmlinux.64 ] && {
39 mv /boot/vmlinux.64 /boot/vmlinux.64.previous
40 mv /boot/vmlinux.64.md5 /boot/vmlinux.64.md5.previous
41 }
42
43 mkdir -p /boot
44 mount -t vfat /dev/sda1 /boot
45 tar xf $tar_file sysupgrade-erlite/kernel -O > /boot/vmlinux.64
46 md5sum /boot/vmlinux.64 | cut -f1 -d " " > /boot/vmlinux.64.md5
47 tar xf $tar_file sysupgrade-erlite/root -O | dd of="${rootfs}" bs=4096
48 sync
49 umount /mnt
50 return 0
51 ;;
52 esac
53
54 return 1
55
56 }
57
58 platform_check_image() {
59 local board=$(octeon_board_name)
60
61 case "$board" in
62 erlite)
63 local tar_file="$1"
64 local kernel_length=`(tar xf $tar_file sysupgrade-erlite/kernel -O | wc -c) 2> /dev/null`
65 local rootfs_length=`(tar xf $tar_file sysupgrade-erlite/root -O | wc -c) 2> /dev/null`
66 [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
67 echo "The upgarde image is corrupt."
68 return 1
69 }
70 return 0
71 ;;
72 esac
73
74 echo "Sysupgrade is not yet supported on $board."
75 return 1
76 }