mpc85xx: Add Aerohive HiveAP-330 Access Point
[openwrt/staging/stintel.git] / target / linux / mpc85xx / base-files / lib / upgrade / platform.sh
1 #
2 # Copyright (C) 2011 OpenWrt.org
3 #
4
5 PART_NAME=firmware
6
7 get_magic_long_at() {
8 (get_image "$1" | dd bs=4 count=1 skip="$2" | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null
9 }
10
11 tplink_get_hwid() {
12 local part
13
14 part=$(find_mtd_part u-boot)
15 [ -z "$part" ] && return 1
16
17 dd if=$part bs=4 count=1 skip=81728 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
18 }
19
20 tplink_get_image_hwid() {
21 get_image "$@" | dd bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
22 }
23
24 tplink_get_image_boot_size() {
25 get_image "$@" | dd bs=4 count=1 skip=37 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
26 }
27
28 platform_check_image() {
29 local board=$(board_name)
30 local magic="$(get_magic_long "$1")"
31
32 [ "$#" -gt 1 ] && return 1
33
34 case $board in
35 hiveap-330)
36 local init_magic=$(get_magic_long_at "$1" "65536")
37 local root_magic=$(get_magic_long_at "$1" "131072")
38 local kernel_magic=$(get_magic_long_at "$1" "10551296")
39
40 [ "$magic" != "d00dfeed" ] && {
41 echo "Invalid dtb image type."
42 return 1
43 }
44 [ "$init_magic" != "27051956" ] && {
45 echo "Invalid initramfs image type."
46 return 1
47 }
48 [ "$root_magic" != "68737173" ] && {
49 echo "Invalid rootfs image type."
50 return 1
51 }
52 [ "$kernel_magic" != "27051956" ] && {
53 echo "Invalid kernel image type."
54 return 1
55 }
56 return 0
57 ;;
58 tl-wdr4900-v1)
59 [ "$magic" != "01000000" ] && {
60 echo "Invalid image type."
61 return 1
62 }
63
64 local hwid
65 local imageid
66
67 hwid=$(tplink_get_hwid)
68 imageid=$(tplink_get_image_hwid "$1")
69
70 [ "$hwid" != "$imageid" ] && {
71 echo "Invalid image, hardware ID mismatch, hw:$hwid image:$imageid."
72 return 1
73 }
74
75 local boot_size
76
77 boot_size=$(tplink_get_image_boot_size "$1")
78 [ "$boot_size" != "00000000" ] && {
79 echo "Invalid image, it contains a bootloader."
80 return 1
81 }
82
83 return 0
84 ;;
85 esac
86
87 echo "Sysupgrade is not yet supported on $board."
88 return 1
89 }
90
91 platform_do_upgrade() {
92 local board=$(board_name)
93
94 case "$board" in
95 *)
96 default_do_upgrade "$ARGV"
97 ;;
98 esac
99 }
100
101 disable_watchdog() {
102 killall watchdog
103 ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
104 echo 'Could not disable watchdog'
105 return 1
106 }
107 }
108
109 append sysupgrade_pre_upgrade disable_watchdog