mediatek: add support for Mercusys MR80X v3
authorSchneider Azima <[email protected]>
Mon, 10 Mar 2025 01:42:51 +0000 (18:42 -0700)
committerHauke Mehrtens <[email protected]>
Wed, 7 May 2025 18:58:33 +0000 (20:58 +0200)
This commit adds support for Mercusys MR80X(EU) v3 router.

Device specification:
 - SoC: Mediatek MT7981b, Cortex-A53, 64-bit
 - RAM: 512MB
 - Flash: SPI NAND GigaDevice GD5F1GQ5UEYIGY (128 MB)
 - Ethernet: 4x 100/1000 Mbps LAN1,LAN2,LAN3 & WAN
 - Wireless: 2.4GHz (802.11 b/g/n/ax)
 - Wireless: 5GHz (802.11 a/n/ac/ax)
 - LEDs: 1 orange and 1 green status LEDs, 4 green gpio-controlled LEDs
   on ethernet ports
 - Buttons: 1 (Reset)
 - Bootloader: Main U-Boot - U-Boot 2022.01-rc4. Additionally, both UBI
   slots contain "seconduboot" (also U-Boot 2022.01-rc4)

Installation (UART):
 - Place OpenWrt initramfs-kernel image on tftp server with IP 192.168.1.2
 - Attach UART, switch on the router and interrupt the boot process by
   pressing 'Ctrl-C'.
 - Set the uboot environment for startup.
   setenv tp_boot_idx 0; setenv bootcmd bootm 0x46000000; saveenv
   If the bootarg is set to boot from ubi1, also change it to ubi0.
 - Load and run OpenWrt initramfs image.
   setenv serverip 192.168.1.2; setenv ipaddr 192.168.1.1; tftpboot initramfs-kernel.bin; bootm
 - Login as root via SSH (IP 192.168.1.1, port 22)
 - Upload OpenWrt sysupgrade.bin image to the /tmp dir of the router
 - Run sysupgrade:
   sysupgrade -n /tmp/sysupgrade.bin

Recovery:
 - Press Reset button and power on the router.
 - Navigate to U-Boot recovery web server (http://192.168.1.1/) and
   upload the OEM firmware.

Stock layout:
0x000000000000-0x000000200000 : "boot"
0x000000200000-0x000000300000 : "u-boot-env"
0x000000300000-0x000003500000 : "ubi0"
0x000003500000-0x000006700000 : "ubi1"
0x000006700000-0x000006f00000 : "userconfig"
0x000006f00000-0x000007300000 : "tp_data"

ubi0/ubi1 format:
U-Boot at boot checks that all volumes are in place:
+-------------------------------+
| Volume Name: uboot   Vol ID: 0|
| Volume Name: kernel  Vol ID: 1|
| Volume Name: rootfs  Vol ID: 2|
+-------------------------------+

MAC addresses:
+---------+-------------------+-----------+
|         | MAC               | Algorithm |
+---------+-------------------+-----------+
| label   | 94:0C:xx:xx:xx:12 | label     |
| WAN     | 94:0C:xx:xx:xx:13 | label+1   |
| LAN     | 94:0C:xx:xx:xx:12 | label     |
| WLAN 2g | 94:0C:xx:xx:xx:11 | label-1   |
| WLAN 5g | 94:0C:xx:xx:xx:10 | label-2   |
+---------+-------------------+-----------+
label MAC address was found in UBI partition "tp_data", file
"default-mac".

Signed-off-by: Schneider Azima <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/18181
(cherry picked from commit 7921e48d43571861f15aa56717798709ff7507b6)
Signed-off-by: Schneider Azima <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/18522
Signed-off-by: Hauke Mehrtens <[email protected]>
package/boot/uboot-envtools/files/mediatek_filogic
target/linux/mediatek/dts/mt7981b-mercusys-mr80x-v3.dts [new file with mode: 0755]
target/linux/mediatek/filogic/base-files/etc/board.d/01_leds
target/linux/mediatek/filogic/base-files/etc/board.d/02_network
target/linux/mediatek/filogic/base-files/etc/hotplug.d/firmware/11-mt76-caldata
target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac
target/linux/mediatek/filogic/base-files/lib/preinit/09_mount_cfg_part
target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh
target/linux/mediatek/image/filogic.mk

index add5dbb3d30ac81109aa235a9f2350188803f9bb..5f586047f5789bd172b3f68a41ecad92112d2e4c 100644 (file)
@@ -108,6 +108,7 @@ gatonetworks,gdsp)
 glinet,gl-mt3000)
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x80000" "0x20000"
        ;;
+mercusys,mr80x-v3|\
 mercusys,mr90x-v1|\
 routerich,ax3000|\
 tplink,re6000xd)
diff --git a/target/linux/mediatek/dts/mt7981b-mercusys-mr80x-v3.dts b/target/linux/mediatek/dts/mt7981b-mercusys-mr80x-v3.dts
new file mode 100755 (executable)
index 0000000..3bd59f7
--- /dev/null
@@ -0,0 +1,237 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/dts-v1/;
+#include <dt-bindings/input/input.h>
+#include <dt-bindings/gpio/gpio.h>
+
+#include "mt7981.dtsi"
+/ {
+       model = "MERCUSYS MR80X v3";
+       compatible = "mercusys,mr80x-v3", "mediatek,mt7981";
+
+       aliases {
+               led-boot = &led_status_green;
+               led-failsafe = &led_status_amber;
+               led-running = &led_status_green;
+               led-upgrade = &led_status_green;
+
+               serial0 = &uart0;
+       };
+
+       chosen {
+               stdout-path = "serial0:115200n8";
+       };
+
+       memory {
+               reg = <0 0x40000000 0 0x20000000>;
+       };
+
+       keys {
+               compatible = "gpio-keys";
+
+               button-reset {
+                       label = "reset";
+                       linux,code = <KEY_RESTART>;
+                       gpios = <&pio 1 GPIO_ACTIVE_LOW>;
+               };
+       };
+
+       leds {
+               compatible = "gpio-leds";
+
+               led_status_amber: led-0 {
+                       color = <LED_COLOR_ID_AMBER>;
+                       function = LED_FUNCTION_STATUS;
+                       gpios = <&pio 4 GPIO_ACTIVE_LOW>;
+               };
+
+               led_status_green: led-1 {
+                       color = <LED_COLOR_ID_GREEN>;
+                       function = LED_FUNCTION_STATUS;
+                       gpios = <&pio 5 GPIO_ACTIVE_LOW>;
+               };
+
+               led-2 {
+                       color = <LED_COLOR_ID_GREEN>;
+                       function = LED_FUNCTION_LAN;
+                       function-enumerator = <1>;
+                       gpios = <&pio 6 GPIO_ACTIVE_LOW>;
+               };
+
+               led-3 {
+                       color = <LED_COLOR_ID_GREEN>;
+                       function = LED_FUNCTION_LAN;
+                       function-enumerator = <2>;
+                       gpios = <&pio 7 GPIO_ACTIVE_LOW>;
+               };
+
+               led-4 {
+                       color = <LED_COLOR_ID_GREEN>;
+                       function = LED_FUNCTION_WAN;
+                       gpios = <&pio 9 GPIO_ACTIVE_LOW>;
+               };
+
+               led-5 {
+                       color = <LED_COLOR_ID_GREEN>;
+                       function = LED_FUNCTION_LAN;
+                       function-enumerator = <3>;
+                       gpios = <&pio 10 GPIO_ACTIVE_LOW>;
+               };
+       };
+};
+
+&uart0 {
+       status = "okay";
+};
+
+&watchdog {
+       status = "okay";
+};
+
+&eth {
+       status = "okay";
+
+       gmac0: mac@0 {
+               compatible = "mediatek,eth-mac";
+               reg = <0>;
+               phy-mode = "2500base-x";
+
+               fixed-link {
+                       speed = <2500>;
+                       full-duplex;
+                       pause;
+               };
+       };
+
+       gmac1: mac@1 {
+               compatible = "mediatek,eth-mac";
+               reg = <1>;
+               phy-mode = "gmii";
+               phy-handle = <&int_gbe_phy>;
+       };
+
+       mdio: mdio-bus {
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               switch@1f {
+                       compatible = "mediatek,mt7531";
+                       reg = <31>;
+                       reset-gpios = <&pio 39 GPIO_ACTIVE_HIGH>;
+
+                       ports {
+                               #address-cells = <1>;
+                               #size-cells = <0>;
+
+                               port@1 {
+                                       reg = <1>;
+                                       label = "lan1";
+                               };
+
+                               port@2 {
+                                       reg = <2>;
+                                       label = "lan2";
+                               };
+
+                               port@3 {
+                                       reg = <3>;
+                                       label = "lan3";
+                               };
+
+                               port@6 {
+                                       reg = <6>;
+                                       label = "cpu";
+                                       ethernet = <&gmac0>;
+                                       phy-mode = "2500base-x";
+
+                                       fixed-link {
+                                               speed = <2500>;
+                                               full-duplex;
+                                               pause;
+                                       };
+                               };
+                       };
+               };
+       };
+};
+
+&spi0 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&spi0_flash_pins>;
+       status = "okay";
+
+       spi_nand: spi_nand@0 {
+               #address-cells = <1>;
+               #size-cells = <1>;
+               compatible = "spi-nand";
+               reg = <0>;
+               spi-max-frequency = <52000000>;
+               spi-tx-bus-width = <4>;
+               spi-rx-bus-width = <4>;
+
+               partitions {
+                       compatible = "fixed-partitions";
+                       #address-cells = <1>;
+                       #size-cells = <1>;
+
+                       partition@0 {
+                               label = "boot";
+                               reg = <0x00000 0x0200000>;
+                               read-only;
+                       };
+
+                       partition@200000 {
+                               label = "u-boot-env";
+                               reg = <0x0200000 0x0100000>;
+                       };
+
+                       partition@300000 {
+                               label = "ubi0";
+                               reg = <0x300000 0x3200000>;
+                       };
+
+                       partition@3500000 {
+                               label = "ubi1";
+                               reg = <0x3500000 0x3200000>;
+                               read-only;
+                       };
+
+                       partition@6700000 {
+                               label = "userconfig";
+                               reg = <0x6700000 0x800000>;
+                               read-only;
+                       };
+
+                       partition@6f00000 {
+                               label = "tp_data";
+                               reg = <0x6f00000 0x800000>;
+                               read-only;
+                       };
+               };
+       };
+};
+
+&pio {
+       spi0_flash_pins: spi0-pins {
+               mux {
+                       function = "spi";
+                       groups = "spi0", "spi0_wp_hold";
+               };
+
+               conf-pu {
+                       pins = "SPI0_CS", "SPI0_HOLD", "SPI0_WP";
+                       drive-strength = <MTK_DRIVE_8mA>;
+                       bias-pull-up = <MTK_PUPD_SET_R1R0_11>;
+               };
+
+               conf-pd {
+                       pins = "SPI0_CLK", "SPI0_MOSI", "SPI0_MISO";
+                       drive-strength = <MTK_DRIVE_8mA>;
+                       bias-pull-down = <MTK_PUPD_SET_R1R0_11>;
+               };
+       };
+};
+
+&wifi {
+       status = "okay";
+};
index 326f09341d7797237cfcc26429a3007b01113674..c7455b78fcc67792e625ac990caf9fe66fec088a 100644 (file)
@@ -55,6 +55,12 @@ glinet,gl-xe3000)
 huasifei,wh3000)
        ucidef_set_led_netdev "wan" "WAN" "red:wan" "eth1" "link tx rx"
        ;;
+mercusys,mr80x-v3)
+       ucidef_set_led_netdev "lan1" "lan-1" "green:lan-1" "lan1" "link tx rx"
+       ucidef_set_led_netdev "lan2" "lan-2" "green:lan-2" "lan2" "link tx rx"
+       ucidef_set_led_netdev "lan3" "lan-3" "green:lan-3" "lan3" "link tx rx"
+       ucidef_set_led_netdev "wan" "wan" "green:wan" "wan" "link tx rx"
+       ;;
 mercusys,mr90x-v1|\
 mercusys,mr90x-v1-ubi)
        ucidef_set_led_netdev "lan-0" "lan-0" "green:lan-0" "lan0" "link tx rx"
index d970b2385864deb4862e758e44d61365709c0cf2..cc01a3d2b42959737a543bdc62ea90e86b97b9ed 100644 (file)
@@ -13,6 +13,7 @@ mediatek_setup_interfaces()
        h3c,magic-nx30-pro|\
        netis,nx31|\
        nokia,ea0326gmp|\
+       mercusys,mr80x-v3|\
        zbtlink,zbt-z8103ax)
                ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" eth1
                ;;
@@ -163,6 +164,12 @@ mediatek_setup_macs()
                lan_mac=$(macaddr_add "$wan_mac" 1)
                label_mac=$wan_mac
                ;;
+       mercusys,mr80x-v3)
+               mac_dirty=$(cat "/tmp/tp_data/default-mac" | sed -n 's/^'"MAC"'://p')
+               label_mac=$(macaddr_canonicalize "$mac_dirty")
+               lan_mac=$label_mac
+               wan_mac=$(macaddr_add "$lan_mac" 1)
+               ;;
        mercusys,mr90x-v1|\
        tplink,re6000xd)
                label_mac=$(get_mac_binary "/tmp/tp_data/default-mac" 0)
index 8456c462b6339b4afe27ef0215dee6b198965758..34aacb931275b2ca66c47bfbf35a50c3746d1cce 100644 (file)
@@ -9,6 +9,10 @@ board=$(board_name)
 case "$FIRMWARE" in
 "mediatek/mt7981_eeprom_mt7976_dbdc.bin")
        case "$board" in
+       mercusys,mr80x-v3)
+               ln -sf /tmp/tp_data/MT7981_EEPROM.bin \
+                       /lib/firmware/$FIRMWARE
+               ;;
        ubnt,unifi-6-plus)
                caldata_extract_mmc "factory" 0x0 0x1000
                ;;
index 194154c0432d4cbab5ddf3d5660d902967a726f4..7251e05d63a6e01264ff412062f4c1d03c67cce3 100644 (file)
@@ -118,6 +118,12 @@ case "$board" in
                [ "$PHYNBR" = "1" ] && \
                        macaddr_setbit_la "$(mtd_get_mac_binary rf-eeprom 0x4)" > /sys${DEVPATH}/macaddress
                ;;
+       mercusys,mr80x-v3)
+               mac_dirty=$(cat "/tmp/tp_data/default-mac" | sed -n 's/^'"MAC"'://p')
+               label_mac=$(macaddr_canonicalize "$mac_dirty")
+               [ "$PHYNBR" = "0" ] && macaddr_add $label_mac -1 > /sys${DEVPATH}/macaddress
+               [ "$PHYNBR" = "1" ] && macaddr_add $label_mac -2 > /sys${DEVPATH}/macaddress
+               ;;
        mercusys,mr90x-v1|\
        tplink,re6000xd)
                addr=$(get_mac_binary "/tmp/tp_data/default-mac" 0)
index 11e3b598af8eae9c9e18ed6c7b018f4b087a8671..1474fad831c5b526ce42c832f8db37349f272610 100644 (file)
@@ -12,6 +12,7 @@ mount_ubi_part() {
 
 preinit_mount_cfg_part() {
        case $(board_name) in
+       mercusys,mr80x-v3|\
        mercusys,mr90x-v1|\
        tplink,re6000xd)
                mount_ubi_part "tp_data"
index f5e8ba962d73c6ebcc7d4e534ca7453b86b3a661..2c6a0372f444dc3f61f9a79de645d97929077bde 100755 (executable)
@@ -134,6 +134,7 @@ platform_do_upgrade() {
                fw_setenv sw_tryactive 0
                nand_do_upgrade "$1"
                ;;
+       mercusys,mr80x-v3|\
        mercusys,mr90x-v1|\
        tplink,re6000xd)
                CI_UBIPART="ubi0"
index 8f4090a74fb606422efde40748b9f6fe8f8b678c..b4449a37fe555db92864a679d1a48e92d45f2d7c 100644 (file)
@@ -1203,6 +1203,20 @@ define Device/mediatek_mt7988a-rfb
 endef
 TARGET_DEVICES += mediatek_mt7988a-rfb
 
+define Device/mercusys_mr80x-v3
+  DEVICE_VENDOR := MERCUSYS
+  DEVICE_MODEL := MR80X
+  DEVICE_VARIANT := v3
+  DEVICE_DTS := mt7981b-mercusys-mr80x-v3
+  DEVICE_DTS_DIR := ../dts
+  DEVICE_PACKAGES := kmod-mt7915e kmod-mt7981-firmware mt7981-wo-firmware
+  UBINIZE_OPTS := -E 5
+  BLOCKSIZE := 128k
+  PAGESIZE := 2048
+  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
+endef
+TARGET_DEVICES += mercusys_mr80x-v3
+
 define Device/mercusys_mr90x-v1
   DEVICE_VENDOR := MERCUSYS
   DEVICE_MODEL := MR90X v1