ipq40xx: add support for Teltonika RUTX50
[openwrt/staging/hauke.git] / target / linux / ipq40xx / base-files / lib / upgrade / platform.sh
1 PART_NAME=firmware
2 REQUIRE_IMAGE_METADATA=1
3
4 RAMFS_COPY_BIN='fw_printenv fw_setenv'
5 RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
6
7 platform_check_image() {
8 case "$(board_name)" in
9 asus,rt-ac42u |\
10 asus,rt-ac58u)
11 local ubidev=$(nand_find_ubi $CI_UBIPART)
12 local asus_root=$(nand_find_volume $ubidev jffs2)
13
14 [ -n "$asus_root" ] || return 0
15
16 cat << EOF
17 jffs2 partition is still present.
18 There's probably no space left
19 to install the filesystem.
20
21 You need to delete the jffs2 partition first:
22 # ubirmvol /dev/ubi0 --name=jffs2
23
24 Once this is done. Retry.
25 EOF
26 return 1
27 ;;
28 zte,mf18a |\
29 zte,mf286d |\
30 zte,mf287plus |\
31 zte,mf289f)
32 CI_UBIPART="rootfs"
33 local mtdnum="$( find_mtd_index $CI_UBIPART )"
34 [ ! "$mtdnum" ] && return 1
35 ubiattach -m "$mtdnum" || true
36 local ubidev="$( nand_find_ubi $CI_UBIPART )"
37 local ubi_rootfs=$(nand_find_volume $ubidev ubi_rootfs)
38 local ubi_rootfs_data=$(nand_find_volume $ubidev ubi_rootfs_data)
39
40 [ -n "$ubi_rootfs" ] || [ -n "$ubi_rootfs_data" ] || return 0
41
42 cat << EOF
43 ubi_rootfs partition is still present.
44
45 You need to delete the stock partition first:
46 # ubirmvol /dev/ubi0 -N ubi_rootfs
47 Please also delete ubi_rootfs_data, if exist:
48 # ubirmvol /dev/ubi0 -N ubi_rootfs_data
49
50 Once this is done. Retry.
51 EOF
52 return 1
53 ;;
54 esac
55 return 0;
56 }
57
58 askey_do_upgrade() {
59 local tar_file="$1"
60
61 local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
62 board_dir=${board_dir%/}
63
64 tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
65
66 nand_do_upgrade "$1"
67 }
68
69 zyxel_do_upgrade() {
70 local tar_file="$1"
71
72 local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
73 board_dir=${board_dir%/}
74
75 tar Oxf $tar_file ${board_dir}/kernel | mtd write - kernel
76
77 if [ -n "$UPGRADE_BACKUP" ]; then
78 tar Oxf $tar_file ${board_dir}/root | mtd -j "$UPGRADE_BACKUP" write - rootfs
79 else
80 tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
81 fi
82 }
83
84 platform_do_upgrade_mikrotik_nand() {
85 local fw_mtd=$(find_mtd_part kernel)
86 fw_mtd="${fw_mtd/block/}"
87 [ -n "$fw_mtd" ] || return
88
89 local board_dir=$(tar tf "$1" | grep -m 1 '^sysupgrade-.*/$')
90 board_dir=${board_dir%/}
91 [ -n "$board_dir" ] || return
92
93 local kernel_len=$(tar xf "$1" ${board_dir}/kernel -O | wc -c)
94 [ -n "$kernel_len" ] || return
95
96 tar xf "$1" ${board_dir}/kernel -O | ubiformat "$fw_mtd" -y -S $kernel_len -f -
97
98 CI_KERNPART="none"
99 nand_do_upgrade "$1"
100 }
101
102 platform_do_upgrade() {
103 case "$(board_name)" in
104 8dev,jalapeno |\
105 aruba,ap-303 |\
106 aruba,ap-303h |\
107 aruba,ap-365 |\
108 avm,fritzbox-7530 |\
109 avm,fritzrepeater-1200 |\
110 avm,fritzrepeater-3000 |\
111 buffalo,wtr-m2133hp |\
112 cilab,meshpoint-one |\
113 edgecore,ecw5211 |\
114 edgecore,oap100 |\
115 engenius,eap2200 |\
116 glinet,gl-a1300 |\
117 glinet,gl-ap1300 |\
118 luma,wrtq-329acn |\
119 mobipromo,cm520-79f |\
120 netgear,wac510 |\
121 p2w,r619ac-64m |\
122 p2w,r619ac-128m |\
123 qxwlan,e2600ac-c2 |\
124 wallys,dr40x9)
125 nand_do_upgrade "$1"
126 ;;
127 glinet,gl-b2200)
128 CI_KERNPART="0:HLOS"
129 CI_ROOTPART="rootfs"
130 CI_DATAPART="rootfs_data"
131 emmc_do_upgrade "$1"
132 ;;
133 alfa-network,ap120c-ac)
134 part="$(awk -F 'ubi.mtd=' '{printf $2}' /proc/cmdline | sed -e 's/ .*$//')"
135 if [ "$part" = "rootfs1" ]; then
136 fw_setenv active 2 || exit 1
137 CI_UBIPART="rootfs2"
138 else
139 fw_setenv active 1 || exit 1
140 CI_UBIPART="rootfs1"
141 fi
142 nand_do_upgrade "$1"
143 ;;
144 asus,map-ac2200)
145 CI_KERNPART="linux"
146 nand_do_upgrade "$1"
147 ;;
148 asus,rt-ac42u |\
149 asus,rt-ac58u)
150 CI_KERNPART="linux"
151 nand_do_upgrade "$1"
152 ;;
153 cellc,rtl30vw)
154 CI_UBIPART="ubifs"
155 askey_do_upgrade "$1"
156 ;;
157 compex,wpj419)
158 nand_do_upgrade "$1"
159 ;;
160 google,wifi)
161 export_bootdevice
162 export_partdevice CI_ROOTDEV 0
163 CI_KERNPART="kernel"
164 CI_ROOTPART="rootfs"
165 emmc_do_upgrade "$1"
166 ;;
167 linksys,ea6350v3 |\
168 linksys,ea8300 |\
169 linksys,mr8300 |\
170 linksys,whw01 |\
171 linksys,whw03v2)
172 platform_do_upgrade_linksys "$1"
173 ;;
174 meraki,mr33 |\
175 meraki,mr74)
176 CI_KERNPART="part.safe"
177 nand_do_upgrade "$1"
178 ;;
179 mikrotik,cap-ac|\
180 mikrotik,hap-ac2|\
181 mikrotik,hap-ac3-lte6-kit|\
182 mikrotik,lhgg-60ad|\
183 mikrotik,sxtsq-5-ac|\
184 mikrotik,wap-ac|\
185 mikrotik,wap-ac-lte|\
186 mikrotik,wap-r-ac)
187 [ "$(rootfs_type)" = "tmpfs" ] && mtd erase firmware
188 default_do_upgrade "$1"
189 ;;
190 mikrotik,hap-ac3)
191 platform_do_upgrade_mikrotik_nand "$1"
192 ;;
193 netgear,rbr50 |\
194 netgear,rbs50 |\
195 netgear,srr60 |\
196 netgear,srs60)
197 platform_do_upgrade_netgear_orbi_upgrade "$1"
198 ;;
199 openmesh,a42 |\
200 openmesh,a62 |\
201 plasmacloud,pa1200 |\
202 plasmacloud,pa2200)
203 PART_NAME="inactive"
204 platform_do_upgrade_dualboot_datachk "$1"
205 ;;
206 sony,ncp-hg100-cellular)
207 sony_emmc_do_upgrade "$1"
208 ;;
209 teltonika,rutx10 |\
210 teltonika,rutx50 |\
211 zte,mf18a |\
212 zte,mf286d |\
213 zte,mf287plus |\
214 zte,mf289f)
215 CI_UBIPART="rootfs"
216 nand_do_upgrade "$1"
217 ;;
218 zyxel,nbg6617)
219 zyxel_do_upgrade "$1"
220 ;;
221 *)
222 default_do_upgrade "$1"
223 ;;
224 esac
225 }
226
227 platform_copy_config() {
228 case "$(board_name)" in
229 glinet,gl-b2200 |\
230 google,wifi)
231 emmc_copy_config
232 ;;
233 esac
234 return 0;
235 }