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