ramips: add support for Ubiquiti EdgeRouter X (UBNT-ERX)
[openwrt.git] / target / linux / ramips / base-files / lib / upgrade / platform.sh
1 #
2 # Copyright (C) 2010 OpenWrt.org
3 #
4
5 . /lib/ramips.sh
6
7 PART_NAME=firmware
8 RAMFS_COPY_DATA=/lib/ramips.sh
9
10 platform_check_image() {
11         local board=$(ramips_board_name)
12         local magic="$(get_magic_long "$1")"
13
14         [ "$#" -gt 1 ] && return 1
15
16         case "$board" in
17         3g150b|\
18         3g300m|\
19         3g-6200n|\
20         3g-6200nl|\
21         a5-v11|\
22         ai-br100|\
23         air3gii|\
24         all0239-3g|\
25         all0256n|\
26         all5002|\
27         all5003|\
28         ar725w|\
29         asl26555|\
30         awapn2403|\
31         awm002-evb|\
32         awm003-evb|\
33         bc2|\
34         broadway|\
35         carambola|\
36         cf-wr800n|\
37         d105|\
38         dap-1350|\
39         db-wrt01|\
40         dcs-930|\
41         dcs-930l-b1|\
42         dir-300-b1|\
43         dir-300-b7|\
44         dir-320-b1|\
45         dir-600-b1|\
46         dir-600-b2|\
47         dir-615-d|\
48         dir-615-h1|\
49         dir-620-a1|\
50         dir-620-d1|\
51         dir-810l|\
52         e1700|\
53         esr-9753|\
54         f7c027|\
55         firewrt|\
56         fonera20n|\
57         freestation5|\
58         hc5*61|\
59         hg255d|\
60         hlk-rm04|\
61         hpm|\
62         ht-tm02|\
63         hw550-3g|\
64         ip2202|\
65         linkits7688|\
66         linkits7688d|\
67         m2m|\
68         m3|\
69         m4|\
70         microwrt|\
71         miniembplug|\
72         miniembwifi|\
73         miwifi-mini|\
74         mlw221|\
75         mlwg2|\
76         mofi3500-3gn|\
77         mpr-a1|\
78         mpr-a2|\
79         mr-102n|\
80         mzk-dp150n|\
81         mzk-w300nh2|\
82         nbg-419n|\
83         nw718|\
84         oy-0001|\
85         pbr-m1|\
86         psr-680w|\
87         px-4885|\
88         re6500|\
89         rp-n53|\
90         rt5350f-olinuxino|\
91         rt5350f-olinuxino-evb|\
92         rt-g32-b1|\
93         rt-n10-plus|\
94         rt-n13u|\
95         rt-n14u|\
96         rt-n15|\
97         rt-n56u|\
98         rut5xx|\
99         sap-g3200u3|\
100         sl-r7205|\
101         tew-691gr|\
102         tew-692gr|\
103         tiny-ac|\
104         ur-326n4g|\
105         ur-336un|\
106         v22rw-2x2|\
107         vocore|\
108         w150m|\
109         w306r-v20|\
110         w502u|\
111         wf-2881|\
112         whr-1166d|\
113         whr-300hp2|\
114         whr-600d|\
115         whr-g300n|\
116         witi|\
117         wizfi630a|\
118         wl-330n|\
119         wl-330n3g|\
120         wl-341v3|\
121         wl-351|\
122         wli-tx4-ag300n|\
123         wmr-300|\
124         wnce2001|\
125         wr512-3gn|\
126         wr6202|\
127         wrtnode|\
128         wsr-600|\
129         wt1520|\
130         wt3020|\
131         wzr-agl300nh|\
132         x5|\
133         x8|\
134         y1|\
135         y1s|\
136         zbt-wa05|\
137         zbt-wg2626|\
138         zbt-wr8305rt|\
139         zte-q7|\
140         youku-yk1)
141                 [ "$magic" != "27051956" ] && {
142                         echo "Invalid image type."
143                         return 1
144                 }
145                 return 0
146                 ;;
147         ar670w)
148                 [ "$magic" != "6d000080" ] && {
149                         echo "Invalid image type."
150                         return 1
151                 }
152                 return 0
153                 ;;
154         br-6475nd)
155                 [ "$magic" != "43535953" ] && {
156                         echo "Invalid image type."
157                         return 1
158                 }
159                 return 0
160                 ;;
161         c20i)
162                 [ "$magic" != "03000000" ] && {
163                         echo "Invalid image type."
164                         return 1
165                 }
166                 return 0
167                 ;;
168         cy-swr1100|\
169         dir-610-a1|\
170         dir-645|\
171         dir-860l-b1)
172                 [ "$magic" != "5ea3a417" ] && {
173                         echo "Invalid image type."
174                         return 1
175                 }
176                 return 0
177                 ;;
178         wsr-1166)
179                 [ "$magic" != "48445230" ] && {
180                         echo "Invalid image type."
181                         return 1
182                 }
183                 return 0
184                 ;;
185         ubnt-erx)
186                 nand_do_platform_check "$board" "$1"
187                 return $?;
188                 ;;
189         esac
190
191         echo "Sysupgrade is not yet supported on $board."
192         return 1
193 }
194
195 platform_nand_pre_upgrade() {
196         local board=$(ramips_board_name)
197
198         case "$board" in
199         ubnt-erx)
200                 platform_upgrade_ubnt_erx "$ARGV"
201                 ;;
202         esac
203 }
204
205 platform_pre_upgrade() {
206         local board=$(ramips_board_name)
207
208         case "$board" in
209         ubnt-erx)
210                 nand_do_upgrade "$ARGV"
211                 ;;
212         esac
213 }
214
215 platform_do_upgrade() {
216         local board=$(ramips_board_name)
217
218         case "$board" in
219         *)
220                 default_do_upgrade "$ARGV"
221                 ;;
222         esac
223 }
224
225 disable_watchdog() {
226         killall watchdog
227         ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
228                 echo 'Could not disable watchdog'
229                 return 1
230         }
231 }
232
233 blink_led() {
234         . /etc/diag.sh; set_state upgrade
235 }
236
237 append sysupgrade_pre_upgrade disable_watchdog
238 append sysupgrade_pre_upgrade blink_led