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