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