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