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