TX1800.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. From 13308161788c98ae6cd48c22b13339fdb8c77130 Mon Sep 17 00:00:00 2001
  2. From: Shiji Yang <[email protected]>
  3. Date: Sun, 20 Mar 2022 23:42:37 +0800
  4. Subject: [PATCH] ramips: add support for H3C TX1800 Plus / TX1801 Plus /
  5. TX1806
  6. H3C TX180x series WiFi6 routers are customized by different carrier.
  7. While these three devices look different, they use the same motherboard
  8. inside. Another minor difference comes from the model name definition
  9. in the u-boot environment variable.
  10. Specifications:
  11. SOC: MT7621 + MT7915
  12. ROM: 128 MiB
  13. RAM: 256 MiB
  14. LED: status *2
  15. Button: reset *1 + wps/mesh *1
  16. Ethernet: lan *3 + wan *1 (10/100/1000Mbps)
  17. TTL Baudrate: 115200
  18. TFTP server IP: 192.168.124.99
  19. MAC Address:
  20. use address(sample 1) address(sample 2) source
  21. label 88:xx:xx:98:xx:12 88:xx:xx:a2:xx:a5 u-boot-env@ethaddr
  22. lan 88:xx:xx:98:xx:13 88:xx:xx:a2:xx:a6 $label +1
  23. wan 88:xx:xx:98:xx:12 88:xx:xx:a2:xx:a5 $label
  24. WiFi4_2G 8a:xx:xx:58:xx:14 8a:xx:xx:52:xx:a7 (Compatibility mode)
  25. WiFi5_5G 8a:xx:xx:b8:xx:14 8a:xx:xx:b2:xx:a7 (Compatibility mode)
  26. WiFi6_2G 8a:xx:xx:18:xx:14 8a:xx:xx:12:xx:a7
  27. WiFi6_5G 8a:xx:xx:78:xx:14 8a:xx:xx:72:xx:a7
  28. Compatibility mode is used to guarantee the connection of old devices
  29. that only support WiFi4 or WiFi5.
  30. TFTP + TTL Installation:
  31. Although a TTL connection is required for installation, we do not need
  32. to tear down it. We can find the TTL port from the cooling hole at the
  33. bottom. It is located below LAN3 and the pins are defined as follows:
  34. |LAN1|LAN2|LAN3|----|WAN|
  35. --------------------
  36. |GND|TX|RX|VCC|
  37. 1. Set tftp server IP to 192.168.124.99 and put initramfs firmware in
  38. server's root directory, rename it to a simple name "initramfs.bin".
  39. 2. Plug in the power supply and wait for power on, connect the TTL cable
  40. and open a TTL session, enter "reboot", then enter "Y" to confirm.
  41. Finally push "0" to interruput boot while booting.
  42. 3. Execute command to install a initramfs system:
  43. # tftp 0x80010000 192.168.124.99:initramfs.bin
  44. # bootm 0x80010000
  45. 4. Backup nand flash by OpenWrt LuCI or dd instruction. We need those
  46. partitions if we want to back to stock firmwre due to official
  47. website does not provide download link.
  48. # dd if=/dev/mtd1 of=/tmp/u-boot-env.bin
  49. # dd if=/dev/mtd4 of=/tmp/firmware.bin
  50. 5. Edit u-boot env to ensure use default bootargs and first image slot:
  51. # fw_setenv bootargs
  52. # fw_setenv bootflag 0
  53. 6. Upgrade sysupgrade firmware.
  54. 7. About restore stock firmware: flash the "firmware" and "u-boot-env"
  55. partitions that we backed up in step 4.
  56. # mtd write /tmp/u-boot-env.bin u-boot-env
  57. # mtd write /tmp/firmware.bin firmware
  58. Additional Info:
  59. The H3C stock firmware has a 160-byte firmware header that appears to
  60. use a non-standard CRC32 verification algorithm. For this part of the
  61. data, the u-boot does not check it so we can just directly replace it
  62. with a placeholder.
  63. Signed-off-by: Shiji Yang <[email protected]>
  64. ---
  65. package/boot/uboot-envtools/files/ramips | 9 +-
  66. .../ramips/dts/mt7621_h3c_tx1800-plus.dts | 8 +
  67. .../ramips/dts/mt7621_h3c_tx1801-plus.dts | 8 +
  68. target/linux/ramips/dts/mt7621_h3c_tx1806.dts | 8 +
  69. .../linux/ramips/dts/mt7621_h3c_tx180x.dtsi | 165 ++++++++++++++++++
  70. target/linux/ramips/image/mt7621.mk | 40 +++++
  71. .../mt7621/base-files/etc/board.d/02_network | 10 ++
  72. .../etc/hotplug.d/ieee80211/10_fix_wifi_mac | 7 +
  73. .../mt7621/base-files/lib/upgrade/platform.sh | 3 +
  74. 9 files changed, 255 insertions(+), 3 deletions(-)
  75. create mode 100644 target/linux/ramips/dts/mt7621_h3c_tx1800-plus.dts
  76. create mode 100644 target/linux/ramips/dts/mt7621_h3c_tx1801-plus.dts
  77. create mode 100644 target/linux/ramips/dts/mt7621_h3c_tx1806.dts
  78. create mode 100644 target/linux/ramips/dts/mt7621_h3c_tx180x.dtsi
  79. diff --git a/package/boot/uboot-envtools/files/ramips b/package/boot/uboot-envtools/files/ramips
  80. index 7514bf65fb10e..738d983af2041 100644
  81. --- a/package/boot/uboot-envtools/files/ramips
  82. +++ b/package/boot/uboot-envtools/files/ramips
  83. @@ -47,6 +47,9 @@ ravpower,rp-wd03)
  84. [ -n "$idx" ] && \
  85. ubootenv_add_uci_config "/dev/mtd$idx" "0x4000" "0x1000" "0x1000"
  86. ;;
  87. +h3c,tx1800-plus|\
  88. +h3c,tx1801-plus|\
  89. +h3c,tx1806|\
  90. asus,rt-ax53u|\
  91. jcg,q20|\
  92. netgear,wax202)
  93. diff --git a/target/linux/ramips/dts/mt7621_h3c_tx1800-plus.dts b/target/linux/ramips/dts/mt7621_h3c_tx1800-plus.dts
  94. new file mode 100644
  95. index 0000000000000..f763dd14dddf9
  96. --- /dev/null
  97. +++ b/target/linux/ramips/dts/mt7621_h3c_tx1800-plus.dts
  98. @@ -0,0 +1,8 @@
  99. +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
  100. +
  101. +#include "mt7621_h3c_tx180x.dtsi"
  102. +
  103. +/ {
  104. + compatible = "h3c,tx1800-plus", "mediatek,mt7621-soc";
  105. + model = "H3C TX1800 Plus";
  106. +};
  107. diff --git a/target/linux/ramips/dts/mt7621_h3c_tx1801-plus.dts b/target/linux/ramips/dts/mt7621_h3c_tx1801-plus.dts
  108. new file mode 100644
  109. index 0000000000000..4588b142c4fbb
  110. --- /dev/null
  111. +++ b/target/linux/ramips/dts/mt7621_h3c_tx1801-plus.dts
  112. @@ -0,0 +1,8 @@
  113. +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
  114. +
  115. +#include "mt7621_h3c_tx180x.dtsi"
  116. +
  117. +/ {
  118. + compatible = "h3c,tx1801-plus", "mediatek,mt7621-soc";
  119. + model = "H3C TX1801 Plus";
  120. +};
  121. diff --git a/target/linux/ramips/dts/mt7621_h3c_tx1806.dts b/target/linux/ramips/dts/mt7621_h3c_tx1806.dts
  122. new file mode 100644
  123. index 0000000000000..1e9b6456eec5c
  124. --- /dev/null
  125. +++ b/target/linux/ramips/dts/mt7621_h3c_tx1806.dts
  126. @@ -0,0 +1,8 @@
  127. +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
  128. +
  129. +#include "mt7621_h3c_tx180x.dtsi"
  130. +
  131. +/ {
  132. + compatible = "h3c,tx1806", "mediatek,mt7621-soc";
  133. + model = "H3C TX1806";
  134. +};
  135. diff --git a/target/linux/ramips/dts/mt7621_h3c_tx180x.dtsi b/target/linux/ramips/dts/mt7621_h3c_tx180x.dtsi
  136. new file mode 100644
  137. index 0000000000000..61f2f8cc98c01
  138. --- /dev/null
  139. +++ b/target/linux/ramips/dts/mt7621_h3c_tx180x.dtsi
  140. @@ -0,0 +1,165 @@
  141. +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
  142. +
  143. +#include "mt7621.dtsi"
  144. +
  145. +#include <dt-bindings/gpio/gpio.h>
  146. +#include <dt-bindings/input/input.h>
  147. +#include <dt-bindings/leds/common.h>
  148. +
  149. +/ {
  150. + aliases {
  151. + led-boot = &led_status_amber;
  152. + led-failsafe = &led_status_green;
  153. + led-running = &led_status_green;
  154. + led-upgrade = &led_status_amber;
  155. + };
  156. +
  157. + chosen {
  158. + bootargs = "console=ttyS0,115200";
  159. + };
  160. +
  161. + keys {
  162. + compatible = "gpio-keys";
  163. +
  164. + reset {
  165. + label = "reset";
  166. + gpios = <&gpio 13 GPIO_ACTIVE_LOW>;
  167. + linux,code = <KEY_RESTART>;
  168. + };
  169. +
  170. + wps {
  171. + label = "wps";
  172. + gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
  173. + linux,code = <KEY_WPS_BUTTON>;
  174. + };
  175. + };
  176. +
  177. + leds {
  178. + compatible = "gpio-leds";
  179. +
  180. + led_status_amber: led-0 {
  181. + label = "amber:status";
  182. + color = <LED_COLOR_ID_AMBER>;
  183. + function = LED_FUNCTION_STATUS;
  184. + gpios = <&gpio 15 GPIO_ACTIVE_LOW>;
  185. + };
  186. +
  187. + led_status_green: led-1 {
  188. + label = "green:status";
  189. + color = <LED_COLOR_ID_GREEN>;
  190. + function = LED_FUNCTION_STATUS;
  191. + gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
  192. + };
  193. + };
  194. +};
  195. +
  196. +&gmac1 {
  197. + status = "okay";
  198. + label = "wan";
  199. + phy-handle = <&ethphy4>;
  200. +};
  201. +
  202. +&mdio {
  203. + ethphy4: ethernet-phy@4 {
  204. + reg = <4>;
  205. + };
  206. +};
  207. +
  208. +&nand {
  209. + status = "okay";
  210. +
  211. + mediatek,nmbm;
  212. + mediatek,bmt-max-ratio = <1>;
  213. + mediatek,bmt-max-reserved-blocks = <64>;
  214. + mediatek,bmt-remap-range = <0x0000000 0x0a00000>;
  215. +
  216. + partitions {
  217. + compatible = "fixed-partitions";
  218. + #address-cells = <1>;
  219. + #size-cells = <1>;
  220. +
  221. + partition@0 {
  222. + label = "u-boot";
  223. + reg = <0x0000000 0x0080000>;
  224. + read-only;
  225. + };
  226. +
  227. + partition@80000 {
  228. + label = "u-boot-env";
  229. + reg = <0x0080000 0x0080000>;
  230. + };
  231. +
  232. + partition@100000 {
  233. + label = "exp";
  234. + reg = <0x0100000 0x0080000>;
  235. + read-only;
  236. + };
  237. +
  238. + factory: partition@180000 {
  239. + label = "factory";
  240. + reg = <0x0180000 0x0080000>;
  241. + read-only;
  242. + };
  243. +
  244. + partition@200000 {
  245. + label = "firmware";
  246. + reg = <0x0200000 0x7600000>;
  247. +
  248. + compatible = "fixed-partitions";
  249. + #address-cells = <1>;
  250. + #size-cells = <1>;
  251. +
  252. + partition@0 {
  253. + label = "kernel";
  254. + reg = <0x0000000 0x0800000>;
  255. + };
  256. +
  257. + partition@800000 {
  258. + label = "ubi";
  259. + reg = <0x0800000 0x6e00000>;
  260. + };
  261. + };
  262. +
  263. + /* last 8 MiB is reserved for NMBM bad block table */
  264. + };
  265. +};
  266. +
  267. +&pcie {
  268. + status = "okay";
  269. +};
  270. +
  271. +&pcie1 {
  272. + wifi@0,0 {
  273. + compatible = "mediatek,mt76";
  274. + reg = <0x0000 0 0 0 0>;
  275. + mediatek,mtd-eeprom = <&factory 0x0>;
  276. + mediatek,disable-radar-background;
  277. + };
  278. +};
  279. +
  280. +&pcie2 {
  281. + status = "disabled";
  282. +};
  283. +
  284. +&switch0 {
  285. + ports {
  286. + port@1 {
  287. + status = "okay";
  288. + label = "lan1";
  289. + };
  290. +
  291. + port@2 {
  292. + status = "okay";
  293. + label = "lan2";
  294. + };
  295. +
  296. + port@3 {
  297. + status = "okay";
  298. + label = "lan3";
  299. + };
  300. + };
  301. +};
  302. +
  303. +&xhci {
  304. + status = "disabled";
  305. +};
  306. diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
  307. index 34eac321127be..b560ce3d95b6a 100644
  308. --- a/target/linux/ramips/image/mt7621.mk
  309. +++ b/target/linux/ramips/image/mt7621.mk
  310. @@ -31,6 +31,12 @@ define Build/gemtek-trailer
  311. printf "%s%08X" ".GEMTEK." "$$(cksum $@ | cut -d ' ' -f1)" >> $@
  312. endef
  313. +define Build/h3c-blank-header
  314. + dd if=/dev/zero [email protected] bs=160 count=1
  315. + cat $@ >> [email protected]
  316. + mv [email protected] $@
  317. +endef
  318. +
  319. define Build/iodata-factory
  320. $(eval fw_size=$(word 1,$(1)))
  321. $(eval fw_type=$(word 2,$(1)))
  322. @@ -752,6 +758,40 @@ define Device/gnubee_gb-pc2
  323. endef
  324. TARGET_DEVICES += gnubee_gb-pc2
  325. +define Device/h3c_tx180x
  326. + $(Device/dsa-migration)
  327. + BLOCKSIZE := 128k
  328. + PAGESIZE := 2048
  329. + KERNEL_SIZE := 8192k
  330. + IMAGE_SIZE := 120832k
  331. + UBINIZE_OPTS := -E 5
  332. + KERNEL_LOADADDR := 0x82000000
  333. + KERNEL_INITRAMFS := kernel-bin | relocate-kernel 0x80001000 | lzma | \
  334. + fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb
  335. + KERNEL := $$(KERNEL_INITRAMFS) | h3c-blank-header
  336. + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
  337. + DEVICE_VENDOR := H3C
  338. + DEVICE_PACKAGES := kmod-mt7915e uboot-envtools
  339. +endef
  340. +
  341. +define Device/h3c_tx1800-plus
  342. + $(Device/h3c_tx180x)
  343. + DEVICE_MODEL := TX1800 Plus
  344. +endef
  345. +TARGET_DEVICES += h3c_tx1800-plus
  346. +
  347. +define Device/h3c_tx1801-plus
  348. + $(Device/h3c_tx180x)
  349. + DEVICE_MODEL := TX1801 Plus
  350. +endef
  351. +TARGET_DEVICES += h3c_tx1801-plus
  352. +
  353. +define Device/h3c_tx1806
  354. + $(Device/h3c_tx180x)
  355. + DEVICE_MODEL := TX1806
  356. +endef
  357. +TARGET_DEVICES += h3c_tx1806
  358. +
  359. define Device/hilink_hlk-7621a-evb
  360. $(Device/dsa-migration)
  361. $(Device/uimage-lzma-loader)
  362. 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
  363. index 320325f487e3f..400b03133ec82 100644
  364. --- a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
  365. +++ b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
  366. @@ -28,6 +28,9 @@ ramips_setup_interfaces()
  367. ;;
  368. ampedwireless,ally-r1900k|\
  369. gehua,ghl-r-001|\
  370. + h3c,tx1800-plus|\
  371. + h3c,tx1801-plus|\
  372. + h3c,tx1806|\
  373. hiwifi,hc5962|\
  374. netgear,wax202|\
  375. xiaomi,mi-router-3-pro|\
  376. @@ -158,6 +161,13 @@ ramips_setup_macs()
  377. wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
  378. label_mac=$wan_mac
  379. ;;
  380. + h3c,tx1800-plus|\
  381. + h3c,tx1801-plus|\
  382. + h3c,tx1806)
  383. + label_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
  384. + lan_mac=$(macaddr_add "$label_mac" 1)
  385. + wan_mac=$label_mac
  386. + ;;
  387. hiwifi,hc5962)
  388. lan_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
  389. label_mac=$lan_mac
  390. diff --git a/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
  391. index bced044234360..0ace1933e3f81 100644
  392. --- a/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
  393. +++ b/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
  394. @@ -37,6 +37,13 @@ case "$board" in
  395. [ "$PHYNBR" = "1" ] && \
  396. macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1 > /sys${DEVPATH}/macaddress
  397. ;;
  398. + h3c,tx1800-plus|\
  399. + h3c,tx1801-plus|\
  400. + h3c,tx1806)
  401. + addr=$(macaddr_setbit $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) 2) 7)
  402. + [ "$PHYNBR" = "0" ] && echo -n ${addr:0:9}'1'${addr:10:7} > /sys${DEVPATH}/macaddress
  403. + [ "$PHYNBR" = "1" ] && echo -n ${addr:0:9}'7'${addr:10:7} > /sys${DEVPATH}/macaddress
  404. + ;;
  405. hiwifi,hc5962)
  406. label_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
  407. [ "$PHYNBR" = "0" ] && [ -n "$label_mac" ] && \
  408. diff --git a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
  409. index 8a84130ab5bef..9af46202ba954 100755
  410. --- a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
  411. +++ b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
  412. @@ -60,6 +60,9 @@ platform_do_upgrade() {
  413. dlink,dir-2640-a1|\
  414. dlink,dir-2660-a1|\
  415. dlink,dir-853-a3|\
  416. + h3c,tx1800-plus|\
  417. + h3c,tx1801-plus|\
  418. + h3c,tx1806|\
  419. hiwifi,hc5962|\
  420. iptime,a3004t|\
  421. iptime,ax2004m|\