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