02-4a-v2.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. From 5dd566ff99d17b2c7e459001b4750bc911ee0d4c Mon Sep 17 00:00:00 2001
  2. From: Dmitry Sokolov <[email protected]>
  3. Date: Mon, 16 Jan 2023 02:52:27 +0500
  4. Subject: [PATCH] ramips: mt7621: add support for Xiaomi Mi Router 4A Gigabit
  5. v2
  6. Device is the same as Xiaomi Mi Router 4A Gigabit, except of:
  7. - 5G WiFi is MT7663
  8. - addresses of leds, wifi and eth ports are slightly changed
  9. Specs:
  10. SoC: MT7621
  11. CPU: 2 x 880 MHz
  12. ROM: 16 MB
  13. RAM: 128 MB
  14. WLAN: MT7603, MT7663
  15. MAC addresses:
  16. WAN **** factory 0xe006 (label)
  17. LAN *:f7 factory 0xe000
  18. 2.4 GHz *:f8 factory 0x0000+0x4 (mtd-eeprom+0x4)
  19. 5 GHz *:f9 factory 0x8000+0x4 (mtd-eeprom+0x4)
  20. Installation:
  21. Factory firmware is based on a custom OpenWrt 17.x.
  22. Installation is the same as for Xiaomi Mi Router 4A Gigabit.
  23. Probably the easiest way to install is to use the script from
  24. this repository: https://github.com/acecilia/OpenWRTInvasion/pull/155
  25. In a more advanced case, you can do everything yourself:
  26. - gain access to the device through one of the exploits described
  27. in the link above
  28. - upload sysupgrade image to /tmp
  29. - overwrite stock firmware:
  30. # mtd -e OS1 -r write /tmp/sysupgrade.bin OS1
  31. Recovery:
  32. Recovery procedure is the same as for Xiaomi Mi Router 4A Gigabit.
  33. Possible options can be found here:
  34. https://openwrt.org/inbox/toh/xiaomi/xiaomi_mi_router_4a_gigabit_edition
  35. One of the ways is to use another router with OpenWrt:
  36. - connect both routers by their LAN ports
  37. - download stock firmware from [1]
  38. - place it inside /tmp/test.bin on the main router
  39. - configure PXE/TFTP on the main router
  40. - power off 4Av2, hold Reset button, power on
  41. - as soon as image download via TFTP starts, Reset can be released
  42. - blinking blue wan LED will indicate the end of the flashing process,
  43. now router can be rebooted
  44. [1] http://cdn.cnbj1.fds.api.mi-img.com/xiaoqiang/rom/r4av2/miwifi_r4av2_firmware_release_2.30.28.bin
  45. Signed-off-by: Dmitry Sokolov <[email protected]>
  46. ---
  47. .../dts/mt7621_xiaomi_mi-router-4a-3g-v2.dtsi | 138 +-----------------
  48. .../mt7621_xiaomi_mi-router-4a-common.dtsi | 138 ++++++++++++++++++
  49. .../mt7621_xiaomi_mi-router-4a-gigabit-v2.dts | 80 ++++++++++
  50. target/linux/ramips/image/mt7621.mk | 11 ++
  51. .../mt7621/base-files/etc/board.d/01_leds | 3 +
  52. .../mt7621/base-files/etc/board.d/02_network | 3 +-
  53. 6 files changed, 241 insertions(+), 132 deletions(-)
  54. create mode 100644 target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi
  55. create mode 100644 target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-gigabit-v2.dts
  56. diff --git a/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-3g-v2.dtsi b/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-3g-v2.dtsi
  57. index a0ee79ae23ce4..d05872337be26 100644
  58. --- a/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-3g-v2.dtsi
  59. +++ b/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-3g-v2.dtsi
  60. @@ -1,23 +1,12 @@
  61. // SPDX-License-Identifier: GPL-2.0-or-later OR MIT
  62. -#include "mt7621.dtsi"
  63. -
  64. -#include <dt-bindings/gpio/gpio.h>
  65. -#include <dt-bindings/input/input.h>
  66. +#include "mt7621_xiaomi_mi-router-4a-common.dtsi"
  67. / {
  68. aliases {
  69. - led-boot = &led_status_yellow;
  70. - led-failsafe = &led_status_yellow;
  71. - led-running = &led_status_blue;
  72. - led-upgrade = &led_status_yellow;
  73. label-mac-device = &wan;
  74. };
  75. - chosen {
  76. - bootargs = "console=ttyS0,115200n8";
  77. - };
  78. -
  79. leds {
  80. compatible = "gpio-leds";
  81. @@ -31,108 +20,16 @@
  82. gpios = <&gpio 10 GPIO_ACTIVE_LOW>;
  83. };
  84. };
  85. -
  86. - keys {
  87. - compatible = "gpio-keys";
  88. -
  89. - reset {
  90. - label = "reset";
  91. - gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
  92. - linux,code = <KEY_RESTART>;
  93. - };
  94. - };
  95. };
  96. -&spi0 {
  97. - status = "okay";
  98. -
  99. - flash@0 {
  100. - compatible = "jedec,spi-nor";
  101. - reg = <0>;
  102. - spi-max-frequency = <50000000>;
  103. - m25p,fast-read;
  104. -
  105. - partitions {
  106. - compatible = "fixed-partitions";
  107. - #address-cells = <1>;
  108. - #size-cells = <1>;
  109. -
  110. - partition@0 {
  111. - label = "u-boot";
  112. - reg = <0x0 0x30000>;
  113. - read-only;
  114. - };
  115. -
  116. - partition@30000 {
  117. - label = "u-boot-env";
  118. - reg = <0x30000 0x10000>;
  119. - read-only;
  120. - };
  121. -
  122. - partition@40000 {
  123. - label = "Bdata";
  124. - reg = <0x40000 0x10000>;
  125. - read-only;
  126. - };
  127. -
  128. - factory: partition@50000 {
  129. - label = "factory";
  130. - reg = <0x50000 0x10000>;
  131. - read-only;
  132. - };
  133. -
  134. - partition@60000 {
  135. - label = "crash";
  136. - reg = <0x60000 0x10000>;
  137. - read-only;
  138. - };
  139. -
  140. - partition@70000 {
  141. - label = "cfg_bak";
  142. - reg = <0x70000 0x10000>;
  143. - read-only;
  144. - };
  145. -
  146. - partition@80000 {
  147. - label = "overlay";
  148. - reg = <0x80000 0x100000>;
  149. - read-only;
  150. - };
  151. -
  152. - firmware: partition@180000 {
  153. - compatible = "denx,uimage";
  154. - label = "firmware";
  155. - reg = <0x180000 0xe80000>;
  156. - };
  157. - };
  158. - };
  159. +&wifi0 {
  160. + mediatek,mtd-eeprom = <&factory 0x8000>;
  161. + ieee80211-freq-limit = <5000000 6000000>;
  162. };
  163. -&pcie {
  164. - status = "okay";
  165. -};
  166. -
  167. -&pcie0 {
  168. - wifi@0,0 {
  169. - compatible = "pci14c3,7662";
  170. - reg = <0x0000 0 0 0 0>;
  171. - mediatek,mtd-eeprom = <&factory 0x8000>;
  172. - ieee80211-freq-limit = <5000000 6000000>;
  173. - };
  174. -};
  175. -
  176. -&pcie1 {
  177. - wifi@0,0 {
  178. - compatible = "pci14c3,7603";
  179. - reg = <0x0000 0 0 0 0>;
  180. - mediatek,mtd-eeprom = <&factory 0x0000>;
  181. - ieee80211-freq-limit = <2400000 2500000>;
  182. - };
  183. -};
  184. -
  185. -&gmac0 {
  186. - nvmem-cells = <&macaddr_factory_e000>;
  187. - nvmem-cell-names = "mac-address";
  188. +&wifi1 {
  189. + mediatek,mtd-eeprom = <&factory 0x0000>;
  190. + ieee80211-freq-limit = <2400000 2500000>;
  191. };
  192. &switch0 {
  193. @@ -163,24 +60,3 @@
  194. };
  195. };
  196. };
  197. -
  198. -&state_default {
  199. - gpio {
  200. - groups = "jtag", "uart2", "uart3", "wdt";
  201. - function = "gpio";
  202. - };
  203. -};
  204. -
  205. -&factory {
  206. - compatible = "nvmem-cells";
  207. - #address-cells = <1>;
  208. - #size-cells = <1>;
  209. -
  210. - macaddr_factory_e000: macaddr@e000 {
  211. - reg = <0xe000 0x6>;
  212. - };
  213. -
  214. - macaddr_factory_e006: macaddr@e006 {
  215. - reg = <0xe006 0x6>;
  216. - };
  217. -};
  218. diff --git a/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi b/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi
  219. new file mode 100644
  220. index 0000000000000..efc32733e9bc1
  221. --- /dev/null
  222. +++ b/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-common.dtsi
  223. @@ -0,0 +1,138 @@
  224. +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
  225. +
  226. +#include "mt7621.dtsi"
  227. +
  228. +#include <dt-bindings/gpio/gpio.h>
  229. +#include <dt-bindings/input/input.h>
  230. +
  231. +/ {
  232. + aliases {
  233. + led-boot = &led_status_yellow;
  234. + led-failsafe = &led_status_yellow;
  235. + led-running = &led_status_blue;
  236. + led-upgrade = &led_status_yellow;
  237. + };
  238. +
  239. + chosen {
  240. + bootargs = "console=ttyS0,115200n8";
  241. + };
  242. +
  243. + keys {
  244. + compatible = "gpio-keys";
  245. +
  246. + reset {
  247. + label = "reset";
  248. + gpios = <&gpio 18 GPIO_ACTIVE_LOW>;
  249. + linux,code = <KEY_RESTART>;
  250. + };
  251. + };
  252. +};
  253. +
  254. +&spi0 {
  255. + status = "okay";
  256. +
  257. + flash@0 {
  258. + compatible = "jedec,spi-nor";
  259. + reg = <0>;
  260. + spi-max-frequency = <50000000>;
  261. + m25p,fast-read;
  262. +
  263. + partitions: partitions {
  264. + compatible = "fixed-partitions";
  265. + #address-cells = <1>;
  266. + #size-cells = <1>;
  267. +
  268. + partition@0 {
  269. + label = "u-boot";
  270. + reg = <0x0 0x30000>;
  271. + read-only;
  272. + };
  273. +
  274. + partition@30000 {
  275. + label = "u-boot-env";
  276. + reg = <0x30000 0x10000>;
  277. + read-only;
  278. + };
  279. +
  280. + partition@40000 {
  281. + label = "Bdata";
  282. + reg = <0x40000 0x10000>;
  283. + read-only;
  284. + };
  285. +
  286. + factory: partition@50000 {
  287. + label = "factory";
  288. + reg = <0x50000 0x10000>;
  289. + read-only;
  290. + };
  291. +
  292. + partition@60000 {
  293. + label = "crash";
  294. + reg = <0x60000 0x10000>;
  295. + read-only;
  296. + };
  297. +
  298. + partition@70000 {
  299. + label = "cfg_bak";
  300. + reg = <0x70000 0x10000>;
  301. + read-only;
  302. + };
  303. +
  304. + partition@80000 {
  305. + label = "overlay";
  306. + reg = <0x80000 0x100000>;
  307. + read-only;
  308. + };
  309. +
  310. + firmware: partition@180000 {
  311. + compatible = "denx,uimage";
  312. + label = "firmware";
  313. + reg = <0x180000 0xe80000>;
  314. + };
  315. + };
  316. + };
  317. +};
  318. +
  319. +&pcie {
  320. + status = "okay";
  321. +};
  322. +
  323. +&pcie0 {
  324. + wifi0: wifi@0,0 {
  325. + compatible = "mediatek,mt76";
  326. + reg = <0x0000 0 0 0 0>;
  327. + };
  328. +};
  329. +
  330. +&pcie1 {
  331. + wifi1: wifi@0,0 {
  332. + compatible = "mediatek,mt76";
  333. + reg = <0x0000 0 0 0 0>;
  334. + };
  335. +};
  336. +
  337. +&gmac0 {
  338. + nvmem-cells = <&macaddr_factory_e000>;
  339. + nvmem-cell-names = "mac-address";
  340. +};
  341. +
  342. +&state_default {
  343. + gpio {
  344. + groups = "jtag", "uart2", "uart3", "wdt";
  345. + function = "gpio";
  346. + };
  347. +};
  348. +
  349. +&factory {
  350. + compatible = "nvmem-cells";
  351. + #address-cells = <1>;
  352. + #size-cells = <1>;
  353. +
  354. + macaddr_factory_e000: macaddr@e000 {
  355. + reg = <0xe000 0x6>;
  356. + };
  357. +
  358. + macaddr_factory_e006: macaddr@e006 {
  359. + reg = <0xe006 0x6>;
  360. + };
  361. +};
  362. diff --git a/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-gigabit-v2.dts b/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-gigabit-v2.dts
  363. new file mode 100644
  364. index 0000000000000..67ff6ea11e161
  365. --- /dev/null
  366. +++ b/target/linux/ramips/dts/mt7621_xiaomi_mi-router-4a-gigabit-v2.dts
  367. @@ -0,0 +1,67 @@
  368. +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
  369. +
  370. +#include "mt7621_xiaomi_mi-router-4a-common.dtsi"
  371. +
  372. +/ {
  373. + compatible = "xiaomi,mi-router-4a-gigabit-v2", "mediatek,mt7621-soc";
  374. + model = "Xiaomi Mi Router 4A Gigabit Edition v2";
  375. +
  376. + aliases {
  377. + label-mac-device = &wan;
  378. + };
  379. +
  380. + leds {
  381. + compatible = "gpio-leds";
  382. +
  383. + led_status_blue: status_blue {
  384. + label = "blue:status";
  385. + gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
  386. + };
  387. +
  388. + led_status_yellow: status_yellow {
  389. + label = "yellow:status";
  390. + gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
  391. + };
  392. +
  393. + wan_blue {
  394. + label = "blue:wan";
  395. + gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
  396. + };
  397. +
  398. + wan_yellow {
  399. + label = "yellow:wan";
  400. + gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
  401. + };
  402. + };
  403. +};
  404. +
  405. +&wifi0 {
  406. + mediatek,mtd-eeprom = <&factory 0x0000>;
  407. + ieee80211-freq-limit = <2400000 2500000>;
  408. +};
  409. +
  410. +&wifi1 {
  411. + mediatek,mtd-eeprom = <&factory 0x8000>;
  412. + ieee80211-freq-limit = <5000000 6000000>;
  413. +};
  414. +
  415. +&switch0 {
  416. + ports {
  417. + port@1 {
  418. + status = "okay";
  419. + label = "lan1";
  420. + };
  421. +
  422. + port@2 {
  423. + status = "okay";
  424. + label = "lan2";
  425. + };
  426. +
  427. + wan: port@3 {
  428. + status = "okay";
  429. + label = "wan";
  430. + nvmem-cells = <&macaddr_factory_e006>;
  431. + nvmem-cell-names = "mac-address";
  432. + };
  433. + };
  434. +};
  435. diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
  436. index 9d01399c5cc3c..6871243a5f6c6 100644
  437. --- a/target/linux/ramips/image/mt7621.mk
  438. +++ b/target/linux/ramips/image/mt7621.mk
  439. @@ -2427,6 +2427,17 @@ define Device/xiaomi_mi-router-4a-gigabit
  440. endef
  441. TARGET_DEVICES += xiaomi_mi-router-4a-gigabit
  442. +define Device/xiaomi_mi-router-4a-gigabit-v2
  443. + $(Device/dsa-migration)
  444. + $(Device/uimage-lzma-loader)
  445. + IMAGE_SIZE := 16064k
  446. + DEVICE_VENDOR := Xiaomi
  447. + DEVICE_MODEL := Mi Router 4A
  448. + DEVICE_VARIANT := Gigabit Edition v2
  449. + DEVICE_PACKAGES := kmod-mt7603 kmod-mt7615e kmod-mt7663-firmware-ap wpad-mini -wpad-basic-wolfssl -coremark -htop -bash -openssh-sftp-server
  450. +endef
  451. +TARGET_DEVICES += xiaomi_mi-router-4a-gigabit-v2
  452. +
  453. define Device/xiaomi_mi-router-ac2100
  454. $(Device/xiaomi_nand_separate)
  455. DEVICE_MODEL := Mi Router AC2100
  456. diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/01_leds b/target/linux/ramips/mt7621/base-files/etc/board.d/01_leds
  457. index 91f3fe6e93c13..597d7302ac88e 100644
  458. --- a/target/linux/ramips/mt7621/base-files/etc/board.d/01_leds
  459. +++ b/target/linux/ramips/mt7621/base-files/etc/board.d/01_leds
  460. @@ -179,6 +179,9 @@ tplink,re650-v2)
  461. tplink,tl-wpa8631p-v3)
  462. ucidef_set_led_netdev "lan" "LAN" "green:lan" "br-lan"
  463. ;;
  464. +xiaomi,mi-router-4a-gigabit-v2)
  465. + ucidef_set_led_netdev "wan" "wan" "blue:wan" "wan" "link"
  466. + ;;
  467. xiaomi,mi-router-ac2100)
  468. ucidef_set_led_netdev "wan-blue" "WAN (blue)" "blue:wan" "wan"
  469. ;;
  470. diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
  471. index ddbbf9891d63a..67f58b10b2715 100644
  472. --- a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
  473. +++ b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
  474. @@ -72,7 +72,8 @@ ramips_setup_interfaces()
  475. xiaomi,mi-router-3g|\
  476. xiaomi,mi-router-3g-v2|\
  477. xiaomi,mi-router-4|\
  478. - xiaomi,mi-router-4a-gigabit)
  479. + xiaomi,mi-router-4a-gigabit|\
  480. + xiaomi,mi-router-4a-gigabit-v2)
  481. ucidef_set_interfaces_lan_wan "lan1 lan2" "wan"
  482. ;;
  483. bolt,arion)