octeon: add er8 sysupgrade support
[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_flash() {
39 local tar_file=$1
40 local board=$2
41 local kernel=$3
42 local rootfs=$4
43
44 mkdir -p /boot
45 mount -t vfat /dev/$kernel /boot
46
47 [ -f /boot/vmlinux.64 -a ! -L /boot/vmlinux.64 ] && {
48 mv /boot/vmlinux.64 /boot/vmlinux.64.previous
49 mv /boot/vmlinux.64.md5 /boot/vmlinux.64.md5.previous
50 }
51
52 echo "flashing kernel to /dev/$kernel"
53 tar xf $tar_file sysupgrade-$board/kernel -O > /boot/vmlinux.64
54 md5sum /boot/vmlinux.64 | cut -f1 -d " " > /boot/vmlinux.64.md5
55 echo "flashing rootfs to ${rootfs}"
56 tar xf $tar_file sysupgrade-$board/root -O | dd of="${rootfs}" bs=4096
57 sync
58 umount /boot
59 }
60
61 platform_do_upgrade() {
62 local tar_file="$1"
63 local board=$(octeon_board_name)
64 local rootfs="$(platform_get_rootfs)"
65 local kernel=
66
67 [ -b "${rootfs}" ] || return 1
68 case "$board" in
69 erlite)
70 kernel=sda1
71 ;;
72 er)
73 kernel=mmcblk0p1
74 ;;
75 *)
76 return 1
77 esac
78
79 platform_do_flash $tar_file $board $kernel $rootfs
80
81 return 0
82
83 }
84
85 platform_check_image() {
86 local board=$(octeon_board_name)
87
88 case "$board" in
89 erlite | \
90 er)
91 local tar_file="$1"
92 local kernel_length=`(tar xf $tar_file sysupgrade-$board/kernel -O | wc -c) 2> /dev/null`
93 local rootfs_length=`(tar xf $tar_file sysupgrade-$board/root -O | wc -c) 2> /dev/null`
94 [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
95 echo "The upgarde image is corrupt."
96 return 1
97 }
98 return 0
99 ;;
100 esac
101
102 echo "Sysupgrade is not yet supported on $board."
103 return 1
104 }