nx30.patch 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. From e78d1a06c8a47be9ea5a306bfb43f3d7ceb89646 Mon Sep 17 00:00:00 2001
  2. From: Chukun Pan <[email protected]>
  3. Date: Sun, 21 May 2023 23:00:16 +0800
  4. Subject: [PATCH] mediatek: filogic: add H3C Magic NX30 Pro support
  5. Hardware specification:
  6. SoC: MediaTek MT7981B 2x A53
  7. Flash: W25N01GVZEIG 128MB
  8. RAM: NT5CB128M16JR-FL 256MB
  9. Ethernet: 4x 10/100/1000 Mbps
  10. Switch: MediaTek MT7531AE
  11. WiFi: MediaTek MT7976C
  12. Button: Reset, WPS
  13. Power: DC 12V 1A
  14. Flash instructions:
  15. 1. PC run command: "telnet 192.168.124.1 99"
  16. Username: H3C, password is the web login
  17. password of the router.
  18. 2. Download preloader.bin and bl31-uboot.fip
  19. 3. PC run command: "python3 -m http.server 80"
  20. 4. Download files in the telnet window:
  21. "wget http://192.168.124.xx/xxx.bin"
  22. Replace xx with your PC's IP and
  23. the preloader.bin and bl31-uboot.fip.
  24. 5. Flushing openwrt's uboot:
  25. "mtd write xxx-preloader.bin BL2"
  26. "mtd write xxx-bl31-uboot.fip FIP"
  27. 6. Connect to the router via the Lan port,
  28. set a static ip of your PC.
  29. (ip 192.168.1.254, gateway 192.168.1.1)
  30. 7. Download initramfs image, reboot router,
  31. waiting for tftp recovery to complete.
  32. 8. After openwrt boots up, perform sysupgrade.
  33. Note:
  34. 1. The u-boot-env partition on mtd is empty,
  35. OEM stores their env on ubi:u-boot-env.
  36. 2. Back up all mtd partitions before flashing.
  37. Signed-off-by: Chukun Pan <[email protected]>
  38. ---
  39. .../dts/mt7981b-h3c-magic-nx30-pro.dts | 239 ++++++++++++++++++
  40. .../filogic/base-files/etc/board.d/02_network | 8 +
  41. .../etc/hotplug.d/ieee80211/11_fix_wifi_mac | 5 +
  42. .../base-files/lib/upgrade/platform.sh | 1 +
  43. target/linux/mediatek/image/filogic.mk | 25 ++
  44. 5 files changed, 278 insertions(+)
  45. create mode 100644 target/linux/mediatek/dts/mt7981b-h3c-magic-nx30-pro.dts
  46. diff --git a/target/linux/mediatek/dts/mt7981b-h3c-magic-nx30-pro.dts b/target/linux/mediatek/dts/mt7981b-h3c-magic-nx30-pro.dts
  47. new file mode 100644
  48. index 0000000000000..358365adba44b
  49. --- /dev/null
  50. +++ b/target/linux/mediatek/dts/mt7981b-h3c-magic-nx30-pro.dts
  51. @@ -0,0 +1,213 @@
  52. +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
  53. +
  54. +/dts-v1/;
  55. +#include <dt-bindings/gpio/gpio.h>
  56. +#include <dt-bindings/input/input.h>
  57. +
  58. +#include "mt7981.dtsi"
  59. +
  60. +/ {
  61. + model = "H3C Magic NX30 Pro";
  62. + compatible = "h3c,magic-nx30-pro", "mediatek,mt7981";
  63. +
  64. + aliases {
  65. + serial0 = &uart0;
  66. + led-boot = &led_status_green;
  67. + led-failsafe = &led_status_red;
  68. + led-running = &led_status_green;
  69. + led-upgrade = &led_status_red;
  70. + };
  71. +
  72. + chosen {
  73. + stdout-path = "serial0:115200n8";
  74. + };
  75. +
  76. + memory {
  77. + reg = <0 0x40000000 0 0x10000000>;
  78. + };
  79. +
  80. + gpio-keys {
  81. + compatible = "gpio-keys";
  82. +
  83. + reset {
  84. + label = "reset";
  85. + linux,code = <KEY_RESTART>;
  86. + gpios = <&pio 1 GPIO_ACTIVE_LOW>;
  87. + };
  88. +
  89. + wps {
  90. + label = "wps";
  91. + linux,code = <KEY_WPS_BUTTON>;
  92. + gpios = <&pio 0 GPIO_ACTIVE_LOW>;
  93. + };
  94. + };
  95. +
  96. + leds {
  97. + compatible = "gpio-leds";
  98. +
  99. + led_status_green: green {
  100. + label = "green:status";
  101. + gpios = <&pio 4 GPIO_ACTIVE_LOW>;
  102. + };
  103. +
  104. + led_status_red: red {
  105. + label = "red:status";
  106. + gpios = <&pio 5 GPIO_ACTIVE_LOW>;
  107. + };
  108. + };
  109. +};
  110. +
  111. +&eth {
  112. + status = "okay";
  113. +
  114. + gmac0: mac@0 {
  115. + compatible = "mediatek,eth-mac";
  116. + reg = <0>;
  117. + phy-mode = "2500base-x";
  118. +
  119. + fixed-link {
  120. + speed = <2500>;
  121. + full-duplex;
  122. + pause;
  123. + };
  124. + };
  125. +
  126. + gmac1: mac@1 {
  127. + compatible = "mediatek,eth-mac";
  128. + reg = <1>;
  129. + phy-mode = "gmii";
  130. + phy-handle = <&int_gbe_phy>;
  131. + };
  132. +};
  133. +
  134. +&mdio_bus {
  135. + switch: switch@0 {
  136. + compatible = "mediatek,mt7531";
  137. + reg = <31>;
  138. + reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>;
  139. + interrupt-controller;
  140. + #interrupt-cells = <1>;
  141. + interrupt-parent = <&pio>;
  142. + interrupts = <38 IRQ_TYPE_LEVEL_HIGH>;
  143. + };
  144. +};
  145. +
  146. +&spi0 {
  147. + pinctrl-names = "default";
  148. + pinctrl-0 = <&spi0_flash_pins>;
  149. + status = "okay";
  150. +
  151. + spi_nand@0 {
  152. + compatible = "spi-nand";
  153. + #address-cells = <1>;
  154. + #size-cells = <1>;
  155. + reg = <0>;
  156. +
  157. + spi-max-frequency = <52000000>;
  158. + spi-tx-buswidth = <4>;
  159. + spi-rx-buswidth = <4>;
  160. +
  161. + partitions {
  162. + compatible = "fixed-partitions";
  163. + #address-cells = <1>;
  164. + #size-cells = <1>;
  165. +
  166. + partition@0 {
  167. + label = "BL2";
  168. + reg = <0x0000000 0x0100000>;
  169. + read-only;
  170. + };
  171. +
  172. + partition@100000 {
  173. + label = "u-boot-env";
  174. + reg = <0x0100000 0x0080000>;
  175. + };
  176. +
  177. + factory: partition@180000 {
  178. + label = "Factory";
  179. + reg = <0x0180000 0x0200000>;
  180. + read-only;
  181. + };
  182. +
  183. + partition@380000 {
  184. + label = "FIP";
  185. + reg = <0x0380000 0x0200000>;
  186. + read-only;
  187. + };
  188. +
  189. + partition@580000 {
  190. + label = "ubi";
  191. + reg = <0x0580000 0x04000000>;
  192. + };
  193. + };
  194. + };
  195. +};
  196. +
  197. +&switch {
  198. + ports {
  199. + #address-cells = <1>;
  200. + #size-cells = <0>;
  201. +
  202. + port@0 {
  203. + reg = <0>;
  204. + label = "lan1";
  205. + };
  206. +
  207. + port@1 {
  208. + reg = <1>;
  209. + label = "lan2";
  210. + };
  211. +
  212. + port@2 {
  213. + reg = <2>;
  214. + label = "lan3";
  215. + };
  216. +
  217. + port@6 {
  218. + reg = <6>;
  219. + ethernet = <&gmac0>;
  220. + phy-mode = "2500base-x";
  221. +
  222. + fixed-link {
  223. + speed = <2500>;
  224. + full-duplex;
  225. + pause;
  226. + };
  227. + };
  228. + };
  229. +};
  230. +
  231. +&pio {
  232. + spi0_flash_pins: spi0-pins {
  233. + mux {
  234. + function = "spi";
  235. + groups = "spi0", "spi0_wp_hold";
  236. + };
  237. +
  238. + conf-pu {
  239. + pins = "SPI0_CS", "SPI0_HOLD", "SPI0_WP";
  240. + drive-strength = <8>;
  241. + mediatek,pull-up-adv = <0>; /* bias-disable */
  242. + };
  243. +
  244. + conf-pd {
  245. + pins = "SPI0_CLK", "SPI0_MOSI", "SPI0_MISO";
  246. + drive-strength = <8>;
  247. + mediatek,pull-up-adv = <0>; /* bias-disable */
  248. + };
  249. + };
  250. +};
  251. +
  252. +&uart0 {
  253. + status = "okay";
  254. +};
  255. +
  256. +&watchdog {
  257. + status = "okay";
  258. +};
  259. +
  260. +&wifi {
  261. + status = "okay";
  262. +
  263. + mediatek,mtd-eeprom = <&factory 0x0>;
  264. +};
  265. diff --git a/target/linux/mediatek/filogic/base-files/etc/board.d/02_network b/target/linux/mediatek/filogic/base-files/etc/board.d/02_network
  266. index c05c5d25e4621..6abc81a0b0561 100644
  267. --- a/target/linux/mediatek/filogic/base-files/etc/board.d/02_network
  268. +++ b/target/linux/mediatek/filogic/base-files/etc/board.d/02_network
  269. @@ -23,6 +23,9 @@
  270. glinet,gl-mt3000)
  271. ucidef_set_interfaces_lan_wan eth1 eth0
  272. ;;
  273. + h3c,magic-nx30-pro)
  274. + ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" eth1
  275. + ;;
  276. mediatek,mt7986a-rfb)
  277. ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 lan6" "eth1 wan"
  278. ;;
  279. @@ -69,6 +72,11 @@
  280. bananapi,bpi-r3)
  281. wan_mac=$(macaddr_add $(cat /sys/class/net/eth0/address) 1)
  282. ;;
  283. + h3c,magic-nx30-pro)
  284. + wan_mac=$(mtd_get_mac_ascii pdt_data_1 ethaddr)
  285. + lan_mac=$(macaddr_add "$wan_mac" 1)
  286. + label_mac=$wan_mac
  287. + ;;
  288. netgear,wax220)
  289. lan_mac=$(mtd_get_mac_ascii u-boot-env mac)
  290. label_mac=$lan_mac
  291. diff --git a/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac b/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac
  292. index 4b7047eec5e5a..ab23b100444ce 100644
  293. --- a/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac
  294. +++ b/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac
  295. @@ -32,6 +32,11 @@
  296. [ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
  297. [ "$PHYNBR" = "1" ] && macaddr_setbit_la $(macaddr_add $addr 1) > /sys${DEVPATH}/macaddress
  298. ;;
  299. + h3c,magic-nx30-pro)
  300. + addr=$(mtd_get_mac_ascii pdt_data_1 ethaddr)
  301. + [ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
  302. + [ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
  303. + ;;
  304. netgear,wax220)
  305. hw_mac_addr=$(mtd_get_mac_ascii u-boot-env mac)
  306. [ "$PHYNBR" = "0" ] && macaddr_add $hw_mac_addr 2 > /sys${DEVPATH}/macaddress
  307. diff --git a/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh b/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh
  308. index 11c2c5c66439d..186abfa5a8d82 100755
  309. --- a/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh
  310. +++ b/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh
  311. @@ -74,6 +74,7 @@ platform_do_upgrade() {
  312. CI_UBIPART="ubi0"
  313. nand_do_upgrade "$1"
  314. ;;
  315. + h3c,magic-nx30-pro|\
  316. qihoo,360t7|\
  317. tplink,tl-xdr4288|\
  318. tplink,tl-xdr6086|\
  319. diff --git a/target/linux/mediatek/image/filogic.mk b/target/linux/mediatek/image/filogic.mk
  320. index fd83b9d4416f9..2ace305140b2e 100644
  321. --- a/target/linux/mediatek/image/filogic.mk
  322. +++ b/target/linux/mediatek/image/filogic.mk
  323. @@ -176,6 +176,21 @@ define Device/glinet_gl-mt3000
  324. endef
  325. TARGET_DEVICES += glinet_gl-mt3000
  326. +define Device/h3c_magic-nx30-pro
  327. + DEVICE_VENDOR := H3C
  328. + DEVICE_MODEL := Magic NX30 Pro
  329. + DEVICE_DTS := mt7981b-h3c-magic-nx30-pro
  330. + DEVICE_DTS_DIR := ../dts
  331. + UBINIZE_OPTS := -E 5
  332. + BLOCKSIZE := 128k
  333. + PAGESIZE := 2048
  334. + KERNEL_IN_UBI := 1
  335. + IMAGE_SIZE := 65536k
  336. + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
  337. + DEVICE_PACKAGES := kmod-mt7981-firmware mt7981-wo-firmware
  338. +endef
  339. +TARGET_DEVICES += h3c_magic-nx30-pro
  340. +
  341. define Device/netgear_wax220
  342. DEVICE_VENDOR := Netgear
  343. DEVICE_MODEL := WAX220