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