tools/pkgconf: update to 2.2.0
[openwrt/openwrt.git] / target / linux / mediatek / filogic / base-files / lib / upgrade / platform.sh
1 REQUIRE_IMAGE_METADATA=1
2 RAMFS_COPY_BIN='fitblk'
3
4 asus_initial_setup()
5 {
6 # initialize UBI if it's running on initramfs
7 [ "$(rootfs_type)" = "tmpfs" ] || return 0
8
9 ubirmvol /dev/ubi0 -N rootfs
10 ubirmvol /dev/ubi0 -N rootfs_data
11 ubirmvol /dev/ubi0 -N jffs2
12 ubimkvol /dev/ubi0 -N jffs2 -s 0x3e000
13 }
14
15 xiaomi_initial_setup()
16 {
17 # initialize UBI and setup uboot-env if it's running on initramfs
18 [ "$(rootfs_type)" = "tmpfs" ] || return 0
19
20 local mtdnum="$( find_mtd_index ubi )"
21 if [ ! "$mtdnum" ]; then
22 echo "unable to find mtd partition ubi"
23 return 1
24 fi
25
26 local kern_mtdnum="$( find_mtd_index ubi_kernel )"
27 if [ ! "$kern_mtdnum" ]; then
28 echo "unable to find mtd partition ubi_kernel"
29 return 1
30 fi
31
32 ubidetach -m "$mtdnum"
33 ubiformat /dev/mtd$mtdnum -y
34
35 ubidetach -m "$kern_mtdnum"
36 ubiformat /dev/mtd$kern_mtdnum -y
37
38 if ! fw_printenv -n flag_try_sys2_failed &>/dev/null; then
39 echo "failed to access u-boot-env. skip env setup."
40 return 0
41 fi
42
43 fw_setenv boot_wait on
44 fw_setenv uart_en 1
45 fw_setenv flag_boot_rootfs 0
46 fw_setenv flag_last_success 1
47 fw_setenv flag_boot_success 1
48 fw_setenv flag_try_sys1_failed 8
49 fw_setenv flag_try_sys2_failed 8
50
51 local board=$(board_name)
52 case "$board" in
53 xiaomi,mi-router-ax3000t|\
54 xiaomi,mi-router-wr30u-stock)
55 fw_setenv mtdparts "nmbm0:1024k(bl2),256k(Nvram),256k(Bdata),2048k(factory),2048k(fip),256k(crash),256k(crash_log),34816k(ubi),34816k(ubi1),32768k(overlay),12288k(data),256k(KF)"
56 ;;
57 xiaomi,redmi-router-ax6000-stock)
58 fw_setenv mtdparts "nmbm0:1024k(bl2),256k(Nvram),256k(Bdata),2048k(factory),2048k(fip),256k(crash),256k(crash_log),30720k(ubi),30720k(ubi1),51200k(overlay)"
59 ;;
60 esac
61 }
62
63 platform_do_upgrade() {
64 local board=$(board_name)
65
66 case "$board" in
67 acer,predator-w6|\
68 smartrg,sdg-8612|\
69 smartrg,sdg-8614|\
70 smartrg,sdg-8622|\
71 smartrg,sdg-8632|\
72 smartrg,sdg-8733|\
73 smartrg,sdg-8734)
74 CI_KERNPART="kernel"
75 CI_ROOTPART="rootfs"
76 emmc_do_upgrade "$1"
77 ;;
78 asus,rt-ax59u|\
79 asus,tuf-ax4200|\
80 asus,tuf-ax6000)
81 CI_UBIPART="UBI_DEV"
82 CI_KERNPART="linux"
83 nand_do_upgrade "$1"
84 ;;
85 bananapi,bpi-r3|\
86 bananapi,bpi-r3-mini|\
87 bananapi,bpi-r4|\
88 bananapi,bpi-r4-poe|\
89 jdcloud,re-cp-03|\
90 mediatek,mt7988a-rfb|\
91 openwrt,one)
92 [ -e /dev/fit0 ] && fitblk /dev/fit0
93 [ -e /dev/fitrw ] && fitblk /dev/fitrw
94 bootdev="$(fitblk_get_bootdev)"
95 case "$bootdev" in
96 mmcblk*)
97 EMMC_KERN_DEV="/dev/$bootdev"
98 emmc_do_upgrade "$1"
99 ;;
100 mtdblock*)
101 PART_NAME="/dev/mtd${bootdev:8}"
102 default_do_upgrade "$1"
103 ;;
104 ubiblock*)
105 CI_KERNPART="fit"
106 nand_do_upgrade "$1"
107 ;;
108 esac
109 ;;
110 cmcc,rax3000m)
111 case "$(cmdline_get_var root)" in
112 /dev/mmc*)
113 CI_KERNPART="production"
114 emmc_do_upgrade "$1"
115 ;;
116 *)
117 CI_KERNPART="fit"
118 nand_do_upgrade "$1"
119 ;;
120 esac
121 ;;
122 cudy,re3000-v1|\
123 cudy,wr3000-v1|\
124 yuncore,ax835)
125 default_do_upgrade "$1"
126 ;;
127 glinet,gl-mt2500|\
128 glinet,gl-mt6000|\
129 glinet,gl-x3000|\
130 glinet,gl-xe3000)
131 CI_KERNPART="kernel"
132 CI_ROOTPART="rootfs"
133 emmc_do_upgrade "$1"
134 ;;
135 h3c,magic-nx30-pro|\
136 jcg,q30-pro|\
137 mediatek,mt7981-rfb|\
138 netcore,n60|\
139 qihoo,360t7|\
140 xiaomi,mi-router-ax3000t-ubootmod|\
141 xiaomi,mi-router-wr30u-ubootmod)
142 CI_KERNPART="fit"
143 nand_do_upgrade "$1"
144 ;;
145 mercusys,mr90x-v1)
146 CI_UBIPART="ubi0"
147 nand_do_upgrade "$1"
148 ;;
149 nokia,ea0326gmp|\
150 tplink,tl-xdr4288|\
151 tplink,tl-xdr6086|\
152 tplink,tl-xdr6088|\
153 xiaomi,redmi-router-ax6000-ubootmod)
154 [ -e /dev/fit0 ] && fitblk /dev/fit0
155 [ -e /dev/fitrw ] && fitblk /dev/fitrw
156 CI_KERNPART="fit"
157 nand_do_upgrade "$1"
158 ;;
159 ubnt,unifi-6-plus)
160 CI_KERNPART="kernel0"
161 EMMC_ROOT_DEV="$(cmdline_get_var root)"
162 emmc_do_upgrade "$1"
163 ;;
164 xiaomi,mi-router-ax3000t|\
165 xiaomi,mi-router-wr30u-stock|\
166 xiaomi,redmi-router-ax6000-stock)
167 CI_KERN_UBIPART=ubi_kernel
168 CI_ROOT_UBIPART=ubi
169 nand_do_upgrade "$1"
170 ;;
171 zyxel,ex5601-t0-ubootmod)
172 CI_KERNPART="fit"
173 CI_ROOTPART="ubi_rootfs"
174 nand_do_upgrade "$1"
175 ;;
176 unielec,u7981-01*)
177 local rootdev="$(cmdline_get_var root)"
178 rootdev="${rootdev##*/}"
179 rootdev="${rootdev%p[0-9]*}"
180 case "$rootdev" in
181 mmc*)
182 CI_ROOTDEV="$rootdev"
183 CI_KERNPART="kernel"
184 CI_ROOTPART="rootfs"
185 emmc_do_upgrade "$1"
186 ;;
187 *)
188 CI_KERNPART="fit"
189 nand_do_upgrade "$1"
190 ;;
191 esac
192 ;;
193 *)
194 nand_do_upgrade "$1"
195 ;;
196 esac
197 }
198
199 PART_NAME=firmware
200
201 platform_check_image() {
202 local board=$(board_name)
203 local magic="$(get_magic_long "$1")"
204
205 [ "$#" -gt 1 ] && return 1
206
207 case "$board" in
208 bananapi,bpi-r3|\
209 bananapi,bpi-r4|\
210 bananapi,bpi-r4-poe|\
211 cmcc,rax3000m)
212 [ "$magic" != "d00dfeed" ] && {
213 echo "Invalid image type."
214 return 1
215 }
216 return 0
217 ;;
218 *)
219 nand_do_platform_check "$board" "$1"
220 return $?
221 ;;
222 esac
223
224 return 0
225 }
226
227 platform_copy_config() {
228 case "$(board_name)" in
229 cmcc,rax3000m)
230 case "$(cmdline_get_var root)" in
231 /dev/mmc*)
232 emmc_copy_config
233 ;;
234 esac
235 ;;
236 bananapi,bpi-r3|\
237 bananapi,bpi-r3-mini|\
238 bananapi,bpi-r4|\
239 bananapi,bpi-r4-poe)
240 case "$(fitblk_get_bootdev)" in
241 mmcblk*)
242 emmc_copy_config
243 ;;
244 esac
245 ;;
246 acer,predator-w6|\
247 glinet,gl-mt2500|\
248 glinet,gl-mt6000|\
249 glinet,gl-x3000|\
250 glinet,gl-xe3000|\
251 jdcloud,re-cp-03|\
252 smartrg,sdg-8612|\
253 smartrg,sdg-8614|\
254 smartrg,sdg-8622|\
255 smartrg,sdg-8632|\
256 smartrg,sdg-8733|\
257 smartrg,sdg-8734|\
258 ubnt,unifi-6-plus)
259 emmc_copy_config
260 ;;
261 esac
262 }
263
264 platform_pre_upgrade() {
265 local board=$(board_name)
266
267 case "$board" in
268 asus,rt-ax59u|\
269 asus,tuf-ax4200|\
270 asus,tuf-ax6000)
271 asus_initial_setup
272 ;;
273 xiaomi,mi-router-ax3000t|\
274 xiaomi,mi-router-wr30u-stock|\
275 xiaomi,redmi-router-ax6000-stock)
276 xiaomi_initial_setup
277 ;;
278 esac
279 }