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