· 6 years ago · Oct 17, 2019, 04:42 PM
1diff --git a/docs/package/gluon-ebtables-limit-arp.rst b/docs/package/gluon-ebtables-limit-arp.rst
2index e4ba6b4b..9431f004 100644
3--- a/docs/package/gluon-ebtables-limit-arp.rst
4+++ b/docs/package/gluon-ebtables-limit-arp.rst
5@@ -1,17 +1,17 @@
6 gluon-ebtables-limit-arp
7 ========================
8
9-The *gluon-ebtables-limit-arp* package adds filters to limit the
10-amount of ARP requests client devices are allowed to send into the
11-mesh.
12+The *gluon-ebtables-limit-arp* package adds filters to limit the
13+amount of ARP requests client devices are allowed to send into the
14+mesh.
15
16 The limits per client device, identified by its MAC address, are
17-6 packets per minute and 1 per second per node in total.
18+6 packets per minute and 1 per second per node in total.
19 A burst of up to 50 ARP requests is allowed until the rate-limiting
20 takes effect (see ``--limit-burst`` in ``ebtables(8)``).
21
22 Furthermore, ARP requests for a target IP already present in the
23-batman-adv DAT cache are excluded from rate-limiting, in regard
24+batman-adv DAT cache are excluded from rate-limiting, in regard
25 to both counting and filtering, as batman-adv will be able
26 to respond locally without a burden for the mesh. Therefore, this
27 limiter should not affect popular target IP addresses, like those
28@@ -21,8 +21,8 @@ However it mitigates the impact on the mesh when a larger range of
29 its IPv4 subnet is being scanned, which would otherwise result in
30 a significant amount of ARP chatter, even for unused IP addresses.
31
32-This package is selected by default if the installed routing
33-package is gluon-mesh-batman-adv-14 or gluon-mesh-batman-adv-15.
34+This package is installed by default if the selected routing
35+feature is *mesh-batman-adv-15*.
36 It can be unselected via::
37
38 GLUON_SITE_PACKAGES := \
39diff --git a/docs/package/gluon-mesh-batman-adv.rst b/docs/package/gluon-mesh-batman-adv.rst
40index 6bef7cea..29135324 100644
41--- a/docs/package/gluon-mesh-batman-adv.rst
42+++ b/docs/package/gluon-mesh-batman-adv.rst
43@@ -20,49 +20,11 @@ B.A.T.M.A.N. Advanced project homepage:
44
45 * https://www.open-mesh.org/projects/batman-adv/wiki/Wiki
46
47-Flavours
48---------
49-
50-Gluon currently supports two main build flavours of batman-adv:
51-
52-gluon-mesh-batman-adv-15
53-^^^^^^^^^^^^^^^^^^^^^^^^
54-
55-This is the recommended batman-adv flavour to use.
56-
57-It follows recent, upstream batman-adv releases and is flexible to new feature additions.
58-
59-gluon-mesh-batman-adv-14 (`batman-adv-legacy`)
60-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
61-
62-`gluon-mesh-batman-adv-14`, also known as `batman-adv-legacy` or batman-adv v2013.4
63-is the last batman-adv release with the batman-adv compatibility version 14, which
64-was released in October 2013.
65-
66-With batman-adv v2014.0.0 a compat breakage became necessary for the introduction
67-of new features. However, one of these features was the addition of TVLV support
68-(type-version-length-value fields) which from then on allowed adding features
69-without breaking packet format compatibility. This made it possible to stay with
70-compatibility version 15 so far.
71-
72-For new installations `gluon-mesh-batman-adv-14` is **not recommended**. It misses
73-a lot of bugfixes and is currently only available for existing communities
74-until they have migrated. This package will soon be deprecated and removed.
75-
76-Also see:
77-
78-* https://www.open-mesh.org/projects/batman-adv/wiki/Compatversion
79-* https://www.open-mesh.org/news/56
80-* https://github.com/freifunk-gluon/batman-adv-legacy/
81-
82-
83 B.A.T.M.A.N. Routing Algorithms
84 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85
86-For the `gluon-mesh-batman-adv-15` package two routing algorithms are selectable
87-via :ref:`site.conf mesh section <user-site-mesh>`: BATMAN_IV and BATMAN_V.
88-
89-For the `gluon-mesh-batman-adv-14` package, BATMAN_IV_LEGACY needs to be selected.
90+Two routing algorithms are selectable via
91+:ref:`site.conf mesh section <user-site-mesh>`: BATMAN_IV and BATMAN_V.
92
93 BATMAN_IV - stable
94 """"""""""""""""""
95@@ -92,8 +54,8 @@ mesh protocol, it quickly reaches its limit.
96
97 For meshes with about **50 nodes / 100 clients, or more** it is therefore highly
98 recommended to add the :doc:`gluon-ebtables-filter-multicast`
99-package. Also, with gluon-mesh-batman-adv-15 or gluon-mesh-batman-adv-14
100-installed :doc:`gluon-ebtables-limit-arp` is selected by default.
101+package. Also, with the *mesh-batman-adv-15* feature,
102+:doc:`gluon-ebtables-limit-arp` is selected by default.
103
104 Furthermore, by default IGMP and MLD messages are filtered. See
105 :ref:`site.conf mesh section <user-site-mesh>` and
106diff --git a/docs/user/faq.rst b/docs/user/faq.rst
107index 2c01814f..d40fcb5c 100644
108--- a/docs/user/faq.rst
109+++ b/docs/user/faq.rst
110@@ -45,9 +45,8 @@ Consider these key values:
111 .. _MSS clamping: https://www.tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.cookbook.mtu-mss.html
112
113 - Encapsulation: Account for the overhead created by the configured mesh protocol
114- encapsulating the payload, which is
115- - up to 32 Byte (14 Byte Ethernet + 18 Byte batadv) for batman-adv compat v15 (v2014.0 and later)
116- - up to 28 Byte (14 Byte Ethernet + 14 Byte batadv) for batman-adv compat v14 (v2011.3.0 until and including v2013.4.0)
117+ encapsulating the payload, which is up to 32 Byte (14 Byte Ethernet + 18 Byte
118+ batadv).
119
120 - PMTU: What MTU does the path between your gateway and each of its peers support?
121
122@@ -106,4 +105,4 @@ Conclusion
123 Determining the maximum MTU can be a tedious process, especially since the PMTU
124 of peers could change at any time. The general recommendation for maximized
125 compatibility is therefore the minimum MTU of 1312 Byte, which works well with
126-all combinations of IPv4, IPv6, batman-adv compat v14 and v15.
127+both IPv4 and IPv6.
128diff --git a/docs/user/site.rst b/docs/user/site.rst
129index 9ef4f4b3..c60f4d86 100644
130--- a/docs/user/site.rst
131+++ b/docs/user/site.rst
132@@ -244,12 +244,8 @@ mesh
133 The mandatory value *routing_algo* selects the batman-adv protocol variant.
134 The following values are supported:
135
136- - ``BATMAN_IV_LEGACY`` (*mesh-batman-adv-14*)
137- - ``BATMAN_IV`` (*mesh-batman-adv-15*)
138- - ``BATMAN_V`` (*mesh-batman-adv-15*)
139-
140- When both *mesh-batman-adv-14* and *mesh-batman-adv-15* are included, this
141- setting specifies which one to use.
142+ - ``BATMAN_IV``
143+ - ``BATMAN_V``
144
145 The optional value *gw_sel_class* sets the gateway selection class, the
146 default is ``20`` for B.A.T.M.A.N. IV and ``5000`` kbit/s for B.A.T.M.A.N. V.
147@@ -598,12 +594,12 @@ prefix: The feature flag corresponding to the package *gluon-mesh-batman-adv-15*
148
149 The file ``package/features`` in the Gluon repository (or
150 ``features`` in site feeds) can specify additional rules for deriving package lists
151-from feature flags, e.g. specifying both *status-page* and either *mesh-batman-adv-14*
152-or *mesh-batman-adv-15* will automatically select the additional package
153+from feature flags, e.g. specifying both *status-page* and *mesh-batman-adv-15*
154+will automatically select the additional package
155 *gluon-status-page-mesh-batman-adv*. In the future, selecting the flags
156 *mesh-vpn-fastd* and *respondd* might automatically enable the additional
157 package *gluon-mesh-vpn-fastd-respondd*, and enabling *status-page* and
158-*mesh-batman-adv-15* (or *-14*) with ``de`` in *GLUON_LANGS* could
159+*mesh-batman-adv-15* with ``de`` in *GLUON_LANGS* could
160 add the package *gluon-status-page-mesh-batman-adv-i18n-de*.
161
162 In short, it is not necessary anymore to list all the individual packages that are
163diff --git a/docs/user/supported_devices.rst b/docs/user/supported_devices.rst
164index 5515dc9a..354ec7b7 100644
165--- a/docs/user/supported_devices.rst
166+++ b/docs/user/supported_devices.rst
167@@ -13,10 +13,6 @@ ar71xx-generic
168 - AP121 [#deprecated]_
169 - AP121F
170 - AP121U [#deprecated]_
171- - Hornet-UB [#deprecated]_
172- - Tube2H [#deprecated]_
173- - N2 [#deprecated]_
174- - N5 [#deprecated]_
175
176 * Allnet
177
178diff --git a/modules b/modules
179index dc700bc5..9d5b3716 100644
180--- a/modules
181+++ b/modules
182@@ -1,20 +1,20 @@
183 GLUON_FEEDS='packages routing luci gluon'
184
185 OPENWRT_REPO=https://git.openwrt.org/openwrt/openwrt.git
186-OPENWRT_BRANCH=openwrt-18.06
187-OPENWRT_COMMIT=491e839262fd2bf7417c57e12ebb7383011dae1c
188+OPENWRT_BRANCH=openwrt-19.07
189+OPENWRT_COMMIT=2155e94d4b8e586e5a110e8d8eb58555720ae474
190
191 PACKAGES_PACKAGES_REPO=https://github.com/openwrt/packages.git
192-PACKAGES_PACKAGES_BRANCH=openwrt-18.06
193-PACKAGES_PACKAGES_COMMIT=6305d09b1a56ae05f2c0f175b6d84cd2e584d786
194+PACKAGES_PACKAGES_BRANCH=openwrt-19.07
195+PACKAGES_PACKAGES_COMMIT=f745880429ca7a1903f7846306ce3e1b8139b11b
196
197 PACKAGES_ROUTING_REPO=https://github.com/openwrt-routing/packages.git
198-PACKAGES_ROUTING_BRANCH=openwrt-18.06
199-PACKAGES_ROUTING_COMMIT=7589804a56baac804421b492c93004c28a627abb
200+PACKAGES_ROUTING_BRANCH=openwrt-19.07
201+PACKAGES_ROUTING_COMMIT=931f947dd682ffb9fa9c3401d5e2019d678ab019
202
203 PACKAGES_LUCI_REPO=https://github.com/openwrt/luci.git
204-PACKAGES_LUCI_BRANCH=openwrt-18.06
205-PACKAGES_LUCI_COMMIT=b99e77d5c36a9d51559bae3bb61a138695d60b95
206+PACKAGES_LUCI_BRANCH=openwrt-19.07
207+PACKAGES_LUCI_COMMIT=f5bed30d3cbb930e9a9b6463bfa6fa7350c4fab6
208
209 PACKAGES_GLUON_REPO=https://github.com/freifunk-gluon/packages.git
210-PACKAGES_GLUON_COMMIT=e130b6f54d0f99ca923e981801043c41e794d9b5
211+PACKAGES_GLUON_COMMIT=de7b228cae72e87f2dfb3eed5b0354bd7cec4ca7
212diff --git a/package/features b/package/features
213index ba274503..1f0d825a 100644
214--- a/package/features
215+++ b/package/features
216@@ -23,10 +23,10 @@ packages 'web-advanced' \
217 packages 'web-advanced & autoupdater' \
218 'gluon-web-autoupdater'
219
220-packages 'status-page & (mesh-batman-adv-14 | mesh-batman-adv-15)' \
221+packages 'status-page & mesh-batman-adv-15' \
222 'gluon-status-page-mesh-batman-adv'
223
224-packages 'mesh-batman-adv-14 | mesh-batman-adv-15' \
225+packages 'mesh-batman-adv-15' \
226 'gluon-ebtables-limit-arp' \
227 'gluon-radvd'
228
229diff --git a/package/gluon-config-mode-geo-location/i18n/de.po b/package/gluon-config-mode-geo-location/i18n/de.po
230index 0ff3d433..d844548e 100644
231--- a/package/gluon-config-mode-geo-location/i18n/de.po
232+++ b/package/gluon-config-mode-geo-location/i18n/de.po
233@@ -26,6 +26,9 @@ msgstr "Breitengrad"
234 msgid "Longitude"
235 msgstr "Längengrad"
236
237+msgid "Set node position"
238+msgstr "Knotenposition setzen"
239+
240 msgid "Advertise node position"
241 msgstr "Knotenposition veröffentlichen"
242
243diff --git a/package/gluon-config-mode-geo-location/i18n/fr.po b/package/gluon-config-mode-geo-location/i18n/fr.po
244index 5a725cb6..5010a7a2 100644
245--- a/package/gluon-config-mode-geo-location/i18n/fr.po
246+++ b/package/gluon-config-mode-geo-location/i18n/fr.po
247@@ -24,6 +24,9 @@ msgstr "Latitude"
248 msgid "Longitude"
249 msgstr "Longitude"
250
251+msgid "Set node position"
252+msgstr ""
253+
254 msgid "Advertise node position"
255 msgstr ""
256
257diff --git a/package/gluon-config-mode-geo-location/i18n/gluon-config-mode-geo-location.pot b/package/gluon-config-mode-geo-location/i18n/gluon-config-mode-geo-location.pot
258index 27ab905d..3dfa782a 100644
259--- a/package/gluon-config-mode-geo-location/i18n/gluon-config-mode-geo-location.pot
260+++ b/package/gluon-config-mode-geo-location/i18n/gluon-config-mode-geo-location.pot
261@@ -15,6 +15,9 @@ msgstr ""
262 msgid "Longitude"
263 msgstr ""
264
265+msgid "Set node position"
266+msgstr ""
267+
268 msgid "Advertise node position"
269 msgstr ""
270
271diff --git a/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua b/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua
272index e2d0bdb7..04ebf63a 100644
273--- a/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua
274+++ b/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua
275@@ -32,26 +32,41 @@ return function(form, uci)
276
277 local o
278
279- local share_location = s:option(Flag, "location", pkg_i18n.translate("Advertise node position"))
280- share_location.default = uci:get_bool("gluon-node-info", location, "share_location")
281- function share_location:write(data)
282- uci:set("gluon-node-info", location, "share_location", data)
283+ local own_latitude = uci:get("gluon-node-info", location, "latitude")
284+ local own_longitude = uci:get("gluon-node-info", location, "longitude")
285+
286+ local set_location = s:option(Flag, "location", pkg_i18n.translate("Set node position"))
287+ set_location.default = own_latitude or own_longitude
288+
289+ -- Delete already saved coordinates
290+ function set_location:write(data)
291+ if not data then
292+ uci:delete("gluon-node-info", location, "latitude")
293+ uci:delete("gluon-node-info", location, "longitude")
294+ uci:set("gluon-node-info", location, "share_location", false)
295+ end
296
297- -- The config mode does not have a nicer place to put this at the moment...
298- if not show_altitude then
299+ if not show_altitude or not data then
300 uci:delete("gluon-node-info", location, "altitude")
301 end
302 end
303
304+ local share_location = s:option(Flag, "share_location", pkg_i18n.translate("Advertise node position"))
305+ share_location.default = uci:get_bool("gluon-node-info", location, "share_location")
306+ share_location:depends(set_location, true)
307+ function share_location:write(data)
308+ uci:set("gluon-node-info", location, "share_location", data)
309+ end
310+
311 local map
312 if osm then
313 map = s:option(osm.MapValue, "map", osm.options())
314- map:depends(share_location, true)
315+ map:depends(set_location, true)
316 end
317
318 o = s:option(Value, "latitude", pkg_i18n.translate("Latitude"), pkg_i18n.translatef("e.g. %s", "53.873621"))
319- o.default = uci:get("gluon-node-info", location, "latitude")
320- o:depends(share_location, true)
321+ o.default = own_latitude
322+ o:depends(set_location, true)
323 o.datatype = "float"
324 function o:write(data)
325 uci:set("gluon-node-info", location, "latitude", data)
326@@ -61,8 +76,8 @@ return function(form, uci)
327 end
328
329 o = s:option(Value, "longitude", pkg_i18n.translate("Longitude"), pkg_i18n.translatef("e.g. %s", "10.689901"))
330- o.default = uci:get("gluon-node-info", location, "longitude")
331- o:depends(share_location, true)
332+ o.default = own_longitude
333+ o:depends(set_location, true)
334 o.datatype = "float"
335 function o:write(data)
336 uci:set("gluon-node-info", location, "longitude", data)
337@@ -77,7 +92,7 @@ return function(form, uci)
338 pkg_i18n.translatef("e.g. %s", "11.51")
339 )
340 o.default = uci:get("gluon-node-info", location, "altitude")
341- o:depends(share_location, true)
342+ o:depends(set_location, true)
343 o.datatype = "float"
344 o.optional = true
345 function o:write(data)
346diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac b/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac
347index 69b91501..1e4b2e2f 100755
348--- a/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac
349+++ b/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac
350@@ -28,6 +28,7 @@ if platform.match('ar71xx', 'generic', {'tl-wdr3600', 'tl-wdr4300',
351 table.insert(try_files, 1, '/sys/class/ieee80211/phy1/macaddress')
352 elseif platform.match('ar71xx', 'generic', {'a40', 'a60',
353 'archer-c25-v1',
354+ 'archer-c60-v2',
355 'archer-c7-v4', 'archer-c7-v5',
356 'carambola2',
357 'koala',
358diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg b/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg
359index eecedaf3..bf0d15dc 100755
360--- a/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg
361+++ b/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg
362@@ -14,7 +14,7 @@ local util = require 'gluon.util'
363 local subst = {}
364
365
366-local f = io.popen('. /etc/os-release; echo "$ID"; echo "$VERSION_ID"; echo "$LEDE_BOARD"; echo "$LEDE_ARCH"')
367+local f = io.popen('. /etc/os-release; echo "$ID"; echo "$VERSION_ID"; echo "$OPENWRT_BOARD"; echo "$OPENWRT_ARCH"')
368 subst['%%d'] = f:read()
369 subst['%%v'] = f:read():gsub('-snapshot', '')
370 subst['%%S'] = f:read()
371diff --git a/package/gluon-mesh-babel/src/neighbours-babel.c b/package/gluon-mesh-babel/src/neighbours-babel.c
372index 8d9ae76c..31f9c606 100644
373--- a/package/gluon-mesh-babel/src/neighbours-babel.c
374+++ b/package/gluon-mesh-babel/src/neighbours-babel.c
375@@ -18,7 +18,7 @@ int main(void) {
376 continue;
377
378 bhelper_ctx.debug = false;
379- babelhelper_readbabeldata(&bhelper_ctx, (void*)neighbours, handle_neighbour);
380+ babelhelper_readbabeldata(&bhelper_ctx, "dump", (void*)neighbours, handle_neighbour);
381
382 printf("data: %s\n\n", json_object_to_json_string(neighbours));
383 fflush(stdout);
384diff --git a/package/gluon-mesh-babel/src/respondd.c b/package/gluon-mesh-babel/src/respondd.c
385index 29f20ccf..d82ce6af 100644
386--- a/package/gluon-mesh-babel/src/respondd.c
387+++ b/package/gluon-mesh-babel/src/respondd.c
388@@ -388,10 +388,9 @@ static struct json_object * respondd_provider_nodeinfo(void) {
389
390 static uint64_t getnumber(const char *ifname, const char *stat) {
391 const char *format = "/sys/class/net/%s/statistics/%s";
392- char path[strlen(format) + strlen(ifname) + strlen(stat)];
393+ char path[strlen(format) + strlen(ifname) + strlen(stat) + 1];
394 snprintf(path, sizeof(path), format, ifname, stat);
395- if (! access(path, F_OK))
396- {
397+ if (! access(path, F_OK)) {
398 char *line=gluonutil_read_line(path);
399 long long i = atoll(line);
400 free(line);
401diff --git a/package/gluon-mesh-batman-adv/Makefile b/package/gluon-mesh-batman-adv/Makefile
402index 70e9d999..eac84ac5 100644
403--- a/package/gluon-mesh-batman-adv/Makefile
404+++ b/package/gluon-mesh-batman-adv/Makefile
405@@ -5,9 +5,11 @@ PKG_VERSION:=1
406
407 include ../gluon.mk
408
409-define Package/gluon-mesh-batman-adv-common
410- TITLE:=Gluon scripts for batman-adv and batman-adv-legacy
411- DEPENDS:= \
412+define Package/gluon-mesh-batman-adv-15
413+ PROVIDES:=gluon-mesh-batman-adv
414+ TITLE:=Support for batman-adv meshing (compat level 15)
415+ DEPENDS+= \
416+ +kmod-batman-adv \
417 +gluon-core \
418 +libgluonutil \
419 +gluon-client-bridge \
420@@ -23,36 +25,4 @@ define Package/gluon-mesh-batman-adv-common
421 +@GLUON_SPECIALIZE_KERNEL:KERNEL_LIBCRC32C
422 endef
423
424-define Package/gluon-mesh-batman-adv-14
425- PROVIDES:=gluon-mesh-batman-adv
426- TITLE:=Support for batman-adv meshing (compat level 14)
427- DEPENDS+= \
428- +gluon-mesh-batman-adv-common \
429- +kmod-batman-adv-legacy
430-endef
431-
432-define Package/gluon-mesh-batman-adv-15
433- PROVIDES:=gluon-mesh-batman-adv
434- TITLE:=Support for batman-adv meshing (compat level 15)
435- DEPENDS+= \
436- +gluon-mesh-batman-adv-common \
437- +kmod-batman-adv
438-endef
439-
440-define Package/gluon-mesh-batman-adv-common/install
441- $(Gluon/Build/Install)
442-endef
443-
444-define Package/gluon-mesh-batman-adv-14/install
445- $(INSTALL_DIR) $(1)/lib/gluon/mesh-batman-adv
446- touch $(1)/lib/gluon/mesh-batman-adv/compat-14
447-endef
448-#
449-define Package/gluon-mesh-batman-adv-15/install
450- $(INSTALL_DIR) $(1)/lib/gluon/mesh-batman-adv
451- touch $(1)/lib/gluon/mesh-batman-adv/compat-15
452-endef
453-
454-$(eval $(call BuildPackageGluon,gluon-mesh-batman-adv-common))
455-$(eval $(call BuildPackageGluon,gluon-mesh-batman-adv-14))
456 $(eval $(call BuildPackageGluon,gluon-mesh-batman-adv-15))
457diff --git a/package/gluon-mesh-batman-adv/check_site.lua b/package/gluon-mesh-batman-adv/check_site.lua
458index aa930955..c0b6f305 100644
459--- a/package/gluon-mesh-batman-adv/check_site.lua
460+++ b/package/gluon-mesh-batman-adv/check_site.lua
461@@ -2,18 +2,4 @@
462 need_boolean(in_domain({'mesh', 'vxlan'}), not this_domain())
463
464 need_number({'mesh', 'batman_adv', 'gw_sel_class'}, false)
465-
466-
467-local allowed_algos = {}
468-local has_compat_14 = (os.execute('exec ls "$IPKG_INSTROOT"/lib/gluon/mesh-batman-adv/compat-14 >/dev/null 2>&1') == 0)
469-local has_compat_15 = (os.execute('exec ls "$IPKG_INSTROOT"/lib/gluon/mesh-batman-adv/compat-15 >/dev/null 2>&1') == 0)
470-
471-if has_compat_14 then
472- table.insert(allowed_algos, 'BATMAN_IV_LEGACY')
473-end
474-if has_compat_15 then
475- table.insert(allowed_algos, 'BATMAN_IV')
476- table.insert(allowed_algos, 'BATMAN_V')
477-end
478-
479-need_one_of({'mesh', 'batman_adv', 'routing_algo'}, allowed_algos)
480+need_one_of({'mesh', 'batman_adv', 'routing_algo'}, {'BATMAN_IV', 'BATMAN_V'})
481diff --git a/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh b/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh
482index dcc28f60..aaf9c908 100755
483--- a/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh
484+++ b/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh
485@@ -8,6 +8,13 @@ proto_gluon_bat0_init_config() {
486 no_device=1
487 available=1
488 renew_handler=1
489+
490+ proto_config_add_string 'gw_mode'
491+}
492+
493+lookup_site() {
494+ local path="$1" default="$2"
495+ lua -e "print(require('gluon.site').$path('$default'))"
496 }
497
498 proto_gluon_bat0_renew() {
499@@ -36,22 +43,43 @@ proto_gluon_bat0_renew() {
500 proto_gluon_bat0_setup() {
501 local config="$1"
502
503+ local routing_algo=$(lookup_site 'mesh.batman_adv.routing_algo' 'BATMAN_IV')
504+
505+ local gw_mode
506+ json_get_vars gw_mode
507+
508+ batctl routing_algo "$routing_algo"
509+ batctl interface create
510+
511+ batctl orig_interval 5000
512+ batctl hop_penalty 15
513+ batctl multicast_mode 0
514+
515+ case "$gw_mode" in
516+ server)
517+ batctl gw_mode "server"
518+ ;;
519+ client)
520+ local gw_sel_class="$(lookup_site 'mesh.batman_adv.gw_sel_class')"
521+ if [ -n "$gw_sel_class" ]; then
522+ batctl gw_mode "client" "$gw_sel_class"
523+ else
524+ batctl gw_mode "client"
525+ fi
526+ ;;
527+ *)
528+ batctl gw_mode "off"
529+ ;;
530+ esac
531+
532+
533 local primary0_mac="$(lua -e 'print(require("gluon.util").generate_mac(3))')"
534
535 ip link add primary0 type dummy
536 echo 1 > /proc/sys/net/ipv6/conf/primary0/disable_ipv6
537 ip link set primary0 address "$primary0_mac" mtu 1532 up
538
539- local routing_algo="$(lua -e 'print(require("gluon.site").mesh.batman_adv.routing_algo())')"
540-
541- if [ "$routing_algo" = 'BATMAN_IV_LEGACY' ]; then
542- modprobe batman-adv-legacy
543- else
544- modprobe batman-adv
545- (echo "$routing_algo" >/sys/module/batman_adv/parameters/routing_algo) 2>/dev/null
546- fi
547-
548- echo bat0 > /sys/class/net/primary0/batman_adv/mesh_iface
549+ batctl interface add primary0
550
551 proto_init_update primary0 1
552 proto_send_update "$config"
553@@ -62,10 +90,8 @@ proto_gluon_bat0_setup() {
554 proto_gluon_bat0_teardown() {
555 local config="$1"
556
557- ip link del bat0
558+ batctl interface destroy
559 ip link del primary0
560-
561- rmmod batman-adv
562 }
563
564 add_protocol gluon_bat0
565diff --git a/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-mesh b/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-mesh
566index b864dda7..9ba1289f 100755
567--- a/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-mesh
568+++ b/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-mesh
569@@ -1,43 +1,23 @@
570 #!/usr/bin/lua
571
572 local sysconfig = require 'gluon.sysconfig'
573-local site = require 'gluon.site'
574 local util = require 'gluon.util'
575
576 local uci = require('simple-uci').cursor()
577
578
579-local gw_mode = uci:get('batman-adv', 'bat0', 'gw_mode') or uci:get('batman-adv-legacy', 'bat0', 'gw_mode') or 'client'
580-local gw_sel_class = site.mesh.batman_adv.gw_sel_class()
581-local routing_algo = site.mesh.batman_adv.routing_algo()
582+local gw_mode = uci:get('network', 'gluon_bat0', 'gw_mode') or uci:get('network', 'bat0', 'gw_mode') or 'client'
583
584 uci:delete('batman-adv-legacy', 'bat0')
585-uci:delete('batman-adv', 'bat0')
586-
587-if routing_algo == 'BATMAN_IV_LEGACY' then
588- uci:section('batman-adv-legacy', 'mesh', 'bat0', {
589- orig_interval = 5000,
590- gw_mode = gw_mode,
591- gw_sel_class = gw_sel_class,
592- hop_penalty = 15,
593- })
594-else
595- uci:section('batman-adv', 'mesh', 'bat0', {
596- orig_interval = 5000,
597- gw_mode = gw_mode,
598- gw_sel_class = gw_sel_class,
599- hop_penalty = 15,
600- routing_algo = routing_algo,
601- multicast_mode = false,
602- })
603-end
604-
605 uci:save('batman-adv-legacy')
606+
607+uci:delete('batman-adv', 'bat0')
608 uci:save('batman-adv')
609
610 uci:delete('network', 'gluon_bat0')
611 uci:section('network', 'interface', 'gluon_bat0', {
612 proto = 'gluon_bat0',
613+ gw_mode = gw_mode,
614 })
615
616 uci:delete('network', 'bat0')
617diff --git a/package/gluon-mesh-batman-adv/src/respondd.c b/package/gluon-mesh-batman-adv/src/respondd.c
618index 7d84d149..c2b20399 100644
619--- a/package/gluon-mesh-batman-adv/src/respondd.c
620+++ b/package/gluon-mesh-batman-adv/src/respondd.c
621@@ -232,24 +232,9 @@ static struct json_object * get_mesh(void) {
622 return ret;
623 }
624
625-static struct json_object * get_batman_adv_compat(const char *version) {
626- int compat = 15;
627-
628- if (!version)
629- return NULL;
630-
631- if (strcmp(version, "2013.4.0") == 0)
632- compat = 14;
633-
634- return json_object_new_int(compat);
635-}
636-
637 static struct json_object * respondd_provider_nodeinfo(void) {
638 struct json_object *ret = json_object_new_object();
639
640- char *version = gluonutil_read_line("/sys/module/batman_adv/version");
641- struct json_object *compat = get_batman_adv_compat(version);
642-
643 struct json_object *network = json_object_new_object();
644 json_object_object_add(network, "addresses", get_addresses());
645 json_object_object_add(network, "mesh", get_mesh());
646@@ -257,8 +242,9 @@ static struct json_object * respondd_provider_nodeinfo(void) {
647
648 struct json_object *software = json_object_new_object();
649 struct json_object *software_batman_adv = json_object_new_object();
650- json_object_object_add(software_batman_adv, "version", gluonutil_wrap_and_free_string(version));
651- json_object_object_add(software_batman_adv, "compat", compat);
652+ json_object_object_add(software_batman_adv, "version",
653+ gluonutil_wrap_and_free_string(gluonutil_read_line("/sys/module/batman_adv/version")));
654+ json_object_object_add(software_batman_adv, "compat", json_object_new_int(15));
655 json_object_object_add(software, "batman-adv", software_batman_adv);
656 json_object_object_add(ret, "software", software);
657
658diff --git a/package/gluon-mmfd/Makefile b/package/gluon-mmfd/Makefile
659new file mode 100644
660index 00000000..dc66bf4f
661--- /dev/null
662+++ b/package/gluon-mmfd/Makefile
663@@ -0,0 +1,13 @@
664+include $(TOPDIR)/rules.mk
665+
666+PKG_NAME:=gluon-mmfd
667+PKG_VERSION:=1
668+
669+include ../gluon.mk
670+
671+define Package/gluon-mmfd
672+ TITLE:=Mesh multicast forwarding daemon - Gluon integration
673+ DEPENDS:=+mmfd +uc +gluon-core
674+endef
675+
676+$(eval $(call BuildPackageGluon,gluon-mmfd))
677diff --git a/package/gluon-mmfd/files/etc/init.d/mmfd b/package/gluon-mmfd/files/etc/init.d/mmfd
678new file mode 100755
679index 00000000..4307c7e7
680--- /dev/null
681+++ b/package/gluon-mmfd/files/etc/init.d/mmfd
682@@ -0,0 +1,60 @@
683+#!/bin/sh /etc/rc.common
684+
685+USE_PROCD=1
686+START=50
687+DAEMON=/usr/sbin/mmfd
688+SOCKET=/var/run/mmfd.sock
689+
690+start_service() {
691+ local interfaces=$(for dev in $(gluon-list-mesh-interfaces); do echo " -i $dev"; done)
692+
693+ procd_open_instance
694+ procd_set_param command $DAEMON -s $SOCKET $interfaces
695+ procd_set_param respawn ${respawn_threshold:-60} ${respawn_timeout:-1} ${respawn_retry:-0}
696+ procd_set_param stderr 1
697+ procd_set_param stdout 1
698+ procd_close_instance
699+}
700+
701+mmfd_get_interfaces() {
702+ echo get_meshifs | uc $SOCKET | jsonfilter -e "@.mesh_interfaces[@]"
703+}
704+
705+mmfd_has_interface() {
706+ mmfd_get_interfaces | grep -q "^$1$"
707+}
708+
709+addif() {
710+ echo "add_meshif $@" | uc $SOCKET
711+}
712+
713+delif() {
714+ echo "del_meshif $@" | uc $SOCKET
715+}
716+
717+reload_service() {
718+ waitforsocket
719+
720+ for i in $(ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device")
721+ do
722+ if ! mmfd_has_interface $i; then
723+ addif $i
724+ fi
725+ done
726+
727+ for i in $(mmfd_get_interfaces)
728+ do
729+ if ! ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device" | grep -q "^$i$"; then
730+ delif $i
731+ fi
732+ done
733+}
734+
735+service_triggers() {
736+ local script=$(readlink "$initscript")
737+ local name=$(basename "${script:-$initscript}")
738+
739+ procd_open_trigger
740+ procd_add_raw_trigger "interface.*" 0 "/etc/init.d/$name" reload
741+ procd_close_trigger
742+}
743diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear
744index 590aede3..2bbf1c29 100755
745--- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear
746+++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear
747@@ -9,7 +9,7 @@ start_service() {
748
749 . /etc/init.d/dropbear
750
751- [ -s /etc/dropbear/dropbear_rsa_host_key ] || keygen
752+ hk_generate_as_needed
753
754 . /lib/functions.sh
755 . /lib/functions/network.sh
756diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led
757index b01ae599..7242451c 100755
758--- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led
759+++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led
760@@ -6,6 +6,12 @@ start() {
761 /etc/init.d/led start
762
763 . /etc/diag.sh
764- get_status_led
765+
766+ get_status_led 2> /dev/null
767+
768+ if [ -z $status_led ]; then
769+ status_led="$running"
770+ fi
771+
772 status_led_set_timer 1000 300
773 }
774diff --git a/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html b/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html
775index 94c1d433..6e18b010 100644
776--- a/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html
777+++ b/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html
778@@ -116,6 +116,10 @@
779 <% if nodeinfo.software.fastd then -%>
780 <dt><%:Mesh VPN%></dt><dd><%| enabled(nodeinfo.software.fastd.enabled) %></dd>
781 <%- end %>
782+ <dt><%:Site%></dt><dd><%| site.site_name() %></dd>
783+ <% if nodeinfo.system.domain_code then -%>
784+ <dt><%:Domain%></dt><dd><%| site.domain_names[nodeinfo.system.domain_code]() %></dd>
785+ <%- end %>
786 <% if nodeinfo.software.autoupdater then -%>
787 <dt><%:Automatic updates%></dt><dd><%| enabled(nodeinfo.software.autoupdater.enabled) %><%|
788 nodeinfo.software.autoupdater.enabled and
789diff --git a/package/gluon-status-page/i18n/de.po b/package/gluon-status-page/i18n/de.po
790index 2e2d54b9..ede125ba 100644
791--- a/package/gluon-status-page/i18n/de.po
792+++ b/package/gluon-status-page/i18n/de.po
793@@ -117,3 +117,9 @@ msgstr "aktiviert"
794
795 msgid "not connected"
796 msgstr "nicht verbunden"
797+
798+msgid "Domain"
799+msgstr "Domäne"
800+
801+msgid "Site"
802+msgstr "Site"
803diff --git a/package/gluon-status-page/i18n/gluon-status-page.pot b/package/gluon-status-page/i18n/gluon-status-page.pot
804index 1b4cd75b..08b6f386 100644
805--- a/package/gluon-status-page/i18n/gluon-status-page.pot
806+++ b/package/gluon-status-page/i18n/gluon-status-page.pot
807@@ -108,3 +108,9 @@ msgstr ""
808
809 msgid "not connected"
810 msgstr ""
811+
812+msgid "Domain"
813+msgstr ""
814+
815+msgid "Site"
816+msgstr ""
817diff --git a/package/gluon-status-page/luasrc/lib/gluon/status-page/controller/status-page.lua b/package/gluon-status-page/luasrc/lib/gluon/status-page/controller/status-page.lua
818index bdd46979..ceb5d855 100644
819--- a/package/gluon-status-page/luasrc/lib/gluon/status-page/controller/status-page.lua
820+++ b/package/gluon-status-page/luasrc/lib/gluon/status-page/controller/status-page.lua
821@@ -82,5 +82,5 @@ entry({}, call(function(http, renderer)
822 end
823
824
825- renderer.render('status-page', { nodeinfo = nodeinfo }, 'gluon-status-page')
826+ renderer.render('status-page', { nodeinfo = nodeinfo, site = site }, 'gluon-status-page')
827 end))
828diff --git a/patches/openwrt/0005-dropbear-add-a-failsafe-mode-that-will-always-allow-password-less-root-login.patch b/patches/openwrt/0005-dropbear-add-a-failsafe-mode-that-will-always-allow-password-less-root-login.patch
829index a6e9213b..d2010181 100644
830--- a/patches/openwrt/0005-dropbear-add-a-failsafe-mode-that-will-always-allow-password-less-root-login.patch
831+++ b/patches/openwrt/0005-dropbear-add-a-failsafe-mode-that-will-always-allow-password-less-root-login.patch
832@@ -6,24 +6,13 @@ Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
833
834 diff --git a/package/network/services/dropbear/patches/700-failsafe-mode.patch b/package/network/services/dropbear/patches/700-failsafe-mode.patch
835 new file mode 100644
836-index 0000000000000000000000000000000000000000..d379da0d0a7890e0a25d87e227c2e065cd2750ee
837+index 0000000000000000000000000000000000000000..bd9cf1ce4234d94bcc5b782cc753f59993f999bc
838 --- /dev/null
839 +++ b/package/network/services/dropbear/patches/700-failsafe-mode.patch
840 @@ -0,0 +1,57 @@
841-+--- a/runopts.h
842-++++ b/runopts.h
843-+@@ -98,6 +98,8 @@ typedef struct svr_runopts {
844-+ int allowblankpass;
845-+ unsigned int maxauthtries;
846-+
847-++ int failsafe_mode;
848-++
849-+ #ifdef ENABLE_SVR_REMOTETCPFWD
850-+ int noremotetcp;
851-+ #endif
852 +--- a/svr-auth.c
853 ++++ b/svr-auth.c
854-+@@ -149,10 +149,11 @@ void recv_msg_userauth_request() {
855++@@ -125,10 +125,11 @@ void recv_msg_userauth_request() {
856 + AUTH_METHOD_NONE_LEN) == 0) {
857 + TRACE(("recv_msg_userauth_request: 'none' request"))
858 + if (valid_user
859@@ -41,23 +30,23 @@ index 0000000000000000000000000000000000000000..d379da0d0a7890e0a25d87e227c2e065
860 + "Auth succeeded with blank password for '%s' from %s",
861 +--- a/svr-runopts.c
862 ++++ b/svr-runopts.c
863-+@@ -72,6 +72,7 @@ static void printhelp(const char * progn
864++@@ -77,6 +77,7 @@ static void printhelp(const char * progn
865 + "-s Disable password logins\n"
866 + "-g Disable password logins for root\n"
867 + "-B Allow blank password logins\n"
868 ++ "-f Failsafe mode: always allow password-less root login\n"
869 + #endif
870-+ "-T <1 to %d> Maximum authentication tries (default %d)\n"
871-+ #ifdef ENABLE_SVR_LOCALTCPFWD
872-+@@ -133,6 +134,7 @@ void svr_getopts(int argc, char ** argv)
873++ "-T Maximum authentication tries (default %d)\n"
874++ #if DROPBEAR_SVR_LOCALTCPFWD
875++@@ -144,6 +145,7 @@ void svr_getopts(int argc, char ** argv)
876 + svr_opts.noauthpass = 0;
877 + svr_opts.norootpass = 0;
878 + svr_opts.allowblankpass = 0;
879 ++ svr_opts.failsafe_mode = 0;
880-+ svr_opts.maxauthtries = DEFAULT_AUTH_TRIES;
881++ svr_opts.maxauthtries = MAX_AUTH_TRIES;
882 + svr_opts.inetdmode = 0;
883 + svr_opts.portcount = 0;
884-+@@ -251,6 +253,9 @@ void svr_getopts(int argc, char ** argv)
885++@@ -266,6 +268,9 @@ void svr_getopts(int argc, char ** argv)
886 + case 'B':
887 + svr_opts.allowblankpass = 1;
888 + break;
889@@ -67,3 +56,14 @@ index 0000000000000000000000000000000000000000..d379da0d0a7890e0a25d87e227c2e065
890 + #endif
891 + case 'h':
892 + printhelp(argv[0]);
893++--- a/runopts.h
894+++++ b/runopts.h
895++@@ -106,6 +106,8 @@ typedef struct svr_runopts {
896++ int allowblankpass;
897++ unsigned int maxauthtries;
898++
899+++ int failsafe_mode;
900+++
901++ #if DROPBEAR_SVR_REMOTETCPFWD
902++ int noremotetcp;
903++ #endif
904diff --git a/patches/openwrt/0006-generic-vxlan-backport-support-for-VXLAN-over-link-local-IPv6-to-4.9.patch b/patches/openwrt/0006-generic-vxlan-backport-support-for-VXLAN-over-link-local-IPv6-to-4.9.patch
905deleted file mode 100644
906index ccc1623e..00000000
907--- a/patches/openwrt/0006-generic-vxlan-backport-support-for-VXLAN-over-link-local-IPv6-to-4.9.patch
908+++ /dev/null
909@@ -1,464 +0,0 @@
910-From: Matthias Schiffer <mschiffer@universe-factory.net>
911-Date: Tue, 9 Jan 2018 22:38:19 +0100
912-Subject: generic: vxlan: backport support for VXLAN over link-local IPv6 to 4.9
913-
914-Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
915-
916-diff --git a/target/linux/generic/backport-4.9/095-0001-vxlan-improve-validation-of-address-family-configura.patch b/target/linux/generic/backport-4.9/095-0001-vxlan-improve-validation-of-address-family-configura.patch
917-new file mode 100644
918-index 0000000000000000000000000000000000000000..2114562536675cd59450928f591e70d66f8fc7b9
919---- /dev/null
920-+++ b/target/linux/generic/backport-4.9/095-0001-vxlan-improve-validation-of-address-family-configura.patch
921-@@ -0,0 +1,73 @@
922-+From f45ba82cd83d27b5d44d3dc417e0e480ba0d3703 Mon Sep 17 00:00:00 2001
923-+Message-Id: <f45ba82cd83d27b5d44d3dc417e0e480ba0d3703.1515533863.git.mschiffer@universe-factory.net>
924-+From: Matthias Schiffer <mschiffer@universe-factory.net>
925-+Date: Mon, 19 Jun 2017 10:03:57 +0200
926-+Subject: [PATCH 1/4] vxlan: improve validation of address family configuration
927-+
928-+Address families of source and destination addresses must match, and
929-+changelink operations can't change the address family.
930-+
931-+In addition, always use the VXLAN_F_IPV6 to check if a VXLAN device uses
932-+IPv4 or IPv6.
933-+
934-+Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
935-+Signed-off-by: David S. Miller <davem@davemloft.net>
936-+[Matthias Schiffer: rebase to v4.9.y]
937-+---
938-+ drivers/net/vxlan.c | 23 +++++++++++++++--------
939-+ 1 file changed, 15 insertions(+), 8 deletions(-)
940-+
941-+diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
942-+index 983e941bdf29..fbe8da7fa296 100644
943-+--- a/drivers/net/vxlan.c
944-++++ b/drivers/net/vxlan.c
945-+@@ -2867,12 +2867,20 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
946-+
947-+ memcpy(&dst->remote_ip, &conf->remote_ip, sizeof(conf->remote_ip));
948-+
949-+- /* Unless IPv6 is explicitly requested, assume IPv4 */
950-+- if (!dst->remote_ip.sa.sa_family)
951-++ if (!dst->remote_ip.sa.sa_family && !conf->saddr.sa.sa_family) {
952-++ /* Unless IPv6 is explicitly requested, assume IPv4 */
953-+ dst->remote_ip.sa.sa_family = AF_INET;
954-++ conf->saddr.sa.sa_family = AF_INET;
955-++ } else if (!dst->remote_ip.sa.sa_family) {
956-++ dst->remote_ip.sa.sa_family = conf->saddr.sa.sa_family;
957-++ } else if (!conf->saddr.sa.sa_family) {
958-++ conf->saddr.sa.sa_family = dst->remote_ip.sa.sa_family;
959-++ }
960-++
961-++ if (conf->saddr.sa.sa_family != dst->remote_ip.sa.sa_family)
962-++ return -EINVAL;
963-+
964-+- if (dst->remote_ip.sa.sa_family == AF_INET6 ||
965-+- vxlan->cfg.saddr.sa.sa_family == AF_INET6) {
966-++ if (conf->saddr.sa.sa_family == AF_INET6) {
967-+ if (!IS_ENABLED(CONFIG_IPV6))
968-+ return -EPFNOSUPPORT;
969-+ use_ipv6 = true;
970-+@@ -2938,11 +2946,9 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
971-+
972-+ list_for_each_entry(tmp, &vn->vxlan_list, next) {
973-+ if (tmp->cfg.vni == conf->vni &&
974-+- (tmp->default_dst.remote_ip.sa.sa_family == AF_INET6 ||
975-+- tmp->cfg.saddr.sa.sa_family == AF_INET6) == use_ipv6 &&
976-+ tmp->cfg.dst_port == vxlan->cfg.dst_port &&
977-+- (tmp->flags & VXLAN_F_RCV_FLAGS) ==
978-+- (vxlan->flags & VXLAN_F_RCV_FLAGS)) {
979-++ (tmp->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)) ==
980-++ (vxlan->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6))) {
981-+ pr_info("duplicate VNI %u\n", be32_to_cpu(conf->vni));
982-+ return -EEXIST;
983-+ }
984-+@@ -2987,6 +2993,7 @@ static int vxlan_newlink(struct net *src_net, struct net_device *dev,
985-+
986-+ if (data[IFLA_VXLAN_GROUP]) {
987-+ conf.remote_ip.sin.sin_addr.s_addr = nla_get_in_addr(data[IFLA_VXLAN_GROUP]);
988-++ conf.remote_ip.sa.sa_family = AF_INET;
989-+ } else if (data[IFLA_VXLAN_GROUP6]) {
990-+ if (!IS_ENABLED(CONFIG_IPV6))
991-+ return -EPFNOSUPPORT;
992-+--
993-+2.15.1
994-+
995-diff --git a/target/linux/generic/backport-4.9/095-0002-vxlan-check-valid-combinations-of-address-scopes.patch b/target/linux/generic/backport-4.9/095-0002-vxlan-check-valid-combinations-of-address-scopes.patch
996-new file mode 100644
997-index 0000000000000000000000000000000000000000..b38b9977bca192eafe9a0d9b8c36a120b3a2c590
998---- /dev/null
999-+++ b/target/linux/generic/backport-4.9/095-0002-vxlan-check-valid-combinations-of-address-scopes.patch
1000-@@ -0,0 +1,91 @@
1001-+From 0eb4ccfc77e07fb4bfc7b1778a7ecb136b47aba4 Mon Sep 17 00:00:00 2001
1002-+Message-Id: <0eb4ccfc77e07fb4bfc7b1778a7ecb136b47aba4.1515533863.git.mschiffer@universe-factory.net>
1003-+In-Reply-To: <f45ba82cd83d27b5d44d3dc417e0e480ba0d3703.1515533863.git.mschiffer@universe-factory.net>
1004-+References: <f45ba82cd83d27b5d44d3dc417e0e480ba0d3703.1515533863.git.mschiffer@universe-factory.net>
1005-+From: Matthias Schiffer <mschiffer@universe-factory.net>
1006-+Date: Mon, 19 Jun 2017 10:03:58 +0200
1007-+Subject: [PATCH 2/4] vxlan: check valid combinations of address scopes
1008-+
1009-+* Multicast addresses are never valid as local address
1010-+* Link-local IPv6 unicast addresses may only be used as remote when the
1011-+ local address is link-local as well
1012-+* Don't allow link-local IPv6 local/remote addresses without interface
1013-+
1014-+We also store in the flags field if link-local addresses are used for the
1015-+follow-up patches that actually make VXLAN over link-local IPv6 work.
1016-+
1017-+Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
1018-+Signed-off-by: David S. Miller <davem@davemloft.net>
1019-+[Matthias Schiffer: rebase to v4.9.y]
1020-+---
1021-+ drivers/net/vxlan.c | 29 +++++++++++++++++++++++++++++
1022-+ include/net/vxlan.h | 1 +
1023-+ 2 files changed, 30 insertions(+)
1024-+
1025-+diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
1026-+index fbe8da7fa296..863d9528b900 100644
1027-+--- a/drivers/net/vxlan.c
1028-++++ b/drivers/net/vxlan.c
1029-+@@ -2880,11 +2880,35 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
1030-+ if (conf->saddr.sa.sa_family != dst->remote_ip.sa.sa_family)
1031-+ return -EINVAL;
1032-+
1033-++ if (vxlan_addr_multicast(&conf->saddr))
1034-++ return -EINVAL;
1035-++
1036-+ if (conf->saddr.sa.sa_family == AF_INET6) {
1037-+ if (!IS_ENABLED(CONFIG_IPV6))
1038-+ return -EPFNOSUPPORT;
1039-+ use_ipv6 = true;
1040-+ vxlan->flags |= VXLAN_F_IPV6;
1041-++
1042-++ if (!(conf->flags & VXLAN_F_COLLECT_METADATA)) {
1043-++ int local_type =
1044-++ ipv6_addr_type(&conf->saddr.sin6.sin6_addr);
1045-++ int remote_type =
1046-++ ipv6_addr_type(&dst->remote_ip.sin6.sin6_addr);
1047-++
1048-++ if (local_type & IPV6_ADDR_LINKLOCAL) {
1049-++ if (!(remote_type & IPV6_ADDR_LINKLOCAL) &&
1050-++ (remote_type != IPV6_ADDR_ANY))
1051-++ return -EINVAL;
1052-++
1053-++ vxlan->flags |= VXLAN_F_IPV6_LINKLOCAL;
1054-++ } else {
1055-++ if (remote_type ==
1056-++ (IPV6_ADDR_UNICAST | IPV6_ADDR_LINKLOCAL))
1057-++ return -EINVAL;
1058-++
1059-++ vxlan->flags &= ~VXLAN_F_IPV6_LINKLOCAL;
1060-++ }
1061-++ }
1062-+ }
1063-+
1064-+ if (conf->label && !use_ipv6) {
1065-+@@ -2918,6 +2942,11 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
1066-+ } else if (vxlan_addr_multicast(&dst->remote_ip)) {
1067-+ pr_info("multicast destination requires interface to be specified\n");
1068-+ return -EINVAL;
1069-++ } else {
1070-++#if IS_ENABLED(CONFIG_IPV6)
1071-++ if (vxlan->flags & VXLAN_F_IPV6_LINKLOCAL)
1072-++ return -EINVAL;
1073-++#endif
1074-+ }
1075-+
1076-+ if (conf->mtu) {
1077-+diff --git a/include/net/vxlan.h b/include/net/vxlan.h
1078-+index 9fce47e3e13e..c1c0d03e3456 100644
1079-+--- a/include/net/vxlan.h
1080-++++ b/include/net/vxlan.h
1081-+@@ -267,6 +267,7 @@ struct vxlan_dev {
1082-+ #define VXLAN_F_REMCSUM_NOPARTIAL 0x1000
1083-+ #define VXLAN_F_COLLECT_METADATA 0x2000
1084-+ #define VXLAN_F_GPE 0x4000
1085-++#define VXLAN_F_IPV6_LINKLOCAL 0x8000
1086-+
1087-+ /* Flags that are used in the receive path. These flags must match in
1088-+ * order for a socket to be shareable
1089-+--
1090-+2.15.1
1091-+
1092-diff --git a/target/linux/generic/backport-4.9/095-0003-vxlan-fix-snooping-for-link-local-IPv6-addresses.patch b/target/linux/generic/backport-4.9/095-0003-vxlan-fix-snooping-for-link-local-IPv6-addresses.patch
1093-new file mode 100644
1094-index 0000000000000000000000000000000000000000..89523ac027b227a9f84b1130db06a7fc67ff68ce
1095---- /dev/null
1096-+++ b/target/linux/generic/backport-4.9/095-0003-vxlan-fix-snooping-for-link-local-IPv6-addresses.patch
1097-@@ -0,0 +1,88 @@
1098-+From 010b2b541d958e12d78ba1c79734c700f169610b Mon Sep 17 00:00:00 2001
1099-+Message-Id: <010b2b541d958e12d78ba1c79734c700f169610b.1515533863.git.mschiffer@universe-factory.net>
1100-+In-Reply-To: <f45ba82cd83d27b5d44d3dc417e0e480ba0d3703.1515533863.git.mschiffer@universe-factory.net>
1101-+References: <f45ba82cd83d27b5d44d3dc417e0e480ba0d3703.1515533863.git.mschiffer@universe-factory.net>
1102-+From: Matthias Schiffer <mschiffer@universe-factory.net>
1103-+Date: Mon, 19 Jun 2017 10:03:59 +0200
1104-+Subject: [PATCH 3/4] vxlan: fix snooping for link-local IPv6 addresses
1105-+
1106-+If VXLAN is run over link-local IPv6 addresses, it is necessary to store
1107-+the ifindex in the FDB entries. Otherwise, the used interface is undefined
1108-+and unicast communication will most likely fail.
1109-+
1110-+Support for link-local IPv4 addresses should be possible as well, but as
1111-+the semantics aren't as well defined as for IPv6, and there doesn't seem to
1112-+be much interest in having the support, it's not implemented for now.
1113-+
1114-+Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
1115-+Signed-off-by: David S. Miller <davem@davemloft.net>
1116-+[Matthias Schiffer: rebase to v4.9.y]
1117-+---
1118-+ drivers/net/vxlan.c | 20 +++++++++++++++-----
1119-+ 1 file changed, 15 insertions(+), 5 deletions(-)
1120-+
1121-+--- a/drivers/net/vxlan.c
1122-++++ b/drivers/net/vxlan.c
1123-+@@ -917,16 +917,25 @@ out:
1124-+ * Return true if packet is bogus and should be dropped.
1125-+ */
1126-+ static bool vxlan_snoop(struct net_device *dev,
1127-+- union vxlan_addr *src_ip, const u8 *src_mac)
1128-++ union vxlan_addr *src_ip, const u8 *src_mac,
1129-++ u32 src_ifindex)
1130-+ {
1131-+ struct vxlan_dev *vxlan = netdev_priv(dev);
1132-+ struct vxlan_fdb *f;
1133-++ u32 ifindex = 0;
1134-++
1135-++#if IS_ENABLED(CONFIG_IPV6)
1136-++ if (src_ip->sa.sa_family == AF_INET6 &&
1137-++ (ipv6_addr_type(&src_ip->sin6.sin6_addr) & IPV6_ADDR_LINKLOCAL))
1138-++ ifindex = src_ifindex;
1139-++#endif
1140-+
1141-+ f = vxlan_find_mac(vxlan, src_mac);
1142-+ if (likely(f)) {
1143-+ struct vxlan_rdst *rdst = first_remote_rcu(f);
1144-+
1145-+- if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip)))
1146-++ if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip) &&
1147-++ rdst->remote_ifindex == ifindex))
1148-+ return false;
1149-+
1150-+ /* Don't migrate static entries, drop packets */
1151-+@@ -952,7 +961,7 @@ static bool vxlan_snoop(struct net_devic
1152-+ NLM_F_EXCL|NLM_F_CREATE,
1153-+ vxlan->cfg.dst_port,
1154-+ vxlan->default_dst.remote_vni,
1155-+- 0, NTF_SELF);
1156-++ ifindex, NTF_SELF);
1157-+ spin_unlock(&vxlan->hash_lock);
1158-+ }
1159-+
1160-+@@ -1223,6 +1232,7 @@ static bool vxlan_set_mac(struct vxlan_d
1161-+ struct sk_buff *skb)
1162-+ {
1163-+ union vxlan_addr saddr;
1164-++ u32 ifindex = skb->dev->ifindex;
1165-+
1166-+ skb_reset_mac_header(skb);
1167-+ skb->protocol = eth_type_trans(skb, vxlan->dev);
1168-+@@ -1244,7 +1254,7 @@ static bool vxlan_set_mac(struct vxlan_d
1169-+ }
1170-+
1171-+ if ((vxlan->flags & VXLAN_F_LEARN) &&
1172-+- vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source))
1173-++ vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source, ifindex))
1174-+ return false;
1175-+
1176-+ return true;
1177-+@@ -1939,7 +1949,7 @@ static void vxlan_encap_bypass(struct sk
1178-+ }
1179-+
1180-+ if (dst_vxlan->flags & VXLAN_F_LEARN)
1181-+- vxlan_snoop(dev, &loopback, eth_hdr(skb)->h_source);
1182-++ vxlan_snoop(dev, &loopback, eth_hdr(skb)->h_source, 0);
1183-+
1184-+ u64_stats_update_begin(&tx_stats->syncp);
1185-+ tx_stats->tx_packets++;
1186-diff --git a/target/linux/generic/backport-4.9/095-0004-vxlan-allow-multiple-VXLANs-with-same-VNI-for-IPv6-l.patch b/target/linux/generic/backport-4.9/095-0004-vxlan-allow-multiple-VXLANs-with-same-VNI-for-IPv6-l.patch
1187-new file mode 100644
1188-index 0000000000000000000000000000000000000000..18ae230a3b04d2b57184109fa14f9533f0fb7192
1189---- /dev/null
1190-+++ b/target/linux/generic/backport-4.9/095-0004-vxlan-allow-multiple-VXLANs-with-same-VNI-for-IPv6-l.patch
1191-@@ -0,0 +1,182 @@
1192-+From 95583c75a95449dade713e1dad4ed0a8dcc1b391 Mon Sep 17 00:00:00 2001
1193-+Message-Id: <95583c75a95449dade713e1dad4ed0a8dcc1b391.1515533863.git.mschiffer@universe-factory.net>
1194-+In-Reply-To: <f45ba82cd83d27b5d44d3dc417e0e480ba0d3703.1515533863.git.mschiffer@universe-factory.net>
1195-+References: <f45ba82cd83d27b5d44d3dc417e0e480ba0d3703.1515533863.git.mschiffer@universe-factory.net>
1196-+From: Matthias Schiffer <mschiffer@universe-factory.net>
1197-+Date: Mon, 19 Jun 2017 10:04:00 +0200
1198-+Subject: [PATCH 4/4] vxlan: allow multiple VXLANs with same VNI for IPv6
1199-+ link-local addresses
1200-+
1201-+As link-local addresses are only valid for a single interface, we can allow
1202-+to use the same VNI for multiple independent VXLANs, as long as the used
1203-+interfaces are distinct. This way, VXLANs can always be used as a drop-in
1204-+replacement for VLANs with greater ID space.
1205-+
1206-+This also extends VNI lookup to respect the ifindex when link-local IPv6
1207-+addresses are used, so using the same VNI on multiple interfaces can
1208-+actually work.
1209-+
1210-+Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
1211-+Signed-off-by: David S. Miller <davem@davemloft.net>
1212-+[Matthias Schiffer: rebase to v4.9.y]
1213-+---
1214-+ drivers/net/vxlan.c | 60 ++++++++++++++++++++++++++++++++++++-----------------
1215-+ 1 file changed, 41 insertions(+), 19 deletions(-)
1216-+
1217-+diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
1218-+index c28c6f34b3b3..9208e3d9ec43 100644
1219-+--- a/drivers/net/vxlan.c
1220-++++ b/drivers/net/vxlan.c
1221-+@@ -225,7 +225,8 @@ static struct vxlan_sock *vxlan_find_sock(struct net *net, sa_family_t family,
1222-+ return NULL;
1223-+ }
1224-+
1225-+-static struct vxlan_dev *vxlan_vs_find_vni(struct vxlan_sock *vs, __be32 vni)
1226-++static struct vxlan_dev *vxlan_vs_find_vni(struct vxlan_sock *vs, int ifindex,
1227-++ __be32 vni)
1228-+ {
1229-+ struct vxlan_dev_node *node;
1230-+
1231-+@@ -234,17 +235,27 @@ static struct vxlan_dev *vxlan_vs_find_vni(struct vxlan_sock *vs, __be32 vni)
1232-+ vni = 0;
1233-+
1234-+ hlist_for_each_entry_rcu(node, vni_head(vs, vni), hlist) {
1235-+- if (node->vxlan->default_dst.remote_vni == vni)
1236-+- return node->vxlan;
1237-++ if (node->vxlan->default_dst.remote_vni != vni)
1238-++ continue;
1239-++
1240-++ if (IS_ENABLED(CONFIG_IPV6)) {
1241-++ const struct vxlan_config *cfg = &node->vxlan->cfg;
1242-++
1243-++ if ((node->vxlan->flags & VXLAN_F_IPV6_LINKLOCAL) &&
1244-++ cfg->remote_ifindex != ifindex)
1245-++ continue;
1246-++ }
1247-++
1248-++ return node->vxlan;
1249-+ }
1250-+
1251-+ return NULL;
1252-+ }
1253-+
1254-+ /* Look up VNI in a per net namespace table */
1255-+-static struct vxlan_dev *vxlan_find_vni(struct net *net, __be32 vni,
1256-+- sa_family_t family, __be16 port,
1257-+- u32 flags)
1258-++static struct vxlan_dev *vxlan_find_vni(struct net *net, int ifindex,
1259-++ __be32 vni, sa_family_t family,
1260-++ __be16 port, u32 flags)
1261-+ {
1262-+ struct vxlan_sock *vs;
1263-+
1264-+@@ -252,7 +263,7 @@ static struct vxlan_dev *vxlan_find_vni(struct net *net, __be32 vni,
1265-+ if (!vs)
1266-+ return NULL;
1267-+
1268-+- return vxlan_vs_find_vni(vs, vni);
1269-++ return vxlan_vs_find_vni(vs, ifindex, vni);
1270-+ }
1271-+
1272-+ /* Fill in neighbour message in skbuff. */
1273-+@@ -1317,7 +1328,8 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
1274-+ if (!vs)
1275-+ goto drop;
1276-+
1277-+- vxlan = vxlan_vs_find_vni(vs, vxlan_vni(vxlan_hdr(skb)->vx_vni));
1278-++ vxlan = vxlan_vs_find_vni(vs, skb->dev->ifindex,
1279-++ vxlan_vni(vxlan_hdr(skb)->vx_vni));
1280-+ if (!vxlan)
1281-+ goto drop;
1282-+
1283-+@@ -1976,6 +1988,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1284-+ __be32 vni, label;
1285-+ __be16 df = 0;
1286-+ __u8 tos, ttl;
1287-++ int ifindex;
1288-+ int err;
1289-+ u32 flags = vxlan->flags;
1290-+ bool udp_sum = false;
1291-+@@ -1987,6 +2000,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1292-+ if (rdst) {
1293-+ dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port;
1294-+ vni = rdst->remote_vni;
1295-++ ifindex = rdst->remote_ifindex;
1296-+ dst = &rdst->remote_ip;
1297-+ local_ip = vxlan->cfg.saddr;
1298-+ dst_cache = &rdst->dst_cache;
1299-+@@ -1998,6 +2012,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1300-+ }
1301-+ dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port;
1302-+ vni = tunnel_id_to_key32(info->key.tun_id);
1303-++ ifindex = 0;
1304-+ remote_ip.sa.sa_family = ip_tunnel_info_af(info);
1305-+ if (remote_ip.sa.sa_family == AF_INET) {
1306-+ remote_ip.sin.sin_addr.s_addr = info->key.u.ipv4.dst;
1307-+@@ -2053,7 +2068,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1308-+ sk = sock4->sock->sk;
1309-+
1310-+ rt = vxlan_get_route(vxlan, skb,
1311-+- rdst ? rdst->remote_ifindex : 0, tos,
1312-++ ifindex, tos,
1313-+ dst->sin.sin_addr.s_addr,
1314-+ &local_ip.sin.sin_addr.s_addr,
1315-+ dst_cache, info);
1316-+@@ -2077,7 +2092,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1317-+ struct vxlan_dev *dst_vxlan;
1318-+
1319-+ ip_rt_put(rt);
1320-+- dst_vxlan = vxlan_find_vni(vxlan->net, vni,
1321-++ dst_vxlan = vxlan_find_vni(vxlan->net, ifindex, vni,
1322-+ dst->sa.sa_family, dst_port,
1323-+ vxlan->flags);
1324-+ if (!dst_vxlan)
1325-+@@ -2112,7 +2127,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1326-+ sk = sock6->sock->sk;
1327-+
1328-+ ndst = vxlan6_get_route(vxlan, skb,
1329-+- rdst ? rdst->remote_ifindex : 0, tos,
1330-++ ifindex, tos,
1331-+ label, &dst->sin6.sin6_addr,
1332-+ &local_ip.sin6.sin6_addr,
1333-+ dst_cache, info);
1334-+@@ -2138,7 +2153,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1335-+ struct vxlan_dev *dst_vxlan;
1336-+
1337-+ dst_release(ndst);
1338-+- dst_vxlan = vxlan_find_vni(vxlan->net, vni,
1339-++ dst_vxlan = vxlan_find_vni(vxlan->net, ifindex, vni,
1340-+ dst->sa.sa_family, dst_port,
1341-+ vxlan->flags);
1342-+ if (!dst_vxlan)
1343-+@@ -2984,13 +2999,20 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
1344-+ vxlan->cfg.age_interval = FDB_AGE_DEFAULT;
1345-+
1346-+ list_for_each_entry(tmp, &vn->vxlan_list, next) {
1347-+- if (tmp->cfg.vni == conf->vni &&
1348-+- tmp->cfg.dst_port == vxlan->cfg.dst_port &&
1349-+- (tmp->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)) ==
1350-+- (vxlan->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6))) {
1351-+- pr_info("duplicate VNI %u\n", be32_to_cpu(conf->vni));
1352-+- return -EEXIST;
1353-+- }
1354-++ if (tmp->cfg.vni != conf->vni)
1355-++ continue;
1356-++ if (tmp->cfg.dst_port != vxlan->cfg.dst_port)
1357-++ continue;
1358-++ if ((tmp->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)) !=
1359-++ (vxlan->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)))
1360-++ continue;
1361-++
1362-++ if ((vxlan->flags & VXLAN_F_IPV6_LINKLOCAL) &&
1363-++ tmp->cfg.remote_ifindex != vxlan->cfg.remote_ifindex)
1364-++ continue;
1365-++
1366-++ pr_info("duplicate VNI %u\n", be32_to_cpu(conf->vni));
1367-++ return -EEXIST;
1368-+ }
1369-+
1370-+ dev->ethtool_ops = &vxlan_ethtool_ops;
1371-+--
1372-+2.15.1
1373-+
1374diff --git a/patches/openwrt/0007-kernel-ebtables-add-support-for-ICMP-IGMP-type-matches.patch b/patches/openwrt/0006-kernel-ebtables-add-support-for-ICMP-IGMP-type-matches.patch
1375similarity index 100%
1376rename from patches/openwrt/0007-kernel-ebtables-add-support-for-ICMP-IGMP-type-matches.patch
1377rename to patches/openwrt/0006-kernel-ebtables-add-support-for-ICMP-IGMP-type-matches.patch
1378diff --git a/patches/openwrt/0011-ath10k-ct-reduce-memory-consumption.patch b/patches/openwrt/0007-ath10k-ct-reduce-memory-consumption.patch
1379similarity index 100%
1380rename from patches/openwrt/0011-ath10k-ct-reduce-memory-consumption.patch
1381rename to patches/openwrt/0007-ath10k-ct-reduce-memory-consumption.patch
1382diff --git a/patches/openwrt/0008-ath10k-firmware-retrieve-wave-1-firmware-from-kvalo.patch b/patches/openwrt/0008-ath10k-firmware-retrieve-wave-1-firmware-from-kvalo.patch
1383new file mode 100644
1384index 00000000..6723d348
1385--- /dev/null
1386+++ b/patches/openwrt/0008-ath10k-firmware-retrieve-wave-1-firmware-from-kvalo.patch
1387@@ -0,0 +1,53 @@
1388+From: David Bauer <mail@david-bauer.net>
1389+Date: Sat, 5 Oct 2019 02:12:56 +0200
1390+Subject: ath10k-firmware: retrieve wave 1 firmware from kvalo
1391+
1392+This commit changes the source of the Wave 1 ath10k-firmware
1393+from linux-firmware to Kall Valos ath10k-firmware repository.
1394+
1395+This is necessary as the firmware selected in linux-firmware produces
1396+frequent crashes in some circumstances.
1397+
1398+This patch can be removed as soon as linux-firmware carries
1399+10.2.4-1.0-00047 firmware.
1400+
1401+Signed-off-by: David Bauer <mail@david-bauer.net>
1402+
1403+diff --git a/package/firmware/ath10k-firmware/Makefile b/package/firmware/ath10k-firmware/Makefile
1404+index e5e541635dfa86e8b37a3325f38f1ecbcbf9af9f..15d9d0ce992a8161953ab3cc91058fc3ba36c096 100644
1405+--- a/package/firmware/ath10k-firmware/Makefile
1406++++ b/package/firmware/ath10k-firmware/Makefile
1407+@@ -606,9 +606,9 @@ define Package/ath10k-firmware-qca9888-ct-htt/install
1408+ $(1)/lib/firmware/ath10k/QCA9888/hw2.0/ct-firmware-5.bin
1409+ endef
1410+
1411+-#$(eval $(call BuildPackage,ath10k-firmware-qca9887))
1412++$(eval $(call BuildPackage,ath10k-firmware-qca9887))
1413+ #$(eval $(call BuildPackage,ath10k-firmware-qca9888))
1414+-#$(eval $(call BuildPackage,ath10k-firmware-qca988x))
1415++$(eval $(call BuildPackage,ath10k-firmware-qca988x))
1416+ #$(eval $(call BuildPackage,ath10k-firmware-qca99x0))
1417+ #$(eval $(call BuildPackage,ath10k-firmware-qca6174))
1418+ #$(eval $(call BuildPackage,ath10k-firmware-qca9984))
1419+diff --git a/package/firmware/linux-firmware/qca_ath10k.mk b/package/firmware/linux-firmware/qca_ath10k.mk
1420+index a7c5b13b84e69fd8a9f0f38e9889c4f9539af007..72735819fd16148f7fbd59309e4920475a719e23 100644
1421+--- a/package/firmware/linux-firmware/qca_ath10k.mk
1422++++ b/package/firmware/linux-firmware/qca_ath10k.mk
1423+@@ -31,7 +31,7 @@ define Package/ath10k-firmware-qca9887/install
1424+ $(PKG_BUILD_DIR)/ath10k/QCA9887/hw1.0/board.bin \
1425+ $(1)/lib/firmware/ath10k/QCA9887/hw1.0/board.bin
1426+ endef
1427+-$(eval $(call BuildPackage,ath10k-firmware-qca9887))
1428++# $(eval $(call BuildPackage,ath10k-firmware-qca9887))
1429+
1430+ Package/ath10k-firmware-qca9888 = $(call Package/firmware-default,ath10k qca9888 firmware)
1431+ define Package/ath10k-firmware-qca9888/install
1432+@@ -55,7 +55,7 @@ define Package/ath10k-firmware-qca988x/install
1433+ $(PKG_BUILD_DIR)/ath10k/QCA988X/hw2.0/firmware-5.bin \
1434+ $(1)/lib/firmware/ath10k/QCA988X/hw2.0/firmware-5.bin
1435+ endef
1436+-$(eval $(call BuildPackage,ath10k-firmware-qca988x))
1437++# $(eval $(call BuildPackage,ath10k-firmware-qca988x))
1438+
1439+ Package/ath10k-firmware-qca6174 = $(call Package/firmware-default,ath10k qca6174 firmware)
1440+ define Package/ath10k-firmware-qca6174/install
1441diff --git a/patches/openwrt/0008-ipq40xx-add-support-for-the-ZyXEL-NBG6617.patch b/patches/openwrt/0008-ipq40xx-add-support-for-the-ZyXEL-NBG6617.patch
1442deleted file mode 100644
1443index d80a24de..00000000
1444--- a/patches/openwrt/0008-ipq40xx-add-support-for-the-ZyXEL-NBG6617.patch
1445+++ /dev/null
1446@@ -1,1023 +0,0 @@
1447-From: Christian Lamparter <chunkeey@googlemail.com>
1448-Date: Thu, 21 Jun 2018 14:24:59 +0200
1449-Subject: ipq40xx: add support for the ZyXEL NBG6617
1450-
1451-This patch adds support for ZyXEL NBG6617
1452-
1453-Hardware highlights:
1454-
1455-SOC: IPQ4018 / QCA Dakota
1456-CPU: Quad-Core ARMv7 Processor rev 5 (v7l) Cortex-A7
1457-DRAM: 256 MiB DDR3L-1600/1866 Nanya NT5CC128M16IP-DI @ 537 MHz
1458-NOR: 32 MiB Macronix MX25L25635F
1459-ETH: Qualcomm Atheros QCA8075 Gigabit Switch (4 x LAN, 1 x WAN)
1460-USB: 1 x 3.0 (via Synopsys DesignWare DWC3 controller in the SoC)
1461-WLAN1: Qualcomm Atheros QCA4018 2.4GHz 802.11bgn 2:2x2
1462-WLAN2: Qualcomm Atheros QCA4018 5GHz 802.11a/n/ac 2:2x2
1463-INPUT: RESET Button, WIFI/Rfkill Togglebutton, WPS Button
1464-LEDS: Power, WAN, LAN 1-4, WLAN 2.4GHz, WLAN 5GHz, USB, WPS
1465-
1466-Serial:
1467- WARNING: The serial port needs a TTL/RS-232 3.3v level converter!
1468- The Serial setting is 115200-8-N-1. The 1x4 .1" header comes
1469- pre-soldered. Pinout:
1470- 1. 3v3 (Label printed on the PCB), 2. RX, 3. GND, 4. TX
1471-
1472-first install / debricking / restore stock:
1473- 0. Have a PC running a tftp-server @ 192.168.1.99/24
1474- 1. connect the PC to any LAN-Ports
1475- 2. put the openwrt...-factory.bin (or V1.00(ABCT.X).bin for stock) file
1476- into the tftp-server root directory and rename it to just "ras.bin".
1477- 3. power-cycle the router and hold down the the WPS button (for 30sek)
1478- 4. Wait (for a long time - the serial console provides some progress
1479- reports. The u-boot says it best: "Please be patient".
1480- 5. Once the power LED starts to flashes slowly and the USB + WPS LEDs
1481- flashes fast at the same time. You have to reboot the device and
1482- it should then come right up.
1483-
1484-Installation via Web-UI:
1485- 0. Connect a PC to the powered-on router. It will assign your PC a
1486- IP-address via DHCP
1487- 1. Access the Web-UI at 192.168.1.1 (Default Passwort: 1234)
1488- 2. Go to the "Expert Mode"
1489- 3. Under "Maintenance", select "Firmware-Upgrade"
1490- 4. Upload the OpenWRT factory image
1491- 5. Wait for the Device to finish.
1492- It will reboot into OpenWRT without any additional actions needed.
1493-
1494-To open the ZyXEL NBG6617:
1495- 0. remove the four rubber feet glued on the backside
1496- 1. remove the four philips screws and pry open the top cover
1497- (by applying force between the plastic top housing from the
1498- backside/lan-port side)
1499-
1500-Access the real u-boot shell:
1501-ZyXEL uses a proprietary loader/shell on top of u-boot: "ZyXEL zloader v2.02"
1502-When the device is starting up, the user can enter the the loader shell
1503-by simply pressing a key within the 3 seconds once the following string
1504-appears on the serial console:
1505-
1506-| Hit any key to stop autoboot: 3
1507-
1508-The user is then dropped to a locked shell.
1509-
1510-|NBG6617> HELP
1511-|ATEN x[,y] set BootExtension Debug Flag (y=password)
1512-|ATSE x show the seed of password generator
1513-|ATSH dump manufacturer related data in ROM
1514-|ATRT [x,y,z,u] RAM read/write test (x=level, y=start addr, z=end addr, u=iterations)
1515-|ATGO boot up whole system
1516-|ATUR x upgrade RAS image (filename)
1517-|NBG6617>
1518-
1519-In order to escape/unlock a password challenge has to be passed.
1520-Note: the value is dynamic! you have to calculate your own!
1521-
1522-First use ATSE $MODELNAME (MODELNAME is the hostname in u-boot env)
1523-to get the challange value/seed.
1524-
1525-|NBG6617> ATSE NBG6617
1526-|012345678901
1527-
1528-This seed/value can be converted to the password with the help of this
1529-bash script (Thanks to http://www.adslayuda.com/Zyxel650-9.html authors):
1530-
1531-- tool.sh -
1532-ror32() {
1533- echo $(( ($1 >> $2) | (($1 << (32 - $2) & (2**32-1)) ) ))
1534-}
1535-v="0x$1"
1536-a="0x${v:2:6}"
1537-b=$(( $a + 0x10F0A563))
1538-c=$(( 0x${v:12:14} & 7 ))
1539-p=$(( $(ror32 $b $c) ^ $a ))
1540-printf "ATEN 1,%X\n" $p
1541-- end of tool.sh -
1542-
1543-|# bash ./tool.sh 012345678901
1544-|
1545-|ATEN 1,879C711
1546-
1547-copy and paste the result into the shell to unlock zloader.
1548-
1549-|NBG6617> ATEN 1,0046B0017430
1550-
1551-If the entered code was correct the shell will change to
1552-use the ATGU command to enter the real u-boot shell.
1553-
1554-|NBG6617> ATGU
1555-|NBG6617#
1556-
1557-Co-authored-by: David Bauer <mail@david-bauer.net>
1558-Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
1559-Signed-off-by: David Bauer <mail@david-bauer.net>
1560-
1561-diff --git a/include/image-commands.mk b/include/image-commands.mk
1562-index 4d3f025b123f44cfd48d5b6cf081ae7633577277..28b39c310e499caea4fe8a6d9ad6dceb5d95363b 100644
1563---- a/include/image-commands.mk
1564-+++ b/include/image-commands.mk
1565-@@ -49,6 +49,19 @@ define Build/eva-image
1566- mv $@.new $@
1567- endef
1568-
1569-+define Build/make-ras
1570-+ let \
1571-+ newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
1572-+ $(TOPDIR)/scripts/make-ras.sh \
1573-+ --board $(RAS_BOARD) \
1574-+ --version $(RAS_VERSION) \
1575-+ --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
1576-+ --rootfs $@ \
1577-+ --rootfssize $$newsize \
1578-+ $@.new
1579-+ @mv $@.new $@
1580-+endef
1581-+
1582- define Build/netgear-chk
1583- $(STAGING_DIR_HOST)/bin/mkchkimg \
1584- -o $@.new \
1585-diff --git a/package/boot/uboot-envtools/files/ipq40xx b/package/boot/uboot-envtools/files/ipq40xx
1586-index d475e566299416176af3b8646a7510cd3c9787e7..8cd4799b295fd38c9e846af5769c9fa9f5490f8b 100644
1587---- a/package/boot/uboot-envtools/files/ipq40xx
1588-+++ b/package/boot/uboot-envtools/files/ipq40xx
1589-@@ -35,6 +35,9 @@ openmesh,a42 |\
1590- openmesh,a62)
1591- ubootenv_add_uci_config "/dev/mtd5" "0x0" "0x10000" "0x10000"
1592- ;;
1593-+zyxel,nbg6617)
1594-+ ubootenv_add_uci_config "/dev/mtd6" "0x0" "0x10000" "0x10000"
1595-+ ;;
1596- esac
1597-
1598- config_load ubootenv
1599-diff --git a/package/firmware/ipq-wifi/Makefile b/package/firmware/ipq-wifi/Makefile
1600-index 1cfcc33de3af58e9773d22cdcbe0c95f1633e2d9..b1428f173ddb507f0c92313dcca7aae57284a0b8 100644
1601---- a/package/firmware/ipq-wifi/Makefile
1602-+++ b/package/firmware/ipq-wifi/Makefile
1603-@@ -14,7 +14,7 @@ define Build/Compile
1604- endef
1605-
1606- #ALLWIFIBOARDS:=<devicename>
1607--ALLWIFIBOARDS:=zyxel_wre6606
1608-+ALLWIFIBOARDS:=zyxel_nbg6617 zyxel_wre6606
1609- ALLWIFIPACKAGES:=$(foreach BOARD,$(ALLWIFIBOARDS),ipq-wifi-$(BOARD))
1610-
1611- define Package/ipq-wifi-default
1612-@@ -50,5 +50,6 @@ endef
1613-
1614- $(eval $(call generate-ipq-wifi-package,zyxel_wre6606,board-zyxel_wre6606.bin,ZyXEL WRE6606))
1615- #$(eval $(call generate-ipq-wifi-package,<devicename>,<filename>,<displayname>))
1616-+$(eval $(call generate-ipq-wifi-package,zyxel_nbg6617,board-zyxel_nbg6617.bin,ZyXEL NBG6617))
1617-
1618- $(foreach PACKAGE,$(ALLWIFIPACKAGES),$(eval $(call BuildPackage,$(PACKAGE))))
1619-diff --git a/package/firmware/ipq-wifi/board-zyxel_nbg6617.bin b/package/firmware/ipq-wifi/board-zyxel_nbg6617.bin
1620-new file mode 100644
1621-index 0000000000000000000000000000000000000000..ab4d43e8cbc949c06f74e332807b8d92239a7de0
1622-GIT binary patch
1623-literal 24276
1624-zcmeHPdr(tX8b3f3b+K|ohzNKIAwYr<AW#hwc}5x_1xpnPun5!#NsaO_AcQX1@j)RX
1625-z0<}O0pk+`VO%WN3FR)r$JEP40xwC(?JNxL)th07UyVK6>F7CNWZXS>;2@eZ$zi`g^
1626-z&f`1hJHLB!bMHMr?mLO`A@RFK;bEyE3F+|}LLisR0hFvzEC#?IhC)Tzj)J1X;6k}H
1627-z<h>$kafo#Pjxb%W@MuBlek>cl71}w#whU;;2(38j-~gOzsF9giA3;4Z$_HSbvnx~p
1628-zfbkm<I?Z~-;V`kT0Emc)`03d*2LWw0_~kF>V)5Wavu<ZY>D}pVn)D-q7f`0x5$896
1629-z6O4EeFQmY^=s$Q{%tu@|rLlAO*whKs))~iT0R6|J8fIuz^O9Jav$ON6RjZuL1b{ns
1630-z%+wurXCCM<ZywA?vqj$k#g=x<p-pk)5VmX#V(Ibtkh-DrKz3>}fBc%drBa@~J2_!|
1631-zKz*jZRQgWx*6~58l}R&_-~0v2gKs#2VEi+6ePv;GGOQd{H&sfrcO}P+_hZdq86O%n
1632-z)K_GSlcRM84+De1_*L~;IKtb>QRAOO1DVdC4|Y<Noyup!?wTu$vorW%27^FL|7OWm
1633-zLYbwBWi@GFiHG&v>wuE=nJur<-iCsTr~`qS-l_LmN^6qj+<oo|cLqw@lg_Y9J@VTJ
1634-zbK0ZMFv{Et`sxc5QH25TZce`4bfkKxG&sjS=Ij2-PtwnD%QnAvbFiZQ?S_yF?}MXf
1635-zi;l+};AA3Ew_rP=jGN;YbGc92CaT|3;Z=0wv-0lH8lPgf{N;rb=`D`HD(AJoS-$~s
1636-zbKkhhYcqbrH%qZ|?8^l9122fM$kEZ!0gIiS;Lq}EgE)`16^j@TKiI`XSu8*J=g;)@
1637-z^<(-nnVFO|z;K0v`$DFRk3d#dMjDgp0|)x~=Vw1oO<`9+e2%}LzU;q0{_zL%GOXcd
1638-z7iUKb<$ti<26(_s_RpU`eWGu>*j^V8!Rrw?NO4W$5EiiUA`QZW62=V<VzZZ~W(^wz
1639-zMUZ$j9tlUokzz$v&B>1%TiRwSfQ?B|P|$!;5g6pQQSmfLhf$%TR4(-q74bwpxt?NI
1640-z)D`hS6VL>1!lMKv1x?|mh~v;WM1=BC9+&rshipf;bGM7b&@hCL8lBKwvaSLaD@-r!
1641-zEAv-%vx5^13h1-0;?ooej5A(D)!QhYM$MZ*r5UBwsL{+->phsYbwk~rx*=Yu7uQRi
1642-zh$cQwL{iaIZmKu}jd&V?M5EE%XmM3dRSmv0^aq5=4Cq6<ULNaE(*s5r>)g}N%@FHc
1643-z)6c*VV{5ngBh8R`@Smrc{j^wBt$knSTJ}0zlah0=<>-?rkth)$KrRgeU@VGPBuW+t
1644-zkQovI5&;qc5&;qc5`h(rz((Fi#E1G8?=2*qx{bFDiKVW=1!NR9UmCe@9_#M4?T%)S
1645-zu@;vF8)F3@LUQVMBJg~M*xA8iHMez#z}9w)<>w;xE6y!ajXnkdrpHx1qmQSj@KG%G
1646-z>^p$PT;dw`)L8H7($tnHev7oM7OdMifB?52IJE$Tg8<0S34m-M79>G2VZhQRYB*pr
1647-zy}g;!q!pIWEM+otTUbC4>;Qf`3P7tf;t&@J0DBDr1VBK^UyT4qcgJ<PFm-j+Z8|R4
1648-zJjjlg9s)0hU1*M!{cr~Y?k+o0)_elxA{5-yF(~sX6KBDbYtQJnL}_4vKkL^F`kg!d
1649-zUY&k-PP}V(R&M_OB2`msTW3%2m7(F$u{&Qr`1Y~=6@bl|DcDZj7W*sgzWOCL@G!`<
1650-z(*=`BSYg;uqx%}gU<-8npkitrz7wk30~IIK;k%%^{ZBEk4&MQ_A4Eb6FcVu2M~Ch*
1651-zs~|p7%d3WP`Min>!X;{dg)Mu=X_<M48!vSAX|GRwL!@uU7NcIa%tv3SRRGBg9svd+
1652-z(&=<M4f}4hpb+V_DH`I9dUL(SG$5Q3B4Sj`6^n%+aw-xLpaQNy9BJkL8bvWEULM;r
1653-zQ%_HfsG*PPbjWssewt!KIggH@)FfUKl1AOi+ls_cvpcZQ%>MD;IXqo1w>b9l>$h3(
1654-z>yPjp93Z*=c$1Fp?cM_^NBNMa?W{)unT=mBvEbK(1?1OX!;b@=&Xr$}+24QU0)!6w
1655-z58fZnuSek|O`_+yJFj+HMKLnn0l5CcUfR74{Cd-%P+I_AKRmqwEZ_pav;YgZ*qL7s
1656-z1vi~*$|N+5qxH~!PrK{RpzosB(uYl65?WYR3>w6;lqhFOeIaT!d-;mowk0P$`@#TV
1657-z38G|++hiLO0TKZcf#r&Ti63u`U;m$f{Pj=YfBy$KIX&kd<JZ6V=imSQ<jLP)84<r;
1658-zAczdp^Yf>s{{63o=iHP0dhEUp-U1HbcVV}Uijh`tR7ifk5gj|Z_|_@$)=Le~Mqtuv
1659-zU7gj;mS-ieAHQClg+0{1^VsqZ!<3uty!ze9M60G;nJEeV?#6^#Q?1OC@F%WoE+|VR
1660-zNqql_5pAzZDU<NMvHuCXeK(K|ph1g9q1+?kP7Z6&tB%StBz*0trbi}|r166%zR)x)
1661-z<&p$G12edDFE9}3n#q)z%FM}|+D?^1_O4``_NMBBtW+fA^PoYC@-S{NelL&%CU0xI
1662-zROPVWHz$U*pQ@^55{W=Np;F6^iFUF*bR)bk%h9_uaSysQc|)t#oKVSSJ14GcFKOzb
1663-zahmp)s$Ett60yA|#xx)6T=KzOx_h6^0dT6_+H)F(Dj&L}(VSA1C?(pfnr@j~6weQx
1664-zyrsRQs+8^Jd+H510oWXxHC3vE$~0Knr8+L#B?*O&v?~>oR6b|&y0$}ADoYo!FoQ4e
1665-zaUe?9CfYS+sywA|atv0MDRX5h(9Mew%Q!v?YdbX+vP97)oxuY*2YX}*Uh0!B*>V6$
1666-zlt`2a5O^Jy2Eo+G;uVWP+sKj2v8^F>Uga0Hzf}v*1y*l5a_mCVNluApp-a-;-UDZM
1667-zDE$s?lw2G+b~&LXw9ZR0GJH^za(>J2ypEph$!rX-V#qe6ecgY!Ij+`Uz9~;Nyr-Lg
1668-z-lv)>tLx9}<ef$p)WWeVB^Tm8<djnP+#is(#Mb&9_Q<Oq+|w0O=UM(n!N73Er*Vz!
1669-z>WxJzb=s-$WA1y`@4V4p*u1@l@xFV`S2vUc>FU4}bh-Ab;!<=yvz)rGzCHbPWVwgL
1670-zMRaX&-^ct9edO+WeOhU^@Ek*d<o6GjX#}U3C9aau?$XA@>R>rN<KgEi4Z)S04!Z8`
1671-zA3oHR)Xb`)9c&vo(iK}DaGX|fxm{WpqX;_WmfCmaXh-x(zfxLWM}I+ke1mTpHLtZ#
1672-z+95dYSLT*`wsG$VkuqiuHEv{}tTXK_yTaqZid{J5#7P8R0|e&#whj2sE0b8k!}PWd
1673-ze}5MIgKyek`1$%WeKWz5dE3TJ?mJGeUt?u&9)A#HUpjLPoL;|n!N#xxKUqW~U=@KG
1674-z^!n%1n%PS3Sm<`s+*oN@l3x%1ci>ep@=1RE9KTv7UVSfoyClm6hBp9+gM9mSy_{NI
1675-z_{x;(IP#7Z14kY>2q8Z|D2i3$N(l$fwd)v`fx?)hQ>57|Kmg;vQy~96tL@5z#o)g$
1676-z_7sSC^?3QO$*sr6Ci(SdEPFy8v|;m&<k#z%`xsAn%K~!v?Ypa4x~&P9&#R~)T%z_@
1677-o*s^C##HlwgpAV<r+;*XkI1#7byqt(rZ(dIF>lgc1^X2{jAHkef%K!iX
1678-
1679-literal 0
1680-HcmV?d00001
1681-
1682-diff --git a/scripts/make-ras.sh b/scripts/make-ras.sh
1683-new file mode 100755
1684-index 0000000000000000000000000000000000000000..ccddaa0016b0c926d4737abb5757e7212b0a1157
1685---- /dev/null
1686-+++ b/scripts/make-ras.sh
1687-@@ -0,0 +1,196 @@
1688-+#!/usr/bin/env bash
1689-+#
1690-+# --- ZyXEL header format ---
1691-+# Original Version by Benjamin Berg <benjamin@sipsolutions.net>
1692-+#
1693-+# The firmware image prefixed with a header (which is written into the MTD device).
1694-+# The header is one erase block (~64KiB) in size, but the checksum only convers the
1695-+# first 2KiB. Padding is 0xff. All integers are in big-endian.
1696-+#
1697-+# The checksum is always a 16-Bit System V checksum (sum -s) stored in a 32-Bit integer.
1698-+#
1699-+# 4 bytes: checksum of the rootfs image
1700-+# 4 bytes: length of the contained rootfs image file (big endian)
1701-+# 32 bytes: Firmware Version string (NUL terminated, 0xff padded)
1702-+# 4 bytes: checksum over the header partition (big endian - see below)
1703-+# 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded)
1704-+# 4 bytes: checksum of the kernel partition
1705-+# 4 bytes: length of the contained kernel image file (big endian)
1706-+# rest: 0xff padding
1707-+#
1708-+# The checksums are calculated by adding up all bytes and if a 16bit
1709-+# overflow occurs, one is added and the sum is masked to 16 bit:
1710-+# csum = csum + databyte; if (csum > 0xffff) { csum += 1; csum &= 0xffff };
1711-+# Should the file have an odd number of bytes then the byte len-0x800 is
1712-+# used additionally.
1713-+#
1714-+# The checksum for the header is calculated over the first 2048 bytes with
1715-+# the rootfs image checksum as the placeholder during calculation.
1716-+#
1717-+# The header is padded with 0xff to the erase block size of the device.
1718-+#
1719-+board=""
1720-+version=""
1721-+kernel=""
1722-+rootfs=""
1723-+outfile=""
1724-+err=""
1725-+
1726-+while [ "$1" ]; do
1727-+ case "$1" in
1728-+ "--board")
1729-+ board="$2"
1730-+ shift
1731-+ shift
1732-+ continue
1733-+ ;;
1734-+ "--version")
1735-+ version="$2"
1736-+ shift
1737-+ shift
1738-+ continue
1739-+ ;;
1740-+ "--kernel")
1741-+ kernel="$2"
1742-+ shift
1743-+ shift
1744-+ continue
1745-+ ;;
1746-+ "--rootfs")
1747-+ rootfs="$2"
1748-+ shift
1749-+ shift
1750-+ continue
1751-+ ;;
1752-+ "--rootfssize")
1753-+ rootfssize="$2"
1754-+ shift
1755-+ shift
1756-+ continue
1757-+ ;;
1758-+ *)
1759-+ if [ ! "$outfile" ]; then
1760-+ outfile=$1
1761-+ shift
1762-+ continue
1763-+ fi
1764-+ ;;
1765-+ esac
1766-+done
1767-+
1768-+if [ ! -n "$board" -o ! -n "$version" -o ! -r "$kernel" -o ! -r "$rootfs" -o ! "$rootfssize" -o ! "$outfile" ]; then
1769-+ echo "syntax: $0 [--board ras-boardname] [--version ras-version] [--kernel kernelimage] [--rootfs rootfs] out"
1770-+ exit 1
1771-+fi
1772-+
1773-+rootfs_len=$(wc -c < "$rootfs")
1774-+
1775-+if [ "$rootfs_len" -lt "$rootfssize" ]; then
1776-+ dd if=$rootfs of=$rootfs.new bs=$rootfssize conv=sync
1777-+ mv $rootfs.new $rootfs
1778-+fi
1779-+
1780-+if [ ${#version} -ge 28 ]; then
1781-+ echo "version: '$version' is too long"
1782-+ exit 1
1783-+fi
1784-+
1785-+tmpdir="$( mktemp -d 2> /dev/null )"
1786-+if [ -z "$tmpdir" ]; then
1787-+ # try OSX signature
1788-+ tmpdir="$( mktemp -t 'ubitmp' -d )"
1789-+fi
1790-+
1791-+if [ -z "$tmpdir" ]; then
1792-+ exit 1
1793-+fi
1794-+
1795-+to_be() {
1796-+ local val="$1"
1797-+ local size="$2"
1798-+
1799-+ case "$size" in
1800-+ 4)
1801-+ echo $(( "$val" >> 24 | ("$val" & 0xff0000) >> 8 | ("$val" & 0xff00) << 8 | ("$val" & 0xff) << 24 ))
1802-+ ;;
1803-+ 2)
1804-+ echo $(( "$val" >> 8 | ("$val" & 0xff) << 8))
1805-+ ;;
1806-+ esac
1807-+}
1808-+
1809-+checksum_file() {
1810-+ local file=$1
1811-+
1812-+ # ZyXEL seems to use System V sum mode... Now this is classy, who would have thought?!
1813-+ echo $(sum -s ${file} | cut -f1 -d" ")
1814-+}
1815-+
1816-+append_bin() {
1817-+ local val=$1
1818-+ local size=$2
1819-+ local file=$3
1820-+
1821-+ while [ "$size" -ne 0 ]; do
1822-+ printf \\$(printf %o $(("$val" & 0xff))) >> "$file"
1823-+ val=$(($val >> 8))
1824-+ let size-=1
1825-+ done
1826-+ return
1827-+}
1828-+
1829-+tf=${tmpdir}/out
1830-+pad=$(printf '%0.1s' $(printf "\xff"){1..64})
1831-+
1832-+rootfs_header_file="$tmpdir/rootfs_header"
1833-+rootfs_chksum=$(to_be $(checksum_file ${rootfs}) 4)
1834-+rootfs_len=$(to_be $(wc -c < "$rootfs") 4)
1835-+
1836-+versionpadlen=$(( 32 - ( ${#version} + 1) ))
1837-+
1838-+# 4 bytes: checksum of the rootfs image
1839-+append_bin "$rootfs_chksum" 4 "$rootfs_header_file"
1840-+# 4 bytes: length of the contained rootfs image file (big endian)
1841-+append_bin "$rootfs_len" 4 "$rootfs_header_file"
1842-+# 32 bytes: Firmware Version string (NUL terminated, 0xff padded)
1843-+printf "%s\x00%.*s" "$version" "$versionpadlen" "$pad" >> "$rootfs_header_file"
1844-+
1845-+kernel_header_file="$tmpdir/kernel_header"
1846-+kernel_chksum=$(to_be $(checksum_file ${kernel}) 4)
1847-+kernel_len=$(to_be $(wc -c < "$kernel") 4)
1848-+
1849-+# 4 bytes: checksum of the kernel image
1850-+append_bin "$kernel_chksum" 4 "$kernel_header_file"
1851-+# 4 bytes: length of the contained kernel image file (big endian)
1852-+append_bin "$kernel_len" 4 "$kernel_header_file"
1853-+
1854-+board_header_file="$tmpdir/board_header"
1855-+board_file="$tmpdir/board"
1856-+boardpadlen=$(( 64 - ( ${#board} + 1) ))
1857-+# 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded)
1858-+printf "%s\x00%.*s" "$board" "$boardpadlen" "$pad" > "$board_file"
1859-+cat "$kernel_header_file" >> "$board_file"
1860-+printf "%.12s" "$pad" >> "$board_file"
1861-+# rest: 0xff padding
1862-+for i in {1..511}; do
1863-+ printf "%s%s" "$pad" "$pad" >> "$board_file"
1864-+done
1865-+
1866-+tmp_board_file="$tmpdir/tmp_board_file"
1867-+cat "$rootfs_header_file" > "$tmp_board_file"
1868-+
1869-+# The checksum for the header is calculated over the first 2048 bytes with
1870-+# the rootfs image checksum as the placeholder during calculation.
1871-+append_bin "$rootfs_chksum" 4 "$tmp_board_file"
1872-+cat "$board_file" >> "$tmp_board_file"
1873-+
1874-+truncate -s 2048 $tmp_board_file
1875-+board_chksum=$(to_be $(checksum_file ${tmp_board_file}) 4)
1876-+
1877-+# 4 bytes: checksum over the header partition (big endian)
1878-+append_bin "$board_chksum" 4 "$board_header_file"
1879-+cat "$board_file" >> "$board_header_file"
1880-+
1881-+cat "$rootfs_header_file" "$board_header_file" "$rootfs" "$kernel" > "$outfile"
1882-+
1883-+rm -rf "$tmpdir"
1884-diff --git a/target/linux/ipq40xx/base-files/etc/board.d/01_leds b/target/linux/ipq40xx/base-files/etc/board.d/01_leds
1885-index fcba2aea543cdead03ef372bc6b751481846fbf7..475a8623f705d683a7ee3521ee71f2b57fa2e44d 100755
1886---- a/target/linux/ipq40xx/base-files/etc/board.d/01_leds
1887-+++ b/target/linux/ipq40xx/base-files/etc/board.d/01_leds
1888-@@ -34,6 +34,11 @@ netgear,ex6150v2)
1889- meraki,mr33)
1890- ucidef_set_interface_lan "eth0"
1891- ;;
1892-+zyxel,nbg6617)
1893-+ ucidef_set_led_wlan "wlan2g" "WLAN2G" "$board:green:wlan2G" "phy0tpt"
1894-+ ucidef_set_led_wlan "wlan5g" "WLAN5G" "$board:green:wlan5G" "phy1tpt"
1895-+ ucidef_set_led_usbport "usb" "USB" "${board}:green:usb" "usb1-port1" "usb2-port1" "usb3-port1" "usb4-port1"
1896-+ ;;
1897- zyxel,wre6606)
1898- ucidef_set_led_wlan "wlan2g" "WLAN2G" "${boardname}:green:wlan2g" "phy0tpt"
1899- ucidef_set_led_wlan "wlan5g" "WLAN5G" "${boardname}:green:wlan5g" "phy1tpt"
1900-diff --git a/target/linux/ipq40xx/base-files/etc/board.d/02_network b/target/linux/ipq40xx/base-files/etc/board.d/02_network
1901-index 03e0c0e16c33f43fafcbba9c5af4baf6dd73e425..5c90ef136fd7cbbe023001030d8c9003347bd249 100755
1902---- a/target/linux/ipq40xx/base-files/etc/board.d/02_network
1903-+++ b/target/linux/ipq40xx/base-files/etc/board.d/02_network
1904-@@ -48,6 +48,11 @@ netgear,ex6150v2 |\
1905- zyxel,wre6606)
1906- ucidef_set_interface_lan "eth0"
1907- ;;
1908-+zyxel,nbg6617)
1909-+ ucidef_set_interfaces_lan_wan "eth0" "eth1"
1910-+ ucidef_add_switch "switch0" \
1911-+ "0u@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
1912-+ ;;
1913- *)
1914- echo "Unsupported hardware. Network interfaces not intialized"
1915- ;;
1916-diff --git a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
1917-index d89ddf6e57ee9f759f6dcc7c7f8152c11305499b..1d4fd9cd8f9a3983ac3323ce72153c1dcc17a69a 100644
1918---- a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
1919-+++ b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
1920-@@ -146,6 +146,7 @@ case "$FIRMWARE" in
1921- openmesh,a62)
1922- ath10kcal_extract "0:ART" 4096 12064
1923- ;;
1924-+ zyxel,nbg6617 |\
1925- zyxel,wre6606)
1926- ath10kcal_extract "ART" 4096 12064
1927- ath10kcal_patch_mac_crc $(macaddr_add $(cat /sys/class/net/eth0/address) -2)
1928-@@ -181,6 +182,7 @@ case "$FIRMWARE" in
1929- openmesh,a62)
1930- ath10kcal_extract "0:ART" 20480 12064
1931- ;;
1932-+ zyxel,nbg6617 |\
1933- zyxel,wre6606)
1934- ath10kcal_extract "ART" 20480 12064
1935- ath10kcal_patch_mac_crc $(macaddr_add $(cat /sys/class/net/eth0/address) -1)
1936-diff --git a/target/linux/ipq40xx/base-files/lib/preinit/05_set_iface_mac_ipq40xx.sh b/target/linux/ipq40xx/base-files/lib/preinit/05_set_iface_mac_ipq40xx.sh
1937-index 1acd7366c81f7c70ef9018d97a833e4d355e8119..44e81ca366dd57d3d5d7fbb9065254925e94061a 100644
1938---- a/target/linux/ipq40xx/base-files/lib/preinit/05_set_iface_mac_ipq40xx.sh
1939-+++ b/target/linux/ipq40xx/base-files/lib/preinit/05_set_iface_mac_ipq40xx.sh
1940-@@ -8,6 +8,10 @@ preinit_set_mac_address() {
1941- mac_lan=$(get_mac_binary "/sys/bus/i2c/devices/0-0050/eeprom" 102)
1942- [ -n "$mac_lan" ] && ip link set dev eth0 address "$mac_lan"
1943- ;;
1944-+ zyxel,nbg6617)
1945-+ base_mac=$(cat /sys/class/net/eth0/address)
1946-+ ip link set dev eth0 address $(macaddr_add "$base_mac" +2)
1947-+ ip link set dev eth1 address $(macaddr_add "$base_mac" +3)
1948- esac
1949- }
1950-
1951-diff --git a/target/linux/ipq40xx/base-files/lib/preinit/06_set_preinit_iface_ipq40xx.sh b/target/linux/ipq40xx/base-files/lib/preinit/06_set_preinit_iface_ipq40xx.sh
1952-new file mode 100644
1953-index 0000000000000000000000000000000000000000..578ddbe4c4f6e91d925ea3a0de9e060daac82e72
1954---- /dev/null
1955-+++ b/target/linux/ipq40xx/base-files/lib/preinit/06_set_preinit_iface_ipq40xx.sh
1956-@@ -0,0 +1,19 @@
1957-+#!/bin/sh
1958-+
1959-+set_preinit_iface() {
1960-+ . /lib/functions.sh
1961-+
1962-+ case $(board_name) in
1963-+ asus,rt-ac58u| \
1964-+ avm,fritzbox-4040| \
1965-+ glinet,gl-b1300| \
1966-+ meraki,mr33| \
1967-+ zyxel,nbg6617)
1968-+ ifname=eth0
1969-+ ;;
1970-+ *)
1971-+ ;;
1972-+ esac
1973-+}
1974-+
1975-+boot_hook_add preinit_main set_preinit_iface
1976-diff --git a/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh b/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh
1977-index 4096e127ea9eaa8106475a3143b0b2ea796b5c7c..0e29302465fb5fca6f2a2194c751728f492053d5 100644
1978---- a/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh
1979-+++ b/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh
1980-@@ -29,6 +29,21 @@ EOF
1981- return 0;
1982- }
1983-
1984-+zyxel_do_upgrade() {
1985-+ local tar_file="$1"
1986-+
1987-+ local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
1988-+ board_dir=${board_dir%/}
1989-+
1990-+ tar Oxf $tar_file ${board_dir}/kernel | mtd write - kernel
1991-+
1992-+ if [ "$SAVE_CONFIG" -eq 1 ]; then
1993-+ tar Oxf $tar_file ${board_dir}/root | mtd -j "$CONF_TAR" write - rootfs
1994-+ else
1995-+ tar Oxf $tar_file ${board_dir}/root | mtd write - rootfs
1996-+ fi
1997-+}
1998-+
1999- platform_do_upgrade() {
2000- case "$(board_name)" in
2001- 8dev,jalapeno)
2002-@@ -48,6 +63,9 @@ platform_do_upgrade() {
2003- CI_KERNPART="part.safe"
2004- nand_do_upgrade "$1"
2005- ;;
2006-+ zyxel,nbg6617)
2007-+ zyxel_do_upgrade "$1"
2008-+ ;;
2009- *)
2010- default_do_upgrade "$ARGV"
2011- ;;
2012-diff --git a/target/linux/ipq40xx/files-4.14/arch/arm/boot/dts/qcom-ipq4018-nbg6617.dts b/target/linux/ipq40xx/files-4.14/arch/arm/boot/dts/qcom-ipq4018-nbg6617.dts
2013-new file mode 100644
2014-index 0000000000000000000000000000000000000000..d7f8c5955caee15d373a342b75c8c1947f5b8022
2015---- /dev/null
2016-+++ b/target/linux/ipq40xx/files-4.14/arch/arm/boot/dts/qcom-ipq4018-nbg6617.dts
2017-@@ -0,0 +1,321 @@
2018-+/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2019-+ *
2020-+ * Permission to use, copy, modify, and/or distribute this software for any
2021-+ * purpose with or without fee is hereby granted, provided that the above
2022-+ * copyright notice and this permission notice appear in all copies.
2023-+ *
2024-+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
2025-+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
2026-+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
2027-+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2028-+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
2029-+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2030-+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2031-+ *
2032-+ */
2033-+
2034-+#include "qcom-ipq4019.dtsi"
2035-+#include "qcom-ipq4019-bus.dtsi"
2036-+#include <dt-bindings/gpio/gpio.h>
2037-+#include <dt-bindings/input/input.h>
2038-+#include <dt-bindings/input/linux-event-codes.h>
2039-+#include <dt-bindings/soc/qcom,tcsr.h>
2040-+
2041-+/ {
2042-+ model = "ZyXEL NBG6617";
2043-+ compatible = "zyxel,nbg6617", "qcom,ipq4019";
2044-+
2045-+ chosen {
2046-+ /*
2047-+ * the vendor u-boot adds root and mtdparts cmdline parameters
2048-+ * which we don't want... but we have to overwrite them or else
2049-+ * the kernel will take them at face value.
2050-+ */
2051-+ bootargs-append = " mtdparts= root=31:13";
2052-+ };
2053-+
2054-+ aliases {
2055-+ led-boot = &power;
2056-+ led-failsafe = &power;
2057-+ led-running = &power;
2058-+ led-upgrade = &power;
2059-+ };
2060-+
2061-+ soc {
2062-+ mdio@90000 {
2063-+ status = "okay";
2064-+ };
2065-+
2066-+ ess-psgmii@98000 {
2067-+ status = "okay";
2068-+ };
2069-+
2070-+ tcsr@1949000 {
2071-+ compatible = "qcom,tcsr";
2072-+ reg = <0x1949000 0x100>;
2073-+ qcom,wifi_glb_cfg = <TCSR_WIFI_GLB_CFG>;
2074-+ };
2075-+
2076-+ tcsr@194b000 {
2077-+ compatible = "qcom,tcsr";
2078-+ reg = <0x194b000 0x100>;
2079-+ qcom,usb-hsphy-mode-select = <TCSR_USB_HSPHY_HOST_MODE>;
2080-+ };
2081-+
2082-+ ess_tcsr@1953000 {
2083-+ compatible = "qcom,tcsr";
2084-+ reg = <0x1953000 0x1000>;
2085-+ qcom,ess-interface-select = <TCSR_ESS_PSGMII>;
2086-+ };
2087-+
2088-+ tcsr@1957000 {
2089-+ compatible = "qcom,tcsr";
2090-+ reg = <0x1957000 0x100>;
2091-+ qcom,wifi_noc_memtype_m0_m2 = <TCSR_WIFI_NOC_MEMTYPE_M0_M2>;
2092-+ };
2093-+
2094-+ usb2@60f8800 {
2095-+ status = "okay";
2096-+ };
2097-+
2098-+ serial@78af000 {
2099-+ pinctrl-0 = <&serial_pins>;
2100-+ pinctrl-names = "default";
2101-+ status = "okay";
2102-+ };
2103-+
2104-+ usb3@8af8800 {
2105-+ status = "okay";
2106-+ };
2107-+
2108-+ crypto@8e3a000 {
2109-+ status = "okay";
2110-+ };
2111-+
2112-+ watchdog@b017000 {
2113-+ status = "okay";
2114-+ };
2115-+
2116-+ ess-switch@c000000 {
2117-+ status = "okay";
2118-+ };
2119-+
2120-+ edma@c080000 {
2121-+ status = "okay";
2122-+ };
2123-+ };
2124-+
2125-+ gpio-keys {
2126-+ compatible = "gpio-keys";
2127-+
2128-+ wlan {
2129-+ label = "wlan";
2130-+ gpios = <&tlmm 2 GPIO_ACTIVE_HIGH>;
2131-+ linux,code = <KEY_RFKILL>;
2132-+ linux,input-type = <EV_SW>;
2133-+ };
2134-+
2135-+ wps {
2136-+ label = "wps";
2137-+ gpios = <&tlmm 63 GPIO_ACTIVE_LOW>;
2138-+ linux,code = <KEY_WPS_BUTTON>;
2139-+ };
2140-+
2141-+ reset {
2142-+ label = "reset";
2143-+ gpios = <&tlmm 4 GPIO_ACTIVE_LOW>;
2144-+ linux,code = <KEY_RESTART>;
2145-+ };
2146-+ };
2147-+
2148-+ gpio-leds {
2149-+ compatible = "gpio-leds";
2150-+ pinctrl-0 = <&led_pins>;
2151-+ pinctrl-names = "default";
2152-+
2153-+ power: power {
2154-+ label = "nbg6617:green:power";
2155-+ gpios = <&tlmm 3 GPIO_ACTIVE_HIGH>;
2156-+ };
2157-+
2158-+ usb {
2159-+ label = "nbg6617:green:usb";
2160-+ gpios = <&tlmm 0 GPIO_ACTIVE_HIGH>;
2161-+ };
2162-+
2163-+ wlan2G {
2164-+ label = "nbg6617:green:wlan2G";
2165-+ gpios = <&tlmm 58 GPIO_ACTIVE_HIGH>;
2166-+ };
2167-+
2168-+ wlan5G {
2169-+ label = "nbg6617:green:wlan5G";
2170-+ gpios = <&tlmm 5 GPIO_ACTIVE_HIGH>;
2171-+ };
2172-+
2173-+ wps {
2174-+ label = "nbg6617:green:wps";
2175-+ gpios = <&tlmm 1 GPIO_ACTIVE_HIGH>;
2176-+ };
2177-+ };
2178-+};
2179-+
2180-+&tlmm {
2181-+ serial_pins: serial_pinmux {
2182-+ mux {
2183-+ pins = "gpio60", "gpio61";
2184-+ function = "blsp_uart0";
2185-+ bias-disable;
2186-+ };
2187-+ };
2188-+ spi_0_pins: spi_0_pinmux {
2189-+ mux {
2190-+ function = "blsp_spi0";
2191-+ pins = "gpio55", "gpio56", "gpio57";
2192-+ drive-strength = <12>;
2193-+ bias-disable;
2194-+ };
2195-+
2196-+ mux_cs {
2197-+ function = "gpio";
2198-+ pins = "gpio54";
2199-+ drive-strength = <2>;
2200-+ bias-disable;
2201-+ output-low;
2202-+ };
2203-+ };
2204-+ led_pins: led_pinmux {
2205-+ mux {
2206-+ pins = "gpio0", "gpio1", "gpio3", "gpio5", "gpio58";
2207-+ drive-strength = <0x8>;
2208-+ bias-disable;
2209-+ output-low;
2210-+ };
2211-+ };
2212-+};
2213-+
2214-+&spi_0 { /* BLSP1 QUP1 */
2215-+ pinctrl-0 = <&spi_0_pins>;
2216-+ pinctrl-names = "default";
2217-+ status = "okay";
2218-+ cs-gpios = <&tlmm 54 GPIO_ACTIVE_HIGH>;
2219-+
2220-+ mx25l25635f@0 {
2221-+ compatible = "mx25l25635f", "jedec,spi-nor";
2222-+ #address-cells = <1>;
2223-+ #size-cells = <0>;
2224-+ reg = <0>;
2225-+ spi-max-frequency = <24000000>;
2226-+ status = "okay";
2227-+ m25p,fast-read;
2228-+
2229-+ partitions {
2230-+ compatible = "fixed-partitions";
2231-+ #address-cells = <1>;
2232-+ #size-cells = <1>;
2233-+
2234-+ partition0@0 {
2235-+ label = "SBL1";
2236-+ reg = <0x00000000 0x00040000>;
2237-+ read-only;
2238-+ };
2239-+ partition1@40000 {
2240-+ label = "MIBIB";
2241-+ reg = <0x00040000 0x00020000>;
2242-+ read-only;
2243-+ };
2244-+ partition2@60000 {
2245-+ label = "QSEE";
2246-+ reg = <0x00060000 0x00060000>;
2247-+ read-only;
2248-+ };
2249-+ partition3@c0000 {
2250-+ label = "CDT";
2251-+ reg = <0x000c0000 0x00010000>;
2252-+ read-only;
2253-+ };
2254-+ partition4@d0000 {
2255-+ label = "DDRPARAMS";
2256-+ reg = <0x000d0000 0x00010000>;
2257-+ read-only;
2258-+ };
2259-+ partition5@e0000 {
2260-+ label = "APPSBL"; /* u-boot */
2261-+ reg = <0x000e0000 0x00080000>;
2262-+ /* U-Boot Standalone App "zloader" is located at 0x64000 */
2263-+ read-only;
2264-+ };
2265-+ partition6@160000 {
2266-+ label = "APPSBLENV"; /* u-boot env */
2267-+ reg = <0x00160000 0x00010000>;
2268-+ };
2269-+ partition7@170000 {
2270-+ /* make a backup of this partition! */
2271-+ label = "ART";
2272-+ reg = <0x00170000 0x00010000>;
2273-+ read-only;
2274-+ };
2275-+ partition8@180000 {
2276-+ label = "kernel";
2277-+ reg = <0x00180000 0x00400000>;
2278-+ };
2279-+ partition9@580000 {
2280-+ label = "dualflag";
2281-+ reg = <0x00580000 0x00010000>;
2282-+ read-only;
2283-+ };
2284-+ partition10@590000 {
2285-+ label = "header";
2286-+ reg = <0x00590000 0x00010000>;
2287-+ };
2288-+ partition11@5a0000 {
2289-+ label = "romd";
2290-+ reg = <0x005a0000 0x00100000>;
2291-+ read-only;
2292-+ };
2293-+ partition12@6a0000 {
2294-+ label = "not_root_data";
2295-+ /*
2296-+ * for some strange reason, someone at ZyXEL
2297-+ * had the "great" idea to put the rootfs_data
2298-+ * in front of rootfs... Don't do that!
2299-+ * As a result this one, full MebiByte remains
2300-+ * unused.
2301-+ */
2302-+ reg = <0x006a0000 0x00100000>;
2303-+ };
2304-+ partition13@7a0000 {
2305-+ label = "rootfs";
2306-+ reg = <0x007a0000 0x01860000>;
2307-+ };
2308-+ };
2309-+ };
2310-+};
2311-+
2312-+&cryptobam {
2313-+ status = "okay";
2314-+};
2315-+
2316-+&blsp_dma {
2317-+ status = "okay";
2318-+};
2319-+
2320-+&wifi0 {
2321-+ status = "okay";
2322-+};
2323-+
2324-+&wifi1 {
2325-+ status = "okay";
2326-+};
2327-+
2328-+&usb3_ss_phy {
2329-+ status = "okay";
2330-+};
2331-+
2332-+&usb3_hs_phy {
2333-+ status = "okay";
2334-+};
2335-+
2336-+&usb2_hs_phy {
2337-+ status = "okay";
2338-+};
2339-diff --git a/target/linux/ipq40xx/image/Makefile b/target/linux/ipq40xx/image/Makefile
2340-index 90d9dfeff0c228765ac24247ce72dec497dc63f0..cb79baccd21b3fa7f35df543bfca1a7d6ba8f83f 100644
2341---- a/target/linux/ipq40xx/image/Makefile
2342-+++ b/target/linux/ipq40xx/image/Makefile
2343-@@ -1,6 +1,8 @@
2344- include $(TOPDIR)/rules.mk
2345- include $(INCLUDE_DIR)/image.mk
2346-
2347-+DEVICE_VARS += RAS_BOARD RAS_ROOTFS_SIZE RAS_VERSION
2348-+
2349- define Device/Default
2350- PROFILES := Default
2351- KERNEL_DEPENDS = $$(wildcard $(DTS_DIR)/$$(DEVICE_DTS).dts)
2352-@@ -205,6 +207,26 @@ define Device/qcom_ap-dk04.1-c1
2353- endef
2354- TARGET_DEVICES += qcom_ap-dk04.1-c1
2355-
2356-+define Device/zyxel_nbg6617
2357-+ $(call Device/FitImageLzma)
2358-+ DEVICE_DTS := qcom-ipq4018-nbg6617
2359-+ DEVICE_TITLE := ZyXEL NBG6617
2360-+ ROOTFS_SIZE := 24960k
2361-+ RAS_BOARD := NBG6617
2362-+ RAS_ROOTFS_SIZE := 19840k
2363-+ RAS_VERSION := "$(VERSION_DIST) $(REVISION)"
2364-+ IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata
2365-+ IMAGES := sysupgrade.bin factory.bin
2366-+# The ZyXEL firmware allows flashing thru the web-gui only when the rootfs is
2367-+# at least as large as the one of the initial firmware image (not the current
2368-+# one on the device). This only applies to the Web-UI, the bootlaoder ignores
2369-+# this minimum-size. However, the larger image can be flashed both ways.
2370-+ IMAGE/factory.bin := append-rootfs | pad-rootfs | check-size $$$$(ROOTFS_SIZE) | make-ras
2371-+ IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-rootfs | check-size $$$$(ROOTFS_SIZE) | sysupgrade-tar rootfs=$$$$@ | append-metadata
2372-+ DEVICE_PACKAGES := ipq-wifi-zyxel_nbg6617 uboot-envtools
2373-+endef
2374-+TARGET_DEVICES += zyxel_nbg6617
2375-+
2376- define Device/zyxel_wre6606
2377- $(call Device/FitImage)
2378- DEVICE_TITLE := ZyXEL WRE6606
2379-diff --git a/target/linux/ipq40xx/patches-4.14/069-arm-boot-add-dts-files.patch b/target/linux/ipq40xx/patches-4.14/069-arm-boot-add-dts-files.patch
2380-index 3aa368be8381d9c48aefccbe6d4cc768b00dc41e..8066f986a4e030c9c8fe0ec4438e92d30daa77f0 100644
2381---- a/target/linux/ipq40xx/patches-4.14/069-arm-boot-add-dts-files.patch
2382-+++ b/target/linux/ipq40xx/patches-4.14/069-arm-boot-add-dts-files.patch
2383-@@ -10,7 +10,7 @@ Signed-off-by: John Crispin <john@phrozen.org>
2384-
2385- --- a/arch/arm/boot/dts/Makefile
2386- +++ b/arch/arm/boot/dts/Makefile
2387--@@ -697,7 +697,19 @@ dtb-$(CONFIG_ARCH_QCOM) += \
2388-+@@ -697,7 +697,20 @@ dtb-$(CONFIG_ARCH_QCOM) += \
2389- qcom-apq8074-dragonboard.dtb \
2390- qcom-apq8084-ifc6540.dtb \
2391- qcom-apq8084-mtp.dtb \
2392-@@ -19,6 +19,7 @@ Signed-off-by: John Crispin <john@phrozen.org>
2393- + qcom-ipq4018-ex6150v2.dtb \
2394- + qcom-ipq4018-fritz4040.dtb \
2395- + qcom-ipq4018-jalapeno.dtb \
2396-++ qcom-ipq4018-nbg6617.dtb \
2397- + qcom-ipq4018-rt-ac58u.dtb \
2398- + qcom-ipq4018-wre6606.dtb \
2399- qcom-ipq4019-ap.dk01.1-c1.dtb \
2400-diff --git a/target/linux/ipq40xx/patches-4.14/303-spi-nor-enable-4B-opcodes-for-mx25l25635f.patch b/target/linux/ipq40xx/patches-4.14/303-spi-nor-enable-4B-opcodes-for-mx25l25635f.patch
2401-new file mode 100644
2402-index 0000000000000000000000000000000000000000..7c513a6ad8ec817bf388c67e1181f08982888fa5
2403---- /dev/null
2404-+++ b/target/linux/ipq40xx/patches-4.14/303-spi-nor-enable-4B-opcodes-for-mx25l25635f.patch
2405-@@ -0,0 +1,64 @@
2406-+Index: linux-4.14.50/drivers/mtd/spi-nor/spi-nor.c
2407-+===================================================================
2408-+--- linux-4.14.50.orig/drivers/mtd/spi-nor/spi-nor.c
2409-++++ linux-4.14.50/drivers/mtd/spi-nor/spi-nor.c
2410-+@@ -1025,6 +1025,7 @@ static const struct flash_info spi_nor_i
2411-+ { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
2412-+ { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) },
2413-+ { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
2414-++ { "mx25l25635f", INFO(0xc22019, 0, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
2415-+ { "mx25u25635f", INFO(0xc22539, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_4B_OPCODES) },
2416-+ { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) },
2417-+ { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
2418-+@@ -1189,11 +1190,12 @@ static const struct flash_info spi_nor_i
2419-+ { },
2420-+ };
2421-+
2422-+-static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
2423-++static const struct flash_info *spi_nor_read_id(struct spi_nor *nor,
2424-++ const char *name)
2425-+ {
2426-+ int tmp;
2427-+ u8 id[SPI_NOR_MAX_ID_LEN];
2428-+- const struct flash_info *info;
2429-++ const struct flash_info *info, *first_match = NULL;
2430-+
2431-+ tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN);
2432-+ if (tmp < 0) {
2433-+@@ -1204,10 +1206,16 @@ static const struct flash_info *spi_nor_
2434-+ for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
2435-+ info = &spi_nor_ids[tmp];
2436-+ if (info->id_len) {
2437-+- if (!memcmp(info->id, id, info->id_len))
2438-+- return &spi_nor_ids[tmp];
2439-++ if (!memcmp(info->id, id, info->id_len)) {
2440-++ if (!name || !strcmp(name, info->name))
2441-++ return info;
2442-++ if (!first_match)
2443-++ first_match = info;
2444-++ }
2445-+ }
2446-+ }
2447-++ if (first_match)
2448-++ return first_match;
2449-+ dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %02x, %02x\n",
2450-+ id[0], id[1], id[2]);
2451-+ return ERR_PTR(-ENODEV);
2452-+@@ -2667,7 +2675,7 @@ int spi_nor_scan(struct spi_nor *nor, co
2453-+ info = spi_nor_match_id(name);
2454-+ /* Try to auto-detect if chip name wasn't specified or not found */
2455-+ if (!info)
2456-+- info = spi_nor_read_id(nor);
2457-++ info = spi_nor_read_id(nor, NULL);
2458-+ if (IS_ERR_OR_NULL(info))
2459-+ return -ENOENT;
2460-+
2461-+@@ -2678,7 +2686,7 @@ int spi_nor_scan(struct spi_nor *nor, co
2462-+ if (name && info->id_len) {
2463-+ const struct flash_info *jinfo;
2464-+
2465-+- jinfo = spi_nor_read_id(nor);
2466-++ jinfo = spi_nor_read_id(nor, name);
2467-+ if (IS_ERR(jinfo)) {
2468-+ return PTR_ERR(jinfo);
2469-+ } else if (jinfo != info) {
2470diff --git a/patches/openwrt/0009-ath10k-firmware-update-wave-1-firmware-to-10.2.4-1.0-00047.patch b/patches/openwrt/0009-ath10k-firmware-update-wave-1-firmware-to-10.2.4-1.0-00047.patch
2471new file mode 100644
2472index 00000000..820c1ee1
2473--- /dev/null
2474+++ b/patches/openwrt/0009-ath10k-firmware-update-wave-1-firmware-to-10.2.4-1.0-00047.patch
2475@@ -0,0 +1,35 @@
2476+From: David Bauer <mail@david-bauer.net>
2477+Date: Sat, 5 Oct 2019 12:27:44 +0200
2478+Subject: ath10k-firmware: update wave 1 firmware to 10.2.4-1.0-00047
2479+
2480+This fixes frequent crashes observed on a UniFi AC Mesh using OpenWrt
2481+master and 19.07. 18.06 seems not affected from our testing.
2482+
2483+Signed-off-by: David Bauer <mail@david-bauer.net>
2484+
2485+diff --git a/package/firmware/ath10k-firmware/Makefile b/package/firmware/ath10k-firmware/Makefile
2486+index 15d9d0ce992a8161953ab3cc91058fc3ba36c096..00803771cea408b86b07f49c13abb44b306cc89d 100644
2487+--- a/package/firmware/ath10k-firmware/Makefile
2488++++ b/package/firmware/ath10k-firmware/Makefile
2489+@@ -8,9 +8,9 @@
2490+ include $(TOPDIR)/rules.mk
2491+
2492+ PKG_NAME:=ath10k-firmware
2493+-PKG_SOURCE_DATE:=2019-06-28
2494+-PKG_SOURCE_VERSION:=7651f5bb299c40e34e05179b1bd15b211856a4b0
2495+-PKG_MIRROR_HASH:=9c87fc79bc9f209069ca77f2eb15f6d6ca0299fb789c2ce2032c69d9d561a5c9
2496++PKG_SOURCE_DATE:=2019-10-03
2497++PKG_SOURCE_VERSION:=d622d160e9f552ead68d9ae81b715422892dc2ef
2498++PKG_MIRROR_HASH:=9d56a9942b7be7effdeed6d0688a9bdcfae76a2921a630714c3e2d8390ea8934
2499+ PKG_RELEASE:=1
2500+
2501+ PKG_SOURCE_PROTO:=git
2502+@@ -433,7 +433,7 @@ define Package/ath10k-firmware-qca988x/install
2503+ $(PKG_BUILD_DIR)/QCA988X/hw2.0/board.bin \
2504+ $(1)/lib/firmware/ath10k/QCA988X/hw2.0/
2505+ $(INSTALL_DATA) \
2506+- $(PKG_BUILD_DIR)/QCA988X/hw2.0/10.2.4-1.0/firmware-5.bin_10.2.4-1.0-00037 \
2507++ $(PKG_BUILD_DIR)/QCA988X/hw2.0/10.2.4-1.0/firmware-5.bin_10.2.4-1.0-00047 \
2508+ $(1)/lib/firmware/ath10k/QCA988X/hw2.0/firmware-5.bin
2509+ endef
2510+
2511diff --git a/patches/openwrt/0009-build-add-mkrasimage.patch b/patches/openwrt/0009-build-add-mkrasimage.patch
2512deleted file mode 100644
2513index cd5ab7eb..00000000
2514--- a/patches/openwrt/0009-build-add-mkrasimage.patch
2515+++ /dev/null
2516@@ -1,782 +0,0 @@
2517-From: David Bauer <mail@david-bauer.net>
2518-Date: Wed, 22 Aug 2018 17:30:44 +0200
2519-Subject: build: add mkrasimage
2520-
2521-The current make-ras.sh image generation script for the ZyXEL NBG6617
2522-has portability issues with bash. Because of this, factory images are
2523-currently not built correctly by the OpenWRT buildbots.
2524-
2525-This commit replaces the make-ras.sh by C-written mkrasimage.
2526-
2527-The new mkrasimage is also compatible with other ZyXEL devices using
2528-the ras image-format.
2529-This is not tested with the NBG6616 but it correctly builds the
2530-header for ZyXEL factory image.
2531-
2532-Signed-off-by: David Bauer <mail@david-bauer.net>
2533-
2534-diff --git a/include/image-commands.mk b/include/image-commands.mk
2535-index 28b39c310e499caea4fe8a6d9ad6dceb5d95363b..552d8db1cbacf533c12d0d8e2e5cffbe5591adb4 100644
2536---- a/include/image-commands.mk
2537-+++ b/include/image-commands.mk
2538-@@ -49,17 +49,17 @@ define Build/eva-image
2539- mv $@.new $@
2540- endef
2541-
2542--define Build/make-ras
2543-+define Build/zyxel-ras-image
2544- let \
2545- newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
2546-- $(TOPDIR)/scripts/make-ras.sh \
2547-- --board $(RAS_BOARD) \
2548-- --version $(RAS_VERSION) \
2549-- --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
2550-- --rootfs $@ \
2551-- --rootfssize $$newsize \
2552-- $@.new
2553-- @mv $@.new $@
2554-+ $(STAGING_DIR_HOST)/bin/mkrasimage \
2555-+ -b $(RAS_BOARD) \
2556-+ -v $(RAS_VERSION) \
2557-+ -r $@ \
2558-+ -s $$newsize \
2559-+ -o $@.new \
2560-+ $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
2561-+ && mv $@.new $@
2562- endef
2563-
2564- define Build/netgear-chk
2565-diff --git a/scripts/make-ras.sh b/scripts/make-ras.sh
2566-deleted file mode 100755
2567-index ccddaa0016b0c926d4737abb5757e7212b0a1157..0000000000000000000000000000000000000000
2568---- a/scripts/make-ras.sh
2569-+++ /dev/null
2570-@@ -1,196 +0,0 @@
2571--#!/usr/bin/env bash
2572--#
2573--# --- ZyXEL header format ---
2574--# Original Version by Benjamin Berg <benjamin@sipsolutions.net>
2575--#
2576--# The firmware image prefixed with a header (which is written into the MTD device).
2577--# The header is one erase block (~64KiB) in size, but the checksum only convers the
2578--# first 2KiB. Padding is 0xff. All integers are in big-endian.
2579--#
2580--# The checksum is always a 16-Bit System V checksum (sum -s) stored in a 32-Bit integer.
2581--#
2582--# 4 bytes: checksum of the rootfs image
2583--# 4 bytes: length of the contained rootfs image file (big endian)
2584--# 32 bytes: Firmware Version string (NUL terminated, 0xff padded)
2585--# 4 bytes: checksum over the header partition (big endian - see below)
2586--# 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded)
2587--# 4 bytes: checksum of the kernel partition
2588--# 4 bytes: length of the contained kernel image file (big endian)
2589--# rest: 0xff padding
2590--#
2591--# The checksums are calculated by adding up all bytes and if a 16bit
2592--# overflow occurs, one is added and the sum is masked to 16 bit:
2593--# csum = csum + databyte; if (csum > 0xffff) { csum += 1; csum &= 0xffff };
2594--# Should the file have an odd number of bytes then the byte len-0x800 is
2595--# used additionally.
2596--#
2597--# The checksum for the header is calculated over the first 2048 bytes with
2598--# the rootfs image checksum as the placeholder during calculation.
2599--#
2600--# The header is padded with 0xff to the erase block size of the device.
2601--#
2602--board=""
2603--version=""
2604--kernel=""
2605--rootfs=""
2606--outfile=""
2607--err=""
2608--
2609--while [ "$1" ]; do
2610-- case "$1" in
2611-- "--board")
2612-- board="$2"
2613-- shift
2614-- shift
2615-- continue
2616-- ;;
2617-- "--version")
2618-- version="$2"
2619-- shift
2620-- shift
2621-- continue
2622-- ;;
2623-- "--kernel")
2624-- kernel="$2"
2625-- shift
2626-- shift
2627-- continue
2628-- ;;
2629-- "--rootfs")
2630-- rootfs="$2"
2631-- shift
2632-- shift
2633-- continue
2634-- ;;
2635-- "--rootfssize")
2636-- rootfssize="$2"
2637-- shift
2638-- shift
2639-- continue
2640-- ;;
2641-- *)
2642-- if [ ! "$outfile" ]; then
2643-- outfile=$1
2644-- shift
2645-- continue
2646-- fi
2647-- ;;
2648-- esac
2649--done
2650--
2651--if [ ! -n "$board" -o ! -n "$version" -o ! -r "$kernel" -o ! -r "$rootfs" -o ! "$rootfssize" -o ! "$outfile" ]; then
2652-- echo "syntax: $0 [--board ras-boardname] [--version ras-version] [--kernel kernelimage] [--rootfs rootfs] out"
2653-- exit 1
2654--fi
2655--
2656--rootfs_len=$(wc -c < "$rootfs")
2657--
2658--if [ "$rootfs_len" -lt "$rootfssize" ]; then
2659-- dd if=$rootfs of=$rootfs.new bs=$rootfssize conv=sync
2660-- mv $rootfs.new $rootfs
2661--fi
2662--
2663--if [ ${#version} -ge 28 ]; then
2664-- echo "version: '$version' is too long"
2665-- exit 1
2666--fi
2667--
2668--tmpdir="$( mktemp -d 2> /dev/null )"
2669--if [ -z "$tmpdir" ]; then
2670-- # try OSX signature
2671-- tmpdir="$( mktemp -t 'ubitmp' -d )"
2672--fi
2673--
2674--if [ -z "$tmpdir" ]; then
2675-- exit 1
2676--fi
2677--
2678--to_be() {
2679-- local val="$1"
2680-- local size="$2"
2681--
2682-- case "$size" in
2683-- 4)
2684-- echo $(( "$val" >> 24 | ("$val" & 0xff0000) >> 8 | ("$val" & 0xff00) << 8 | ("$val" & 0xff) << 24 ))
2685-- ;;
2686-- 2)
2687-- echo $(( "$val" >> 8 | ("$val" & 0xff) << 8))
2688-- ;;
2689-- esac
2690--}
2691--
2692--checksum_file() {
2693-- local file=$1
2694--
2695-- # ZyXEL seems to use System V sum mode... Now this is classy, who would have thought?!
2696-- echo $(sum -s ${file} | cut -f1 -d" ")
2697--}
2698--
2699--append_bin() {
2700-- local val=$1
2701-- local size=$2
2702-- local file=$3
2703--
2704-- while [ "$size" -ne 0 ]; do
2705-- printf \\$(printf %o $(("$val" & 0xff))) >> "$file"
2706-- val=$(($val >> 8))
2707-- let size-=1
2708-- done
2709-- return
2710--}
2711--
2712--tf=${tmpdir}/out
2713--pad=$(printf '%0.1s' $(printf "\xff"){1..64})
2714--
2715--rootfs_header_file="$tmpdir/rootfs_header"
2716--rootfs_chksum=$(to_be $(checksum_file ${rootfs}) 4)
2717--rootfs_len=$(to_be $(wc -c < "$rootfs") 4)
2718--
2719--versionpadlen=$(( 32 - ( ${#version} + 1) ))
2720--
2721--# 4 bytes: checksum of the rootfs image
2722--append_bin "$rootfs_chksum" 4 "$rootfs_header_file"
2723--# 4 bytes: length of the contained rootfs image file (big endian)
2724--append_bin "$rootfs_len" 4 "$rootfs_header_file"
2725--# 32 bytes: Firmware Version string (NUL terminated, 0xff padded)
2726--printf "%s\x00%.*s" "$version" "$versionpadlen" "$pad" >> "$rootfs_header_file"
2727--
2728--kernel_header_file="$tmpdir/kernel_header"
2729--kernel_chksum=$(to_be $(checksum_file ${kernel}) 4)
2730--kernel_len=$(to_be $(wc -c < "$kernel") 4)
2731--
2732--# 4 bytes: checksum of the kernel image
2733--append_bin "$kernel_chksum" 4 "$kernel_header_file"
2734--# 4 bytes: length of the contained kernel image file (big endian)
2735--append_bin "$kernel_len" 4 "$kernel_header_file"
2736--
2737--board_header_file="$tmpdir/board_header"
2738--board_file="$tmpdir/board"
2739--boardpadlen=$(( 64 - ( ${#board} + 1) ))
2740--# 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded)
2741--printf "%s\x00%.*s" "$board" "$boardpadlen" "$pad" > "$board_file"
2742--cat "$kernel_header_file" >> "$board_file"
2743--printf "%.12s" "$pad" >> "$board_file"
2744--# rest: 0xff padding
2745--for i in {1..511}; do
2746-- printf "%s%s" "$pad" "$pad" >> "$board_file"
2747--done
2748--
2749--tmp_board_file="$tmpdir/tmp_board_file"
2750--cat "$rootfs_header_file" > "$tmp_board_file"
2751--
2752--# The checksum for the header is calculated over the first 2048 bytes with
2753--# the rootfs image checksum as the placeholder during calculation.
2754--append_bin "$rootfs_chksum" 4 "$tmp_board_file"
2755--cat "$board_file" >> "$tmp_board_file"
2756--
2757--truncate -s 2048 $tmp_board_file
2758--board_chksum=$(to_be $(checksum_file ${tmp_board_file}) 4)
2759--
2760--# 4 bytes: checksum over the header partition (big endian)
2761--append_bin "$board_chksum" 4 "$board_header_file"
2762--cat "$board_file" >> "$board_header_file"
2763--
2764--cat "$rootfs_header_file" "$board_header_file" "$rootfs" "$kernel" > "$outfile"
2765--
2766--rm -rf "$tmpdir"
2767-diff --git a/target/linux/ar71xx/image/generic.mk b/target/linux/ar71xx/image/generic.mk
2768-index 640557532c8a02f37bc6f84ade8cb34e7172162d..4568b656219419e9ca1156c6716bd2124074cb32 100644
2769---- a/target/linux/ar71xx/image/generic.mk
2770-+++ b/target/linux/ar71xx/image/generic.mk
2771-@@ -1086,8 +1086,12 @@ define Device/NBG6616
2772- IMAGE_SIZE := 15323k
2773- MTDPARTS := spi0.0:192k(u-boot)ro,64k(env)ro,64k(RFdata)ro,384k(zyxel_rfsd),384k(romd),64k(header),2048k(kernel),13184k(rootfs),15232k@0x120000(firmware)
2774- CMDLINE += mem=128M
2775-- IMAGES := sysupgrade.bin
2776-+ RAS_BOARD := NBG6616
2777-+ RAS_ROOTFS_SIZE := 14464k
2778-+ RAS_VERSION := "$(VERSION_DIST) $(REVISION)"
2779-+ IMAGES := factory.bin sysupgrade.bin
2780- KERNEL := kernel-bin | patch-cmdline | lzma | uImage lzma | jffs2 boot/vmlinux.lzma.uImage
2781-+ IMAGE/factory.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-rootfs | pad-rootfs | pad-to 64k | check-size $$$$(IMAGE_SIZE) | zyxel-ras-image
2782- IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-rootfs | pad-rootfs | check-size $$$$(IMAGE_SIZE)
2783- # We cannot currently build a factory image. It is the sysupgrade image
2784- # prefixed with a header (which is actually written into the MTD device).
2785-diff --git a/target/linux/ipq40xx/image/Makefile b/target/linux/ipq40xx/image/Makefile
2786-index cb79baccd21b3fa7f35df543bfca1a7d6ba8f83f..a0f81f7d631b6c53a5612dee172e752a9fecd06d 100644
2787---- a/target/linux/ipq40xx/image/Makefile
2788-+++ b/target/linux/ipq40xx/image/Makefile
2789-@@ -221,7 +221,7 @@ define Device/zyxel_nbg6617
2790- # at least as large as the one of the initial firmware image (not the current
2791- # one on the device). This only applies to the Web-UI, the bootlaoder ignores
2792- # this minimum-size. However, the larger image can be flashed both ways.
2793-- IMAGE/factory.bin := append-rootfs | pad-rootfs | check-size $$$$(ROOTFS_SIZE) | make-ras
2794-+ IMAGE/factory.bin := append-rootfs | pad-rootfs | pad-to 64k | check-size $$$$(ROOTFS_SIZE) | zyxel-ras-image separate-kernel
2795- IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-rootfs | check-size $$$$(ROOTFS_SIZE) | sysupgrade-tar rootfs=$$$$@ | append-metadata
2796- DEVICE_PACKAGES := ipq-wifi-zyxel_nbg6617 uboot-envtools
2797- endef
2798-diff --git a/target/linux/ipq806x/image/Makefile b/target/linux/ipq806x/image/Makefile
2799-index 2902af3231a87592e9c040e7e7e1e4e1958a01a5..a7f740ff62e05c7f6f24caa6da538302abee8d8f 100644
2800---- a/target/linux/ipq806x/image/Makefile
2801-+++ b/target/linux/ipq806x/image/Makefile
2802-@@ -67,7 +67,8 @@ define Device/ZyXELImage
2803- KERNEL_SUFFIX := -uImage
2804- KERNEL = kernel-bin | append-dtb | uImage none | pad-to $${KERNEL_SIZE}
2805- KERNEL_NAME := zImage
2806-- IMAGES := sysupgrade.bin mmcblk0p5-rootfs.bin mmcblk0p4-kernel.bin
2807-+ IMAGES := factory.bin sysupgrade.bin mmcblk0p5-rootfs.bin mmcblk0p4-kernel.bin
2808-+ IMAGE/factory.bin := append-rootfs | pad-rootfs | pad-to $$$$(BLOCKSIZE) | zyxel-ras-image separate-kernel
2809- IMAGE/sysupgrade.bin/squashfs := append-rootfs | pad-to $$$${BLOCKSIZE} | sysupgrade-tar rootfs=$$$$@ | append-metadata
2810- IMAGE/mmcblk0p5-rootfs.bin := append-rootfs | pad-rootfs | pad-to $$$${BLOCKSIZE}
2811- IMAGE/mmcblk0p4-kernel.bin := append-kernel
2812-@@ -245,6 +246,9 @@ define Device/zyxel_nbg6817
2813- KERNEL_SIZE := 4096k
2814- BLOCKSIZE := 64k
2815- BOARD_NAME := nbg6817
2816-+ RAS_BOARD := NBG6817
2817-+ RAS_ROOTFS_SIZE := 20934k
2818-+ RAS_VERSION := "V1.99(OWRT.9999)C0"
2819- SUPPORTED_DEVICES += nbg6817
2820- DEVICE_TITLE := ZyXEL NBG6817
2821- DEVICE_PACKAGES := ath10k-firmware-qca9984 e2fsprogs kmod-fs-ext4 losetup
2822-diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile
2823-index 4b4af999088455e3d9231b227fecfa71c8284b2f..a6379e35eb01f1cbbe2b1ece3fc9eb20bcd68d90 100644
2824---- a/tools/firmware-utils/Makefile
2825-+++ b/tools/firmware-utils/Makefile
2826-@@ -70,6 +70,7 @@ define Host/Compile
2827- $(call cc,fix-u-media-header cyg_crc32,-Wall)
2828- $(call cc,hcsmakeimage bcmalgo)
2829- $(call cc,mkporayfw, -Wall)
2830-+ $(call cc,mkrasimage, --std=gnu99)
2831- $(call cc,mkhilinkfw, -lcrypto)
2832- $(call cc,mkdcs932, -Wall)
2833- $(call cc,mkheader_gemtek,-lz)
2834-diff --git a/tools/firmware-utils/src/mkrasimage.c b/tools/firmware-utils/src/mkrasimage.c
2835-new file mode 100644
2836-index 0000000000000000000000000000000000000000..8eee29cc086a04104b51e263aeac0e73340056ca
2837---- /dev/null
2838-+++ b/tools/firmware-utils/src/mkrasimage.c
2839-@@ -0,0 +1,459 @@
2840-+/*
2841-+ * --- ZyXEL header format ---
2842-+ * Original Version by Benjamin Berg <benjamin@sipsolutions.net>
2843-+ * C implementation based on generation-script by Christian Lamparter <chunkeey@gmail.com>
2844-+ *
2845-+ * The firmware image prefixed with a header (which is written into the MTD device).
2846-+ * The header is one erase block (~64KiB) in size, but the checksum only convers the
2847-+ * first 2KiB. Padding is 0xff. All integers are in big-endian.
2848-+ *
2849-+ * The checksum is always a 16-Bit System V checksum (sum -s) stored in a 32-Bit integer.
2850-+ *
2851-+ * 4 bytes: checksum of the rootfs image
2852-+ * 4 bytes: length of the contained rootfs image file (big endian)
2853-+ * 32 bytes: Firmware Version string (NUL terminated, 0xff padded)
2854-+ * 4 bytes: checksum over the header partition (big endian - see below)
2855-+ * 64 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded)
2856-+ * 4 bytes: checksum of the kernel partition
2857-+ * 4 bytes: length of the contained kernel image file (big endian)
2858-+ * rest: 0xff padding (To erase block size)
2859-+ *
2860-+ * The kernel partition checksum and length is not used for every device.
2861-+ * If it's notused, pad those 8 bytes with 0xFF.
2862-+ *
2863-+ * The checksums are calculated by adding up all bytes and if a 16bit
2864-+ * overflow occurs, one is added and the sum is masked to 16 bit:
2865-+ * csum = csum + databyte; if (csum > 0xffff) { csum += 1; csum &= 0xffff };
2866-+ * Should the file have an odd number of bytes then the byte len-0x800 is
2867-+ * used additionally.
2868-+ *
2869-+ * The checksum for the header is calculated over the first 2048 bytes with
2870-+ * the rootfs image checksum as the placeholder during calculation.
2871-+ *
2872-+ * This program is free software; you can redistribute it and/or modify it
2873-+ * under the terms of the GNU General Public License version 2 as published
2874-+ * by the Free Software Foundation.
2875-+ *
2876-+ */
2877-+#include <fcntl.h>
2878-+#include <getopt.h>
2879-+#include <libgen.h>
2880-+#include <stdio.h>
2881-+#include <string.h>
2882-+#include <stdlib.h>
2883-+#include <unistd.h>
2884-+
2885-+#include <sys/mman.h>
2886-+#include <sys/stat.h>
2887-+
2888-+#include <arpa/inet.h>
2889-+
2890-+#define VERSION_STRING_LEN 31
2891-+#define ROOTFS_HEADER_LEN 40
2892-+
2893-+#define KERNEL_HEADER_LEN 8
2894-+
2895-+#define BOARD_NAME_LEN 64
2896-+#define BOARD_HEADER_LEN 68
2897-+
2898-+#define HEADER_PARTITION_CALC_LENGTH 2048
2899-+#define HEADER_PARTITION_LENGTH 0x10000
2900-+
2901-+struct file_info {
2902-+ char *name; /* name of the file */
2903-+ char *data; /* file content */
2904-+ size_t size; /* length of the file */
2905-+};
2906-+
2907-+static char *progname;
2908-+
2909-+static char *board_name = 0;
2910-+static char *version_name = 0;
2911-+static unsigned int rootfs_size = 0;
2912-+
2913-+static struct file_info kernel = { NULL, NULL, 0 };
2914-+static struct file_info rootfs = { NULL, NULL, 0 };
2915-+static struct file_info rootfs_out = { NULL, NULL, 0 };
2916-+static struct file_info out = { NULL, NULL, 0 };
2917-+
2918-+#define ERR(fmt, ...) do { \
2919-+ fprintf(stderr, "[%s] *** error: " fmt "\n", \
2920-+ progname, ## __VA_ARGS__ ); \
2921-+} while (0)
2922-+
2923-+void map_file(struct file_info *finfo)
2924-+{
2925-+ struct stat file_stat = {0};
2926-+ int fd;
2927-+
2928-+ fd = open(finfo->name, O_RDONLY, (mode_t)0600);
2929-+ if (fd == -1) {
2930-+ ERR("Error while opening file %s.", finfo->name);
2931-+ exit(EXIT_FAILURE);
2932-+ }
2933-+
2934-+ if (fstat(fd, &file_stat) == -1) {
2935-+ ERR("Error getting file size for %s.", finfo->name);
2936-+ exit(EXIT_FAILURE);
2937-+ }
2938-+
2939-+ finfo->size = file_stat.st_size;
2940-+ finfo->data = mmap(0, finfo->size, PROT_READ, MAP_SHARED, fd, 0);
2941-+
2942-+ if (finfo->data == MAP_FAILED) {
2943-+ ERR("Error mapping file %s.", finfo->name);
2944-+ exit(EXIT_FAILURE);
2945-+ }
2946-+
2947-+ close(fd);
2948-+}
2949-+
2950-+void unmap_file(struct file_info *finfo)
2951-+{
2952-+ if(munmap(finfo->data, finfo->size) == -1) {
2953-+ ERR("Error unmapping file %s.", finfo->name);
2954-+ exit(EXIT_FAILURE);
2955-+ }
2956-+}
2957-+
2958-+void write_file(struct file_info *finfo)
2959-+{
2960-+ FILE *fout = fopen(finfo->name, "w");
2961-+
2962-+ fwrite(finfo->data, finfo->size, 1, fout);
2963-+
2964-+ if (ferror(fout)) {
2965-+ ERR("Wanted to write, but something went wrong.");
2966-+ exit(EXIT_FAILURE);
2967-+ }
2968-+
2969-+ fclose(fout);
2970-+}
2971-+
2972-+void usage(int status)
2973-+{
2974-+ FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
2975-+
2976-+ fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
2977-+ fprintf(stream,
2978-+ "\n"
2979-+ "Options:\n"
2980-+ " -k <kernel> path for kernel image\n"
2981-+ " -r <rootfs> path for rootfs image\n"
2982-+ " -s <rfssize> size of output rootfs\n"
2983-+ " -v <version> version string\n"
2984-+ " -b <boardname> name of board to generate image for\n"
2985-+ " -o <out_name> name of output image\n"
2986-+ " -h show this screen\n"
2987-+ );
2988-+
2989-+ exit(status);
2990-+}
2991-+
2992-+static int sysv_chksm(const unsigned char *data, int size)
2993-+{
2994-+ int r;
2995-+ int checksum;
2996-+ unsigned int s = 0; /* The sum of all the input bytes, modulo (UINT_MAX + 1). */
2997-+
2998-+
2999-+ for (int i = 0; i < size; i++) {
3000-+ s += data[i];
3001-+ }
3002-+
3003-+ r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
3004-+ checksum = (r & 0xffff) + (r >> 16);
3005-+
3006-+ return checksum;
3007-+}
3008-+
3009-+static int zyxel_chksm(const unsigned char *data, int size)
3010-+{
3011-+ return htonl(sysv_chksm(data, size));
3012-+}
3013-+
3014-+char *generate_rootfs_header(struct file_info filesystem, char *version)
3015-+{
3016-+ size_t version_string_length;
3017-+ unsigned int chksm, size;
3018-+ char *rootfs_header;
3019-+ size_t ptr = 0;
3020-+
3021-+ rootfs_header = malloc(ROOTFS_HEADER_LEN);
3022-+ if (!rootfs_header) {
3023-+ ERR("Couldn't allocate memory for rootfs header!");
3024-+ exit(EXIT_FAILURE);
3025-+ }
3026-+
3027-+ /* Prepare padding for firmware-version string here */
3028-+ memset(rootfs_header, 0xff, ROOTFS_HEADER_LEN);
3029-+
3030-+ chksm = zyxel_chksm((const unsigned char *)filesystem.data, filesystem.size);
3031-+ size = htonl(filesystem.size);
3032-+
3033-+ /* 4 bytes: checksum of the rootfs image */
3034-+ memcpy(rootfs_header + ptr, &chksm, 4);
3035-+ ptr += 4;
3036-+
3037-+ /* 4 bytes: length of the contained rootfs image file (big endian) */
3038-+ memcpy(rootfs_header + ptr, &size, 4);
3039-+ ptr += 4;
3040-+
3041-+ /* 32 bytes: Firmware Version string (NUL terminated, 0xff padded) */
3042-+ version_string_length = strlen(version) <= VERSION_STRING_LEN ? strlen(version) : VERSION_STRING_LEN;
3043-+ memcpy(rootfs_header + ptr, version, version_string_length);
3044-+ ptr += version_string_length;
3045-+ /* Add null-terminator */
3046-+ rootfs_header[ptr] = 0x0;
3047-+
3048-+ return rootfs_header;
3049-+}
3050-+
3051-+char *generate_kernel_header(struct file_info kernel)
3052-+{
3053-+ unsigned int chksm, size;
3054-+ char *kernel_header;
3055-+ size_t ptr = 0;
3056-+
3057-+ kernel_header = malloc(KERNEL_HEADER_LEN);
3058-+ if (!kernel_header) {
3059-+ ERR("Couldn't allocate memory for kernel header!");
3060-+ exit(EXIT_FAILURE);
3061-+ }
3062-+
3063-+ chksm = zyxel_chksm((const unsigned char *)kernel.data, kernel.size);
3064-+ size = htonl(kernel.size);
3065-+
3066-+ /* 4 bytes: checksum of the kernel image */
3067-+ memcpy(kernel_header + ptr, &chksm, 4);
3068-+ ptr += 4;
3069-+
3070-+ /* 4 bytes: length of the contained kernel image file (big endian) */
3071-+ memcpy(kernel_header + ptr, &size, 4);
3072-+
3073-+ return kernel_header;
3074-+}
3075-+
3076-+unsigned int generate_board_header_checksum(char *kernel_hdr, char *rootfs_hdr, char *boardname)
3077-+{
3078-+ char *board_hdr_tmp;
3079-+ unsigned int sum;
3080-+ size_t ptr = 0;
3081-+
3082-+ /*
3083-+ * The checksum of the board header is calculated over the first 2048 bytes of
3084-+ * the header partition with the rootfs checksum used as a placeholder for then
3085-+ * board checksum we calculate in this step. The checksum gained from this step
3086-+ * is then used for the final board header partition.
3087-+ */
3088-+
3089-+ board_hdr_tmp = malloc(HEADER_PARTITION_CALC_LENGTH);
3090-+ if (!board_hdr_tmp) {
3091-+ ERR("Couldn't allocate memory for temporary board header!");
3092-+ exit(EXIT_FAILURE);
3093-+ }
3094-+ memset(board_hdr_tmp, 0xff, HEADER_PARTITION_CALC_LENGTH);
3095-+
3096-+ /* 40 bytes: RootFS header */
3097-+ memcpy(board_hdr_tmp, rootfs_hdr, ROOTFS_HEADER_LEN);
3098-+ ptr += ROOTFS_HEADER_LEN;
3099-+
3100-+ /* 4 bytes: RootFS checksum (BE) as placeholder for board-header checksum */
3101-+ memcpy(board_hdr_tmp + ptr, rootfs_hdr, 4);
3102-+ ptr += 4;
3103-+
3104-+ /* 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded) */
3105-+ memcpy(board_hdr_tmp + ptr, boardname, strlen(boardname));
3106-+ ptr += strlen(boardname);
3107-+ /* Add null-terminator */
3108-+ board_hdr_tmp[ptr] = 0x0;
3109-+ ptr = ROOTFS_HEADER_LEN + 4 + BOARD_NAME_LEN;
3110-+
3111-+ /* 8 bytes: Kernel header */
3112-+ if (kernel_hdr)
3113-+ memcpy(board_hdr_tmp + ptr, kernel_hdr, 8);
3114-+
3115-+ /* Calculate the checksum over the first 2048 bytes */
3116-+ sum = zyxel_chksm((const unsigned char *)board_hdr_tmp, HEADER_PARTITION_CALC_LENGTH);
3117-+ free(board_hdr_tmp);
3118-+ return sum;
3119-+}
3120-+
3121-+char *generate_board_header(char *kernel_hdr, char *rootfs_hdr, char *boardname)
3122-+{
3123-+ unsigned int board_checksum;
3124-+ char *board_hdr;
3125-+
3126-+ board_hdr = malloc(BOARD_HEADER_LEN);
3127-+ if (!board_hdr) {
3128-+ ERR("Couldn't allocate memory for board header!");
3129-+ exit(EXIT_FAILURE);
3130-+ }
3131-+ memset(board_hdr, 0xff, BOARD_HEADER_LEN);
3132-+
3133-+ /* 4 bytes: checksum over the header partition (big endian) */
3134-+ board_checksum = generate_board_header_checksum(kernel_hdr, rootfs_hdr, boardname);
3135-+ memcpy(board_hdr, &board_checksum, 4);
3136-+
3137-+ /* 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded) */
3138-+ memcpy(board_hdr + 4, boardname, strlen(boardname));
3139-+ board_hdr[4 + strlen(boardname)] = 0x0;
3140-+
3141-+ return board_hdr;
3142-+}
3143-+
3144-+int build_image()
3145-+{
3146-+ char *rootfs_header = NULL;
3147-+ char *kernel_header = NULL;
3148-+ char *board_header = NULL;
3149-+
3150-+ size_t ptr;
3151-+
3152-+ /* Load files */
3153-+ if (kernel.name)
3154-+ map_file(&kernel);
3155-+ map_file(&rootfs);
3156-+
3157-+ /*
3158-+ * Allocate memory and copy input rootfs for temporary output rootfs.
3159-+ * This is important as we have to generate the rootfs checksum over the
3160-+ * entire rootfs partition. As we might have to pad the partition to allow
3161-+ * for flashing via ZyXEL's Web-GUI, we prepare the rootfs partition for the
3162-+ * output image here (and also use it for calculating the rootfs checksum).
3163-+ *
3164-+ * The roofs padding has to be done with 0x00.
3165-+ */
3166-+ rootfs_out.data = calloc(rootfs_out.size, sizeof(char));
3167-+ memcpy(rootfs_out.data, rootfs.data, rootfs.size);
3168-+
3169-+ /* Prepare headers */
3170-+ rootfs_header = generate_rootfs_header(rootfs_out, version_name);
3171-+ if (kernel.name)
3172-+ kernel_header = generate_kernel_header(kernel);
3173-+ board_header = generate_board_header(kernel_header, rootfs_header, board_name);
3174-+
3175-+ /* Prepare output file */
3176-+ out.size = HEADER_PARTITION_LENGTH + rootfs_out.size;
3177-+ if (kernel.name)
3178-+ out.size += kernel.size;
3179-+ out.data = malloc(out.size);
3180-+ memset(out.data, 0xFF, out.size);
3181-+
3182-+ /* Build output image */
3183-+ memcpy(out.data, rootfs_header, ROOTFS_HEADER_LEN);
3184-+ memcpy(out.data + ROOTFS_HEADER_LEN, board_header, BOARD_HEADER_LEN);
3185-+ if (kernel.name)
3186-+ memcpy(out.data + ROOTFS_HEADER_LEN + BOARD_HEADER_LEN, kernel_header, KERNEL_HEADER_LEN);
3187-+ ptr = HEADER_PARTITION_LENGTH;
3188-+ memcpy(out.data + ptr, rootfs_out.data, rootfs_out.size);
3189-+ ptr += rootfs_out.size;
3190-+ if (kernel.name)
3191-+ memcpy(out.data + ptr, kernel.data, kernel.size);
3192-+
3193-+ /* Write back output image */
3194-+ write_file(&out);
3195-+
3196-+ /* Free allocated memory */
3197-+ if (kernel.name)
3198-+ unmap_file(&kernel);
3199-+ unmap_file(&rootfs);
3200-+ free(out.data);
3201-+ free(rootfs_out.data);
3202-+
3203-+ free(rootfs_header);
3204-+ if (kernel.name)
3205-+ free(kernel_header);
3206-+ free(board_header);
3207-+
3208-+ return 0;
3209-+}
3210-+
3211-+int check_options()
3212-+{
3213-+ if (!rootfs.name) {
3214-+ ERR("No rootfs filename supplied");
3215-+ return -2;
3216-+ }
3217-+
3218-+ if (!out.name) {
3219-+ ERR("No output filename supplied");
3220-+ return -3;
3221-+ }
3222-+
3223-+ if (!board_name) {
3224-+ ERR("No board-name supplied");
3225-+ return -4;
3226-+ }
3227-+
3228-+ if (!version_name) {
3229-+ ERR("No version supplied");
3230-+ return -5;
3231-+ }
3232-+
3233-+ if (rootfs_size <= 0) {
3234-+ ERR("Invalid rootfs size supplied");
3235-+ return -6;
3236-+ }
3237-+
3238-+ if (strlen(board_name) > 31) {
3239-+ ERR("Board name is to long");
3240-+ return -7;
3241-+ }
3242-+ return 0;
3243-+}
3244-+
3245-+int main(int argc, char *argv[])
3246-+{
3247-+ int ret;
3248-+ progname = basename(argv[0]);
3249-+ while (1) {
3250-+ int c;
3251-+
3252-+ c = getopt(argc, argv, "b:k:o:r:s:v:h");
3253-+ if (c == -1)
3254-+ break;
3255-+
3256-+ switch (c) {
3257-+ case 'b':
3258-+ board_name = optarg;
3259-+ break;
3260-+ case 'h':
3261-+ usage(EXIT_SUCCESS);
3262-+ break;
3263-+ case 'k':
3264-+ kernel.name = optarg;
3265-+ break;
3266-+ case 'o':
3267-+ out.name = optarg;
3268-+ break;
3269-+ case 'r':
3270-+ rootfs.name = optarg;
3271-+ break;
3272-+ case 's':
3273-+ sscanf(optarg, "%u", &rootfs_size);
3274-+ break;
3275-+ case 'v':
3276-+ version_name = optarg;
3277-+ break;
3278-+ default:
3279-+ usage(EXIT_FAILURE);
3280-+ break;
3281-+ }
3282-+ }
3283-+
3284-+ ret = check_options();
3285-+ if (ret)
3286-+ usage(EXIT_FAILURE);
3287-+
3288-+ /* As ZyXEL Web-GUI only accept images with a rootfs equal or larger than the first firmware shipped
3289-+ * for the device, we need to pad rootfs partition to this size. To perform further calculations, we
3290-+ * decide the size of this part here. In case the rootfs we want to integrate in our image is larger,
3291-+ * take it's size, otherwise the supplied size.
3292-+ *
3293-+ * Be careful! We rely on assertion of correct size to be performed beforehand. It is unknown if images
3294-+ * with a to large rootfs are accepted or not.
3295-+ */
3296-+ rootfs_out.size = rootfs_size < rootfs.size ? rootfs.size : rootfs_size;
3297-+ return build_image();
3298-+}
3299diff --git a/patches/openwrt/0010-ipq40xx-fix-NBG6617-LED-mapping.patch b/patches/openwrt/0010-ipq40xx-fix-NBG6617-LED-mapping.patch
3300deleted file mode 100644
3301index b3fff8d2..00000000
3302--- a/patches/openwrt/0010-ipq40xx-fix-NBG6617-LED-mapping.patch
3303+++ /dev/null
3304@@ -1,27 +0,0 @@
3305-From: David Bauer <mail@david-bauer.net>
3306-Date: Sun, 4 Nov 2018 01:00:18 +0100
3307-Subject: ipq40xx: fix NBG6617 LED mapping
3308-
3309-The NBG6617's LEDs are wrongly identified in the 01_leds boardinit
3310-script (board instead of boardname), thus referencing non-existant LEDs
3311-in UCI.
3312-
3313-Signed-off-by: David Bauer <mail@david-bauer.net>
3314-
3315-diff --git a/target/linux/ipq40xx/base-files/etc/board.d/01_leds b/target/linux/ipq40xx/base-files/etc/board.d/01_leds
3316-index 475a8623f705d683a7ee3521ee71f2b57fa2e44d..ab2f77ee10a8e4371d8c52d6d6b6a35bae8aceb6 100755
3317---- a/target/linux/ipq40xx/base-files/etc/board.d/01_leds
3318-+++ b/target/linux/ipq40xx/base-files/etc/board.d/01_leds
3319-@@ -35,9 +35,9 @@ meraki,mr33)
3320- ucidef_set_interface_lan "eth0"
3321- ;;
3322- zyxel,nbg6617)
3323-- ucidef_set_led_wlan "wlan2g" "WLAN2G" "$board:green:wlan2G" "phy0tpt"
3324-- ucidef_set_led_wlan "wlan5g" "WLAN5G" "$board:green:wlan5G" "phy1tpt"
3325-- ucidef_set_led_usbport "usb" "USB" "${board}:green:usb" "usb1-port1" "usb2-port1" "usb3-port1" "usb4-port1"
3326-+ ucidef_set_led_wlan "wlan2g" "WLAN2G" "${boardname}:green:wlan2G" "phy0tpt"
3327-+ ucidef_set_led_wlan "wlan5g" "WLAN5G" "${boardname}:green:wlan5G" "phy1tpt"
3328-+ ucidef_set_led_usbport "usb" "USB" "${boardname}:green:usb" "usb1-port1" "usb2-port1" "usb3-port1" "usb4-port1"
3329- ;;
3330- zyxel,wre6606)
3331- ucidef_set_led_wlan "wlan2g" "WLAN2G" "${boardname}:green:wlan2g" "phy0tpt"
3332diff --git a/patches/openwrt/0012-tools-mktplinkfw2-add-split-uboot-layout.patch b/patches/openwrt/0012-tools-mktplinkfw2-add-split-uboot-layout.patch
3333deleted file mode 100644
3334index 4df76cf6..00000000
3335--- a/patches/openwrt/0012-tools-mktplinkfw2-add-split-uboot-layout.patch
3336+++ /dev/null
3337@@ -1,26 +0,0 @@
3338-From: David Bauer <mail@david-bauer.net>
3339-Date: Wed, 28 Nov 2018 23:56:31 +0100
3340-Subject: tools: mktplinkfw2: add split-uboot layout
3341-
3342-This commit adds the split-uboot partition layout used by the
3343-Archer C50 v4 to mktplinkfw2.
3344-
3345-Signed-off-by: David Bauer <mail@david-bauer.net>
3346-
3347-diff --git a/tools/firmware-utils/src/mktplinkfw2.c b/tools/firmware-utils/src/mktplinkfw2.c
3348-index dead49e7af8839bac5d1dee7445cf8921208c970..35db848bbab9f8315526dfa24ed351ad58878dde 100644
3349---- a/tools/firmware-utils/src/mktplinkfw2.c
3350-+++ b/tools/firmware-utils/src/mktplinkfw2.c
3351-@@ -146,6 +146,12 @@ static struct flash_layout layouts[] = {
3352- .kernel_la = 0x80000000,
3353- .kernel_ep = 0x80000000,
3354- .rootfs_ofs = 0x140000,
3355-+ }, {
3356-+ .id = "8MSUmtk", /* Split U-Boot OS */
3357-+ .fw_max_len = 0x770000,
3358-+ .kernel_la = 0x80000000,
3359-+ .kernel_ep = 0x80000000,
3360-+ .rootfs_ofs = 0x140000,
3361- }, {
3362- .id = "8MLmtk",
3363- .fw_max_len = 0x7b0000,
3364diff --git a/patches/openwrt/0013-ramips-add-support-for-Archer-C50-v4.patch b/patches/openwrt/0013-ramips-add-support-for-Archer-C50-v4.patch
3365deleted file mode 100644
3366index 52c5a9d6..00000000
3367--- a/patches/openwrt/0013-ramips-add-support-for-Archer-C50-v4.patch
3368+++ /dev/null
3369@@ -1,370 +0,0 @@
3370-From: David Bauer <mail@david-bauer.net>
3371-Date: Sun, 3 Feb 2019 00:23:18 +0100
3372-Subject: ramips: add support for Archer C50 v4
3373-
3374-This adds support for the TP-Link Archer C50 v4.
3375-It uses the same hardware as the v3 variant, sharing the same FCC-ID.
3376-
3377-CPU: MediaTek MT7628 (580MHz)
3378-RAM: 64M DDR2
3379-FLASH: 8M SPI
3380-WiFi: 2.4GHz 2x2 MT7628 b/g/n integrated
3381-WiFI: 5GHz 2x2 MT7612 a/n/ac
3382-ETH: 1x WAN 4x LAN
3383-LED: Power, WiFi2, WiFi5, LAN, WAN, WPS
3384-BTN: WPS/WiFi, RESET
3385-UART: Near ETH ports, 115200 8n1, TP-Link pinout
3386-
3387-Create Factory image
3388---------------------
3389-As all installation methods require a U-Boot to be integrated into the
3390-Image (and we do not ship one with the image) we are not able to create
3391-an image in the OpenWRT build-process.
3392-
3393-Download a TP-Link image from their Wesite and a OpenWRT sysupgrade
3394-image for the device and build yourself a factory image like following:
3395-
3396-TP-Link image: tpl.bin
3397-OpenWRT sysupgrade image: owrt.bin
3398-
3399- > dd if=tpl.bin of=boot.bin bs=131584 count=1
3400- > cat owrt.bin >> boot.bin
3401-
3402-Installing via Web-UI
3403----------------------
3404-Upload the boot.bin via TP-Links firmware upgrade tool in the
3405-web-interface.
3406-
3407-Installing via Recovery
3408------------------------
3409-Activate Web-Recovery by beginning the upgrade Process with a
3410-Firmware-Image from TP-Link. After starting the Firmware Upgrade,
3411-wait ~3 seconds (When update status is switching to 0%), then
3412-disconnect the power supply from the device. Upgrade flag (which
3413-activates Web-Recovery) is written before the OS-image is touched and
3414-removed after write is succesfull, so this procedure should be safe.
3415-
3416-Plug the power back in. It will come up in Recovery-Mode on 192.168.0.1.
3417-When active, all LEDs but the WPS LED are off.
3418-Remeber to assign yourself a static IP-address as DHCP is not active in
3419-this mode.
3420-
3421-The boot.bin can now be uploaded and flashed using the web-recovery.
3422-
3423-Installing via TFTP
3424--------------------
3425-Prepare an image like following (Filenames from factory image steps
3426-apply here)
3427-
3428- > dd if=/dev/zero of=tp_recovery.bin bs=196608 count=1
3429- > dd if=tpl.bin of=tmp.bin bs=131584 count=1
3430- > dd if=tmp.bin of=boot.bin bs=512 skip=1
3431- > cat boot.bin >> tp_recovery.bin
3432- > cat owrt.bin >> tp_recovery.bin
3433-
3434-Place tp_recovery.bin in root directory of TFTP server and listen on
3435-192.168.0.66/24.
3436-
3437-Connect router LAN ports with your computer and power up the router
3438-while pressing the reset button. The router will download the image via
3439-tftp and after ~1 Minute reboot into OpenWRT.
3440-
3441-U-Boot CLI
3442-----------
3443-U-Boot CLI can be activated by holding down '4' on bootup.
3444-
3445-Dual U-Boot
3446------------
3447-This is the first TP-Link MediaTek device to feature a split-uboot
3448-design. The first (factory-uboot) provides recovery via TFTP and HTTP,
3449-jumping straight into the second (firmware-uboot) if no recovery needs
3450-to be performed. The firmware-uboot unpacks and executed the kernel.
3451-
3452-Web-Recovery
3453-------------
3454-TP-Link integrated a new Web-Recovery like the one on the Archer C7v4 /
3455-TL-WR1043v5. Stock-firmware sets a flag in the "romfile" partition
3456-before beginning to write and removes it afterwards. If the router boots
3457-with this flag set, bootloader will automatically start Web-recovery and
3458-listens on 192.168.0.1. This way, the vendor-firmware or an OpenWRT
3459-factory image can be written.
3460-
3461-It is important to note that Web-Recovery is only based on this flag. It
3462-can't detect e.g. a crashing kernel or other means. Once activated it
3463-won't boot the OS before a recovery action (either via TFTP or HTTP) is
3464-performed. This recovery-mode is indicated by an illuminated WPS-LED on
3465-boot.
3466-
3467-Signed-off-by: David Bauer <mail@david-bauer.net>
3468-
3469-diff --git a/target/linux/ramips/base-files/etc/board.d/01_leds b/target/linux/ramips/base-files/etc/board.d/01_leds
3470-index 6057275978591192e3b7799a8e6d97761c3e23a5..19386b9e139a25fd1ac29cd9a66b738b5b092cdf 100755
3471---- a/target/linux/ramips/base-files/etc/board.d/01_leds
3472-+++ b/target/linux/ramips/base-files/etc/board.d/01_leds
3473-@@ -410,7 +410,8 @@ tplink,c20-v4)
3474- ucidef_set_led_switch "wan" "wan" "$boardname:green:wan" "switch0" "0x01"
3475- ucidef_set_led_netdev "wlan2g" "wlan2g" "$boardname:green:wlan2g" "wlan0"
3476- ;;
3477--tplink,c50-v3)
3478-+tplink,c50-v3|\
3479-+tplink,c50-v4)
3480- ucidef_set_led_switch "lan" "lan" "$boardname:green:lan" "switch0" "0x1e"
3481- ucidef_set_led_switch "wan" "wan" "$boardname:green:wan" "switch0" "0x01"
3482- ucidef_set_led_wlan "wlan2g" "wlan2g" "$boardname:green:wlan2g" "phy0tpt"
3483-diff --git a/target/linux/ramips/base-files/etc/board.d/02_network b/target/linux/ramips/base-files/etc/board.d/02_network
3484-index ebf40ad1fa874d324b43c8f0613bca53a19ab2d0..1c6cc6b0af745b43b81bbfffc9b5462c1b88defc 100755
3485---- a/target/linux/ramips/base-files/etc/board.d/02_network
3486-+++ b/target/linux/ramips/base-files/etc/board.d/02_network
3487-@@ -205,6 +205,7 @@ ramips_setup_interfaces()
3488- rt-n14u|\
3489- tplink,c20-v4|\
3490- tplink,c50-v3|\
3491-+ tplink,c50-v4|\
3492- tplink,tl-mr3420-v5|\
3493- tplink,tl-wr842n-v5|\
3494- tl-wr840n-v4|\
3495-diff --git a/target/linux/ramips/base-files/etc/diag.sh b/target/linux/ramips/base-files/etc/diag.sh
3496-index 2f51add331fef4693e997433a4ab0e665da80e02..6d021b6def2f1fe7b71a67f36749c440f3bad1d4 100644
3497---- a/target/linux/ramips/base-files/etc/diag.sh
3498-+++ b/target/linux/ramips/base-files/etc/diag.sh
3499-@@ -42,6 +42,7 @@ get_status_led() {
3500- r6220|\
3501- tplink,c20-v4|\
3502- tplink,c50-v3|\
3503-+ tplink,c50-v4|\
3504- tplink,tl-mr3420-v5|\
3505- tplink,tl-wr842n-v5|\
3506- tplink,tl-wr902ac-v3|\
3507-diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh b/target/linux/ramips/base-files/lib/upgrade/platform.sh
3508-index ffdc5e73e0ede286c10396810954a230c8ea32fc..8055853508fc850a1826166c7e0cbdf443df27cb 100755
3509---- a/target/linux/ramips/base-files/lib/upgrade/platform.sh
3510-+++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh
3511-@@ -256,6 +256,7 @@ platform_check_image() {
3512- tplink,c20-v1|\
3513- tplink,c20-v4|\
3514- tplink,c50-v3|\
3515-+ tplink,c50-v4|\
3516- tplink,tl-mr3420-v5|\
3517- tplink,tl-wr842n-v5|\
3518- tplink,tl-wr902ac-v3|\
3519-diff --git a/target/linux/ramips/dts/ArcherC50V4.dts b/target/linux/ramips/dts/ArcherC50V4.dts
3520-new file mode 100644
3521-index 0000000000000000000000000000000000000000..bb4a65436fa435e5636aca3bf326b5a3ca61f7e3
3522---- /dev/null
3523-+++ b/target/linux/ramips/dts/ArcherC50V4.dts
3524-@@ -0,0 +1,93 @@
3525-+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
3526-+/dts-v1/;
3527-+
3528-+#include "TPLINK-8M-SPLIT-UBOOT.dtsi"
3529-+
3530-+#include <dt-bindings/gpio/gpio.h>
3531-+#include <dt-bindings/input/input.h>
3532-+
3533-+/ {
3534-+ compatible = "tplink,c50-v4", "mediatek,mt7628an-soc";
3535-+ model = "TP-Link Archer C50 v4";
3536-+
3537-+ keys {
3538-+ compatible = "gpio-keys-polled";
3539-+ poll-interval = <20>;
3540-+
3541-+ reset {
3542-+ label = "reset";
3543-+ gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
3544-+ linux,code = <KEY_RESTART>;
3545-+ };
3546-+
3547-+ rfkill {
3548-+ label = "rfkill";
3549-+ gpios = <&gpio0 5 GPIO_ACTIVE_LOW>;
3550-+ linux,code = <KEY_RFKILL>;
3551-+ };
3552-+ };
3553-+
3554-+ leds {
3555-+ compatible = "gpio-leds";
3556-+
3557-+ led_power: power {
3558-+ label = "c50-v4:green:power";
3559-+ gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
3560-+ };
3561-+
3562-+ wlan2 {
3563-+ label = "c50-v4:green:wlan2g";
3564-+ gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
3565-+ };
3566-+
3567-+ wlan5 {
3568-+ label = "c50-v4:green:wlan5g";
3569-+ gpios = <&gpio1 10 GPIO_ACTIVE_LOW>;
3570-+ };
3571-+
3572-+ lan {
3573-+ label = "c50-v4:green:lan";
3574-+ gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
3575-+ };
3576-+
3577-+ wan {
3578-+ label = "c50-v4:green:wan";
3579-+ gpios = <&gpio1 7 GPIO_ACTIVE_LOW>;
3580-+ };
3581-+
3582-+ wan_orange {
3583-+ label = "c50-v4:orange:wan";
3584-+ gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
3585-+ };
3586-+
3587-+ wps {
3588-+ label = "c50-v4:green:wps";
3589-+ gpios = <&gpio1 11 GPIO_ACTIVE_LOW>;
3590-+ };
3591-+ };
3592-+};
3593-+
3594-+&pinctrl {
3595-+ state_default: pinctrl0 {
3596-+ gpio {
3597-+ ralink,group = "i2c", "p0led_an", "p1led_an", "p2led_an",
3598-+ "p3led_an", "p4led_an", "wdt", "wled_an";
3599-+ ralink,function = "gpio";
3600-+ };
3601-+ };
3602-+};
3603-+
3604-+&pcie {
3605-+ status = "okay";
3606-+
3607-+ pcie-bridge {
3608-+ mt76@0,0 {
3609-+ reg = <0x0000 0 0 0 0>;
3610-+ device_type = "pci";
3611-+ mediatek,mtd-eeprom = <&radio 0x8000>;
3612-+ ieee80211-freq-limit = <5000000 6000000>;
3613-+ mtd-mac-address = <&rom 0xf100>;
3614-+ mtd-mac-address-increment = <(-1)>;
3615-+ };
3616-+ };
3617-+};
3618-\ No newline at end of file
3619-diff --git a/target/linux/ramips/dts/TPLINK-8M-SPLIT-UBOOT.dtsi b/target/linux/ramips/dts/TPLINK-8M-SPLIT-UBOOT.dtsi
3620-new file mode 100644
3621-index 0000000000000000000000000000000000000000..539f476dce6e1fe43769f3ed41ae94d5f6fbc2cc
3622---- /dev/null
3623-+++ b/target/linux/ramips/dts/TPLINK-8M-SPLIT-UBOOT.dtsi
3624-@@ -0,0 +1,90 @@
3625-+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
3626-+#include "mt7628an.dtsi"
3627-+
3628-+/ {
3629-+ chosen {
3630-+ bootargs = "console=ttyS0,115200";
3631-+ };
3632-+
3633-+ memory@0 {
3634-+ device_type = "memory";
3635-+ reg = <0x0 0x4000000>;
3636-+ };
3637-+};
3638-+
3639-+&spi0 {
3640-+ status = "okay";
3641-+
3642-+ flash@0 {
3643-+ compatible = "jedec,spi-nor";
3644-+ reg = <0>;
3645-+ spi-max-frequency = <10000000>;
3646-+ m25p,chunked-io = <32>;
3647-+
3648-+ partitions {
3649-+ compatible = "fixed-partitions";
3650-+ #address-cells = <1>;
3651-+ #size-cells = <1>;
3652-+
3653-+ partition@0 {
3654-+ label = "factory-uboot";
3655-+ reg = <0x0 0x30000>;
3656-+ read-only;
3657-+ };
3658-+
3659-+ partition@30000 {
3660-+ label = "boot";
3661-+ reg = <0x30000 0x20000>;
3662-+ read-only;
3663-+ };
3664-+
3665-+ partition@50000 {
3666-+ compatible = "tplink,firmware";
3667-+ label = "firmware";
3668-+ reg = <0x50000 0x770000>;
3669-+ };
3670-+
3671-+ partition@7c0000 {
3672-+ label = "config";
3673-+ reg = <0x7c0000 0x10000>;
3674-+ read-only;
3675-+ };
3676-+
3677-+ rom: partition@7d0000 {
3678-+ label = "rom";
3679-+ reg = <0x7d0000 0x10000>;
3680-+ read-only;
3681-+ };
3682-+
3683-+ partition@7e0000 {
3684-+ label = "romfile";
3685-+ reg = <0x7e0000 0x10000>;
3686-+ };
3687-+
3688-+ radio: partition@7f0000 {
3689-+ label = "radio";
3690-+ reg = <0x7f0000 0x10000>;
3691-+ read-only;
3692-+ };
3693-+ };
3694-+ };
3695-+};
3696-+
3697-+&ehci {
3698-+ status = "disabled";
3699-+};
3700-+
3701-+&ohci {
3702-+ status = "disabled";
3703-+};
3704-+
3705-+&wmac {
3706-+ status = "okay";
3707-+ mtd-mac-address = <&rom 0xf100>;
3708-+ mediatek,mtd-eeprom = <&radio 0x0>;
3709-+};
3710-+
3711-+ðernet {
3712-+ mtd-mac-address = <&rom 0xf100>;
3713-+ mediatek,portmap = "llllw";
3714-+};
3715-diff --git a/target/linux/ramips/image/mt76x8.mk b/target/linux/ramips/image/mt76x8.mk
3716-index 21c5357a089fdd0675afa6f131ff5b34a9a8f54d..34bd662f3a9490bdb0fd125af5ffa8a0f77c5f16 100644
3717---- a/target/linux/ramips/image/mt76x8.mk
3718-+++ b/target/linux/ramips/image/mt76x8.mk
3719-@@ -182,6 +182,20 @@ define Device/tplink_c50-v3
3720- endef
3721- TARGET_DEVICES += tplink_c50-v3
3722-
3723-+define Device/tplink_c50-v4
3724-+ $(Device/tplink)
3725-+ DTS := ArcherC50V4
3726-+ IMAGE_SIZE := 7616k
3727-+ DEVICE_TITLE := TP-Link ArcherC50 v4
3728-+ TPLINK_FLASHLAYOUT := 8MSUmtk
3729-+ TPLINK_HWID := 0x001D589B
3730-+ TPLINK_HWREV := 0x93
3731-+ TPLINK_HWREVADD := 0x2
3732-+ TPLINK_HVERSION := 3
3733-+ IMAGES := sysupgrade.bin
3734-+endef
3735-+TARGET_DEVICES += tplink_c50-v4
3736-+
3737- define Device/tplink_tl-mr3420-v5
3738- $(Device/tplink)
3739- DTS := TL-MR3420V5
3740diff --git a/patches/openwrt/0014-mac80211-ath10k-support-for-multicast-and-management-rate-control.patch b/patches/openwrt/0014-mac80211-ath10k-support-for-multicast-and-management-rate-control.patch
3741deleted file mode 100644
3742index e03d9042..00000000
3743--- a/patches/openwrt/0014-mac80211-ath10k-support-for-multicast-and-management-rate-control.patch
3744+++ /dev/null
3745@@ -1,420 +0,0 @@
3746-From: Sven Eckelmann <sven@narfation.org>
3747-Date: Fri, 8 Feb 2019 21:20:20 +0100
3748-Subject: mac80211: ath10k: support for multicast and management rate control
3749-
3750-Drivers with software rate control can directly use the selected multicast
3751-rate for multicast/broadcast frames and the minimal basic rate for
3752-management frames. But drivers with offloaded rate control algorithms must
3753-be informed about such upper layer decisions to configure the
3754-hardware/firmware.
3755-
3756-A new BSS_CHANGED_MCAST_RATE is introduced in mac80211 to automatically
3757-inform all drivers. ath10k can detect this event and forward it via WMI to
3758-the driver. The already existing BSS_CHANGED_BASIC_RATES can be used to
3759-select the management rate.
3760-
3761-Without the WMI commands, a low rate (not necessarily one from the basic
3762-rates) is used for bcast/mcast/management frames. This means that the
3763-/etc/config/wireless settings basic_rate and mcast_rate would have no
3764-effect on the rates selected by this driver for the mentioned frames.
3765-
3766-Signed-off-by: Sven Eckelmann <sven@narfation.org>
3767-
3768-diff --git a/package/kernel/mac80211/patches/975-mac80211-notify-driver-for-change-in-multicast-rates.patch b/package/kernel/mac80211/patches/975-mac80211-notify-driver-for-change-in-multicast-rates.patch
3769-new file mode 100644
3770-index 0000000000000000000000000000000000000000..fb07fa23ecc0518d69eef1f5064328f5c5968360
3771---- /dev/null
3772-+++ b/package/kernel/mac80211/patches/975-mac80211-notify-driver-for-change-in-multicast-rates.patch
3773-@@ -0,0 +1,98 @@
3774-+From: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
3775-+Date: Thu, 22 Mar 2018 12:18:03 -0700
3776-+Subject: [PATCH] mac80211: notify driver for change in multicast rates
3777-+
3778-+With drivers implementing rate control in driver or firmware
3779-+rate_control_send_low() may not get called, and thus the
3780-+driver needs to know about changes in the multicast rate.
3781-+
3782-+Add and use a new BSS change flag for this.
3783-+
3784-+Signed-off-by: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
3785-+[rewrite commit message]
3786-+Signed-off-by: Johannes Berg <johannes.berg@intel.com>
3787-+
3788-+Origin: backport, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=dcbe73ca55a42712bfd0e9966cd2d5a48355ace3
3789-+---
3790-+ include/net/mac80211.h | 3 +++
3791-+ net/mac80211/cfg.c | 2 ++
3792-+ net/mac80211/ibss.c | 2 +-
3793-+ net/mac80211/mesh.c | 3 ++-
3794-+ net/mac80211/util.c | 3 ++-
3795-+ 5 files changed, 10 insertions(+), 3 deletions(-)
3796-+
3797-+diff --git a/include/net/mac80211.h b/include/net/mac80211.h
3798-+index 885690fa39c8d8f4a48f2fa25447646d3d0a7856..48cfee4e26bdf3c7b7dbaaeecd6520492fa375a9 100644
3799-+--- a/include/net/mac80211.h
3800-++++ b/include/net/mac80211.h
3801-+@@ -301,6 +301,8 @@ struct ieee80211_vif_chanctx_switch {
3802-+ * @BSS_CHANGED_MU_GROUPS: VHT MU-MIMO group id or user position changed
3803-+ * @BSS_CHANGED_KEEP_ALIVE: keep alive options (idle period or protected
3804-+ * keep alive) changed.
3805-++ * @BSS_CHANGED_MCAST_RATE: Multicast Rate setting changed for this interface
3806-++ *
3807-+ */
3808-+ enum ieee80211_bss_change {
3809-+ BSS_CHANGED_ASSOC = 1<<0,
3810-+@@ -328,6 +330,7 @@ enum ieee80211_bss_change {
3811-+ BSS_CHANGED_OCB = 1<<22,
3812-+ BSS_CHANGED_MU_GROUPS = 1<<23,
3813-+ BSS_CHANGED_KEEP_ALIVE = 1<<24,
3814-++ BSS_CHANGED_MCAST_RATE = 1<<25,
3815-+
3816-+ /* when adding here, make sure to change ieee80211_reconfig */
3817-+ };
3818-+diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
3819-+index fb15d3b97cb214078f1533f880350fe280b57c69..0b1984b8e3ab4184b009b6423c73dd0b6959d777 100644
3820-+--- a/net/mac80211/cfg.c
3821-++++ b/net/mac80211/cfg.c
3822-+@@ -2310,6 +2310,8 @@ static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
3823-+ memcpy(sdata->vif.bss_conf.mcast_rate, rate,
3824-+ sizeof(int) * NUM_NL80211_BANDS);
3825-+
3826-++ ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
3827-++
3828-+ return 0;
3829-+ }
3830-+
3831-+diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
3832-+index e9c6aa3ed05b8ddb8cf03decce82c00e59b4c0a7..f4b0634b80dedecfc3c05998132bdb6dcd043ed1 100644
3833-+--- a/net/mac80211/ibss.c
3834-++++ b/net/mac80211/ibss.c
3835-+@@ -1840,7 +1840,7 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
3836-+ IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
3837-+ | IEEE80211_HT_PARAM_RIFS_MODE;
3838-+
3839-+- changed |= BSS_CHANGED_HT;
3840-++ changed |= BSS_CHANGED_HT | BSS_CHANGED_MCAST_RATE;
3841-+ ieee80211_bss_info_change_notify(sdata, changed);
3842-+
3843-+ sdata->smps_mode = IEEE80211_SMPS_OFF;
3844-+diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
3845-+index a550c707cd8a6130ef5756cedf2fa4738ae9a0e7..e9f5c2ae46a7bd83907d0b5ca1ceb0b8d6afd3fe 100644
3846-+--- a/net/mac80211/mesh.c
3847-++++ b/net/mac80211/mesh.c
3848-+@@ -880,7 +880,8 @@ int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
3849-+ BSS_CHANGED_BEACON_ENABLED |
3850-+ BSS_CHANGED_HT |
3851-+ BSS_CHANGED_BASIC_RATES |
3852-+- BSS_CHANGED_BEACON_INT;
3853-++ BSS_CHANGED_BEACON_INT |
3854-++ BSS_CHANGED_MCAST_RATE;
3855-+
3856-+ local->fif_other_bss++;
3857-+ /* mesh ifaces must set allmulti to forward mcast traffic */
3858-+diff --git a/net/mac80211/util.c b/net/mac80211/util.c
3859-+index 6aef6793d05236c19afe00a51f4ddc91bc060a39..6594df0c3e7afe90cf103bac89580e0ad71ed045 100644
3860-+--- a/net/mac80211/util.c
3861-++++ b/net/mac80211/util.c
3862-+@@ -1971,7 +1971,8 @@ int ieee80211_reconfig(struct ieee80211_local *local)
3863-+ BSS_CHANGED_CQM |
3864-+ BSS_CHANGED_QOS |
3865-+ BSS_CHANGED_IDLE |
3866-+- BSS_CHANGED_TXPOWER;
3867-++ BSS_CHANGED_TXPOWER |
3868-++ BSS_CHANGED_MCAST_RATE;
3869-+
3870-+ if (sdata->vif.mu_mimo_owner)
3871-+ changed |= BSS_CHANGED_MU_GROUPS;
3872-diff --git a/package/kernel/mac80211/patches/976-ath10k-support-for-multicast-rate-control.patch b/package/kernel/mac80211/patches/976-ath10k-support-for-multicast-rate-control.patch
3873-new file mode 100644
3874-index 0000000000000000000000000000000000000000..94bc108fb2e1a99f716135d842e0959f8c7cb602
3875---- /dev/null
3876-+++ b/package/kernel/mac80211/patches/976-ath10k-support-for-multicast-rate-control.patch
3877-@@ -0,0 +1,112 @@
3878-+From: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
3879-+Date: Wed, 25 Jul 2018 10:59:39 +0300
3880-+Subject: [PATCH] ath10k: support for multicast rate control
3881-+
3882-+Issues a wmi command to firmware when multicast rate change is received with the
3883-+new BSS_CHANGED_MCAST_RATE flag. Also fixes the incorrect fixed_rate setting
3884-+for CCK rates which got introduced with addition of ath10k_rates_rev2 enum.
3885-+
3886-+Tested on QCA9984 with firmware ver 10.4-3.6-00104
3887-+
3888-+Signed-off-by: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
3889-+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
3890-+
3891-+Origin: backport, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cd93b83ad927b2c7979e0add0343ace59328b461
3892-+---
3893-+ drivers/net/wireless/ath/ath10k/mac.c | 54 +++++++++++++++++++++++++--
3894-+ 1 file changed, 50 insertions(+), 4 deletions(-)
3895-+
3896-+diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
3897-+index 5683f1a5330eedae677aad5bf2621a6232781346..1937526c8c18da85f7730429759391d47e12cf81 100644
3898-+--- a/drivers/net/wireless/ath/ath10k/mac.c
3899-++++ b/drivers/net/wireless/ath/ath10k/mac.c
3900-+@@ -100,6 +100,8 @@ static struct ieee80211_rate ath10k_rates_rev2[] = {
3901-+ #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
3902-+ #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
3903-+
3904-++#define ath10k_wmi_legacy_rates ath10k_rates
3905-++
3906-+ static bool ath10k_mac_bitrate_is_cck(int bitrate)
3907-+ {
3908-+ switch (bitrate) {
3909-+@@ -5389,8 +5391,12 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3910-+ {
3911-+ struct ath10k *ar = hw->priv;
3912-+ struct ath10k_vif *arvif = (void *)vif->drv_priv;
3913-+- int ret = 0;
3914-++ struct cfg80211_chan_def def;
3915-+ u32 vdev_param, pdev_param, slottime, preamble;
3916-++ u16 bitrate, hw_value;
3917-++ u8 rate;
3918-++ int rateidx, ret = 0;
3919-++ enum nl80211_band band;
3920-+
3921-+ mutex_lock(&ar->conf_mutex);
3922-+
3923-+@@ -5558,6 +5564,44 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3924-+ arvif->vdev_id, ret);
3925-+ }
3926-+
3927-++ if (changed & BSS_CHANGED_MCAST_RATE &&
3928-++ !WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) {
3929-++ band = def.chan->band;
3930-++ rateidx = vif->bss_conf.mcast_rate[band] - 1;
3931-++
3932-++ if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3933-++ rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
3934-++
3935-++ bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
3936-++ hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
3937-++ if (ath10k_mac_bitrate_is_cck(bitrate))
3938-++ preamble = WMI_RATE_PREAMBLE_CCK;
3939-++ else
3940-++ preamble = WMI_RATE_PREAMBLE_OFDM;
3941-++
3942-++ rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
3943-++
3944-++ ath10k_dbg(ar, ATH10K_DBG_MAC,
3945-++ "mac vdev %d mcast_rate %x\n",
3946-++ arvif->vdev_id, rate);
3947-++
3948-++ vdev_param = ar->wmi.vdev_param->mcast_data_rate;
3949-++ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3950-++ vdev_param, rate);
3951-++ if (ret)
3952-++ ath10k_warn(ar,
3953-++ "failed to set mcast rate on vdev %i: %d\n",
3954-++ arvif->vdev_id, ret);
3955-++
3956-++ vdev_param = ar->wmi.vdev_param->bcast_data_rate;
3957-++ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3958-++ vdev_param, rate);
3959-++ if (ret)
3960-++ ath10k_warn(ar,
3961-++ "failed to set bcast rate on vdev %i: %d\n",
3962-++ arvif->vdev_id, ret);
3963-++ }
3964-++
3965-+ mutex_unlock(&ar->conf_mutex);
3966-+ }
3967-+
3968-+@@ -6826,7 +6870,6 @@ ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
3969-+ const struct cfg80211_bitrate_mask *mask,
3970-+ u8 *rate, u8 *nss)
3971-+ {
3972-+- struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
3973-+ int rate_idx;
3974-+ int i;
3975-+ u16 bitrate;
3976-+@@ -6836,8 +6879,11 @@ ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
3977-+ if (hweight32(mask->control[band].legacy) == 1) {
3978-+ rate_idx = ffs(mask->control[band].legacy) - 1;
3979-+
3980-+- hw_rate = sband->bitrates[rate_idx].hw_value;
3981-+- bitrate = sband->bitrates[rate_idx].bitrate;
3982-++ if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3983-++ rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
3984-++
3985-++ hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
3986-++ bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
3987-+
3988-+ if (ath10k_mac_bitrate_is_cck(bitrate))
3989-+ preamble = WMI_RATE_PREAMBLE_CCK;
3990-diff --git a/package/kernel/mac80211/patches/977-ath10k-add-support-for-configuring-management-packet.patch b/package/kernel/mac80211/patches/977-ath10k-add-support-for-configuring-management-packet.patch
3991-new file mode 100644
3992-index 0000000000000000000000000000000000000000..4b2aa5effdb19141178a5bb71eb9488ee7575b93
3993---- /dev/null
3994-+++ b/package/kernel/mac80211/patches/977-ath10k-add-support-for-configuring-management-packet.patch
3995-@@ -0,0 +1,94 @@
3996-+From: Sriram R <srirrama@codeaurora.org>
3997-+Date: Mon, 10 Sep 2018 11:09:40 +0530
3998-+Subject: [PATCH] ath10k: add support for configuring management packet rate
3999-+
4000-+By default the firmware uses 1Mbps and 6Mbps rate for management packets
4001-+in 2G and 5G bands respectively. But when the user selects different
4002-+basic rates from the userspace, we need to send the management
4003-+packets at the lowest basic rate selected by the user.
4004-+
4005-+This change makes use of WMI_VDEV_PARAM_MGMT_RATE param for configuring the
4006-+management packets rate to the firmware.
4007-+
4008-+Chipsets Tested : QCA988X, QCA9887, QCA9984
4009-+FW Tested : 10.2.4-1.0-41, 10.4-3.6.104
4010-+
4011-+Signed-off-by: Sriram R <srirrama@codeaurora.org>
4012-+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
4013-+
4014-+Origin: backport, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f279294e9ee22a8f306fdc8e4181cf555e6f0f70
4015-+---
4016-+ drivers/net/wireless/ath/ath10k/mac.c | 45 +++++++++++++++++++++++++--
4017-+ 1 file changed, 43 insertions(+), 2 deletions(-)
4018-+
4019-+diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
4020-+index 1937526c8c18da85f7730429759391d47e12cf81..47e5992afcd7564743f513eb250b57381aba3233 100644
4021-+--- a/drivers/net/wireless/ath/ath10k/mac.c
4022-++++ b/drivers/net/wireless/ath/ath10k/mac.c
4023-+@@ -155,6 +155,22 @@ u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
4024-+ return 0;
4025-+ }
4026-+
4027-++static int ath10k_mac_get_rate_hw_value(int bitrate)
4028-++{
4029-++ int i;
4030-++ u8 hw_value_prefix = 0;
4031-++
4032-++ if (ath10k_mac_bitrate_is_cck(bitrate))
4033-++ hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6;
4034-++
4035-++ for (i = 0; i < sizeof(ath10k_rates); i++) {
4036-++ if (ath10k_rates[i].bitrate == bitrate)
4037-++ return hw_value_prefix | ath10k_rates[i].hw_value;
4038-++ }
4039-++
4040-++ return -EINVAL;
4041-++}
4042-++
4043-+ static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
4044-+ {
4045-+ switch ((mcs_map >> (2 * nss)) & 0x3) {
4046-+@@ -5394,9 +5410,10 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4047-+ struct cfg80211_chan_def def;
4048-+ u32 vdev_param, pdev_param, slottime, preamble;
4049-+ u16 bitrate, hw_value;
4050-+- u8 rate;
4051-+- int rateidx, ret = 0;
4052-++ u8 rate, basic_rate_idx;
4053-++ int rateidx, ret = 0, hw_rate_code;
4054-+ enum nl80211_band band;
4055-++ const struct ieee80211_supported_band *sband;
4056-+
4057-+ mutex_lock(&ar->conf_mutex);
4058-+
4059-+@@ -5602,6 +5619,30 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4060-+ arvif->vdev_id, ret);
4061-+ }
4062-+
4063-++ if (changed & BSS_CHANGED_BASIC_RATES) {
4064-++ if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) {
4065-++ mutex_unlock(&ar->conf_mutex);
4066-++ return;
4067-++ }
4068-++
4069-++ sband = ar->hw->wiphy->bands[def.chan->band];
4070-++ basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
4071-++ bitrate = sband->bitrates[basic_rate_idx].bitrate;
4072-++
4073-++ hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
4074-++ if (hw_rate_code < 0) {
4075-++ ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
4076-++ mutex_unlock(&ar->conf_mutex);
4077-++ return;
4078-++ }
4079-++
4080-++ vdev_param = ar->wmi.vdev_param->mgmt_rate;
4081-++ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4082-++ hw_rate_code);
4083-++ if (ret)
4084-++ ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
4085-++ }
4086-++
4087-+ mutex_unlock(&ar->conf_mutex);
4088-+ }
4089-+
4090-diff --git a/package/kernel/mac80211/patches/978-ath10k-fix-possible-out-of-bound-access-of-ath10k_ra.patch b/package/kernel/mac80211/patches/978-ath10k-fix-possible-out-of-bound-access-of-ath10k_ra.patch
4091-new file mode 100644
4092-index 0000000000000000000000000000000000000000..b496332574f93b1f6474226e8c09970d6fe0e2fe
4093---- /dev/null
4094-+++ b/package/kernel/mac80211/patches/978-ath10k-fix-possible-out-of-bound-access-of-ath10k_ra.patch
4095-@@ -0,0 +1,70 @@
4096-+From: Sriram R <srirrama@codeaurora.org>
4097-+Date: Wed, 3 Oct 2018 08:43:50 +0530
4098-+Subject: [PATCH] ath10k: fix possible out of bound access of ath10k_rates array
4099-+
4100-+While using 'ath10k_mac_get_rate_hw_value()' to obtain the hw value
4101-+from the passed bitrate, there is a chance of out of bound array access
4102-+when wrong bitrate is passed. This is fixed by comparing the bitrates
4103-+within the correct size of the ath10k_rates array.
4104-+
4105-+Fixes commit f279294e9ee2 ("ath10k: add support for configuring management
4106-+packet rate"). Also correction made to some indents used in the above commit.
4107-+
4108-+Signed-off-by: Sriram R <srirrama@codeaurora.org>
4109-+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
4110-+
4111-+Origin: backport, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e141eea7dd8525dd1ef7a925459e455b4d307f
4112-+---
4113-+ drivers/net/wireless/ath/ath10k/mac.c | 30 +++++++++++++--------------
4114-+ 1 file changed, 15 insertions(+), 15 deletions(-)
4115-+
4116-+diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
4117-+index 47e5992afcd7564743f513eb250b57381aba3233..e93b04c8e6fb2fa7968b910e0cc97ad8144bd7e8 100644
4118-+--- a/drivers/net/wireless/ath/ath10k/mac.c
4119-++++ b/drivers/net/wireless/ath/ath10k/mac.c
4120-+@@ -163,7 +163,7 @@ static int ath10k_mac_get_rate_hw_value(int bitrate)
4121-+ if (ath10k_mac_bitrate_is_cck(bitrate))
4122-+ hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6;
4123-+
4124-+- for (i = 0; i < sizeof(ath10k_rates); i++) {
4125-++ for (i = 0; i < ARRAY_SIZE(ath10k_rates); i++) {
4126-+ if (ath10k_rates[i].bitrate == bitrate)
4127-+ return hw_value_prefix | ath10k_rates[i].hw_value;
4128-+ }
4129-+@@ -5625,22 +5625,22 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4130-+ return;
4131-+ }
4132-+
4133-+- sband = ar->hw->wiphy->bands[def.chan->band];
4134-+- basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
4135-+- bitrate = sband->bitrates[basic_rate_idx].bitrate;
4136-++ sband = ar->hw->wiphy->bands[def.chan->band];
4137-++ basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
4138-++ bitrate = sband->bitrates[basic_rate_idx].bitrate;
4139-+
4140-+- hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
4141-+- if (hw_rate_code < 0) {
4142-+- ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
4143-+- mutex_unlock(&ar->conf_mutex);
4144-+- return;
4145-+- }
4146-++ hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
4147-++ if (hw_rate_code < 0) {
4148-++ ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
4149-++ mutex_unlock(&ar->conf_mutex);
4150-++ return;
4151-++ }
4152-+
4153-+- vdev_param = ar->wmi.vdev_param->mgmt_rate;
4154-+- ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4155-+- hw_rate_code);
4156-+- if (ret)
4157-+- ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
4158-++ vdev_param = ar->wmi.vdev_param->mgmt_rate;
4159-++ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4160-++ hw_rate_code);
4161-++ if (ret)
4162-++ ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
4163-+ }
4164-+
4165-+ mutex_unlock(&ar->conf_mutex);
4166diff --git a/patches/openwrt/0015-ath10k-ct-support-for-multicast-and-management-rate-control.patch b/patches/openwrt/0015-ath10k-ct-support-for-multicast-and-management-rate-control.patch
4167deleted file mode 100644
4168index 8b2a6777..00000000
4169--- a/patches/openwrt/0015-ath10k-ct-support-for-multicast-and-management-rate-control.patch
4170+++ /dev/null
4171@@ -1,316 +0,0 @@
4172-From: Sven Eckelmann <sven@narfation.org>
4173-Date: Fri, 8 Feb 2019 21:20:20 +0100
4174-Subject: ath10k-ct: support for multicast and management rate control
4175-
4176-Drivers with software rate control can directly use the selected multicast
4177-rate for multicast/broadcast frames and the minimal basic rate for
4178-management frames. But drivers with offloaded rate control algorithms must
4179-be informed about such upper layer decisions to configure the
4180-hardware/firmware.
4181-
4182-A new BSS_CHANGED_MCAST_RATE is introduced in mac80211 to automatically
4183-inform all drivers. ath10k-ct can detect this event and forward it via WMI
4184-to the driver. The already existing BSS_CHANGED_BASIC_RATES can be used to
4185-select the management rate.
4186-
4187-Without the WMI commands, a low rate (not necessarily one from the basic
4188-rates) is used for bcast/mcast/management frames. This means that the
4189-/etc/config/wireless settings basic_rate and mcast_rate would have no
4190-effect on the rates selected by this driver for the mentioned frames.
4191-
4192-Signed-off-by: Sven Eckelmann <sven@narfation.org>
4193-
4194-diff --git a/package/kernel/ath10k-ct/patches/976-ath10k-support-for-multicast-rate-control.patch b/package/kernel/ath10k-ct/patches/976-ath10k-support-for-multicast-rate-control.patch
4195-new file mode 100644
4196-index 0000000000000000000000000000000000000000..bd60bf317dec3a2eec1fd9263037acc30d272e39
4197---- /dev/null
4198-+++ b/package/kernel/ath10k-ct/patches/976-ath10k-support-for-multicast-rate-control.patch
4199-@@ -0,0 +1,112 @@
4200-+From: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
4201-+Date: Wed, 25 Jul 2018 10:59:39 +0300
4202-+Subject: [PATCH] ath10k: support for multicast rate control
4203-+
4204-+Issues a wmi command to firmware when multicast rate change is received with the
4205-+new BSS_CHANGED_MCAST_RATE flag. Also fixes the incorrect fixed_rate setting
4206-+for CCK rates which got introduced with addition of ath10k_rates_rev2 enum.
4207-+
4208-+Tested on QCA9984 with firmware ver 10.4-3.6-00104
4209-+
4210-+Signed-off-by: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
4211-+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
4212-+
4213-+Origin: backport, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cd93b83ad927b2c7979e0add0343ace59328b461
4214-+---
4215-+ ath10k-4.13/mac.c | 54 +++++++++++++++++++++++++--
4216-+ 1 file changed, 50 insertions(+), 4 deletions(-)
4217-+
4218-+diff --git a/ath10k-4.13/mac.c b/ath10k-4.13/mac.c
4219-+index 5683f1a5330eedae677aad5bf2621a6232781346..1937526c8c18da85f7730429759391d47e12cf81 100644
4220-+--- a/ath10k-4.13/mac.c
4221-++++ b/ath10k-4.13/mac.c
4222-+@@ -100,6 +100,8 @@ static struct ieee80211_rate ath10k_rates_rev2[] = {
4223-+ #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
4224-+ #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
4225-+
4226-++#define ath10k_wmi_legacy_rates ath10k_rates
4227-++
4228-+ static bool ath10k_mac_bitrate_is_cck(int bitrate)
4229-+ {
4230-+ switch (bitrate) {
4231-+@@ -5389,8 +5391,12 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4232-+ {
4233-+ struct ath10k *ar = hw->priv;
4234-+ struct ath10k_vif *arvif = (void *)vif->drv_priv;
4235-+- int ret = 0;
4236-++ struct cfg80211_chan_def def;
4237-+ u32 vdev_param, pdev_param, slottime, preamble;
4238-++ u16 bitrate, hw_value;
4239-++ u8 rate;
4240-++ int rateidx, ret = 0;
4241-++ enum nl80211_band band;
4242-+
4243-+ mutex_lock(&ar->conf_mutex);
4244-+
4245-+@@ -5558,6 +5564,44 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4246-+ arvif->vdev_id, ret);
4247-+ }
4248-+
4249-++ if (changed & BSS_CHANGED_MCAST_RATE &&
4250-++ !WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) {
4251-++ band = def.chan->band;
4252-++ rateidx = vif->bss_conf.mcast_rate[band] - 1;
4253-++
4254-++ if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
4255-++ rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
4256-++
4257-++ bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
4258-++ hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
4259-++ if (ath10k_mac_bitrate_is_cck(bitrate))
4260-++ preamble = WMI_RATE_PREAMBLE_CCK;
4261-++ else
4262-++ preamble = WMI_RATE_PREAMBLE_OFDM;
4263-++
4264-++ rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
4265-++
4266-++ ath10k_dbg(ar, ATH10K_DBG_MAC,
4267-++ "mac vdev %d mcast_rate %x\n",
4268-++ arvif->vdev_id, rate);
4269-++
4270-++ vdev_param = ar->wmi.vdev_param->mcast_data_rate;
4271-++ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4272-++ vdev_param, rate);
4273-++ if (ret)
4274-++ ath10k_warn(ar,
4275-++ "failed to set mcast rate on vdev %i: %d\n",
4276-++ arvif->vdev_id, ret);
4277-++
4278-++ vdev_param = ar->wmi.vdev_param->bcast_data_rate;
4279-++ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4280-++ vdev_param, rate);
4281-++ if (ret)
4282-++ ath10k_warn(ar,
4283-++ "failed to set bcast rate on vdev %i: %d\n",
4284-++ arvif->vdev_id, ret);
4285-++ }
4286-++
4287-+ mutex_unlock(&ar->conf_mutex);
4288-+ }
4289-+
4290-+@@ -6826,7 +6870,6 @@ ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
4291-+ const struct cfg80211_bitrate_mask *mask,
4292-+ u8 *rate, u8 *nss)
4293-+ {
4294-+- struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
4295-+ int rate_idx;
4296-+ int i;
4297-+ u16 bitrate;
4298-+@@ -6836,8 +6879,11 @@ ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
4299-+ if (hweight32(mask->control[band].legacy) == 1) {
4300-+ rate_idx = ffs(mask->control[band].legacy) - 1;
4301-+
4302-+- hw_rate = sband->bitrates[rate_idx].hw_value;
4303-+- bitrate = sband->bitrates[rate_idx].bitrate;
4304-++ if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
4305-++ rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
4306-++
4307-++ hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
4308-++ bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
4309-+
4310-+ if (ath10k_mac_bitrate_is_cck(bitrate))
4311-+ preamble = WMI_RATE_PREAMBLE_CCK;
4312-diff --git a/package/kernel/ath10k-ct/patches/977-ath10k-add-support-for-configuring-management-packet.patch b/package/kernel/ath10k-ct/patches/977-ath10k-add-support-for-configuring-management-packet.patch
4313-new file mode 100644
4314-index 0000000000000000000000000000000000000000..6cc6df271fc73431b9467ac9878c360345e0754f
4315---- /dev/null
4316-+++ b/package/kernel/ath10k-ct/patches/977-ath10k-add-support-for-configuring-management-packet.patch
4317-@@ -0,0 +1,94 @@
4318-+From: Sriram R <srirrama@codeaurora.org>
4319-+Date: Mon, 10 Sep 2018 11:09:40 +0530
4320-+Subject: [PATCH] ath10k: add support for configuring management packet rate
4321-+
4322-+By default the firmware uses 1Mbps and 6Mbps rate for management packets
4323-+in 2G and 5G bands respectively. But when the user selects different
4324-+basic rates from the userspace, we need to send the management
4325-+packets at the lowest basic rate selected by the user.
4326-+
4327-+This change makes use of WMI_VDEV_PARAM_MGMT_RATE param for configuring the
4328-+management packets rate to the firmware.
4329-+
4330-+Chipsets Tested : QCA988X, QCA9887, QCA9984
4331-+FW Tested : 10.2.4-1.0-41, 10.4-3.6.104
4332-+
4333-+Signed-off-by: Sriram R <srirrama@codeaurora.org>
4334-+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
4335-+
4336-+Origin: backport, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f279294e9ee22a8f306fdc8e4181cf555e6f0f70
4337-+---
4338-+ ath10k-4.13/mac.c | 45 +++++++++++++++++++++++++--
4339-+ 1 file changed, 43 insertions(+), 2 deletions(-)
4340-+
4341-+diff --git a/ath10k-4.13/mac.c b/ath10k-4.13/mac.c
4342-+index 1937526c8c18da85f7730429759391d47e12cf81..47e5992afcd7564743f513eb250b57381aba3233 100644
4343-+--- a/ath10k-4.13/mac.c
4344-++++ b/ath10k-4.13/mac.c
4345-+@@ -155,6 +155,22 @@ u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
4346-+ return 0;
4347-+ }
4348-+
4349-++static int ath10k_mac_get_rate_hw_value(int bitrate)
4350-++{
4351-++ int i;
4352-++ u8 hw_value_prefix = 0;
4353-++
4354-++ if (ath10k_mac_bitrate_is_cck(bitrate))
4355-++ hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6;
4356-++
4357-++ for (i = 0; i < sizeof(ath10k_rates); i++) {
4358-++ if (ath10k_rates[i].bitrate == bitrate)
4359-++ return hw_value_prefix | ath10k_rates[i].hw_value;
4360-++ }
4361-++
4362-++ return -EINVAL;
4363-++}
4364-++
4365-+ static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
4366-+ {
4367-+ switch ((mcs_map >> (2 * nss)) & 0x3) {
4368-+@@ -5394,9 +5410,10 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4369-+ struct cfg80211_chan_def def;
4370-+ u32 vdev_param, pdev_param, slottime, preamble;
4371-+ u16 bitrate, hw_value;
4372-+- u8 rate;
4373-+- int rateidx, ret = 0;
4374-++ u8 rate, basic_rate_idx;
4375-++ int rateidx, ret = 0, hw_rate_code;
4376-+ enum nl80211_band band;
4377-++ const struct ieee80211_supported_band *sband;
4378-+
4379-+ mutex_lock(&ar->conf_mutex);
4380-+
4381-+@@ -5602,6 +5619,30 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4382-+ arvif->vdev_id, ret);
4383-+ }
4384-+
4385-++ if (changed & BSS_CHANGED_BASIC_RATES) {
4386-++ if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) {
4387-++ mutex_unlock(&ar->conf_mutex);
4388-++ return;
4389-++ }
4390-++
4391-++ sband = ar->hw->wiphy->bands[def.chan->band];
4392-++ basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
4393-++ bitrate = sband->bitrates[basic_rate_idx].bitrate;
4394-++
4395-++ hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
4396-++ if (hw_rate_code < 0) {
4397-++ ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
4398-++ mutex_unlock(&ar->conf_mutex);
4399-++ return;
4400-++ }
4401-++
4402-++ vdev_param = ar->wmi.vdev_param->mgmt_rate;
4403-++ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4404-++ hw_rate_code);
4405-++ if (ret)
4406-++ ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
4407-++ }
4408-++
4409-+ mutex_unlock(&ar->conf_mutex);
4410-+ }
4411-+
4412-diff --git a/package/kernel/ath10k-ct/patches/978-ath10k-fix-possible-out-of-bound-access-of-ath10k_ra.patch b/package/kernel/ath10k-ct/patches/978-ath10k-fix-possible-out-of-bound-access-of-ath10k_ra.patch
4413-new file mode 100644
4414-index 0000000000000000000000000000000000000000..cc13e547aa7e983fcff6137de9463e0b706651c5
4415---- /dev/null
4416-+++ b/package/kernel/ath10k-ct/patches/978-ath10k-fix-possible-out-of-bound-access-of-ath10k_ra.patch
4417-@@ -0,0 +1,70 @@
4418-+From: Sriram R <srirrama@codeaurora.org>
4419-+Date: Wed, 3 Oct 2018 08:43:50 +0530
4420-+Subject: [PATCH] ath10k: fix possible out of bound access of ath10k_rates array
4421-+
4422-+While using 'ath10k_mac_get_rate_hw_value()' to obtain the hw value
4423-+from the passed bitrate, there is a chance of out of bound array access
4424-+when wrong bitrate is passed. This is fixed by comparing the bitrates
4425-+within the correct size of the ath10k_rates array.
4426-+
4427-+Fixes commit f279294e9ee2 ("ath10k: add support for configuring management
4428-+packet rate"). Also correction made to some indents used in the above commit.
4429-+
4430-+Signed-off-by: Sriram R <srirrama@codeaurora.org>
4431-+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
4432-+
4433-+Origin: backport, https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e141eea7dd8525dd1ef7a925459e455b4d307f
4434-+---
4435-+ ath10k-4.13/mac.c | 30 +++++++++++++--------------
4436-+ 1 file changed, 15 insertions(+), 15 deletions(-)
4437-+
4438-+diff --git a/ath10k-4.13/mac.c b/ath10k-4.13/mac.c
4439-+index 47e5992afcd7564743f513eb250b57381aba3233..e93b04c8e6fb2fa7968b910e0cc97ad8144bd7e8 100644
4440-+--- a/ath10k-4.13/mac.c
4441-++++ b/ath10k-4.13/mac.c
4442-+@@ -163,7 +163,7 @@ static int ath10k_mac_get_rate_hw_value(int bitrate)
4443-+ if (ath10k_mac_bitrate_is_cck(bitrate))
4444-+ hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6;
4445-+
4446-+- for (i = 0; i < sizeof(ath10k_rates); i++) {
4447-++ for (i = 0; i < ARRAY_SIZE(ath10k_rates); i++) {
4448-+ if (ath10k_rates[i].bitrate == bitrate)
4449-+ return hw_value_prefix | ath10k_rates[i].hw_value;
4450-+ }
4451-+@@ -5625,22 +5625,22 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4452-+ return;
4453-+ }
4454-+
4455-+- sband = ar->hw->wiphy->bands[def.chan->band];
4456-+- basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
4457-+- bitrate = sband->bitrates[basic_rate_idx].bitrate;
4458-++ sband = ar->hw->wiphy->bands[def.chan->band];
4459-++ basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
4460-++ bitrate = sband->bitrates[basic_rate_idx].bitrate;
4461-+
4462-+- hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
4463-+- if (hw_rate_code < 0) {
4464-+- ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
4465-+- mutex_unlock(&ar->conf_mutex);
4466-+- return;
4467-+- }
4468-++ hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
4469-++ if (hw_rate_code < 0) {
4470-++ ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
4471-++ mutex_unlock(&ar->conf_mutex);
4472-++ return;
4473-++ }
4474-+
4475-+- vdev_param = ar->wmi.vdev_param->mgmt_rate;
4476-+- ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4477-+- hw_rate_code);
4478-+- if (ret)
4479-+- ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
4480-++ vdev_param = ar->wmi.vdev_param->mgmt_rate;
4481-++ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4482-++ hw_rate_code);
4483-++ if (ret)
4484-++ ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
4485-+ }
4486-+
4487-+ mutex_unlock(&ar->conf_mutex);
4488diff --git a/patches/openwrt/0016-ramips-add-support-for-Netgear-R6120.patch b/patches/openwrt/0016-ramips-add-support-for-Netgear-R6120.patch
4489deleted file mode 100644
4490index 7367a81f..00000000
4491--- a/patches/openwrt/0016-ramips-add-support-for-Netgear-R6120.patch
4492+++ /dev/null
4493@@ -1,271 +0,0 @@
4494-From: Ludwig Thomeczek <ledesrc@wxorx.net>
4495-Date: Tue, 12 Jun 2018 21:17:23 +0200
4496-Subject: ramips: add support for Netgear R6120
4497-
4498-This patch adds support for the Netgear R6120, aka Netgear AC1200.
4499-
4500-Specification:
4501-- SoC: MediaTek MT7628 (580 MHz)
4502-- Flash: 16 MiB
4503-- RAM: 64 MiB
4504-- Wireless: 2.4Ghz(builtin) and 5Ghz (MT7612E)
4505-- LAN speed: 10/100
4506-- LAN ports: 4
4507-- WAN speed: 10/100
4508-- WAN ports: 1
4509-- Serial baud rate of Bootloader and factory firmware: 57600
4510-
4511-To flash use nmrpflash with the provided factory.img.
4512-Flashing via webinterface will not work, for now.
4513-
4514-Signed-off-by: Ludwig Thomeczek <ledesrc@wxorx.net>
4515-
4516-diff --git a/target/linux/ramips/base-files/etc/board.d/01_leds b/target/linux/ramips/base-files/etc/board.d/01_leds
4517-index 19386b9e139a25fd1ac29cd9a66b738b5b092cdf..4203773b4fa3ec771f07b7a8c414a416a0da0f20 100755
4518---- a/target/linux/ramips/base-files/etc/board.d/01_leds
4519-+++ b/target/linux/ramips/base-files/etc/board.d/01_leds
4520-@@ -301,6 +301,11 @@ mzk-ex750np)
4521- na930)
4522- set_usb_led "$boardname:blue:status"
4523- ;;
4524-+netgear,r6120)
4525-+ ucidef_set_led_switch "lan" "lan" "$boardname:green:lan" "switch0" "0x0f"
4526-+ ucidef_set_led_switch "wan" "wan" "$boardname:green:wan" "switch0" "0x10"
4527-+ ucidef_set_led_wlan "wlan2g" "WiFi 2.4GHz" "$boardname:green:wlan2g" "phy0tpt"
4528-+ ;;
4529- newifi-d1)
4530- set_usb_led "$boardname:red:status"
4531- ;;
4532-diff --git a/target/linux/ramips/base-files/etc/board.d/02_network b/target/linux/ramips/base-files/etc/board.d/02_network
4533-index 1c6cc6b0af745b43b81bbfffc9b5462c1b88defc..9424c7ddfd64f9149a24ff91e63b71990265d211 100755
4534---- a/target/linux/ramips/base-files/etc/board.d/02_network
4535-+++ b/target/linux/ramips/base-files/etc/board.d/02_network
4536-@@ -301,6 +301,10 @@ ramips_setup_interfaces()
4537- "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
4538- ucidef_set_interface_wan "usb0"
4539- ;;
4540-+ netgear,r6120)
4541-+ ucidef_add_switch "switch0" \
4542-+ "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
4543-+ ;;
4544- mzk-dp150n|\
4545- vocore-8M|\
4546- vocore-16M)
4547-diff --git a/target/linux/ramips/base-files/etc/diag.sh b/target/linux/ramips/base-files/etc/diag.sh
4548-index 6d021b6def2f1fe7b71a67f36749c440f3bad1d4..097cc6df569518f64dbfd641eeccc1a4b1b37a2b 100644
4549---- a/target/linux/ramips/base-files/etc/diag.sh
4550-+++ b/target/linux/ramips/base-files/etc/diag.sh
4551-@@ -38,6 +38,7 @@ get_status_led() {
4552- mzk-w300nh2|\
4553- nbg-419n|\
4554- nbg-419n2|\
4555-+ netgear,r6120|\
4556- pwh2004|\
4557- r6220|\
4558- tplink,c20-v4|\
4559-diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh b/target/linux/ramips/base-files/lib/upgrade/platform.sh
4560-index 8055853508fc850a1826166c7e0cbdf443df27cb..7213b22d0c2734488bd96bc34e921f08649b8c2f 100755
4561---- a/target/linux/ramips/base-files/lib/upgrade/platform.sh
4562-+++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh
4563-@@ -129,6 +129,7 @@ platform_check_image() {
4564- psr-680w|\
4565- px-4885-4M|\
4566- px-4885-8M|\
4567-+ netgear,r6120|\
4568- rb750gr3|\
4569- re6500|\
4570- rp-n53|\
4571-diff --git a/target/linux/ramips/dts/R6120.dts b/target/linux/ramips/dts/R6120.dts
4572-new file mode 100644
4573-index 0000000000000000000000000000000000000000..a0df0072379a7d8f974ec8025483410d5f9f1da1
4574---- /dev/null
4575-+++ b/target/linux/ramips/dts/R6120.dts
4576-@@ -0,0 +1,142 @@
4577-+/dts-v1/;
4578-+
4579-+#include "mt7628an.dtsi"
4580-+
4581-+#include <dt-bindings/gpio/gpio.h>
4582-+#include <dt-bindings/input/input.h>
4583-+
4584-+/ {
4585-+ compatible = "netgear,r6120", "mediatek,mt7628an-soc";
4586-+ model = "Netgear R6120";
4587-+
4588-+ memory@0 {
4589-+ device_type = "memory";
4590-+ reg = <0x0 0x4000000>;
4591-+ };
4592-+
4593-+ gpio-keys-polled {
4594-+ compatible = "gpio-keys-polled";
4595-+ poll-interval = <20>;
4596-+
4597-+ reset {
4598-+ label = "reset";
4599-+ gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
4600-+ linux,code = <KEY_RESTART>;
4601-+ };
4602-+ };
4603-+
4604-+ gpio-leds {
4605-+ compatible = "gpio-leds";
4606-+
4607-+ lan {
4608-+ label = "r6120:green:lan";
4609-+ gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
4610-+ };
4611-+
4612-+ led_power: power {
4613-+ label = "r6120:green:power";
4614-+ gpios = <&gpio1 11 GPIO_ACTIVE_LOW>;
4615-+ };
4616-+
4617-+ wlan {
4618-+ label = "r6120:green:wlan2g";
4619-+ gpios = <&gpio1 10 GPIO_ACTIVE_LOW>;
4620-+ };
4621-+
4622-+ wlan_orange {
4623-+ label = "r6120:orange:wlan2g";
4624-+ gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
4625-+ };
4626-+
4627-+ wan {
4628-+ label = "r6120:green:wan";
4629-+ gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
4630-+ };
4631-+
4632-+ wan_orange {
4633-+ label = "r6120:orange:wan";
4634-+ gpios = <&gpio1 7 GPIO_ACTIVE_LOW>;
4635-+ };
4636-+ };
4637-+};
4638-+
4639-+&pinctrl {
4640-+ state_default: pinctrl0 {
4641-+ gpio {
4642-+ ralink,group = "p0led_an", "p1led_an", "p2led_an",
4643-+ "p3led_an", "p4led_an", "wdt", "wled_an";
4644-+ ralink,function = "gpio";
4645-+ };
4646-+ };
4647-+};
4648-+
4649-+&spi0 {
4650-+ status = "okay";
4651-+
4652-+ flash@0 {
4653-+ compatible = "jedec,spi-nor";
4654-+ reg = <0>;
4655-+ spi-max-frequency = <10000000>;
4656-+ m25p,chunked-io = <32>;
4657-+
4658-+ partitions {
4659-+ compatible = "fixed-partitions";
4660-+ #address-cells = <1>;
4661-+ #size-cells = <1>;
4662-+
4663-+ partition@0 {
4664-+ label = "u-boot";
4665-+ reg = <0x0 0x40000>;
4666-+ read-only;
4667-+ };
4668-+
4669-+ factory: partition@40000 {
4670-+ label = "factory";
4671-+ reg = <0x40000 0x20000>;
4672-+ read-only;
4673-+ };
4674-+
4675-+ partition@60000 {
4676-+ label = "nvram";
4677-+ reg = <0x60000 0x30000>;
4678-+ read-only;
4679-+ };
4680-+
4681-+ partition@90000 {
4682-+ label = "firmware";
4683-+ reg = <0x90000 0xf60000>;
4684-+ };
4685-+
4686-+ partition@ff0000 {
4687-+ label = "reserved";
4688-+ reg = <0xff0000 0x10000>;
4689-+ read-only;
4690-+ };
4691-+ };
4692-+ };
4693-+};
4694-+
4695-+&wmac {
4696-+ status = "okay";
4697-+ mtd-mac-address = <&factory 0x4>;
4698-+ mediatek,mtd-eeprom = <&factory 0x0>;
4699-+};
4700-+
4701-+ðernet {
4702-+ mtd-mac-address = <&factory 0x4>;
4703-+};
4704-+
4705-+&pcie {
4706-+ status = "okay";
4707-+
4708-+ pcie-bridge {
4709-+ mt76@0,0 {
4710-+ reg = <0x0000 0 0 0 0>;
4711-+ device_type = "pci";
4712-+ mediatek,mtd-eeprom = <&factory 0x8000>;
4713-+ ieee80211-freq-limit = <5000000 6000000>;
4714-+ mtd-mac-address = <&factory 0x4>;
4715-+ mtd-mac-address-increment = <(2)>;
4716-+ };
4717-+ };
4718-+};
4719-diff --git a/target/linux/ramips/image/mt76x8.mk b/target/linux/ramips/image/mt76x8.mk
4720-index 34bd662f3a9490bdb0fd125af5ffa8a0f77c5f16..bc282666d8c1a4b6ce5beabe2b492331fb48a23a 100644
4721---- a/target/linux/ramips/image/mt76x8.mk
4722-+++ b/target/linux/ramips/image/mt76x8.mk
4723-@@ -2,6 +2,17 @@
4724- # MT76x8 Profiles
4725- #
4726-
4727-+DEVICE_VARS += SERCOMM_KERNEL_OFFSET SERCOMM_HWID SERCOMM_HWVER SERCOMM_SWVER
4728-+
4729-+define Build/mksercommfw
4730-+ $(STAGING_DIR_HOST)/bin/mksercommfw \
4731-+ $@ \
4732-+ $(SERCOMM_KERNEL_OFFSET) \
4733-+ $(SERCOMM_HWID) \
4734-+ $(SERCOMM_HWVER) \
4735-+ $(SERCOMM_SWVER)
4736-+endef
4737-+
4738- define Device/tplink
4739- TPLINK_FLASHLAYOUT :=
4740- TPLINK_HWID :=
4741-@@ -90,6 +101,23 @@ define Device/mt7628
4742- endef
4743- TARGET_DEVICES += mt7628
4744-
4745-+define Device/netgear_r6120
4746-+ DTS := R6120
4747-+ BLOCKSIZE := 64k
4748-+ IMAGE_SIZE := $(ralink_default_fw_size_16M)
4749-+ DEVICE_TITLE := Netgear R6120
4750-+ DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
4751-+ SERCOMM_KERNEL_OFFSET := 90000
4752-+ SERCOMM_HWID := CGQ
4753-+ SERCOMM_HWVER := A001
4754-+ SERCOMM_SWVER := 0040
4755-+ IMAGES += factory.img
4756-+ IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE)| append-rootfs | pad-rootfs
4757-+ IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | check-size $$$$(IMAGE_SIZE)
4758-+ IMAGE/factory.img := $$(IMAGE/default) | mksercommfw
4759-+endef
4760-+TARGET_DEVICES += netgear_r6120
4761-+
4762- define Device/omega2
4763- DTS := OMEGA2
4764- IMAGE_SIZE := $(ralink_default_fw_size_16M)
4765diff --git a/patches/openwrt/0017-tools-add-zip-utility.patch b/patches/openwrt/0017-tools-add-zip-utility.patch
4766deleted file mode 100644
4767index 60a39a3f..00000000
4768--- a/patches/openwrt/0017-tools-add-zip-utility.patch
4769+++ /dev/null
4770@@ -1,465 +0,0 @@
4771-From: Mathias Kresin <dev@kresin.me>
4772-Date: Sat, 5 Jan 2019 20:51:00 +0100
4773-Subject: tools: add zip utility
4774-
4775-One image requires a zip compressed image, so add the zip util found in
4776-the packages feed, and extend it with some useful debian patches.
4777-
4778-Signed-off-by: Mathias Kresin <dev@kresin.me>
4779-
4780-tools: zip: add option for reproducible archives
4781-
4782-Add the option -mt/--mtime to pass a timestamp which is used as filedate
4783-for the containing files.
4784-
4785-So far, it isn't used for anything written to the extra fields,
4786-therefore requires the -X (eXclude eXtra file attributes) parameter to
4787-be effective.
4788-
4789-Signed-off-by: Mathias Kresin <dev@kresin.me>
4790-
4791-diff --git a/tools/Makefile b/tools/Makefile
4792-index d2b5daf18c233c8e94657fd61922c75770a3b35b..3ac3b226d35311c606e6dcc562fb8a2d31cec584 100644
4793---- a/tools/Makefile
4794-+++ b/tools/Makefile
4795-@@ -32,7 +32,7 @@ tools-$(CONFIG_TARGET_x86) += qemu
4796- tools-$(CONFIG_TARGET_mxs) += elftosb sdimage
4797- tools-$(CONFIG_TARGET_ar71xx) += lzma-old squashfs
4798- tools-$(CONFIG_USES_MINOR) += kernel2minor
4799--tools-y += lzma squashfs4
4800-+tools-y += lzma squashfs4 zip
4801- tools-$(BUILD_B43_TOOLS) += b43-tools
4802- tools-$(BUILD_ISL) += isl
4803- tools-$(CONFIG_USE_SPARSE) += sparse
4804-diff --git a/tools/zip/Makefile b/tools/zip/Makefile
4805-new file mode 100644
4806-index 0000000000000000000000000000000000000000..7dd81a1b8bc3bfeb5773d0770cb57c164f6db157
4807---- /dev/null
4808-+++ b/tools/zip/Makefile
4809-@@ -0,0 +1,36 @@
4810-+#
4811-+# Copyright (C) 2007-2016 OpenWrt.org
4812-+#
4813-+# This is free software, licensed under the GNU General Public License v2.
4814-+# See /LICENSE for more information.
4815-+#
4816-+
4817-+include $(TOPDIR)/rules.mk
4818-+
4819-+PKG_NAME:=zip
4820-+PKG_REV:=30
4821-+PKG_VERSION:=3.0
4822-+
4823-+PKG_SOURCE:=$(PKG_NAME)$(PKG_REV).tar.gz
4824-+PKG_SOURCE_URL:=@SF/infozip
4825-+PKG_HASH:=f0e8bb1f9b7eb0b01285495a2699df3a4b766784c1765a8f1aeedf63c0806369
4826-+
4827-+PKG_LICENSE:=BSD-4-Clause
4828-+PKG_LICENSE_FILES:=LICENSE
4829-+
4830-+HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)-$(PKG_VERSION)/zip$(PKG_REV)
4831-+HOST_BUILD_PARALLEL:=1
4832-+
4833-+include $(INCLUDE_DIR)/host-build.mk
4834-+
4835-+define Host/Compile
4836-+ +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) -I. -f unix/Makefile zip
4837-+endef
4838-+
4839-+define Host/Install
4840-+ $(INSTALL_DIR) $(STAGING_DIR_HOST)/bin/
4841-+ $(INSTALL_BIN) $(HOST_BUILD_DIR)/zip $(STAGING_DIR_HOST)/bin/
4842-+endef
4843-+
4844-+$(eval $(call HostBuild))
4845-+#$(eval $(call BuildPackage,zip))
4846-diff --git a/tools/zip/patches/001-unix-configure-borrow-the-LFS-test-from-autotools.patch b/tools/zip/patches/001-unix-configure-borrow-the-LFS-test-from-autotools.patch
4847-new file mode 100644
4848-index 0000000000000000000000000000000000000000..ef0de6fd9b9bb1f2ee29a9609ce0dbd7799f3410
4849---- /dev/null
4850-+++ b/tools/zip/patches/001-unix-configure-borrow-the-LFS-test-from-autotools.patch
4851-@@ -0,0 +1,89 @@
4852-+From fc392c939b9a18959482f588aff0afc29dd6d30a Mon Sep 17 00:00:00 2001
4853-+From: Romain Naour <romain.naour at openwide.fr>
4854-+Date: Fri, 23 Jan 2015 22:20:18 +0100
4855-+Subject: [PATCH 6/6] unix/configure: borrow the LFS test from autotools.
4856-+
4857-+Infozip's LFS check can't work for cross-compilation
4858-+since it try to run a target's binary on the host system.
4859-+
4860-+Instead, use to LFS test used by autotools which is a
4861-+compilation test.
4862-+(see autotools/lib/autoconf/specific.m4)
4863-+
4864-+Reported-by: Richard Genoud <richard.genoud at gmail.com>
4865-+Signed-off-by: Romain Naour <romain.naour at openwide.fr>
4866-+---
4867-+ configure | 46 +++++++++++++++-------------------------------
4868-+ 1 file changed, 15 insertions(+), 31 deletions(-)
4869-+
4870-+--- a/unix/configure
4871-++++ b/unix/configure
4872-+@@ -399,9 +399,8 @@ else
4873-+ fi
4874-+
4875-+
4876-+-# Now we set the 64-bit file environment and check the size of off_t
4877-+-# Added 11/4/2003 EG
4878-+-# Revised 8/12/2004 EG
4879-++# LFS check borrowed from autotools sources
4880-++# lib/autoconf/specific.m4
4881-+
4882-+ echo Check for Large File Support
4883-+ cat > conftest.c << _EOF_
4884-+@@ -410,23 +409,19 @@ cat > conftest.c << _EOF_
4885-+ # define _FILE_OFFSET_BITS 64 /* select default interface as 64 bit */
4886-+ # define _LARGE_FILES /* some OSes need this for 64-bit off_t */
4887-+ #include <sys/types.h>
4888-+-#include <sys/stat.h>
4889-+-#include <unistd.h>
4890-+-#include <stdio.h>
4891-++
4892-++ /* Check that off_t can represent 2**63 - 1 correctly.
4893-++ We can't simply define LARGE_OFF_T to be 9223372036854775807,
4894-++ since some C++ compilers masquerading as C compilers
4895-++ incorrectly reject 9223372036854775807. */
4896-++#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
4897-++ int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
4898-++ && LARGE_OFF_T % 2147483647 == 1)
4899-++ ? 1 : -1];
4900-++
4901-+ int main()
4902-+ {
4903-+- off_t offset;
4904-+- struct stat s;
4905-+- /* see if have 64-bit off_t */
4906-+- if (sizeof(offset) < 8)
4907-+- return 1;
4908-+- printf(" off_t is %d bytes\n", sizeof(off_t));
4909-+- /* see if have 64-bit stat */
4910-+- if (sizeof(s.st_size) < 8) {
4911-+- printf(" s.st_size is %d bytes\n", sizeof(s.st_size));
4912-+- return 2;
4913-+- }
4914-+- return 3;
4915-++ return 0;
4916-+ }
4917-+ _EOF_
4918-+ # compile it
4919-+@@ -434,19 +429,8 @@ $CC -o conftest conftest.c >/dev/null 2>
4920-+ if [ $? -ne 0 ]; then
4921-+ echo -- no Large File Support
4922-+ else
4923-+-# run it
4924-+- ./conftest
4925-+- r=$?
4926-+- if [ $r -eq 1 ]; then
4927-+- echo -- no Large File Support - no 64-bit off_t
4928-+- elif [ $r -eq 2 ]; then
4929-+- echo -- no Large File Support - no 64-bit stat
4930-+- elif [ $r -eq 3 ]; then
4931-+- echo -- yes we have Large File Support!
4932-+- CFLAGS="${CFLAGS} -DLARGE_FILE_SUPPORT"
4933-+- else
4934-+- echo -- no Large File Support - conftest returned $r
4935-+- fi
4936-++ echo -- yes we have Large File Support!
4937-++ CFLAGS="${CFLAGS} -DLARGE_FILE_SUPPORT"
4938-+ fi
4939-+
4940-+
4941-diff --git a/tools/zip/patches/004-do-not-set-unwanted-cflags.patch b/tools/zip/patches/004-do-not-set-unwanted-cflags.patch
4942-new file mode 100644
4943-index 0000000000000000000000000000000000000000..bfd226077a9742f87a1988747a81e9226e89dfaf
4944---- /dev/null
4945-+++ b/tools/zip/patches/004-do-not-set-unwanted-cflags.patch
4946-@@ -0,0 +1,15 @@
4947-+From: Santiago Vila <sanvila@debian.org>
4948-+Subject: Do not set unwanted CFLAGS, as it breaks DEB_BUILD_OPTIONS
4949-+X-Debian-version: 2.32-1
4950-+
4951-+--- a/unix/configure
4952-++++ b/unix/configure
4953-+@@ -98,7 +98,7 @@ int main()
4954-+ _EOF_
4955-+ $CC $CFLAGS -c conftest.c > /dev/null 2>/dev/null
4956-+ if test $? -eq 0; then
4957-+- CFLAGS_OPT='-O3'
4958-++ # CFLAGS_OPT='-O3'
4959-+ echo " GNU C ($CFLAGS_OPT)"
4960-+ # Special Mac OS X shared library "ld" option?
4961-+ if test ` uname -s 2> /dev/null ` = 'Darwin'; then
4962-diff --git a/tools/zip/patches/006-stack-markings-to-avoid-executable-stack.patch b/tools/zip/patches/006-stack-markings-to-avoid-executable-stack.patch
4963-new file mode 100644
4964-index 0000000000000000000000000000000000000000..8b479faedaeedbe83d378306d386a0a88493b282
4965---- /dev/null
4966-+++ b/tools/zip/patches/006-stack-markings-to-avoid-executable-stack.patch
4967-@@ -0,0 +1,21 @@
4968-+From: Kees Cook <kees@debian.org>
4969-+Subject: put stack markings in i386 assembly to avoid executable stack
4970-+Bug-Debian: http://bugs.debian.org/528280
4971-+X-Debian-version: 3.0-2
4972-+
4973-+--- a/crc_i386.S
4974-++++ b/crc_i386.S
4975-+@@ -302,3 +302,5 @@ _crc32: /* ulg c
4976-+ #endif /* i386 || _i386 || _I386 || __i386 */
4977-+
4978-+ #endif /* !USE_ZLIB && !CRC_TABLE_ONLY */
4979-++.section .note.GNU-stack, "", @progbits
4980-++.previous
4981-+--- a/match.S
4982-++++ b/match.S
4983-+@@ -405,3 +405,5 @@ L__return:
4984-+ #endif /* i386 || _I386 || _i386 || __i386 */
4985-+
4986-+ #endif /* !USE_ZLIB */
4987-++.section .note.GNU-stack, "", @progbits
4988-++.previous
4989-diff --git a/tools/zip/patches/007-fclose-in-file-not-fclose-x.patch b/tools/zip/patches/007-fclose-in-file-not-fclose-x.patch
4990-new file mode 100644
4991-index 0000000000000000000000000000000000000000..402f90a2d5ef3d08a7d71268fe4f5e2484a10664
4992---- /dev/null
4993-+++ b/tools/zip/patches/007-fclose-in-file-not-fclose-x.patch
4994-@@ -0,0 +1,16 @@
4995-+From: Christian Spieler
4996-+Subject: zipnote.c: Close in_file instead of undefined file x
4997-+Bug-Debian: http://bugs.debian.org/628594
4998-+X-Debian-version: 3.0-4
4999-+
5000-+--- a/zipnote.c
5001-++++ b/zipnote.c
5002-+@@ -661,7 +661,7 @@ char **argv; /* command line
5003-+ if ((r = zipcopy(z)) != ZE_OK)
5004-+ ziperr(r, "was copying an entry");
5005-+ }
5006-+- fclose(x);
5007-++ fclose(in_file);
5008-+
5009-+ /* Write central directory and end of central directory with new comments */
5010-+ if ((c = zftello(y)) == (zoff_t)-1) /* get start of central */
5011-diff --git a/tools/zip/patches/008-hardening-build-fix-1.patch b/tools/zip/patches/008-hardening-build-fix-1.patch
5012-new file mode 100644
5013-index 0000000000000000000000000000000000000000..a0c3a91eeec064b2305c3873a8a95669c750ea9b
5014---- /dev/null
5015-+++ b/tools/zip/patches/008-hardening-build-fix-1.patch
5016-@@ -0,0 +1,25 @@
5017-+From: Santiago Vila <sanvila@debian.org>
5018-+Subject: Use format specifier %s to print strings, not the string itself
5019-+Bug-Debian: http://bugs.debian.org/673476
5020-+X-Debian-version: 3.0-5
5021-+
5022-+--- a/zip.c
5023-++++ b/zip.c
5024-+@@ -1028,7 +1028,7 @@ local void help_extended()
5025-+
5026-+ for (i = 0; i < sizeof(text)/sizeof(char *); i++)
5027-+ {
5028-+- printf(text[i]);
5029-++ printf("%s", text[i]);
5030-+ putchar('\n');
5031-+ }
5032-+ #ifdef DOS
5033-+@@ -1225,7 +1225,7 @@ local void version_info()
5034-+ CR_MAJORVER, CR_MINORVER, CR_BETA_VER, CR_VERSION_DATE);
5035-+ for (i = 0; i < sizeof(cryptnote)/sizeof(char *); i++)
5036-+ {
5037-+- printf(cryptnote[i]);
5038-++ printf("%s", cryptnote[i]);
5039-+ putchar('\n');
5040-+ }
5041-+ ++i; /* crypt support means there IS at least one compilation option */
5042-diff --git a/tools/zip/patches/009-hardening-build-fix-2.patch b/tools/zip/patches/009-hardening-build-fix-2.patch
5043-new file mode 100644
5044-index 0000000000000000000000000000000000000000..e295ffbc641879768cc9257641fae85af327a338
5045---- /dev/null
5046-+++ b/tools/zip/patches/009-hardening-build-fix-2.patch
5047-@@ -0,0 +1,16 @@
5048-+From: Santiago Vila <sanvila@debian.org>
5049-+Subject: unix/configure: Take linking flags from the environment
5050-+Bug-Debian: http://bugs.debian.org/673476
5051-+X-Debian-version: 3.0-5
5052-+
5053-+--- a/unix/configure
5054-++++ b/unix/configure
5055-+@@ -18,7 +18,7 @@ trap "rm -f conftest* core a.out; exit 1
5056-+
5057-+ CC=${1-cc}
5058-+ CFLAGS=${2-"-I. -DUNIX"}
5059-+-LFLAGS1=''
5060-++LFLAGS1=${LDFLAGS}
5061-+ LFLAGS2=''
5062-+ LN="ln -s"
5063-+
5064-diff --git a/tools/zip/patches/010-remove-build-date.patch b/tools/zip/patches/010-remove-build-date.patch
5065-new file mode 100644
5066-index 0000000000000000000000000000000000000000..5fc385228a8f6bff01416748bb6c392f2e986322
5067---- /dev/null
5068-+++ b/tools/zip/patches/010-remove-build-date.patch
5069-@@ -0,0 +1,15 @@
5070-+From: Santiago Vila <sanvila@debian.org>
5071-+Subject: Remove (optional) build date to make the build reproducible
5072-+Bug-Debian: http://bugs.debian.org/779042
5073-+
5074-+--- a/unix/unix.c
5075-++++ b/unix/unix.c
5076-+@@ -1020,7 +1020,7 @@ void version_local()
5077-+
5078-+
5079-+ /* Define the compile date string */
5080-+-#ifdef __DATE__
5081-++#if 0
5082-+ # define COMPILE_DATE " on " __DATE__
5083-+ #else
5084-+ # define COMPILE_DATE ""
5085-diff --git a/tools/zip/patches/011-add-option-for-reproducible-archives.patch b/tools/zip/patches/011-add-option-for-reproducible-archives.patch
5086-new file mode 100644
5087-index 0000000000000000000000000000000000000000..45b9d67e159327798535db55cd264ab9eeec6c38
5088---- /dev/null
5089-+++ b/tools/zip/patches/011-add-option-for-reproducible-archives.patch
5090-@@ -0,0 +1,145 @@
5091-+From 6d659fc87451c02c8777dc33f750b16834e4c715 Mon Sep 17 00:00:00 2001
5092-+From: Mathias Kresin <dev@kresin.me>
5093-+Date: Sat, 12 Jan 2019 19:33:33 +0100
5094-+Subject: [PATCH] add option for reproducible archives
5095-+
5096-+Add the option -mt/--mtime to pass a timestamp which is used as filedate
5097-+for the containing files.
5098-+
5099-+So far, it isn't used for anything written to the extra fields,
5100-+therefore requires the -X (eXclude eXtra file attributes) parameter to
5101-+be effective.
5102-+
5103-+Signed-off-by: Mathias Kresin <dev@kresin.me>
5104-+---
5105-+ globals.c | 1 +
5106-+ util.c | 22 ++++++++++++++++++++++
5107-+ zip.c | 6 ++++++
5108-+ zip.h | 1 +
5109-+ zipup.c | 4 +++-
5110-+ 5 files changed, 33 insertions(+), 1 deletion(-)
5111-+
5112-+--- a/globals.c
5113-++++ b/globals.c
5114-+@@ -205,6 +205,7 @@ uzoff_t bytes_this_split = 0; /* byt
5115-+ int read_split_archive = 0; /* 1=scanzipf_reg detected spanning signature */
5116-+ int split_method = 0; /* 0=no splits, 1=seekable, 2=data desc, -1=no */
5117-+ uzoff_t split_size = 0; /* how big each split should be */
5118-++time_t timestamp = -1; /* fixed timestamp for archive content filedate */
5119-+ int split_bell = 0; /* when pause for next split ring bell */
5120-+ uzoff_t bytes_prev_splits = 0; /* total bytes written to all splits before this */
5121-+ uzoff_t bytes_this_entry = 0; /* bytes written for this entry across all splits */
5122-+--- a/util.c
5123-++++ b/util.c
5124-+@@ -1217,6 +1217,7 @@ int DisplayNumString(file, i)
5125-+ return 0;
5126-+ }
5127-+
5128-++
5129-+ /* Read numbers with trailing size multiplier (like 10M) and return number.
5130-+ 10/30/04 EG */
5131-+
5132-+@@ -1279,6 +1280,29 @@ uzoff_t ReadNumString( numstring )
5133-+ }
5134-+
5135-+
5136-++uzoff_t ReadNumStringUL( numstring )
5137-++ char *numstring;
5138-++{
5139-++ zoff_t num = 0;
5140-++
5141-++ /* check if valid number (currently no negatives) */
5142-++ if (numstring == NULL) {
5143-++ zipwarn("Unable to read empty number in ReadNumString", "");
5144-++ return (uzoff_t)-1;
5145-++ }
5146-++ if (numstring[0] < '0' || numstring[0] > '9') {
5147-++ zipwarn("Unable to read number (must start with digit): ", numstring);
5148-++ return (uzoff_t)-1;
5149-++ }
5150-++ if (strlen(numstring) > 10) {
5151-++ zipwarn("Number too long to read (10 characters max): ", numstring);
5152-++ return (uzoff_t)-1;
5153-++ }
5154-++
5155-++ return (uzoff_t)atoll(numstring);
5156-++}
5157-++
5158-++
5159-+ /* Write the number as a string with a multiplier (like 10M) to outstring.
5160-+ Always writes no more than 3 digits followed maybe by a multiplier and
5161-+ returns the characters written or -1 if error.
5162-+--- a/zip.c
5163-++++ b/zip.c
5164-+@@ -1942,6 +1942,7 @@ int set_filetype(out_path)
5165-+ #ifdef UNICODE_TEST
5166-+ #define o_sC 0x146
5167-+ #endif
5168-++#define o_mt 0x255
5169-+
5170-+
5171-+ /* the below is mainly from the old main command line
5172-+@@ -2036,6 +2037,7 @@ struct option_struct far options[] = {
5173-+ {"m", "move", o_NO_VALUE, o_NOT_NEGATABLE, 'm', "add files to archive then delete files"},
5174-+ {"mm", "", o_NO_VALUE, o_NOT_NEGATABLE, o_mm, "not used"},
5175-+ {"MM", "must-match", o_NO_VALUE, o_NOT_NEGATABLE, o_MM, "error if in file not matched/not readable"},
5176-++ {"mt", "mtime", o_REQUIRED_VALUE, o_NOT_NEGATABLE, o_mt, "use fixed timestamp for archive content filedate"},
5177-+ {"n", "suffixes", o_REQUIRED_VALUE, o_NOT_NEGATABLE, 'n', "suffixes to not compress: .gz:.zip"},
5178-+ {"nw", "no-wild", o_NO_VALUE, o_NOT_NEGATABLE, o_nw, "no wildcards during add or update"},
5179-+ #if defined(AMIGA) || defined(MACOS)
5180-+@@ -2440,6 +2442,7 @@ char **argv; /* command line
5181-+ split_method = 0; /* 0=no splits, 1=update LHs, 2=data descriptors */
5182-+ split_size = 0; /* how big each split should be */
5183-+ split_bell = 0; /* when pause for next split ring bell */
5184-++ timestamp = -1; /* fixed timestamp for archive content filedate */
5185-+ bytes_prev_splits = 0; /* total bytes written to all splits before this */
5186-+ bytes_this_entry = 0; /* bytes written for this entry across all splits */
5187-+ noisy_splits = 0; /* be verbose about creating splits */
5188-+@@ -2897,6 +2900,9 @@ char **argv; /* command line
5189-+ dispose = 1; break;
5190-+ case o_MM: /* Exit with error if input file can't be read */
5191-+ bad_open_is_error = 1; break;
5192-++ case o_mt: /* fixed timestamp for archive content filedate */
5193-++ timestamp = ReadNumStringUL(value);
5194-++ break;
5195-+ case 'n': /* Don't compress files with a special suffix */
5196-+ special = value;
5197-+ /* special = NULL; */ /* will be set at next argument */
5198-+--- a/zip.h
5199-++++ b/zip.h
5200-+@@ -502,6 +502,7 @@ extern uzoff_t bytes_this_split; /* byte
5201-+ extern int read_split_archive; /* 1=scanzipf_reg detected spanning signature */
5202-+ extern int split_method; /* 0=no splits, 1=seekable, 2=data descs, -1=no */
5203-+ extern uzoff_t split_size; /* how big each split should be */
5204-++extern time_t timestamp; /* fixed timestamp for archive content filedate */
5205-+ extern int split_bell; /* when pause for next split ring bell */
5206-+ extern uzoff_t bytes_prev_splits; /* total bytes written to all splits before this */
5207-+ extern uzoff_t bytes_this_entry; /* bytes written for this entry across all splits */
5208-+@@ -789,6 +790,7 @@ char *zip_fzofft OF((zoff_t, char
5209-+ int DisplayNumString OF ((FILE *file, uzoff_t i));
5210-+ int WriteNumString OF((uzoff_t num, char *outstring));
5211-+ uzoff_t ReadNumString OF((char *numstring));
5212-++uzoff_t ReadNumStringUL OF((char *numstring));
5213-+
5214-+ /* returns true if abbrev is abbreviation for string */
5215-+ int abbrevmatch OF((char *, char *, int, int));
5216-+--- a/zipup.c
5217-++++ b/zipup.c
5218-+@@ -415,7 +415,6 @@ struct zlist far *z; /* zip entry to
5219-+ char *tempextra = NULL;
5220-+ char *tempcextra = NULL;
5221-+
5222-+-
5223-+ #ifdef WINDLL
5224-+ # ifdef ZIP64_SUPPORT
5225-+ extern _int64 filesize64;
5226-+@@ -441,6 +440,9 @@ struct zlist far *z; /* zip entry to
5227-+ if (tim == 0 || q == (zoff_t) -3)
5228-+ return ZE_OPEN;
5229-+
5230-++ if (timestamp > 0)
5231-++ tim = unix2dostime(×tamp);
5232-++
5233-+ /* q is set to -1 if the input file is a device, -2 for a volume label */
5234-+ if (q == (zoff_t) -2) {
5235-+ isdir = 1;
5236diff --git a/patches/openwrt/0018-firmware-utils-add-sercomm-netgear-tool.patch b/patches/openwrt/0018-firmware-utils-add-sercomm-netgear-tool.patch
5237deleted file mode 100644
5238index e2fd53d2..00000000
5239--- a/patches/openwrt/0018-firmware-utils-add-sercomm-netgear-tool.patch
5240+++ /dev/null
5241@@ -1,469 +0,0 @@
5242-From: Ludwig Thomeczek <ledesrc@wxorx.net>
5243-Date: Tue, 12 Jun 2018 21:16:40 +0200
5244-Subject: firmware-utils: add sercomm/netgear tool
5245-
5246-This adds a tool to generate a firmware file accepted
5247-by Netgear or sercomm devices.
5248-
5249-They use a zip-packed rootfs with header and a custom
5250-checksum. The generated Image can be flashed via the
5251-nmrpflash tool or the webinterface of the router.
5252-
5253-Signed-off-by: Ludwig Thomeczek <ledesrc@wxorx.net>
5254-
5255-firmware-utils/mksercommfw: fix musl build
5256-
5257-* add missing <sys/types.h> for musl
5258-
5259-Signed-off-by: Andy Walsh <andy.walsh44+github@gmail.com>
5260-
5261-firmware-utils/mksercommfw: fix build with clang/macOS
5262-
5263-fixes error: non-void function 'main' should return a value
5264-
5265-Fixes: FS#1770
5266-
5267-Signed-off-by: Ryan Mounce <ryan@mounce.com.au>
5268-
5269-ramips: fix image generation for mt76x8
5270-
5271-Buildbot fails to generate images for targets also generating a
5272-Sercomm binary with following error:
5273-
5274-Opening file: /mnt/ramdisk/koen/firmware/builds/owrt_mt76x8/build_dir/target-mipsel_24kc_musl/linux-ramips_mt76x8/tmp/openwrt-ramips-mt76x8-netgear_r6120-squashfs-factory.img.rootfs.zip
5275-Filesize: 3648606 .
5276-mksercommfw: malloc.c:2427: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
5277-Makefile:287: recipe for target '/mnt/ramdisk/koen/firmware/builds/owrt_mt76x8/build_dir/target-mipsel_24kc_musl/linux-ramips_mt76x8/tmp/openwrt-ramips-mt76x8-netgear_r6120-squashfs-factory.img' failed
5278-
5279-Debugging using valgrind shows stack corruption due to a buffer overflow.
5280-The author of the generator assumes the filename ends with "root",
5281-while it should be "rootfs".
5282-
5283-Fix this by accounting for the 2 missing characters which solves the build issues.
5284-
5285-More work is required to cleanup this source, which will be done later on.
5286-
5287-Reported-by: Hannu Nyman <hannu.nyman@iki.fi>
5288-Signed-off-by: Koen Vandeputte <koen.vandeputte@ncentric.com>
5289-
5290-ramips: fix netgear r6120 factory image generation
5291-
5292-as indicated in commit c5bf408ed6bd "(ramips: fix image generation for mt76x8")
5293-more rework was needed to fix the other issues.
5294-
5295-Building on another machine, but using the same arch, showed
5296-the application failing again for different reasons.
5297-
5298-Fix this by completely rewriting the application, fixing following found issues:
5299-
5300-- buffer overflows, resulting in stack corruption
5301-- flaws in memory requirement calculations (too small, too large)
5302-- memory leaks
5303-- missing bounds checking on string handling
5304-- non-reproducable images, by using unitilized memory in checksum calculation
5305-- missing error handling, resulting in succes on specific image errors
5306-- endianness errors when building on BE machines
5307-- various minor build warnings
5308-- documentation did not match the code actions (header item locations)
5309-- allowing input to be decimal, hex or octal now
5310-
5311-Signed-off-by: Koen Vandeputte <koen.vandeputte@ncentric.com>
5312-
5313-tools: firmware-utils: mksercommfw build on Darwin
5314-
5315-asm/byteorder.h & hence __cpu_to_be32() doesn't exist on Darwin
5316-
5317-Shamelessly copy some byte swap functions from oseama.c
5318-
5319-Acked-by: Koen Vandeputte <koen.vandeputte@ncentric.com>
5320-Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
5321-
5322-firmware-utils: mksercommfw: overhaul image creation
5323-
5324-Move the zip compression into a build recipe. Pad the image using the
5325-existing build recipes as well to remove duplicate functionality
5326-
5327-Change the code to append header and footer in two steps. Allow to use a
5328-fixed filename as the netgear update image does.
5329-
5330-Use a fixed timestamp within the zip archive to make the images
5331-reproducible.
5332-
5333-Due to the changes we are now compatible to the gnu89 c standard used by
5334-default on the buildbots and we don't need to force a more recent
5335-standard anymore.
5336-
5337-Beside all changes, the footer still looks wrong in compare to the
5338-netgear update image.
5339-
5340-Signed-off-by: Mathias Kresin <dev@kresin.me>
5341-
5342-diff --git a/include/image-commands.mk b/include/image-commands.mk
5343-index 552d8db1cbacf533c12d0d8e2e5cffbe5591adb4..aec044294365bf5e964906e022d468d1a1c95fba 100644
5344---- a/include/image-commands.mk
5345-+++ b/include/image-commands.mk
5346-@@ -115,6 +115,16 @@ define Build/tplink-safeloader
5347- $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
5348- endef
5349-
5350-+define Build/mksercommfw
5351-+ -$(STAGING_DIR_HOST)/bin/mksercommfw \
5352-+ $@ \
5353-+ $(KERNEL_OFFSET) \
5354-+ $(HWID) \
5355-+ $(HWVER) \
5356-+ $(SWVER)
5357-+endef
5358-+
5359-+
5360- define Build/append-dtb
5361- cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
5362- endef
5363-@@ -152,6 +162,16 @@ define Build/gzip
5364- @mv $@.new $@
5365- endef
5366-
5367-+define Build/zip
5368-+ mkdir $@.tmp
5369-+ mv $@ $@.tmp/$(1)
5370-+
5371-+ zip -j -X \
5372-+ $(if $(SOURCE_DATE_EPOCH),--mtime="$(SOURCE_DATE_EPOCH)") \
5373-+ $@ $@.tmp/$(if $(1),$(1),$@)
5374-+ rm -rf $@.tmp
5375-+endef
5376-+
5377- define Build/jffs2
5378- rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
5379- mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
5380-diff --git a/target/linux/ramips/image/mt76x8.mk b/target/linux/ramips/image/mt76x8.mk
5381-index bc282666d8c1a4b6ce5beabe2b492331fb48a23a..f1bf78e0713a1bc47d4ac384efdac1d08c1bd8bc 100644
5382---- a/target/linux/ramips/image/mt76x8.mk
5383-+++ b/target/linux/ramips/image/mt76x8.mk
5384-@@ -2,17 +2,22 @@
5385- # MT76x8 Profiles
5386- #
5387-
5388--DEVICE_VARS += SERCOMM_KERNEL_OFFSET SERCOMM_HWID SERCOMM_HWVER SERCOMM_SWVER
5389-+DEVICE_VARS += SERCOMM_HWID SERCOMM_HWVER SERCOMM_SWVER
5390-
5391--define Build/mksercommfw
5392-+define Build/sercom-seal
5393- $(STAGING_DIR_HOST)/bin/mksercommfw \
5394-- $@ \
5395-- $(SERCOMM_KERNEL_OFFSET) \
5396-- $(SERCOMM_HWID) \
5397-- $(SERCOMM_HWVER) \
5398-- $(SERCOMM_SWVER)
5399-+ -i $@ \
5400-+ -b $(SERCOMM_HWID) \
5401-+ -r $(SERCOMM_HWVER) \
5402-+ -v $(SERCOMM_SWVER) \
5403-+ $(1)
5404- endef
5405-
5406-+define Build/sercom-footer
5407-+ $(call Build/sercom-seal,-f)
5408-+endef
5409-+
5410-+
5411- define Device/tplink
5412- TPLINK_FLASHLAYOUT :=
5413- TPLINK_HWID :=
5414-@@ -107,14 +112,14 @@ define Device/netgear_r6120
5415- IMAGE_SIZE := $(ralink_default_fw_size_16M)
5416- DEVICE_TITLE := Netgear R6120
5417- DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
5418-- SERCOMM_KERNEL_OFFSET := 90000
5419- SERCOMM_HWID := CGQ
5420- SERCOMM_HWVER := A001
5421-- SERCOMM_SWVER := 0040
5422-+ SERCOMM_SWVER := 0x0040
5423- IMAGES += factory.img
5424- IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE)| append-rootfs | pad-rootfs
5425- IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | check-size $$$$(IMAGE_SIZE)
5426-- IMAGE/factory.img := $$(IMAGE/default) | mksercommfw
5427-+ IMAGE/factory.img := pad-extra 576k | $$(IMAGE/default) | \
5428-+ sercom-footer | pad-to 128 | zip R6120.bin | sercom-seal
5429- endef
5430- TARGET_DEVICES += netgear_r6120
5431-
5432-diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile
5433-index a6379e35eb01f1cbbe2b1ece3fc9eb20bcd68d90..ca7722163d68d028b88e4cca2f0457875e633af6 100644
5434---- a/tools/firmware-utils/Makefile
5435-+++ b/tools/firmware-utils/Makefile
5436-@@ -85,6 +85,7 @@ define Host/Compile
5437- $(call cc,mkdhpimg buffalo-lib, -Wall)
5438- $(call cc,mkdlinkfw mkdlinkfw-lib, -lz -Wall --std=gnu99)
5439- $(call cc,dns313-header, -Wall)
5440-+ $(call cc,mksercommfw, -Wall)
5441- endef
5442-
5443- define Host/Install
5444-diff --git a/tools/firmware-utils/src/mksercommfw.c b/tools/firmware-utils/src/mksercommfw.c
5445-new file mode 100644
5446-index 0000000000000000000000000000000000000000..f6f1d93f37970be0cdf94e71a5e1093b3e92c040
5447---- /dev/null
5448-+++ b/tools/firmware-utils/src/mksercommfw.c
5449-@@ -0,0 +1,261 @@
5450-+#include <stdio.h>
5451-+#include <string.h>
5452-+#include <stdlib.h>
5453-+#include <sys/types.h>
5454-+#include <unistd.h>
5455-+#include <byteswap.h>
5456-+#include <endian.h>
5457-+#include <getopt.h>
5458-+
5459-+#if !defined(__BYTE_ORDER)
5460-+#error "Unknown byte order"
5461-+#endif
5462-+
5463-+#if __BYTE_ORDER == __BIG_ENDIAN
5464-+#define cpu_to_be32(x) (x)
5465-+#elif __BYTE_ORDER == __LITTLE_ENDIAN
5466-+#define cpu_to_be32(x) bswap_32(x)
5467-+#else
5468-+#error "Unsupported endianness"
5469-+#endif
5470-+
5471-+/* #define DEBUG 1 */
5472-+
5473-+#ifdef DEBUG
5474-+#define DBG(...) {printf(__VA_ARGS__); }
5475-+#else
5476-+#define DBG(...) {}
5477-+#endif
5478-+
5479-+#define ERR(...) {printf(__VA_ARGS__); }
5480-+
5481-+/*
5482-+ * Fw Header Layout for Netgear / Sercomm devices (bytes)
5483-+ *
5484-+ * Size : 512 bytes + zipped image size
5485-+ *
5486-+ * Locations:
5487-+ * magic : 0-6 ASCII
5488-+ * version: 7-11 fixed
5489-+ * hwID : 11-44 ASCII
5490-+ * hwVer : 45-54 ASCII
5491-+ * swVer : 55-62 uint32_t in BE
5492-+ * magic : 63-69 ASCII
5493-+ * ChkSum : 511 Inverse value of the full image checksum while this location is 0x00
5494-+ */
5495-+static const char* magic = "sErCoMm"; /* 7 */
5496-+static const unsigned char version[4] = { 0x00, 0x01, 0x00, 0x00 };
5497-+static const int header_sz = 512;
5498-+static const int footer_sz = 71;
5499-+
5500-+static int is_header = 1;
5501-+
5502-+struct file_info {
5503-+ char* file_name; /* name of the file */
5504-+ char* file_data; /* data of the file in memory */
5505-+ u_int32_t file_size; /* length of the file */
5506-+};
5507-+
5508-+static u_int8_t getCheckSum(char* data, int len) {
5509-+ u_int8_t new = 0;
5510-+ int i;
5511-+
5512-+ if (!data) {
5513-+ ERR("Invalid pointer provided!\n");
5514-+ return 0;
5515-+ }
5516-+
5517-+ for (i = 0; i < len; i++) {
5518-+ new += data[i];
5519-+ }
5520-+
5521-+ return new;
5522-+}
5523-+
5524-+/*
5525-+ * read file into buffer
5526-+ * add space for header/footer
5527-+ */
5528-+static int copyToOutputBuf(struct file_info* finfo) {
5529-+ FILE* fp = NULL;
5530-+
5531-+ int file_sz = 0;
5532-+ int extra_sz;
5533-+ int hdr_pos;
5534-+ int img_pos;
5535-+
5536-+ if (!finfo || !finfo->file_name) {
5537-+ ERR("Invalid pointer provided!\n");
5538-+ return -1;
5539-+ }
5540-+
5541-+ DBG("Opening file: %s\n", finfo->file_name);
5542-+
5543-+ if (!(fp = fopen(finfo->file_name, "rb"))) {
5544-+ ERR("Error opening file: %s\n", finfo->file_name);
5545-+ return -1;
5546-+ }
5547-+
5548-+ /* Get filesize */
5549-+ rewind(fp);
5550-+ fseek(fp, 0L, SEEK_END);
5551-+ file_sz = ftell(fp);
5552-+ rewind(fp);
5553-+
5554-+ if (file_sz < 1) {
5555-+ ERR("Error getting filesize: %s\n", finfo->file_name);
5556-+ fclose(fp);
5557-+ return -1;
5558-+ }
5559-+
5560-+ if (is_header) {
5561-+ extra_sz = header_sz;
5562-+ hdr_pos = 0;
5563-+ img_pos = header_sz;
5564-+ } else {
5565-+ extra_sz = footer_sz;
5566-+ hdr_pos = file_sz;
5567-+ img_pos = 0;
5568-+ }
5569-+
5570-+ DBG("Filesize: %i\n", file_sz);
5571-+ finfo->file_size = file_sz + extra_sz;
5572-+
5573-+ if (!(finfo->file_data = malloc(finfo->file_size))) {
5574-+ ERR("Out of memory!\n");
5575-+ fclose(fp);
5576-+ return -1;
5577-+ }
5578-+
5579-+ /* init header/footer bytes */
5580-+ memset(finfo->file_data + hdr_pos, 0, extra_sz);
5581-+
5582-+ /* read file and take care of leading header if exists */
5583-+ if (fread(finfo->file_data + img_pos, 1, file_sz, fp) != file_sz) {
5584-+ ERR("Error reading file %s\n", finfo->file_name);
5585-+ fclose(fp);
5586-+ return -1;
5587-+ }
5588-+
5589-+ DBG("File: read successful\n");
5590-+ fclose(fp);
5591-+
5592-+ return hdr_pos;
5593-+}
5594-+
5595-+static int writeFile(struct file_info* finfo) {
5596-+ FILE* fp;
5597-+
5598-+ if (!finfo || !finfo->file_name) {
5599-+ ERR("Invalid pointer provided!\n");
5600-+ return -1;
5601-+ }
5602-+
5603-+ DBG("Opening file: %s\n", finfo->file_name);
5604-+
5605-+ if (!(fp = fopen(finfo->file_name, "w"))) {
5606-+ ERR("Error opening file: %s\n", finfo->file_name);
5607-+ return -1;
5608-+ }
5609-+
5610-+ DBG("Writing file: %s\n", finfo->file_name);
5611-+
5612-+ if (fwrite(finfo->file_data, 1, finfo->file_size, fp) != finfo->file_size) {
5613-+ ERR("Wanted to write, but something went wrong!\n");
5614-+ fclose(fp);
5615-+ return -1;
5616-+ }
5617-+
5618-+ fclose(fp);
5619-+ return 0;
5620-+}
5621-+
5622-+static void usage(char* argv[]) {
5623-+ printf("Usage: %s [OPTIONS...]\n"
5624-+ "\n"
5625-+ "Options:\n"
5626-+ " -f add sercom footer (if absent, header)\n"
5627-+ " -b <hwid> use hardware id specified with <hwid> (ASCII)\n"
5628-+ " -r <hwrev> use hardware revision specified with <hwrev> (ASCII)\n"
5629-+ " -v <version> set image version to <version> (decimal, hex or octal notation)\n"
5630-+ " -i <file> input file\n"
5631-+ , argv[0]);
5632-+}
5633-+
5634-+int main(int argc, char* argv[]) {
5635-+ struct file_info image = { 0 };
5636-+
5637-+ char* hwID = NULL;
5638-+ char* hwVer = NULL;
5639-+ u_int32_t swVer = 0;
5640-+ u_int8_t chkSum;
5641-+ int hdr_offset;
5642-+
5643-+ while ( 1 ) {
5644-+ int c;
5645-+
5646-+ c = getopt(argc, argv, "b:i:r:v:f");
5647-+ if (c == -1)
5648-+ break;
5649-+
5650-+ switch (c) {
5651-+ case 'b':
5652-+ hwID = optarg;
5653-+ break;
5654-+ case 'f':
5655-+ is_header = 0;
5656-+ break;
5657-+ case 'i':
5658-+ image.file_name = optarg;
5659-+ break;
5660-+ case 'r':
5661-+ hwVer = optarg;
5662-+ break;
5663-+ case 'v':
5664-+ swVer = (u_int32_t) strtol(optarg, NULL, 0);
5665-+ swVer = cpu_to_be32(swVer);
5666-+ break;
5667-+ default:
5668-+ usage(argv);
5669-+ return EXIT_FAILURE;
5670-+ }
5671-+ }
5672-+
5673-+ if (!hwID || !hwVer || !image.file_name) {
5674-+ usage(argv);
5675-+ return EXIT_FAILURE;
5676-+ }
5677-+
5678-+ /*
5679-+ * copy input to buffer, add extra space for header/footer and return
5680-+ * header position
5681-+ */
5682-+ hdr_offset = copyToOutputBuf(&image);
5683-+ if (hdr_offset < 0)
5684-+ return EXIT_FAILURE;
5685-+
5686-+ DBG("Filling header: %s %s %2X %s\n", hwID, hwVer, swVer, magic);
5687-+
5688-+ strncpy(image.file_data + hdr_offset + 0, magic, 7);
5689-+ memcpy(image.file_data + hdr_offset + 7, version, sizeof(version));
5690-+ strncpy(image.file_data + hdr_offset + 11, hwID, 34);
5691-+ strncpy(image.file_data + hdr_offset + 45, hwVer, 10);
5692-+ memcpy(image.file_data + hdr_offset + 55, &swVer, sizeof(swVer));
5693-+ strncpy(image.file_data + hdr_offset + 63, magic, 7);
5694-+
5695-+ /* calculate checksum and invert checksum */
5696-+ if (is_header) {
5697-+ chkSum = getCheckSum(image.file_data, image.file_size);
5698-+ chkSum = (chkSum ^ 0xFF) + 1;
5699-+ DBG("Checksum for Image: %hhX\n", chkSum);
5700-+
5701-+ /* write checksum to header */
5702-+ image.file_data[511] = (char) chkSum;
5703-+ }
5704-+
5705-+ /* overwrite input file */
5706-+ if (writeFile(&image))
5707-+ return EXIT_FAILURE;
5708-+
5709-+ return EXIT_SUCCESS;
5710-+}
5711diff --git a/patches/openwrt/0019-ath10k-ct-fix-incorrect-multicast-broadcast-rate-setting.patch b/patches/openwrt/0019-ath10k-ct-fix-incorrect-multicast-broadcast-rate-setting.patch
5712deleted file mode 100644
5713index 63d625e0..00000000
5714--- a/patches/openwrt/0019-ath10k-ct-fix-incorrect-multicast-broadcast-rate-setting.patch
5715+++ /dev/null
5716@@ -1,113 +0,0 @@
5717-From: Sven Eckelmann <sven@narfation.org>
5718-Date: Mon, 25 Feb 2019 20:42:28 +0100
5719-Subject: ath10k-ct: fix incorrect multicast/broadcast rate setting
5720-
5721-If no mcast_rate is set for the wifi-iface then there is no rate_idx (0)
5722-set for the bss. This can break for example 5GHz meshpoint interfaces
5723-because 0 maps to a CCK rate (11Mbit/s).
5724-
5725-It must also be avoided that the internal state for the rates is not synced
5726-with the mac80211 rates state. Otherwise, the a rate (e.g. a wifi-iface
5727-mcast_rate for a meshpoint interface) will be set on startup. And a short
5728-while after that, ath10k-ct specific code in
5729-ath10k_check_apply_special_rates is missing a valid rate in its own
5730-structures and is then recalculating a new default rate. This default rate
5731-is in most situations not the requested rate.
5732-
5733-Fixes: 4df3c71cd4c5 ("ath10k-ct: Update to 2018-12-11 and use version based on 4.19")
5734-Signed-off-by: Sven Eckelmann <sven@narfation.org>
5735-
5736-Forwarded: https://github.com/openwrt/openwrt/pull/1862
5737-
5738-diff --git a/package/kernel/ath10k-ct/patches/979-ath10k-fix-incorrect-multicast-broadcast-rate-settin.patch b/package/kernel/ath10k-ct/patches/979-ath10k-fix-incorrect-multicast-broadcast-rate-settin.patch
5739-new file mode 100644
5740-index 0000000000000000000000000000000000000000..0e4f0565d6191a4e91eb2cfdffb25a850dd69a28
5741---- /dev/null
5742-+++ b/package/kernel/ath10k-ct/patches/979-ath10k-fix-incorrect-multicast-broadcast-rate-settin.patch
5743-@@ -0,0 +1,43 @@
5744-+From: Pradeep kumar Chitrapu <pradeepc@codeaurora.org>
5745-+Date: Mon, 10 Dec 2018 20:56:11 -0800
5746-+Subject: ath10k: fix incorrect multicast/broadcast rate setting
5747-+
5748-+Invalid rate code is sent to firmware when multicast rate value of 0 is
5749-+sent to driver indicating disabled case, causing broken mesh path.
5750-+so fix that.
5751-+
5752-+Tested on QCA9984 with firmware 10.4-3.6.1-00827
5753-+
5754-+Fixes: cd93b83ad92 ("ath10k: support for multicast rate control")
5755-+Co-developed-by: Zhi Chen <zhichen@codeaurora.org>
5756-+Signed-off-by: Zhi Chen <zhichen@codeaurora.org>
5757-+Signed-off-by: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
5758-+
5759-+Origin: other, https://patchwork.kernel.org/patch/10723033/
5760-+
5761-+--- a/ath10k-4.13/mac.c
5762-++++ b/ath10k-4.13/mac.c
5763-+@@ -6264,8 +6264,8 @@ static void ath10k_bss_info_changed(stru
5764-+ struct cfg80211_chan_def def;
5765-+ u32 vdev_param, pdev_param, slottime, preamble;
5766-+ u16 bitrate, hw_value;
5767-+- u8 rate, basic_rate_idx;
5768-+- int rateidx, ret = 0, hw_rate_code;
5769-++ u8 rate, basic_rate_idx, rateidx;
5770-++ int ret = 0, hw_rate_code, mcast_rate;
5771-+ enum nl80211_band band;
5772-+ const struct ieee80211_supported_band *sband;
5773-+
5774-+@@ -6438,7 +6438,11 @@ static void ath10k_bss_info_changed(stru
5775-+ if (changed & BSS_CHANGED_MCAST_RATE &&
5776-+ !WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) {
5777-+ band = def.chan->band;
5778-+- rateidx = vif->bss_conf.mcast_rate[band] - 1;
5779-++ mcast_rate = vif->bss_conf.mcast_rate[band];
5780-++ if (mcast_rate > 0)
5781-++ rateidx = mcast_rate - 1;
5782-++ else
5783-++ rateidx = ffs(vif->bss_conf.basic_rates) - 1;
5784-+
5785-+ if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
5786-+ rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
5787-diff --git a/package/kernel/ath10k-ct/patches/980-ath10k-commit-rates-from-mac80211.patch b/package/kernel/ath10k-ct/patches/980-ath10k-commit-rates-from-mac80211.patch
5788-new file mode 100644
5789-index 0000000000000000000000000000000000000000..6b12ba0995cdbd56f1e5dce8c5aba14e7af95c3c
5790---- /dev/null
5791-+++ b/package/kernel/ath10k-ct/patches/980-ath10k-commit-rates-from-mac80211.patch
5792-@@ -0,0 +1,37 @@
5793-+From: Sven Eckelmann <sven@narfation.org>
5794-+Date: Mon, 10 Dec 2018 20:56:11 -0800
5795-+Subject: ath10k-ct: apply mac80211 rates to ath10k-ct rate state
5796-+
5797-+The rates from mac80211 have to be copied to the state of ath10k-ct or
5798-+otherwise the ath10k_check_apply_special_rates function overwrites
5799-+them again with some default values. This breaks for example the
5800-+mcast_rate set for a wifi-iface.
5801-+
5802-+Signed-off-by: Sven Eckelmann <sven@narfation.org>
5803-+
5804-+--- a/ath10k-4.13/mac.c
5805-++++ b/ath10k-4.13/mac.c
5806-+@@ -6460,6 +6460,7 @@ static void ath10k_bss_info_changed(stru
5807-+ "mac vdev %d mcast_rate %x\n",
5808-+ arvif->vdev_id, rate);
5809-+
5810-++ arvif->mcast_rate[band] = rate;
5811-+ vdev_param = ar->wmi.vdev_param->mcast_data_rate;
5812-+ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5813-+ vdev_param, rate);
5814-+@@ -6468,6 +6469,7 @@ static void ath10k_bss_info_changed(stru
5815-+ "failed to set mcast rate on vdev %i: %d\n",
5816-+ arvif->vdev_id, ret);
5817-+
5818-++ arvif->bcast_rate[band] = rate;
5819-+ vdev_param = ar->wmi.vdev_param->bcast_data_rate;
5820-+ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5821-+ vdev_param, rate);
5822-+@@ -6494,6 +6496,7 @@ static void ath10k_bss_info_changed(stru
5823-+ return;
5824-+ }
5825-+
5826-++ arvif->mgt_rate[def.chan->band] = hw_rate_code;
5827-+ vdev_param = ar->wmi.vdev_param->mgmt_rate;
5828-+ ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5829-+ hw_rate_code);
5830diff --git a/patches/openwrt/0020-mac80211-ath10k-fix-incorrect-multicast-broadcast-rate-setting.patch b/patches/openwrt/0020-mac80211-ath10k-fix-incorrect-multicast-broadcast-rate-setting.patch
5831deleted file mode 100644
5832index 17f97608..00000000
5833--- a/patches/openwrt/0020-mac80211-ath10k-fix-incorrect-multicast-broadcast-rate-setting.patch
5834+++ /dev/null
5835@@ -1,60 +0,0 @@
5836-From: Sven Eckelmann <sven@narfation.org>
5837-Date: Mon, 25 Feb 2019 20:42:28 +0100
5838-Subject: mac80211: ath10k: fix incorrect multicast/broadcast rate setting
5839-
5840-If no mcast_rate is set for the wifi-iface then there is no rate_idx (0)
5841-set for the bss. This breaks for example 5GHz meshpoint interfaces because
5842-0 maps to a CCK rate (11Mbit/s).
5843-
5844-Fixes: db90c243a0b9 ("mac80211: update to version based on 4.19-rc4")
5845-Signed-off-by: Sven Eckelmann <sven@narfation.org>
5846-
5847-diff --git a/package/kernel/mac80211/patches/979-ath10k-fix-incorrect-multicast-broadcast-rate-settin.patch b/package/kernel/mac80211/patches/979-ath10k-fix-incorrect-multicast-broadcast-rate-settin.patch
5848-new file mode 100644
5849-index 0000000000000000000000000000000000000000..8695b7e094885bb479e14386a0461a25cf57603d
5850---- /dev/null
5851-+++ b/package/kernel/mac80211/patches/979-ath10k-fix-incorrect-multicast-broadcast-rate-settin.patch
5852-@@ -0,0 +1,43 @@
5853-+From: Pradeep kumar Chitrapu <pradeepc@codeaurora.org>
5854-+Date: Mon, 10 Dec 2018 20:56:11 -0800
5855-+Subject: ath10k: fix incorrect multicast/broadcast rate setting
5856-+
5857-+Invalid rate code is sent to firmware when multicast rate value of 0 is
5858-+sent to driver indicating disabled case, causing broken mesh path.
5859-+so fix that.
5860-+
5861-+Tested on QCA9984 with firmware 10.4-3.6.1-00827
5862-+
5863-+Fixes: cd93b83ad92 ("ath10k: support for multicast rate control")
5864-+Co-developed-by: Zhi Chen <zhichen@codeaurora.org>
5865-+Signed-off-by: Zhi Chen <zhichen@codeaurora.org>
5866-+Signed-off-by: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
5867-+
5868-+Origin: other, https://patchwork.kernel.org/patch/10723033/
5869-+
5870-+--- a/drivers/net/wireless/ath/ath10k/mac.c
5871-++++ b/drivers/net/wireless/ath/ath10k/mac.c
5872-+@@ -5484,8 +5484,8 @@ static void ath10k_bss_info_changed(stru
5873-+ struct cfg80211_chan_def def;
5874-+ u32 vdev_param, pdev_param, slottime, preamble;
5875-+ u16 bitrate, hw_value;
5876-+- u8 rate, basic_rate_idx;
5877-+- int rateidx, ret = 0, hw_rate_code;
5878-++ u8 rate, basic_rate_idx, rateidx;
5879-++ int ret = 0, hw_rate_code, mcast_rate;
5880-+ enum nl80211_band band;
5881-+ const struct ieee80211_supported_band *sband;
5882-+
5883-+@@ -5658,7 +5658,11 @@ static void ath10k_bss_info_changed(stru
5884-+ if (changed & BSS_CHANGED_MCAST_RATE &&
5885-+ !WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) {
5886-+ band = def.chan->band;
5887-+- rateidx = vif->bss_conf.mcast_rate[band] - 1;
5888-++ mcast_rate = vif->bss_conf.mcast_rate[band];
5889-++ if (mcast_rate > 0)
5890-++ rateidx = mcast_rate - 1;
5891-++ else
5892-++ rateidx = ffs(vif->bss_conf.basic_rates) - 1;
5893-+
5894-+ if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
5895-+ rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
5896diff --git a/patches/openwrt/0021-ramips-fix-R6120-factory-image.patch b/patches/openwrt/0021-ramips-fix-R6120-factory-image.patch
5897deleted file mode 100644
5898index ea93569e..00000000
5899--- a/patches/openwrt/0021-ramips-fix-R6120-factory-image.patch
5900+++ /dev/null
5901@@ -1,26 +0,0 @@
5902-From: David Bauer <mail@david-bauer.net>
5903-Date: Thu, 9 May 2019 18:01:13 +0200
5904-Subject: ramips: fix R6120 factory image
5905-
5906-The factory firmware omits the JFFS2 end-marker while flashing via
5907-web-interface. Add a 64k padding after the marker fixes this problem.
5908-
5909-When the end-marker is not present, OpenWRT won't save the overlayfs
5910-after initial flash.
5911-
5912-Reported-by: Andreas Ziegler <dev@andreas-ziegler.de>
5913-Signed-off-by: David Bauer <mail@david-bauer.net>
5914-
5915-diff --git a/target/linux/ramips/image/mt76x8.mk b/target/linux/ramips/image/mt76x8.mk
5916-index f1bf78e0713a1bc47d4ac384efdac1d08c1bd8bc..a096720b09be18bae450edaab187df8be734fe13 100644
5917---- a/target/linux/ramips/image/mt76x8.mk
5918-+++ b/target/linux/ramips/image/mt76x8.mk
5919-@@ -118,7 +118,7 @@ define Device/netgear_r6120
5920- IMAGES += factory.img
5921- IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE)| append-rootfs | pad-rootfs
5922- IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | check-size $$$$(IMAGE_SIZE)
5923-- IMAGE/factory.img := pad-extra 576k | $$(IMAGE/default) | \
5924-+ IMAGE/factory.img := pad-extra 576k | $$(IMAGE/default) | pad-to $$$$(BLOCKSIZE) | \
5925- sercom-footer | pad-to 128 | zip R6120.bin | sercom-seal
5926- endef
5927- TARGET_DEVICES += netgear_r6120
5928diff --git a/patches/openwrt/0022-firmware-utils-tplink-safeloader-Add-CPE210-v3.patch b/patches/openwrt/0022-firmware-utils-tplink-safeloader-Add-CPE210-v3.patch
5929deleted file mode 100644
5930index 71b394ea..00000000
5931--- a/patches/openwrt/0022-firmware-utils-tplink-safeloader-Add-CPE210-v3.patch
5932+++ /dev/null
5933@@ -1,58 +0,0 @@
5934-From: Adrian Schmutzler <freifunk@adrianschmutzler.de>
5935-Date: Wed, 10 Oct 2018 20:05:53 +0200
5936-Subject: firmware-utils: tplink-safeloader: Add CPE210 v3
5937-
5938-Add TP-Link CPE210 v3 to the support list.
5939-It's identical to the v2.
5940-
5941-Signed-off-by: Robert Marko <robimarko@gmail.com>
5942-[Use separate definition to prevent cross-updates]
5943-Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
5944-
5945-diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c
5946-index 4b227e1c97b6c5b236dba29dbdd5f0bcd68621cb..de15faf6796c993efc6c2a36b22bb1e978e3be90 100644
5947---- a/tools/firmware-utils/src/tplink-safeloader.c
5948-+++ b/tools/firmware-utils/src/tplink-safeloader.c
5949-@@ -197,6 +197,42 @@ static struct device_info boards[] = {
5950- .last_sysupgrade_partition = "support-list",
5951- },
5952-
5953-+ /** Firmware layout for the CPE210 V3 */
5954-+ {
5955-+ .id = "CPE210V3",
5956-+ .vendor = "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n",
5957-+ .support_list =
5958-+ "SupportList:\r\n"
5959-+ "CPE210(TP-LINK|EU|N300-2|45550000):3.0\r\n"
5960-+ "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n"
5961-+ "CPE210(TP-LINK|UN|N300-2):3.0\r\n"
5962-+ "CPE210(TP-LINK|EU|N300-2):3.0\r\n",
5963-+ .support_trail = '\xff',
5964-+ .soft_ver = NULL,
5965-+
5966-+ .partitions = {
5967-+ {"fs-uboot", 0x00000, 0x20000},
5968-+ {"partition-table", 0x20000, 0x02000},
5969-+ {"default-mac", 0x30000, 0x00020},
5970-+ {"product-info", 0x31100, 0x00100},
5971-+ {"device-info", 0x31400, 0x00400},
5972-+ {"signature", 0x32000, 0x00400},
5973-+ {"device-id", 0x33000, 0x00100},
5974-+ {"os-image", 0x40000, 0x1c0000},
5975-+ {"file-system", 0x200000, 0x5b0000},
5976-+ {"soft-version", 0x7b0000, 0x00100},
5977-+ {"support-list", 0x7b1000, 0x01000},
5978-+ {"user-config", 0x7c0000, 0x10000},
5979-+ {"default-config", 0x7d0000, 0x10000},
5980-+ {"log", 0x7e0000, 0x10000},
5981-+ {"radio", 0x7f0000, 0x10000},
5982-+ {NULL, 0, 0}
5983-+ },
5984-+
5985-+ .first_sysupgrade_partition = "os-image",
5986-+ .last_sysupgrade_partition = "support-list",
5987-+ },
5988-+
5989- /** Firmware layout for the CPE510/520 */
5990- {
5991- .id = "CPE510",
5992diff --git a/patches/openwrt/0023-ar71xx-Add-support-for-TP-Link-CPE210-v3.patch b/patches/openwrt/0023-ar71xx-Add-support-for-TP-Link-CPE210-v3.patch
5993deleted file mode 100644
5994index 20213733..00000000
5995--- a/patches/openwrt/0023-ar71xx-Add-support-for-TP-Link-CPE210-v3.patch
5996+++ /dev/null
5997@@ -1,141 +0,0 @@
5998-From: Adrian Schmutzler <freifunk@adrianschmutzler.de>
5999-Date: Wed, 10 Oct 2018 20:13:09 +0200
6000-Subject: ar71xx: Add support for TP-Link CPE210 v3
6001-
6002-Looks identical to the v2
6003-
6004-This PR adds support for a popular low-cost 2.4GHz N based AP
6005-
6006-Specifications:
6007- - SoC: Qualcomm Atheros QCA9533 (650MHz)
6008- - RAM: 64MB
6009- - Storage: 8 MB SPI NOR
6010- - Wireless: 2.4GHz N based built into SoC 2x2
6011- - Ethernet: 1x 100/10 Mbps, integrated into SoC, 24V POE IN
6012-
6013-Installation:
6014-Flash factory image through stock firmware WEB UI or
6015-through TFTP
6016-To get to TFTP recovery just hold reset button while
6017-powering on for around 4-5 seconds and release.
6018-Rename factory image to recovery.bin
6019-Stock TFTP server IP:192.168.0.100
6020-Stock device TFTP address:192.168.0.254
6021-
6022-Signed-off-by: Robert Marko <robimarko@gmail.com>
6023-[Adjusted for separate safeloader entry, do not inherit device
6024-definition from cpe210-v2]
6025-Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
6026-
6027-diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds b/target/linux/ar71xx/base-files/etc/board.d/01_leds
6028-index 23f3d23bf53883fb08944bc65b98cac06a16c0a5..e0222f3637b60b89a6ef6c0d10cfb20fbe73f075 100755
6029---- a/target/linux/ar71xx/base-files/etc/board.d/01_leds
6030-+++ b/target/linux/ar71xx/base-files/etc/board.d/01_leds
6031-@@ -249,6 +249,7 @@ cf-e530n)
6032- ;;
6033- cpe210|\
6034- cpe210-v2|\
6035-+cpe210-v3|\
6036- cpe510|\
6037- wbs210|\
6038- wbs510)
6039-@@ -259,7 +260,8 @@ wbs510)
6040- ucidef_set_led_rssi "rssihigh" "RSSIHIGH" "tp-link:green:link4" "wlan0" "76" "100" "-75" "13"
6041-
6042- case "$board" in
6043-- cpe210-v2)
6044-+ cpe210-v2|\
6045-+ cpe210-v3)
6046- ucidef_set_led_netdev "lan" "LAN" "tp-link:green:lan0" "eth0"
6047- ;;
6048- *)
6049-diff --git a/target/linux/ar71xx/base-files/etc/board.d/02_network b/target/linux/ar71xx/base-files/etc/board.d/02_network
6050-index e9522252a2b8ba7de1c8ca7d070ff7f2897aade9..386d93e58451b953937320b1bfe8d71ed73c69fd 100755
6051---- a/target/linux/ar71xx/base-files/etc/board.d/02_network
6052-+++ b/target/linux/ar71xx/base-files/etc/board.d/02_network
6053-@@ -75,6 +75,7 @@ ar71xx_setup_interfaces()
6054- cf-e380ac-v1|\
6055- cf-e380ac-v2|\
6056- cpe210-v2|\
6057-+ cpe210-v3|\
6058- dr342|\
6059- eap120|\
6060- eap300v2|\
6061-diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
6062-index ccbd4e77c324a36e7fba6e6dccad59d8f94a3921..2200069c647b33220126e797b6a61928d1fb428e 100755
6063---- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
6064-+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
6065-@@ -583,6 +583,10 @@ ar71xx_board_detect() {
6066- name="cpe210-v2"
6067- tplink_pharos_board_detect "$(tplink_pharos_v2_get_model_string)"
6068- ;;
6069-+ *"CPE210 v3")
6070-+ name="cpe210-v3"
6071-+ tplink_pharos_board_detect "$(tplink_pharos_v2_get_model_string)"
6072-+ ;;
6073- *"CPE505N")
6074- name="cpe505n"
6075- ;;
6076-diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
6077-index ca1270b7fdc84c53f8417c226f18ca4fff1f27d8..a04dd7441d28e9db4dc7c744707bb5f35936da00 100755
6078---- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
6079-+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
6080-@@ -587,7 +587,8 @@ platform_check_image() {
6081- tplink_pharos_check_image "$1" "7f454c46" "$(tplink_pharos_get_model_string)" '' && return 0
6082- return 1
6083- ;;
6084-- cpe210-v2)
6085-+ cpe210-v2|\
6086-+ cpe210-v3)
6087- tplink_pharos_check_image "$1" "01000000" "$(tplink_pharos_v2_get_model_string)" '\0\xff\r' && return 0
6088- return 1
6089- ;;
6090-diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-cpe510.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-cpe510.c
6091-index ceb1769ddd522d51014228fe65e2662f2f3e627c..f25a69f08e8a69d9b6de0ca9d7d7d14f8dff5fa0 100644
6092---- a/target/linux/ar71xx/files/arch/mips/ath79/mach-cpe510.c
6093-+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-cpe510.c
6094-@@ -236,6 +236,9 @@ MIPS_MACHINE(ATH79_MACH_CPE210, "CPE210", "TP-LINK CPE210/220",
6095- MIPS_MACHINE(ATH79_MACH_CPE210_V2, "CPE210V2", "TP-LINK CPE210 v2",
6096- cpe210_v2_setup);
6097-
6098-+MIPS_MACHINE(ATH79_MACH_CPE210_V3, "CPE210V3", "TP-LINK CPE210 v3",
6099-+ cpe210_v2_setup);
6100-+
6101- MIPS_MACHINE(ATH79_MACH_CPE510, "CPE510", "TP-LINK CPE510/520",
6102- cpe510_setup);
6103-
6104-diff --git a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
6105-index 80f6e1d95b7a4e5559e7d5da041b32d962ad4e84..c82cb17cf613bdb3796a15e384215d4579767468 100644
6106---- a/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
6107-+++ b/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
6108-@@ -75,6 +75,7 @@ enum ath79_mach_type {
6109- ATH79_MACH_CF_E530N, /* COMFAST CF-E530N */
6110- ATH79_MACH_CPE210, /* TP-LINK CPE210 v1 */
6111- ATH79_MACH_CPE210_V2, /* TP-LINK CPE210 v2 */
6112-+ ATH79_MACH_CPE210_V3, /* TP-LINK CPE210 v3 */
6113- ATH79_MACH_CPE505N, /* P&W CPE505N */
6114- ATH79_MACH_CPE510, /* TP-LINK CPE510 */
6115- ATH79_MACH_CPE830, /* YunCore CPE830 */
6116-diff --git a/target/linux/ar71xx/image/generic-tp-link.mk b/target/linux/ar71xx/image/generic-tp-link.mk
6117-index daf6c35ae4610d844bd9e8f44ea5deab72143a48..8ad1f6e38228b639d1d127937ba875c030a6a632 100644
6118---- a/target/linux/ar71xx/image/generic-tp-link.mk
6119-+++ b/target/linux/ar71xx/image/generic-tp-link.mk
6120-@@ -195,6 +195,18 @@ define Device/cpe210-v2
6121- endef
6122- TARGET_DEVICES += cpe210-v2
6123-
6124-+define Device/cpe210-v3
6125-+ $(Device/cpexxx)
6126-+ DEVICE_TITLE := TP-LINK CPE210 v3
6127-+ BOARDNAME := CPE210V3
6128-+ TPLINK_BOARD_ID := CPE210V3
6129-+ KERNEL := kernel-bin | patch-cmdline | lzma | tplink-v1-header
6130-+ TPLINK_HWID := 0x0
6131-+ TPLINK_HWREV := 0
6132-+ TPLINK_HEADER_VERSION := 1
6133-+endef
6134-+TARGET_DEVICES += cpe210-v3
6135-+
6136- define Device/wbs210-v1
6137- $(Device/cpe510-520-v1)
6138- DEVICE_TITLE := TP-LINK WBS210 v1
6139diff --git a/patches/openwrt/0024-ramips-add-support-for-ASUS-RT-AC57U.patch b/patches/openwrt/0024-ramips-add-support-for-ASUS-RT-AC57U.patch
6140deleted file mode 100644
6141index 67bf6a9a..00000000
6142--- a/patches/openwrt/0024-ramips-add-support-for-ASUS-RT-AC57U.patch
6143+++ /dev/null
6144@@ -1,292 +0,0 @@
6145-From: David Bauer <mail@david-bauer.net>
6146-Date: Sun, 23 Jun 2019 15:10:01 +0200
6147-Subject: ramips: add support for ASUS RT-AC57U
6148-
6149-SoC: MediaTek MT7621AT
6150-RAM: 128M (Winbond W631GG6KB-15)
6151-FLASH: 16MB (Spansion S25FL128SA)
6152-WiFi: MediaTek MT7603EN bgn 2SS
6153-WiFi: MediaTek MT7612EN nac 2SS
6154-BTN: Reset - WPS
6155-LED: - Power
6156- - LAN {1-4}
6157- - WAN
6158- - WiFi 2.4 GHz
6159- - WiFi 5 GHz
6160- - USB
6161-UART: UART is present next to the Power LED.
6162- TX - RX - GND - 3V3 / 57600-8N1
6163- 3V3 is the nearest one to the Power LED.
6164-
6165-Installation
6166-------------
6167-Via TFTP:
6168-1. Set your computers IP-Address to 192.168.1.75.
6169-2. Power up the Router with the Reset button pressed.
6170-3. Release the Reset button after 5 seconds.
6171-4. Upload OpenWRT sysupgrade image via TFTP:
6172- > tftp -4 -v -m binary 192.168.1.1 -c put <IMAGE>
6173-
6174-Via SSH:
6175-Note: User/password for SSH is identical with the one used in the
6176-Web-interface.
6177-1. Complete the initial setup wizard.
6178-2. Activate SSH under "Administration" -> "System".
6179-3. Transfer the OpenWrt sysupgrade image via scp:
6180- > scp owrt.bin admin@192.168.1.1:/tmp
6181-4. Connect via SSH to the router.
6182- > ssh admin@192.168.1.1
6183-5. Write the OpenWrt image to flash.
6184- > mtd-write -i /tmp/owrt.bin -d linux
6185-6. Reboot the router
6186- > reboot
6187-
6188-Signed-off-by: David Bauer <mail@david-bauer.net>
6189-
6190-diff --git a/target/linux/ramips/base-files/etc/board.d/02_network b/target/linux/ramips/base-files/etc/board.d/02_network
6191-index 9424c7ddfd64f9149a24ff91e63b71990265d211..7ceec7742aa7a0248ea3c31053b9adda2b247c9c 100755
6192---- a/target/linux/ramips/base-files/etc/board.d/02_network
6193-+++ b/target/linux/ramips/base-files/etc/board.d/02_network
6194-@@ -186,6 +186,7 @@ ramips_setup_interfaces()
6195- ucidef_add_switch "switch0" \
6196- "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
6197- ;;
6198-+ asus,rt-ac57u|\
6199- atp-52b|\
6200- awm002-evb-4M|\
6201- awm002-evb-8M|\
6202-@@ -413,6 +414,11 @@ ramips_setup_macs()
6203- wmdr-143n)
6204- lan_mac=$(cat /sys/class/net/eth0/address)
6205- ;;
6206-+ asus,rt-ac57u|\
6207-+ vr500)
6208-+ lan_mac=$(mtd_get_mac_binary factory 57344)
6209-+ wan_mac=$(mtd_get_mac_binary factory 57350)
6210-+ ;;
6211- all0239-3g|\
6212- carambola|\
6213- freestation5|\
6214-@@ -541,10 +547,6 @@ ramips_setup_macs()
6215- lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
6216- wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
6217- ;;
6218-- vr500)
6219-- lan_mac=$(mtd_get_mac_binary factory 57344)
6220-- wan_mac=$(mtd_get_mac_binary factory 57350)
6221-- ;;
6222- w306r-v20)
6223- lan_mac=$(cat /sys/class/net/eth0/address)
6224- wan_mac=$(macaddr_add "$lan_mac" 5)
6225-diff --git a/target/linux/ramips/base-files/etc/diag.sh b/target/linux/ramips/base-files/etc/diag.sh
6226-index 097cc6df569518f64dbfd641eeccc1a4b1b37a2b..16e482c3879ff727faea9ffde31da634004fee93 100644
6227---- a/target/linux/ramips/base-files/etc/diag.sh
6228-+++ b/target/linux/ramips/base-files/etc/diag.sh
6229-@@ -141,6 +141,7 @@ get_status_led() {
6230- youhua,wr1200js)
6231- status_led="$boardname:blue:wps"
6232- ;;
6233-+ asus,rt-ac57u|\
6234- d240|\
6235- dap-1350|\
6236- na930|\
6237-diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh b/target/linux/ramips/base-files/lib/upgrade/platform.sh
6238-index 7213b22d0c2734488bd96bc34e921f08649b8c2f..e4d813341b0e4d1ac804ee8cf0ec258e9c08fcd1 100755
6239---- a/target/linux/ramips/base-files/lib/upgrade/platform.sh
6240-+++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh
6241-@@ -27,6 +27,7 @@ platform_check_image() {
6242- ar725w|\
6243- asl26555-8M|\
6244- asl26555-16M|\
6245-+ asus,rt-ac57u|\
6246- awapn2403|\
6247- awm002-evb-4M|\
6248- awm002-evb-8M|\
6249-diff --git a/target/linux/ramips/dts/RT-AC57U.dts b/target/linux/ramips/dts/RT-AC57U.dts
6250-new file mode 100644
6251-index 0000000000000000000000000000000000000000..cdab94676e13d259eb80afbcb28347d75d1f08f6
6252---- /dev/null
6253-+++ b/target/linux/ramips/dts/RT-AC57U.dts
6254-@@ -0,0 +1,150 @@
6255-+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
6256-+/dts-v1/;
6257-+
6258-+#include "mt7621.dtsi"
6259-+
6260-+#include <dt-bindings/gpio/gpio.h>
6261-+#include <dt-bindings/input/input.h>
6262-+
6263-+/ {
6264-+ compatible = "asus,rt-ac57u", "mediatek,mt7621-soc";
6265-+ model = "ASUS RT-AC57U";
6266-+
6267-+ aliases {
6268-+ led-boot = &led_power;
6269-+ led-failsafe = &led_power;
6270-+ led-running = &led_power;
6271-+ led-upgrade = &led_power;
6272-+ };
6273-+
6274-+ memory@0 {
6275-+ device_type = "memory";
6276-+ reg = <0x0 0x8000000>;
6277-+ };
6278-+
6279-+ chosen {
6280-+ bootargs = "console=ttyS0,57600";
6281-+ };
6282-+
6283-+ leds {
6284-+ compatible = "gpio-leds";
6285-+
6286-+ led_power: power {
6287-+ label = "rt-ac57u:blue:power";
6288-+ gpios = <&gpio1 16 GPIO_ACTIVE_LOW>;
6289-+ };
6290-+
6291-+ usb {
6292-+ label = "rt-ac57u:blue:usb";
6293-+ gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
6294-+ };
6295-+ };
6296-+
6297-+ keys {
6298-+ compatible = "gpio-keys-polled";
6299-+ poll-interval = <20>;
6300-+
6301-+ wps {
6302-+ label = "wps";
6303-+ gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>;
6304-+ linux,code = <KEY_WPS_BUTTON>;
6305-+ };
6306-+
6307-+ reset {
6308-+ label = "reset";
6309-+ gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
6310-+ linux,code = <KEY_RESTART>;
6311-+ };
6312-+ };
6313-+
6314-+ led-regulator {
6315-+ compatible = "regulator-fixed";
6316-+ regulator-name = "LED-Power";
6317-+ gpio = <&gpio1 14 GPIO_ACTIVE_LOW>;
6318-+ regulator-min-microvolt = <3300000>;
6319-+ regulator-max-microvolt = <3300000>;
6320-+ regulator-always-on;
6321-+ };
6322-+};
6323-+
6324-+&spi0 {
6325-+ status = "okay";
6326-+
6327-+ flash@0 {
6328-+ compatible = "jedec,spi-nor";
6329-+ reg = <0>;
6330-+ spi-max-frequency = <10000000>;
6331-+
6332-+ partitions {
6333-+ compatible = "fixed-partitions";
6334-+ #address-cells = <1>;
6335-+ #size-cells = <1>;
6336-+
6337-+ partition@0 {
6338-+ label = "u-boot";
6339-+ reg = <0x0 0x30000>;
6340-+ read-only;
6341-+ };
6342-+
6343-+ partition@30000 {
6344-+ label = "config";
6345-+ reg = <0x30000 0x10000>;
6346-+ read-only;
6347-+ };
6348-+
6349-+ factory: partition@40000 {
6350-+ label = "factory";
6351-+ reg = <0x40000 0x10000>;
6352-+ read-only;
6353-+ };
6354-+
6355-+ partition@50000 {
6356-+ compatible = "denx,uimage";
6357-+ label = "firmware";
6358-+ reg = <0x50000 0xfb0000>;
6359-+ };
6360-+ };
6361-+ };
6362-+};
6363-+
6364-+&pcie {
6365-+ status = "okay";
6366-+
6367-+ pcie0 {
6368-+ wifi@0,0 {
6369-+ reg = <0x0000 0 0 0 0>;
6370-+ mediatek,mtd-eeprom = <&factory 0x8000>;
6371-+ device_type = "pci";
6372-+
6373-+ led {
6374-+ led-sources = <2>;
6375-+ led-active-low;
6376-+ };
6377-+ };
6378-+ };
6379-+
6380-+ pcie1 {
6381-+ wifi@0,0 {
6382-+ reg = <0x0000 0 0 0 0>;
6383-+ mediatek,mtd-eeprom = <&factory 0x0000>;
6384-+ device_type = "pci";
6385-+
6386-+ led {
6387-+ led-active-low;
6388-+ };
6389-+ };
6390-+ };
6391-+};
6392-+
6393-+ðernet {
6394-+ mtd-mac-address = <&factory 0x4e000>;
6395-+};
6396-+
6397-+&pinctrl {
6398-+ state_default: pinctrl0 {
6399-+ gpio {
6400-+ ralink,group = "sdhci";
6401-+ ralink,function = "gpio";
6402-+ };
6403-+ };
6404-+};
6405-diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
6406-index c8de8bd5ff7d1bec4de5c4ffd84a589892871ecb..e0f8cc65ebbfc93b4bfd765db5e62b5afda27c40 100644
6407---- a/target/linux/ramips/image/mt7621.mk
6408-+++ b/target/linux/ramips/image/mt7621.mk
6409-@@ -49,6 +49,14 @@ define Device/11acnas
6410- endef
6411- TARGET_DEVICES += 11acnas
6412-
6413-+define Device/asus_rt-ac57u
6414-+ DTS := RT-AC57U
6415-+ DEVICE_TITLE := ASUS RT-AC57U
6416-+ IMAGE_SIZE := $(ralink_default_fw_size_16M)
6417-+ DEVICE_PACKAGES := kmod-mt7603 kmod-mt76x2 kmod-usb3 kmod-usb-ledtrig-usbport wpad-basic
6418-+endef
6419-+TARGET_DEVICES += asus_rt-ac57u
6420-+
6421- define Device/dir-860l-b1
6422- DTS := DIR-860L-B1
6423- BLOCKSIZE := 64k
6424-diff --git a/target/linux/ramips/mt7621/config-4.14 b/target/linux/ramips/mt7621/config-4.14
6425-index 2ea80a3ab0c174374fa8febc19031ff5a4dae4c3..0e060237802f2b1d6918f65894368934c225cb17 100644
6426---- a/target/linux/ramips/mt7621/config-4.14
6427-+++ b/target/linux/ramips/mt7621/config-4.14
6428-@@ -228,6 +228,8 @@ CONFIG_RCU_STALL_COMMON=y
6429- CONFIG_REGMAP=y
6430- CONFIG_REGMAP_I2C=y
6431- CONFIG_REGMAP_SPI=y
6432-+CONFIG_REGULATOR=y
6433-+CONFIG_REGULATOR_FIXED_VOLTAGE=y
6434- CONFIG_RESET_CONTROLLER=y
6435- CONFIG_RFS_ACCEL=y
6436- CONFIG_RPS=y
6437diff --git a/patches/openwrt/0025-uboot-fritz4040-add-fixes-for-bootloader-image-generation.patch b/patches/openwrt/0025-uboot-fritz4040-add-fixes-for-bootloader-image-generation.patch
6438deleted file mode 100644
6439index 06cd5209..00000000
6440--- a/patches/openwrt/0025-uboot-fritz4040-add-fixes-for-bootloader-image-generation.patch
6441+++ /dev/null
6442@@ -1,111 +0,0 @@
6443-From: Matthias Schiffer <mschiffer@universe-factory.net>
6444-Date: Sat, 20 Jul 2019 13:12:58 +0200
6445-Subject: uboot-fritz4040: add fixes for bootloader image generation
6446-
6447-Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
6448-
6449-diff --git a/package/boot/uboot-fritz4040/patches/200-fritzcreator-replace-obscure-padding-generation-with.patch b/package/boot/uboot-fritz4040/patches/200-fritzcreator-replace-obscure-padding-generation-with.patch
6450-new file mode 100644
6451-index 0000000000000000000000000000000000000000..44062b88048f483b618992c51b1dffdfe7ca511a
6452---- /dev/null
6453-+++ b/package/boot/uboot-fritz4040/patches/200-fritzcreator-replace-obscure-padding-generation-with.patch
6454-@@ -0,0 +1,63 @@
6455-+From 9af24ea29494a279eba01d2b284c9c94d4fdb267 Mon Sep 17 00:00:00 2001
6456-+Message-Id: <9af24ea29494a279eba01d2b284c9c94d4fdb267.1563619497.git.mschiffer@universe-factory.net>
6457-+From: Matthias Schiffer <mschiffer@universe-factory.net>
6458-+Date: Sat, 20 Jul 2019 12:35:01 +0200
6459-+Subject: [PATCH 1/2] fritzcreator: replace obscure padding generation with
6460-+ something more compatible
6461-+
6462-+It as reported that OpenWrt/Gluon would sometimes generate invalid
6463-+bootloader images with insufficient for the FritzBox 4040, presumably
6464-+depending on the distro version used on the build host.
6465-+
6466-+This commit tries to fix this by replacing the printf-based padding
6467-+generation (that in one case relies on 65536 arguments being passed to the
6468-+printf command) with a more compatible read from /dev/zero.
6469-+
6470-+[1] https://github.com/freifunk-gluon/gluon/issues/1766
6471-+---
6472-+ fritz/fritzcreator.sh | 8 ++++----
6473-+ 1 file changed, 4 insertions(+), 4 deletions(-)
6474-+
6475-+diff --git a/fritz/fritzcreator.sh b/fritz/fritzcreator.sh
6476-+index 8ed0c08cc5ed..8ea412e5aca5 100755
6477-+--- a/fritz/fritzcreator.sh
6478-++++ b/fritz/fritzcreator.sh
6479-+@@ -55,7 +55,7 @@ cat "$FRITZ_DTB" "$FRITZ_DTB" "$FRITZ_DTB" "$FRITZ_DTB" >> $UBOOT_FRITZ4040
6480-+ rm -f "$FRITZ_DTB"
6481-+
6482-+ # Add 512 bytes of pad area
6483-+-printf "%0.s\0" {1..512} >> $UBOOT_FRITZ4040
6484-++dd if=/dev/zero bs=512 count=1 >> $UBOOT_FRITZ4040
6485-+
6486-+ # This table links to the individual DTBs for every HWSubRevision.
6487-+ # A table entry consists of two 32-bit words.
6488-+@@ -84,7 +84,7 @@ mv "$UBOOT_FRITZ4040.new" "$UBOOT_FRITZ4040"
6489-+
6490-+
6491-+ # Add 64k bytes of pad area
6492-+-printf "%0.s\0" {1..65536} >> $UBOOT_FRITZ4040
6493-++dd if=/dev/zero bs=1024 count=64 >> $UBOOT_FRITZ4040
6494-+
6495-+ # Pack it with lzma
6496-+ fritz/lzma e "$UBOOT_FRITZ4040" -lc1 -lp2 -pb2 "$UBOOT_FRITZ4040.new"
6497-+@@ -99,7 +99,7 @@ fritz/lzma2eva $UBOOT_LOADADDR $UBOOT_LOADADDR "$UBOOT_FRITZ4040.new" "$UBOOT_FR
6498-+ # The next bit. The hshqs partition should be aligned to 0x100
6499-+ let size=$(stat -c%s "$UBOOT_FRITZ4040")
6500-+ let "pad = 256 - ( $size % 256) % 256"
6501-+-( printf "%0.s\377" {1..256} | dd conv=sync bs=$pad count=1 ) > $UBOOT_FRITZ4040.pad
6502-++dd if=/dev/zero bs=$pad count=1 | tr '\0' '\377' > $UBOOT_FRITZ4040.pad
6503-+
6504-+ cat "$UBOOT_FRITZ4040" "$UBOOT_FRITZ4040.pad" > $UBOOT_FRITZ4040.new
6505-+
6506-+@@ -109,7 +109,7 @@ rm -f "$UBOOT_FRITZ4040.pad"
6507-+
6508-+ # Apparently, EVA checks for the SquashFS filesystem MAGIC too. Likely for the rootfs
6509-+ # entry.
6510-+-(cat "$UBOOT_FRITZ4040"; echo "hsqs"; printf "%0.s\0" {1..124} ) > $UBOOT_FRITZ4040.new
6511-++(cat "$UBOOT_FRITZ4040"; echo "hsqs"; dd if=/dev/zero bs=124 count=1 ) > $UBOOT_FRITZ4040.new
6512-+
6513-+ # Make it so that this fits into 512k (Note: we have to add 8 Bytes for the final checksum
6514-+ # so 524280 is 512k - 8.
6515-+--
6516-+2.22.0
6517-+
6518-diff --git a/package/boot/uboot-fritz4040/patches/201-fritzcreator-actually-add-checksum-spacer.patch b/package/boot/uboot-fritz4040/patches/201-fritzcreator-actually-add-checksum-spacer.patch
6519-new file mode 100644
6520-index 0000000000000000000000000000000000000000..f92060a23312a4961ddc75716fd06b9d6a106a1d
6521---- /dev/null
6522-+++ b/package/boot/uboot-fritz4040/patches/201-fritzcreator-actually-add-checksum-spacer.patch
6523-@@ -0,0 +1,30 @@
6524-+From dd05d1bb619b372e4717a74da560450dd93d4c3b Mon Sep 17 00:00:00 2001
6525-+Message-Id: <dd05d1bb619b372e4717a74da560450dd93d4c3b.1563619497.git.mschiffer@universe-factory.net>
6526-+In-Reply-To: <9af24ea29494a279eba01d2b284c9c94d4fdb267.1563619497.git.mschiffer@universe-factory.net>
6527-+References: <9af24ea29494a279eba01d2b284c9c94d4fdb267.1563619497.git.mschiffer@universe-factory.net>
6528-+From: Matthias Schiffer <mschiffer@universe-factory.net>
6529-+Date: Sat, 20 Jul 2019 12:43:48 +0200
6530-+Subject: [PATCH 2/2] fritzcreator: actually add checksum spacer
6531-+
6532-+The spacer was written to $UBOOT_FRITZ4040.new, but this file was not used
6533-+at all before it was overwritten again.
6534-+---
6535-+ fritz/fritzcreator.sh | 2 +-
6536-+ 1 file changed, 1 insertion(+), 1 deletion(-)
6537-+
6538-+diff --git a/fritz/fritzcreator.sh b/fritz/fritzcreator.sh
6539-+index 8ea412e5aca5..ea5a50df1f87 100755
6540-+--- a/fritz/fritzcreator.sh
6541-++++ b/fritz/fritzcreator.sh
6542-+@@ -94,7 +94,7 @@ fritz/lzma2eva $UBOOT_LOADADDR $UBOOT_LOADADDR "$UBOOT_FRITZ4040.new" "$UBOOT_FR
6543-+
6544-+ # The bootloader seems to add a TI checksum signature (8 Bytes) as part of the
6545-+ # "check mtd1" command in the FTP prompt. To make this easier we add spacer here.
6546-+-(cat "$UBOOT_FRITZ4040"; printf "\xff\xff\xff\xff\xff\xff\xff\xff" ) > $UBOOT_FRITZ4040.new
6547-++printf "\xff\xff\xff\xff\xff\xff\xff\xff" >> $UBOOT_FRITZ4040
6548-+
6549-+ # The next bit. The hshqs partition should be aligned to 0x100
6550-+ let size=$(stat -c%s "$UBOOT_FRITZ4040")
6551-+--
6552-+2.22.0
6553-+
6554diff --git a/patches/packages/routing/0002-batctl-remove-kmod-batman-adv-dependency.patch b/patches/packages/routing/0002-batctl-remove-kmod-batman-adv-dependency.patch
6555deleted file mode 100644
6556index dc3b4b63..00000000
6557--- a/patches/packages/routing/0002-batctl-remove-kmod-batman-adv-dependency.patch
6558+++ /dev/null
6559@@ -1,22 +0,0 @@
6560-From: Linus Lüssing <linus.luessing@c0d3.blue>
6561-Date: Mon, 18 Feb 2019 18:28:03 +0100
6562-Subject: batctl: remove kmod-batman-adv dependency
6563-
6564-This always pulls in the batman-adv compat 15 kernel module. However,
6565-batctl works just as well with batman-adv-legacy (compat 14).
6566-
6567-Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
6568-
6569-diff --git a/batctl/Makefile b/batctl/Makefile
6570-index 4e67512844d07607852a5447a336dc9f93f5990a..df96ca7325ba3f84bd682da6df32fa4489474113 100644
6571---- a/batctl/Makefile
6572-+++ b/batctl/Makefile
6573-@@ -23,7 +23,7 @@ define Package/batctl
6574- URL:=https://www.open-mesh.org/
6575- SECTION:=net
6576- CATEGORY:=Network
6577-- DEPENDS:=+kmod-batman-adv +libnl-tiny +libc +librt
6578-+ DEPENDS:=+libnl-tiny +libc +librt
6579- TITLE:=B.A.T.M.A.N. Advanced user space configuration tool batctl
6580- MAINTAINER:=Simon Wunderlich <sw@simonwunderlich.de>
6581- endef
6582diff --git a/patches/packages/routing/0003-batman-adv-remove-module-autoload.patch b/patches/packages/routing/0003-batman-adv-remove-module-autoload.patch
6583deleted file mode 100644
6584index cd7a809f..00000000
6585--- a/patches/packages/routing/0003-batman-adv-remove-module-autoload.patch
6586+++ /dev/null
6587@@ -1,21 +0,0 @@
6588-From: Linus Lüssing <linus.luessing@c0d3.blue>
6589-Date: Sun, 16 Jun 2019 00:01:36 +0200
6590-Subject: batman-adv: remove module autoload
6591-
6592-Instead of unconditionally loading this module on boot the gluon_bat0
6593-netifd protocol script will later take care of loading either the batman-adv
6594-or batman-adv-legacy module, depending on the configured routing
6595-algorithm in UCI.
6596-
6597-diff --git a/batman-adv/Makefile b/batman-adv/Makefile
6598-index ae434909c90f61efdf0d80b56352c983cfef25b0..e58f862b0e5fac7ac12d6ba5a09241d23148a252 100644
6599---- a/batman-adv/Makefile
6600-+++ b/batman-adv/Makefile
6601-@@ -30,7 +30,6 @@ define KernelPackage/batman-adv
6602- DEPENDS:=+KMOD_BATMAN_ADV_BLA:kmod-lib-crc16 +kmod-crypto-crc32c +kmod-lib-crc32c +kmod-cfg80211
6603- TITLE:=B.A.T.M.A.N. Adv
6604- FILES:=$(PKG_BUILD_DIR)/net/batman-adv/batman-adv.$(LINUX_KMOD_SUFFIX)
6605-- AUTOLOAD:=$(call AutoProbe,batman-adv)
6606- endef
6607-
6608- define KernelPackage/batman-adv/description
6609diff --git a/targets/ar71xx-generic b/targets/ar71xx-generic
6610index c7c3d7fd..88c7b87d 100644
6611--- a/targets/ar71xx-generic
6612+++ b/targets/ar71xx-generic
6613@@ -2,10 +2,12 @@ config 'CONFIG_GLUON_SPECIALIZE_KERNEL=y'
6614 config 'CONFIG_TARGET_SQUASHFS_BLOCK_SIZE=64'
6615
6616 local ATH10K_PACKAGES = {}
6617+local ATH10K_PACKAGES_QCA9886 = {}
6618 local ATH10K_PACKAGES_QCA9887 = {}
6619-if env.GLUON_WLAN_MESH == 'ibss' then
6620- ATH10K_PACKAGES = {'-kmod-ath10k', 'kmod-ath10k-ct', '-ath10k-firmware-qca988x', 'ath10k-firmware-qca988x-ct'}
6621- ATH10K_PACKAGES_QCA9887 = {'-kmod-ath10k', 'kmod-ath10k-ct', '-ath10k-firmware-qca9887', 'ath10k-firmware-qca9887-ct'}
6622+if env.GLUON_WLAN_MESH == '11s' then
6623+ ATH10K_PACKAGES = {'kmod-ath10k', '-kmod-ath10k-ct', 'ath10k-firmware-qca988x', '-ath10k-firmware-qca988x-ct'}
6624+ ATH10K_PACKAGES_QCA9886 = {'kmod-ath10k', '-kmod-ath10k-ct', 'ath10k-firmware-qca9888', '-ath10k-firmware-qca9888-ct'}
6625+ ATH10K_PACKAGES_QCA9887 = {'kmod-ath10k', '-kmod-ath10k-ct', 'ath10k-firmware-qca9887', '-ath10k-firmware-qca9887-ct'}
6626 end
6627
6628
6629@@ -22,21 +24,6 @@ device('alfa-network-ap121f', 'ap121f', {
6630 factory = false,
6631 })
6632
6633-device('alfa-network-hornet-ub', 'hornet-ub', {
6634- profile = 'HORNETUB',
6635- aliases = { 'alfa-network-ap121', 'alfa-network-ap121u' },
6636- deprecated = true, -- kernel partition too small with OpenWrt 19.07
6637-})
6638-
6639-device('alfa-network-tube2h', 'tube2h-8M', {
6640- profile = 'TUBE2H8M',
6641- deprecated = true, -- kernel partition too small with OpenWrt 19.07
6642-})
6643-device('alfa-network-n2-n5', 'alfa-nx', {
6644- profile = 'ALFANX',
6645- deprecated = true, -- kernel partition too small with OpenWrt 19.07
6646-})
6647-
6648
6649 -- Allnet
6650
6651@@ -260,16 +247,26 @@ device('tp-link-cpe510-v1.0', 'cpe510-520-v1', {
6652 device('tp-link-wbs210-v1.20', 'wbs210-v1')
6653 device('tp-link-wbs510-v1.20', 'wbs510-v1')
6654
6655-device('tp-link-tl-wr710n-v1', 'tl-wr710n-v1')
6656-device('tp-link-tl-wr710n-v2.1', 'tl-wr710n-v2.1')
6657+device('tp-link-tl-wr710n-v1', 'tl-wr710n-v1', {
6658+ packages = { 'zram-swap' },
6659+})
6660+device('tp-link-tl-wr710n-v2.1', 'tl-wr710n-v2.1', {
6661+ packages = { 'zram-swap' },
6662+})
6663
6664 device('tp-link-tl-wr810n-v1', 'tl-wr810n-v1')
6665
6666-device('tp-link-tl-wr842n-nd-v1', 'tl-wr842n-v1')
6667-device('tp-link-tl-wr842n-nd-v2', 'tl-wr842n-v2')
6668+device('tp-link-tl-wr842n-nd-v1', 'tl-wr842n-v1', {
6669+ packages = { 'zram-swap' },
6670+})
6671+device('tp-link-tl-wr842n-nd-v2', 'tl-wr842n-v2', {
6672+ packages = { 'zram-swap' },
6673+})
6674 device('tp-link-tl-wr842n-nd-v3', 'tl-wr842n-v3')
6675
6676-device('tp-link-tl-wr1043n-nd-v1', 'tl-wr1043nd-v1')
6677+device('tp-link-tl-wr1043n-nd-v1', 'tl-wr1043nd-v1', {
6678+ packages = { 'zram-swap' },
6679+})
6680 device('tp-link-tl-wr1043n-nd-v2', 'tl-wr1043nd-v2')
6681 device('tp-link-tl-wr1043n-nd-v3', 'tl-wr1043nd-v3')
6682 device('tp-link-tl-wr1043n-nd-v4', 'tl-wr1043nd-v4')
6683@@ -304,22 +301,32 @@ device('tp-link-archer-c25-v1', 'archer-c25-v1', {
6684 })
6685
6686 device('tp-link-archer-c58-v1', 'archer-c58-v1', {
6687+ packages = ATH10K_PACKAGES_QCA9886,
6688 broken = true, -- OOM with 5GHz enabled in most environments
6689 })
6690
6691 device('tp-link-archer-c59-v1', 'archer-c59-v1', {
6692+ packages = ATH10K_PACKAGES_QCA9886,
6693 broken = (env.GLUON_WLAN_MESH ~= '11s'),
6694 })
6695
6696 device('tp-link-archer-c60-v1', 'archer-c60-v1', {
6697+ packages = ATH10K_PACKAGES_QCA9886,
6698+ broken = true, -- OOM with 5GHz enabled in most environments
6699+})
6700+
6701+device('tp-link-archer-c60-v2', 'archer-c60-v2', {
6702+ packages = ATH10K_PACKAGES_QCA9886,
6703 broken = true, -- OOM with 5GHz enabled in most environments
6704 })
6705
6706 device('tp-link-re355', 're355-v1', {
6707+ packages = ATH10K_PACKAGES,
6708 broken = true, -- OOM with 5GHz enabled in most environments if device is 64M RAM variant
6709 })
6710
6711 device('tp-link-tl-wr902ac-v1', 'tl-wr902ac-v1', {
6712+ packages = ATH10K_PACKAGES_QCA9887,
6713 broken = true, -- OOM due to insufficient RAM for ath10k expected
6714 })
6715
6716@@ -346,6 +353,7 @@ device('ubiquiti-bullet-m', 'ubnt-bullet-m', {
6717 'ubiquiti-bullet-m5',
6718 'ubiquiti-picostation-m2',
6719 },
6720+ packages = { 'zram-swap' },
6721 })
6722
6723 device('ubiquiti-rocket-m', 'ubnt-rocket-m', {
6724@@ -360,6 +368,7 @@ device('ubiquiti-nanostation-m', 'ubnt-nano-m', {
6725 'ubiquiti-nanostation-m2',
6726 'ubiquiti-nanostation-m5',
6727 },
6728+ packages = { 'zram-swap' },
6729 })
6730
6731 device('ubiquiti-loco-m-xw', 'ubnt-loco-m-xw', {
6732diff --git a/targets/ar71xx-nand b/targets/ar71xx-nand
6733index 3ba2671a..dcedccb8 100644
6734--- a/targets/ar71xx-nand
6735+++ b/targets/ar71xx-nand
6736@@ -1,8 +1,8 @@
6737 config 'CONFIG_GLUON_SPECIALIZE_KERNEL=y'
6738
6739 local ATH10K_PACKAGES = {}
6740-if env.GLUON_WLAN_MESH == 'ibss' then
6741- ATH10K_PACKAGES = {'-kmod-ath10k', 'kmod-ath10k-ct', '-ath10k-firmware-qca988x', 'ath10k-firmware-qca988x-ct'}
6742+if env.GLUON_WLAN_MESH == '11s' then
6743+ ATH10K_PACKAGES = {'kmod-ath10k', '-kmod-ath10k-ct', 'ath10k-firmware-qca988x', '-ath10k-firmware-qca988x-ct'}
6744 end
6745
6746
6747diff --git a/targets/generic b/targets/generic
6748index 72cc68b6..0153386d 100644
6749--- a/targets/generic
6750+++ b/targets/generic
6751@@ -64,6 +64,7 @@ packages {
6752 '-ppp',
6753 '-ppp-mod-pppoe',
6754 '-wpad-mini',
6755+ '-wpad-basic',
6756 'gluon-core',
6757 'ip6tables',
6758 }
6759diff --git a/targets/ipq40xx b/targets/ipq40xx
6760index f3c3c33b..e7a67f75 100644
6761--- a/targets/ipq40xx
6762+++ b/targets/ipq40xx
6763@@ -1,19 +1,19 @@
6764 local ATH10K_PACKAGES_IPQ40XX = {}
6765-local ATH10K_PACKAGES_IPQ40XX_QCA9888 = {'ath10k-firmware-qca9888'}
6766-if env.GLUON_WLAN_MESH == 'ibss' then
6767+local ATH10K_PACKAGES_IPQ40XX_QCA9888 = {}
6768+if env.GLUON_WLAN_MESH == '11s' then
6769 ATH10K_PACKAGES_IPQ40XX = {
6770- '-kmod-ath10k',
6771- 'kmod-ath10k-ct',
6772- '-ath10k-firmware-qca4019',
6773- 'ath10k-firmware-qca4019-ct',
6774+ 'kmod-ath10k',
6775+ '-kmod-ath10k-ct',
6776+ 'ath10k-firmware-qca4019',
6777+ '-ath10k-firmware-qca4019-ct',
6778 }
6779 ATH10K_PACKAGES_IPQ40XX_QCA9888 = {
6780- '-kmod-ath10k',
6781- 'kmod-ath10k-ct',
6782- '-ath10k-firmware-qca4019',
6783- 'ath10k-firmware-qca4019-ct',
6784- '-ath10k-firmware-qca9888',
6785- 'ath10k-firmware-qca9888-ct',
6786+ 'kmod-ath10k',
6787+ '-kmod-ath10k-ct',
6788+ 'ath10k-firmware-qca4019',
6789+ '-ath10k-firmware-qca4019-ct',
6790+ 'ath10k-firmware-qca9888',
6791+ '-ath10k-firmware-qca9888-ct',
6792 }
6793 end
6794
6795diff --git a/targets/lantiq-xrx200 b/targets/lantiq-xrx200
6796new file mode 100644
6797index 00000000..e1774b94
6798--- /dev/null
6799+++ b/targets/lantiq-xrx200
6800@@ -0,0 +1,3 @@
6801+device('avm-fritz-box-7412', 'avm_fritz7412', {
6802+ factory = false,
6803+})
6804diff --git a/targets/lantiq-xway b/targets/lantiq-xway
6805new file mode 100644
6806index 00000000..52e5c95f
6807--- /dev/null
6808+++ b/targets/lantiq-xway
6809@@ -0,0 +1,3 @@
6810+device('avm-fritz-box-7312', 'avm_fritz7312', {
6811+ factory = false,
6812+})
6813\ No newline at end of file
6814diff --git a/targets/mvebu-cortexa9 b/targets/mvebu-cortexa9
6815index bcd14907..1a5e640e 100644
6816--- a/targets/mvebu-cortexa9
6817+++ b/targets/mvebu-cortexa9
6818@@ -1,3 +1,3 @@
6819-device('linksys-wrt1200ac', 'linksys-wrt1200ac', {
6820+device('linksys-wrt1200ac', 'linksys_wrt1200ac', {
6821 factory_ext = '.img',
6822 })
6823diff --git a/targets/ramips-mt7621 b/targets/ramips-mt7621
6824index a0bb17c1..6808a3e6 100644
6825--- a/targets/ramips-mt7621
6826+++ b/targets/ramips-mt7621
6827@@ -43,12 +43,10 @@ device('zbt-wg3526-32m', 'zbt-wg3526-32M', {
6828
6829 device('ubnt-erx', 'ubnt-erx', {
6830 factory = false,
6831- sysupgrade_ext = '.tar',
6832 packages = {'-hostapd-mini'},
6833 })
6834
6835 device('ubnt-erx-sfp', 'ubnt-erx-sfp', {
6836 factory = false,
6837- sysupgrade_ext = '.tar',
6838 packages = {'-hostapd-mini'},
6839 })
6840diff --git a/targets/targets.mk b/targets/targets.mk
6841index 1f540829..a07f1c55 100644
6842--- a/targets/targets.mk
6843+++ b/targets/targets.mk
6844@@ -7,6 +7,8 @@ endif
6845 $(eval $(call GluonTarget,ar71xx,nand))
6846 $(eval $(call GluonTarget,brcm2708,bcm2708))
6847 $(eval $(call GluonTarget,brcm2708,bcm2709))
6848+$(eval $(call GluonTarget,lantiq,xway))
6849+$(eval $(call GluonTarget,lantiq,xrx200))
6850 $(eval $(call GluonTarget,mpc85xx,generic))
6851 $(eval $(call GluonTarget,mpc85xx,p1020))
6852 $(eval $(call GluonTarget,ramips,mt7621))