e8c94409a7cc08202bc5f397e232a6e5e87a097a
[openwrt/openwrt.git] / target / linux / ipq40xx / base-files / lib / upgrade / platform.sh
1 PART_NAME=firmware
2 REQUIRE_IMAGE_METADATA=1
3
4 RAMFS_COPY_BIN='fw_printenv fw_setenv'
5 RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
6
7 platform_check_image() {
8 case "$(board_name)" in
9 asus,rt-ac42u |\
10 asus,rt-ac58u)
11 local ubidev=$(nand_find_ubi $CI_UBIPART)
12 local asus_root=$(nand_find_volume $ubidev jffs2)
13
14 [ -n "$asus_root" ] || return 0
15
16 cat << EOF
17 jffs2 partition is still present.
18 There's probably no space left
19 to install the filesystem.
20
21 You need to delete the jffs2 partition first:
22 # ubirmvol /dev/ubi0 --name=jffs2
23
24 Once this is done. Retry.
25 EOF
26 return 1
27 ;;
28 zte,mf286d)
29 CI_UBIPART="rootfs"
30 local mtdnum="$( find_mtd_index $CI_UBIPART )"
31 [ ! "$mtdnum" ] && return 1
32 ubiattach -m "$mtdnum" || true
33 local ubidev="$( nand_find_ubi $CI_UBIPART )"
34 local ubi_rootfs=$(nand_find_volume $ubidev ubi_rootfs)
35 local ubi_rootfs_data=$(nand_find_volume $ubidev ubi_rootfs_data)
36
37 [ -n "$ubi_rootfs" ] || [ -n "$ubi_rootfs_data" ] || return 0
38
39 cat << EOF
40 ubi_rootfs partition is still present.
41
42 You need to delete the stock partition first:
43 # ubirmvol /dev/ubi0 -N ubi_rootfs
44 Please also delete ubi_rootfs_data, if exist:
45 # ubirmvol /dev/ubi0 -N ubi_rootfs_data
46
47 Once this is done. Retry.
48 EOF
49 return 1
50 ;;
51 esac
52 return 0;
53 }
54
55 askey_do_upgrade() {
56 local tar_file="$1"
57
58 local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
59 board_dir=${board_dir%/}
60
61 tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
62
63 nand_do_upgrade "$1"
64 }
65
66 zyxel_do_upgrade() {
67 local tar_file="$1"
68
69 local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
70 board_dir=${board_dir%/}
71
72 tar Oxf $tar_file ${board_dir}/kernel | mtd write - kernel
73
74 if [ -n "$UPGRADE_BACKUP" ]; then
75 tar Oxf $tar_file ${board_dir}/root | mtd -j "$UPGRADE_BACKUP" write - rootfs
76 else
77 tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
78 fi
79 }
80
81 platform_do_upgrade_mikrotik_nand() {
82 local fw_mtd=$(find_mtd_part kernel)
83 fw_mtd="${fw_mtd/block/}"
84 [ -n "$fw_mtd" ] || return
85
86 local board_dir=$(tar tf "$1" | grep -m 1 '^sysupgrade-.*/$')
87 board_dir=${board_dir%/}
88 [ -n "$board_dir" ] || return
89
90 local kernel_len=$(tar xf "$1" ${board_dir}/kernel -O | wc -c)
91 [ -n "$kernel_len" ] || return
92
93 tar xf "$1" ${board_dir}/kernel -O | ubiformat "$fw_mtd" -y -S $kernel_len -f -
94
95 CI_KERNPART="none"
96 nand_do_upgrade "$1"
97 }
98
99 platform_do_upgrade() {
100 case "$(board_name)" in
101 8dev,jalapeno |\
102 aruba,ap-303 |\
103 aruba,ap-303h |\
104 aruba,ap-365 |\
105 avm,fritzbox-7530 |\
106 avm,fritzrepeater-1200 |\
107 avm,fritzrepeater-3000 |\
108 buffalo,wtr-m2133hp |\
109 cilab,meshpoint-one |\
110 edgecore,ecw5211 |\
111 edgecore,oap100 |\
112 engenius,eap2200 |\
113 glinet,gl-ap1300 |\
114 luma,wrtq-329acn |\
115 mobipromo,cm520-79f |\
116 netgear,wac510 |\
117 p2w,r619ac-64m |\
118 p2w,r619ac-128m |\
119 qxwlan,e2600ac-c2)
120 nand_do_upgrade "$1"
121 ;;
122 glinet,gl-b2200)
123 CI_KERNPART="0:HLOS"
124 CI_ROOTPART="rootfs"
125 CI_DATAPART="rootfs_data"
126 emmc_do_upgrade "$1"
127 ;;
128 alfa-network,ap120c-ac)
129 part="$(awk -F 'ubi.mtd=' '{printf $2}' /proc/cmdline | sed -e 's/ .*$//')"
130 if [ "$part" = "rootfs1" ]; then
131 fw_setenv active 2 || exit 1
132 CI_UBIPART="rootfs2"
133 else
134 fw_setenv active 1 || exit 1
135 CI_UBIPART="rootfs1"
136 fi
137 nand_do_upgrade "$1"
138 ;;
139 asus,map-ac2200)
140 CI_KERNPART="linux"
141 nand_do_upgrade "$1"
142 ;;
143 asus,rt-ac42u |\
144 asus,rt-ac58u)
145 CI_KERNPART="linux"
146 nand_do_upgrade "$1"
147 ;;
148 cellc,rtl30vw)
149 CI_UBIPART="ubifs"
150 askey_do_upgrade "$1"
151 ;;
152 compex,wpj419)
153 nand_do_upgrade "$1"
154 ;;
155 linksys,ea6350v3 |\
156 linksys,ea8300 |\
157 linksys,mr8300)
158 platform_do_upgrade_linksys "$1"
159 ;;
160 meraki,mr33)
161 CI_KERNPART="part.safe"
162 nand_do_upgrade "$1"
163 ;;
164 mikrotik,cap-ac|\
165 mikrotik,hap-ac2|\
166 mikrotik,lhgg-60ad|\
167 mikrotik,sxtsq-5-ac)
168 [ "$(rootfs_type)" = "tmpfs" ] && mtd erase firmware
169 default_do_upgrade "$1"
170 ;;
171 mikrotik,hap-ac3)
172 platform_do_upgrade_mikrotik_nand "$1"
173 ;;
174 netgear,rbr50 |\
175 netgear,rbs50 |\
176 netgear,srr60 |\
177 netgear,srs60)
178 platform_do_upgrade_netgear_orbi_upgrade "$1"
179 ;;
180 openmesh,a42 |\
181 openmesh,a62 |\
182 plasmacloud,pa1200 |\
183 plasmacloud,pa2200)
184 PART_NAME="inactive"
185 platform_do_upgrade_dualboot_datachk "$1"
186 ;;
187 teltonika,rutx10 |\
188 zte,mf286d)
189 CI_UBIPART="rootfs"
190 nand_do_upgrade "$1"
191 ;;
192 zyxel,nbg6617)
193 zyxel_do_upgrade "$1"
194 ;;
195 *)
196 default_do_upgrade "$1"
197 ;;
198 esac
199 }
200
201 platform_copy_config() {
202 case "$(board_name)" in
203 glinet,gl-b2200)
204 emmc_copy_config
205 ;;
206 esac
207 return 0;
208 }