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