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