octeon: add support for Itus Shield Router
[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 "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
29 umount /mnt
30 ;;
31 itus,shield-router)
32 mount -t vfat /dev/mmcblk1p1 /mnt
33 cp -af "$UPGRADE_BACKUP" "/mnt/$BACKUP_FILE"
34 umount /mnt
35 ;;
36 esac
37 }
38
39 platform_do_flash() {
40 local tar_file=$1
41 local board=$2
42 local kernel=$3
43 local rootfs=$4
44
45 local board_dir=$(tar tf "$tar_file" | grep -m 1 '^sysupgrade-.*/$')
46 board_dir=${board_dir%/}
47 [ -n "$board_dir" ] || return 1
48
49 mkdir -p /boot
50
51 if [ $board = "itus,shield-router" ]; then
52 # mmcblk1p1 (fat) contains all ELF-bin images for the Shield
53 mount /dev/mmcblk1p1 /boot
54
55 echo "flashing Itus Kernel to /boot/$kernel (/dev/mmblk1p1)"
56 tar -Oxf $tar_file "$board_dir/kernel" > /boot/$kernel
57 else
58 mount -t vfat /dev/$kernel /boot
59
60 [ -f /boot/vmlinux.64 -a ! -L /boot/vmlinux.64 ] && {
61 mv /boot/vmlinux.64 /boot/vmlinux.64.previous
62 mv /boot/vmlinux.64.md5 /boot/vmlinux.64.md5.previous
63 }
64
65 echo "flashing kernel to /dev/$kernel"
66 tar xf $tar_file $board_dir/kernel -O > /boot/vmlinux.64
67 md5sum /boot/vmlinux.64 | cut -f1 -d " " > /boot/vmlinux.64.md5
68 fi
69
70 echo "flashing rootfs to ${rootfs}"
71 tar xf $tar_file $board_dir/root -O | dd of="${rootfs}" bs=4096
72
73 sync
74 umount /boot
75 }
76
77 platform_do_upgrade() {
78 local tar_file="$1"
79 local board=$(board_name)
80 local rootfs="$(platform_get_rootfs)"
81 local kernel=
82
83 [ -b "${rootfs}" ] || return 1
84 case "$board" in
85 er)
86 kernel=mmcblk0p1
87 ;;
88 erlite)
89 kernel=sda1
90 ;;
91 itus,shield-router)
92 kernel=ItusrouterImage
93 ;;
94 *)
95 return 1
96 esac
97
98 platform_do_flash $tar_file $board $kernel $rootfs
99
100 return 0
101 }
102
103 platform_check_image() {
104 local board=$(board_name)
105 local tar_file="$1"
106
107 local board_dir=$(tar tf "$tar_file" | grep -m 1 '^sysupgrade-.*/$')
108 board_dir=${board_dir%/}
109 [ -n "$board_dir" ] || return 1
110
111 case "$board" in
112 er | \
113 erlite | \
114 itus,shield-router)
115 local kernel_length=$(tar xf $tar_file $board_dir/kernel -O | wc -c 2> /dev/null)
116 local rootfs_length=$(tar xf $tar_file $board_dir/root -O | wc -c 2> /dev/null)
117 [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
118 echo "The upgrade image is corrupt."
119 return 1
120 }
121 return 0
122 ;;
123 esac
124
125 echo "Sysupgrade is not yet supported on $board."
126 return 1
127 }