treewide: use the generic board_name function
[openwrt/openwrt.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 tplink_get_hwid() {
8 local part
9
10 part=$(find_mtd_part u-boot)
11 [ -z "$part" ] && return 1
12
13 dd if=$part bs=4 count=1 skip=81728 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
14 }
15
16 tplink_get_image_hwid() {
17 get_image "$@" | dd bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
18 }
19
20 tplink_get_image_boot_size() {
21 get_image "$@" | dd bs=4 count=1 skip=37 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
22 }
23
24 platform_check_image() {
25 local board=$(board_name)
26 local magic="$(get_magic_long "$1")"
27
28 [ "$#" -gt 1 ] && return 1
29
30 case $board in
31 tl-wdr4900-v1)
32 [ "$magic" != "01000000" ] && {
33 echo "Invalid image type."
34 return 1
35 }
36
37 local hwid
38 local imageid
39
40 hwid=$(tplink_get_hwid)
41 imageid=$(tplink_get_image_hwid "$1")
42
43 [ "$hwid" != "$imageid" ] && {
44 echo "Invalid image, hardware ID mismatch, hw:$hwid image:$imageid."
45 return 1
46 }
47
48 local boot_size
49
50 boot_size=$(tplink_get_image_boot_size "$1")
51 [ "$boot_size" != "00000000" ] && {
52 echo "Invalid image, it contains a bootloader."
53 return 1
54 }
55
56 return 0
57 ;;
58 esac
59
60 echo "Sysupgrade is not yet supported on $board."
61 return 1
62 }
63
64 platform_do_upgrade() {
65 local board=$(board_name)
66
67 case "$board" in
68 *)
69 default_do_upgrade "$ARGV"
70 ;;
71 esac
72 }
73
74 disable_watchdog() {
75 killall watchdog
76 ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
77 echo 'Could not disable watchdog'
78 return 1
79 }
80 }
81
82 append sysupgrade_pre_upgrade disable_watchdog