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