889a1e2bd1e7498a8e98c23e1982ee0e7ac1535e
[openwrt/staging/stintel.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_get_bootdev() {
64 local rootdisk="$(cat /sys/firmware/devicetree/base/chosen/rootdisk)"
65 local handle bootdev
66 for handle in /sys/class/block/*/of_node/phandle /sys/class/block/*/device/of_node/phandle; do
67 [ ! -e "$handle" ] && continue
68 if [ "$rootdisk" = "$(cat $handle)" ]; then
69 bootdev="${handle%/of_node/phandle}"
70 bootdev="${bootdev%/device}"
71 bootdev="${bootdev#/sys/class/block/}"
72 echo "$bootdev"
73 break
74 fi
75 done
76 }
77
78 platform_do_upgrade() {
79 local board=$(board_name)
80
81 case "$board" in
82 acer,predator-w6|\
83 smartrg,sdg-8612|\
84 smartrg,sdg-8614|\
85 smartrg,sdg-8622|\
86 smartrg,sdg-8632)
87 CI_KERNPART="kernel"
88 CI_ROOTPART="rootfs"
89 emmc_do_upgrade "$1"
90 ;;
91 asus,rt-ax59u|\
92 asus,tuf-ax4200|\
93 asus,tuf-ax6000)
94 CI_UBIPART="UBI_DEV"
95 CI_KERNPART="linux"
96 nand_do_upgrade "$1"
97 ;;
98 bananapi,bpi-r3)
99 local rootdev="$(cmdline_get_var root)"
100 rootdev="${rootdev##*/}"
101 rootdev="${rootdev%p[0-9]*}"
102 case "$rootdev" in
103 mmc*)
104 CI_ROOTDEV="$rootdev"
105 CI_KERNPART="production"
106 emmc_do_upgrade "$1"
107 ;;
108 mtdblock*)
109 PART_NAME="fit"
110 default_do_upgrade "$1"
111 ;;
112 ubiblock*)
113 CI_KERNPART="fit"
114 nand_do_upgrade "$1"
115 ;;
116 esac
117 ;;
118 bananapi,bpi-r4)
119 [ -e /dev/fit0 ] && fitblk /dev/fit0
120 [ -e /dev/fitrw ] && fitblk /dev/fitrw
121 bootdev="$(platform_get_bootdev)"
122 case "$bootdev" in
123 mmcblk*)
124 EMMC_KERN_DEV="/dev/$bootdev"
125 emmc_do_upgrade "$1"
126 ;;
127 ubiblock*)
128 CI_KERNPART="fit"
129 nand_do_upgrade "$1"
130 ;;
131 esac
132 ;;
133 cmcc,rax3000m)
134 case "$(cmdline_get_var root)" in
135 /dev/mmc*)
136 CI_KERNPART="production"
137 emmc_do_upgrade "$1"
138 ;;
139 *)
140 CI_KERNPART="fit"
141 nand_do_upgrade "$1"
142 ;;
143 esac
144 ;;
145 cudy,wr3000-v1|\
146 yuncore,ax835)
147 default_do_upgrade "$1"
148 ;;
149 glinet,gl-mt2500|\
150 glinet,gl-mt6000)
151 CI_KERNPART="kernel"
152 CI_ROOTPART="rootfs"
153 emmc_do_upgrade "$1"
154 ;;
155 h3c,magic-nx30-pro|\
156 jcg,q30-pro|\
157 mediatek,mt7981-rfb|\
158 qihoo,360t7|\
159 tplink,tl-xdr4288|\
160 tplink,tl-xdr6086|\
161 tplink,tl-xdr6088|\
162 xiaomi,mi-router-ax3000t-ubootmod|\
163 xiaomi,mi-router-wr30u-ubootmod|\
164 xiaomi,redmi-router-ax6000-ubootmod)
165 CI_KERNPART="fit"
166 nand_do_upgrade "$1"
167 ;;
168 jdcloud,re-cp-03)
169 CI_KERNPART="production"
170 emmc_do_upgrade "$1"
171 ;;
172 mercusys,mr90x-v1)
173 CI_UBIPART="ubi0"
174 nand_do_upgrade "$1"
175 ;;
176 ubnt,unifi-6-plus)
177 CI_KERNPART="kernel0"
178 EMMC_ROOT_DEV="$(cmdline_get_var root)"
179 emmc_do_upgrade "$1"
180 ;;
181 xiaomi,mi-router-ax3000t|\
182 xiaomi,mi-router-wr30u-stock|\
183 xiaomi,redmi-router-ax6000-stock)
184 CI_KERN_UBIPART=ubi_kernel
185 CI_ROOT_UBIPART=ubi
186 nand_do_upgrade "$1"
187 ;;
188 zyxel,ex5601-t0-ubootmod)
189 CI_KERNPART="fit"
190 CI_ROOTPART="ubi_rootfs"
191 nand_do_upgrade "$1"
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 cmcc,rax3000m)
211 [ "$magic" != "d00dfeed" ] && {
212 echo "Invalid image type."
213 return 1
214 }
215 return 0
216 ;;
217 *)
218 nand_do_platform_check "$board" "$1"
219 return $?
220 ;;
221 esac
222
223 return 0
224 }
225
226 platform_copy_config() {
227 case "$(board_name)" in
228 bananapi,bpi-r3|\
229 cmcc,rax3000m)
230 case "$(cmdline_get_var root)" in
231 /dev/mmc*)
232 emmc_copy_config
233 ;;
234 esac
235 ;;
236 bananapi,bpi-r4)
237 case "$(platform_get_bootdev)" in
238 mmcblk*)
239 emmc_copy_config
240 ;;
241 esac
242 ;;
243 acer,predator-w6|\
244 glinet,gl-mt2500|\
245 glinet,gl-mt6000|\
246 jdcloud,re-cp-03|\
247 ubnt,unifi-6-plus)
248 emmc_copy_config
249 ;;
250 esac
251 }
252
253 platform_pre_upgrade() {
254 local board=$(board_name)
255
256 case "$board" in
257 asus,rt-ax59u|\
258 asus,tuf-ax4200|\
259 asus,tuf-ax6000)
260 asus_initial_setup
261 ;;
262 xiaomi,mi-router-ax3000t|\
263 xiaomi,mi-router-wr30u-stock|\
264 xiaomi,redmi-router-ax6000-stock)
265 xiaomi_initial_setup
266 ;;
267 esac
268 }