6f69706d79b7ac093ef463094155ebbaf2d4dc19
[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 CI_KERNPART="kernel"
73 CI_ROOTPART="rootfs"
74 emmc_do_upgrade "$1"
75 ;;
76 asus,rt-ax59u|\
77 asus,tuf-ax4200|\
78 asus,tuf-ax6000)
79 CI_UBIPART="UBI_DEV"
80 CI_KERNPART="linux"
81 nand_do_upgrade "$1"
82 ;;
83 bananapi,bpi-r3|\
84 bananapi,bpi-r3-mini|\
85 bananapi,bpi-r4|\
86 tplink,tl-xdr4288|\
87 tplink,tl-xdr6086|\
88 tplink,tl-xdr6088|\
89 xiaomi,redmi-router-ax6000-ubootmod)
90 [ -e /dev/fit0 ] && fitblk /dev/fit0
91 [ -e /dev/fitrw ] && fitblk /dev/fitrw
92 bootdev="$(fitblk_get_bootdev)"
93 case "$bootdev" in
94 mmcblk*)
95 EMMC_KERN_DEV="/dev/$bootdev"
96 emmc_do_upgrade "$1"
97 ;;
98 mtdblock*)
99 PART_NAME="/dev/mtd${bootdev:8}"
100 default_do_upgrade "$1"
101 ;;
102 ubiblock*)
103 CI_KERNPART="fit"
104 nand_do_upgrade "$1"
105 ;;
106 esac
107 ;;
108 cmcc,rax3000m)
109 case "$(cmdline_get_var root)" in
110 /dev/mmc*)
111 CI_KERNPART="production"
112 emmc_do_upgrade "$1"
113 ;;
114 *)
115 CI_KERNPART="fit"
116 nand_do_upgrade "$1"
117 ;;
118 esac
119 ;;
120 cudy,re3000-v1|\
121 cudy,wr3000-v1|\
122 yuncore,ax835)
123 default_do_upgrade "$1"
124 ;;
125 glinet,gl-mt2500|\
126 glinet,gl-mt6000|\
127 glinet,gl-x3000|\
128 glinet,gl-xe3000)
129 CI_KERNPART="kernel"
130 CI_ROOTPART="rootfs"
131 emmc_do_upgrade "$1"
132 ;;
133 h3c,magic-nx30-pro|\
134 jcg,q30-pro|\
135 mediatek,mt7981-rfb|\
136 netcore,n60|\
137 qihoo,360t7|\
138 xiaomi,mi-router-ax3000t-ubootmod|\
139 xiaomi,mi-router-wr30u-ubootmod)
140 CI_KERNPART="fit"
141 nand_do_upgrade "$1"
142 ;;
143 jdcloud,re-cp-03)
144 CI_KERNPART="production"
145 emmc_do_upgrade "$1"
146 ;;
147 mercusys,mr90x-v1)
148 CI_UBIPART="ubi0"
149 nand_do_upgrade "$1"
150 ;;
151 ubnt,unifi-6-plus)
152 CI_KERNPART="kernel0"
153 EMMC_ROOT_DEV="$(cmdline_get_var root)"
154 emmc_do_upgrade "$1"
155 ;;
156 xiaomi,mi-router-ax3000t|\
157 xiaomi,mi-router-wr30u-stock|\
158 xiaomi,redmi-router-ax6000-stock)
159 CI_KERN_UBIPART=ubi_kernel
160 CI_ROOT_UBIPART=ubi
161 nand_do_upgrade "$1"
162 ;;
163 zyxel,ex5601-t0-ubootmod)
164 CI_KERNPART="fit"
165 CI_ROOTPART="ubi_rootfs"
166 nand_do_upgrade "$1"
167 ;;
168 unielec,u7981-01*)
169 local rootdev="$(cmdline_get_var root)"
170 rootdev="${rootdev##*/}"
171 rootdev="${rootdev%p[0-9]*}"
172 case "$rootdev" in
173 mmc*)
174 CI_ROOTDEV="$rootdev"
175 CI_KERNPART="kernel"
176 CI_ROOTPART="rootfs"
177 emmc_do_upgrade "$1"
178 ;;
179 *)
180 CI_KERNPART="fit"
181 nand_do_upgrade "$1"
182 ;;
183 esac
184 ;;
185 *)
186 nand_do_upgrade "$1"
187 ;;
188 esac
189 }
190
191 PART_NAME=firmware
192
193 platform_check_image() {
194 local board=$(board_name)
195 local magic="$(get_magic_long "$1")"
196
197 [ "$#" -gt 1 ] && return 1
198
199 case "$board" in
200 bananapi,bpi-r3|\
201 bananapi,bpi-r4|\
202 cmcc,rax3000m)
203 [ "$magic" != "d00dfeed" ] && {
204 echo "Invalid image type."
205 return 1
206 }
207 return 0
208 ;;
209 *)
210 nand_do_platform_check "$board" "$1"
211 return $?
212 ;;
213 esac
214
215 return 0
216 }
217
218 platform_copy_config() {
219 case "$(board_name)" in
220 cmcc,rax3000m)
221 case "$(cmdline_get_var root)" in
222 /dev/mmc*)
223 emmc_copy_config
224 ;;
225 esac
226 ;;
227 bananapi,bpi-r3|\
228 bananapi,bpi-r3-mini|\
229 bananapi,bpi-r4)
230 case "$(fitblk_get_bootdev)" in
231 mmcblk*)
232 emmc_copy_config
233 ;;
234 esac
235 ;;
236 acer,predator-w6|\
237 glinet,gl-mt2500|\
238 glinet,gl-mt6000|\
239 glinet,gl-x3000|\
240 glinet,gl-xe3000|\
241 jdcloud,re-cp-03|\
242 ubnt,unifi-6-plus)
243 emmc_copy_config
244 ;;
245 esac
246 }
247
248 platform_pre_upgrade() {
249 local board=$(board_name)
250
251 case "$board" in
252 asus,rt-ax59u|\
253 asus,tuf-ax4200|\
254 asus,tuf-ax6000)
255 asus_initial_setup
256 ;;
257 xiaomi,mi-router-ax3000t|\
258 xiaomi,mi-router-wr30u-stock|\
259 xiaomi,redmi-router-ax6000-stock)
260 xiaomi_initial_setup
261 ;;
262 esac
263 }