From d66f4754b74b2b72ef328bced5da0abd2e325ed5 Mon Sep 17 00:00:00 2001 From: hank9999 Date: Tue, 6 Jun 2023 07:24:46 +0000 Subject: [PATCH] mediatek: add support for Xiaomi WR30U Signed-off-by: hank9999 --- target/linux/mediatek/base-files/sbin/smp.sh | 1 + .../mt7981-xiaomi-mi-router-wr30u-112m.dts | 16 ++ .../mt7981-xiaomi-mi-router-wr30u-base.dtsi | 249 ++++++++++++++++++ .../mt7981-xiaomi-mi-router-wr30u-stock.dts | 28 ++ target/linux/mediatek/image/mt7981.mk | 29 ++ .../mt7981/base-files/etc/board.d/01_leds | 6 + .../mt7981/base-files/etc/board.d/02_network | 9 + .../mt7981/base-files/lib/upgrade/platform.sh | 62 +++++ 8 files changed, 400 insertions(+) create mode 100644 target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-112m.dts create mode 100644 target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-base.dtsi create mode 100644 target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-stock.dts diff --git a/target/linux/mediatek/base-files/sbin/smp.sh b/target/linux/mediatek/base-files/sbin/smp.sh index 6bafa109afc..6b866e6e371 100755 --- a/target/linux/mediatek/base-files/sbin/smp.sh +++ b/target/linux/mediatek/base-files/sbin/smp.sh @@ -719,6 +719,7 @@ setup_model() *mt2500* |\ *zr-3020* |\ *360,t7* |\ + xiaomi,mi-router-wr30u* |\ *7981*) MT7981_whnat $num_of_wifi ;; diff --git a/target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-112m.dts b/target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-112m.dts new file mode 100644 index 00000000000..8bcb221a2ce --- /dev/null +++ b/target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-112m.dts @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +/dts-v1/; +#include "mt7981-xiaomi-mi-router-wr30u-base.dtsi" + +/ { + model = "Xiaomi Mi Router WR30U (112M UBI layout)"; + compatible = "xiaomi,mi-router-wr30u-112m", "mediatek,mt7981"; +}; + +&partitions { + partition@600000 { + label = "ubi"; + reg = <0x600000 0x7000000>; + }; +}; diff --git a/target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-base.dtsi b/target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-base.dtsi new file mode 100644 index 00000000000..cdf1aae935f --- /dev/null +++ b/target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-base.dtsi @@ -0,0 +1,249 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +/dts-v1/; +#include +#include + +#include "mt7981.dtsi" + +/ { + aliases { + serial0 = &uart0; + led-boot = &led_system_yellow; + led-failsafe = &led_system_yellow; + led-running = &led_system_blue; + led-upgrade = &led_system_yellow; + }; + + chosen { + stdout-path = "serial0:115200n8"; + }; + + memory { + reg = <0 0x40000000 0 0x10000000>; + }; + + gpio-keys { + compatible = "gpio-keys"; + + reset { + label = "reset"; + gpios = <&pio 1 GPIO_ACTIVE_LOW>; + linux,code = ; + }; + + mesh { + label = "mesh"; + gpios = <&pio 0 GPIO_ACTIVE_LOW>; + linux,code = ; + linux,input-type = ; + }; + }; + + leds { + compatible = "gpio-leds"; + + led_system_blue: system_blue { + label = "blue:system"; + gpios = <&pio 9 GPIO_ACTIVE_LOW>; + }; + + led_system_yellow: system_yellow { + label = "yellow:system"; + gpios = <&pio 10 GPIO_ACTIVE_LOW>; + }; + + led_network_blue { + label = "blue:network"; + gpios = <&pio 11 GPIO_ACTIVE_LOW>; + }; + + led_network_yellow { + label = "yellow:network"; + gpios = <&pio 12 GPIO_ACTIVE_LOW>; + }; + }; + + gsw: gsw@0 { + compatible = "mediatek,mt753x"; + mediatek,ethsys = <ðsys>; + #address-cells = <1>; + #size-cells = <0>; + }; + + nmbm_spim_nand: nmbm_spim_nand { + compatible = "generic,nmbm"; + + #address-cells = <1>; + #size-cells = <1>; + + lower-mtd-device = <&spi_nand>; + forced-create; + }; +}; + +ð { + 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 = "2500base-x"; + + fixed-link { + speed = <2500>; + full-duplex; + pause; + }; + }; + + mdio: mdio-bus { + #address-cells = <1>; + #size-cells = <0>; + }; +}; + +&gsw { + mediatek,mdio = <&mdio>; + mediatek,mdio_master_pinmux = <0>; + reset-gpios = <&pio 39 0>; + interrupt-parent = <&pio>; + interrupts = <38 IRQ_TYPE_LEVEL_HIGH>; + status = "okay"; + + port5: port@5 { + compatible = "mediatek,mt753x-port"; + reg = <5>; + phy-mode = "sgmii"; + + fixed-link { + speed = <2500>; + full-duplex; + }; + }; + + port6: port@6 { + compatible = "mediatek,mt753x-port"; + mediatek,ssc-on; + reg = <6>; + phy-mode = "sgmii"; + + fixed-link { + speed = <2500>; + full-duplex; + }; + }; +}; + +&hnat { + mtketh-wan = "eth1"; + mtketh-lan = "eth0"; + mtketh-max-gmac = <2>; + status = "okay"; +}; + +&spi0 { + pinctrl-names = "default"; + pinctrl-0 = <&spi0_flash_pins>; + status = "okay"; + + spi_nand: flash@0 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "spi-nand"; + reg = <0>; + + spi-max-frequency = <52000000>; + spi-tx-buswidth = <4>; + spi-rx-buswidth = <4>; + }; +}; + +&nmbm_spim_nand { + partitions: partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "BL2"; + reg = <0x00 0x100000>; + }; + + partition@100000 { + label = "Nvram"; + reg = <0x100000 0x40000>; + }; + + partition@140000 { + label = "Bdata"; + reg = <0x140000 0x40000>; + }; + + partition@180000 { + label = "Factory"; + reg = <0x180000 0x200000>; + }; + + partition@380000 { + label = "FIP"; + reg = <0x380000 0x200000>; + }; + + partition@580000 { + label = "crash"; + reg = <0x580000 0x40000>; + }; + + partition@5c0000 { + label = "crash_log"; + reg = <0x5c0000 0x40000>; + }; + + partition@7600000 { + label = "KF"; + reg = <0x7600000 0x40000>; + }; + }; +}; + +&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 = ; + bias-pull-up = ; + }; + + conf-pd { + pins = "SPI0_CLK", "SPI0_MOSI", "SPI0_MISO"; + drive-strength = ; + bias-pull-down = ; + }; + }; +}; + +&uart0 { + status = "okay"; +}; + +&watchdog { + status = "okay"; +}; diff --git a/target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-stock.dts b/target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-stock.dts new file mode 100644 index 00000000000..141f4d0c826 --- /dev/null +++ b/target/linux/mediatek/files-5.4/arch/arm64/boot/dts/mediatek/mt7981-xiaomi-mi-router-wr30u-stock.dts @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +/dts-v1/; +#include "mt7981-xiaomi-mi-router-wr30u-base.dtsi" + +/ { + model = "Xiaomi Mi Router WR30U (stock layout)"; + compatible = "xiaomi,mi-router-wr30u-stock", "mediatek,mt7981"; +}; + +&partitions { + // ubi_kernel is the ubi partition in stock. + partition@600000 { + label = "ubi_kernel"; + reg = <0x600000 0x2200000>; + }; + + /* ubi is the result of squashing + * consecutive stock partitions: + * - ubi1 + * - overlay + * - data + */ + partition@2800000 { + label = "ubi"; + reg = <0x2800000 0x4e00000>; + }; +}; diff --git a/target/linux/mediatek/image/mt7981.mk b/target/linux/mediatek/image/mt7981.mk index bb9fef1a1f5..647f1e76182 100644 --- a/target/linux/mediatek/image/mt7981.mk +++ b/target/linux/mediatek/image/mt7981.mk @@ -223,6 +223,35 @@ define Device/cetron_ct3003 endef TARGET_DEVICES += cetron_ct3003 +define Device/xiaomi_mi-router-wr30u-stock + DEVICE_VENDOR := Xiaomi + DEVICE_MODEL := Mi Router WR30U (stock layout) + DEVICE_DTS := mt7981-xiaomi-mi-router-wr30u-stock + DEVICE_DTS_DIR := $(DTS_DIR)/mediatek + UBINIZE_OPTS := -E 5 + BLOCKSIZE := 128k + PAGESIZE := 2048 + IMAGE_SIZE := 34816k + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata +endef +TARGET_DEVICES += xiaomi_mi-router-wr30u-stock + +define Device/xiaomi_mi-router-wr30u-112m + DEVICE_VENDOR := Xiaomi + DEVICE_MODEL := Mi Router WR30U (112M UBI layout) + DEVICE_DTS := mt7981-xiaomi-mi-router-wr30u-112m + DEVICE_DTS_DIR := $(DTS_DIR)/mediatek + UBINIZE_OPTS := -E 5 + BLOCKSIZE := 128k + PAGESIZE := 2048 + IMAGE_SIZE := 114688k + KERNEL_IN_UBI := 1 + IMAGES += factory.ubi + IMAGE/factory.ubi := append-ubi | check-size $$$$(IMAGE_SIZE) + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata +endef +TARGET_DEVICES += xiaomi_mi-router-wr30u-112m + define Device/glinet_gl-mt3000 DEVICE_VENDOR := GL.iNet DEVICE_MODEL := GL-MT3000 diff --git a/target/linux/mediatek/mt7981/base-files/etc/board.d/01_leds b/target/linux/mediatek/mt7981/base-files/etc/board.d/01_leds index ff01d285cce..796540a4004 100755 --- a/target/linux/mediatek/mt7981/base-files/etc/board.d/01_leds +++ b/target/linux/mediatek/mt7981/base-files/etc/board.d/01_leds @@ -15,6 +15,12 @@ livinet,zr-3020) ucidef_set_led_netdev "internet" "INTERNET" "blue:internet" "eth1" ucidef_set_led_netdev "wlan2g" "WLAN2G" "blue:wlan2g" "ra0" "link" ucidef_set_led_netdev "wlan5g" "WLAN5G" "blue:wlan5g" "rax0" "link" +xiaomi,mi-router-wr30u*) + ucidef_set_led_netdev "wan" "wan" "blue:network" "wan" + ;; +*360,t7*) + ucidef_set_led_default "green" "GREEN" "360t7:green" "1" + ucidef_set_led_default "red" "RED" "360t7:red" "0" ;; esac diff --git a/target/linux/mediatek/mt7981/base-files/etc/board.d/02_network b/target/linux/mediatek/mt7981/base-files/etc/board.d/02_network index 3d8acb55654..31ae903bdf9 100755 --- a/target/linux/mediatek/mt7981/base-files/etc/board.d/02_network +++ b/target/linux/mediatek/mt7981/base-files/etc/board.d/02_network @@ -22,6 +22,11 @@ mediatek_setup_interfaces() *2500wan-p5*) ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" wan ;; + xiaomi,mi-router-wr30u*) + ucidef_set_interfaces_lan_wan "eth0" "eth1" + ucidef_add_switch "switch0" \ + "1:lan" "2:lan" "3:lan" "0:wan" "6u@eth0" "5u@eth1" + ;; *360,t7*) ucidef_set_interfaces_lan_wan "eth0" "eth1" ucidef_add_switch "switch0" \ @@ -119,6 +124,10 @@ mediatek_setup_macs() mtk_facrory_write_mac Factory 4 "$wifi_mac" fi ;; + xiaomi,mi-router-wr30u*) + wan_mac=$(mtd_get_mac_ascii Bdata ethaddr_wan) + lan_mac=$(mtd_get_mac_ascii Bdata ethaddr) + ;; *360,t7*) local part=$(find_mtd_part "stock-factory") if [ -n "$part" ]; then diff --git a/target/linux/mediatek/mt7981/base-files/lib/upgrade/platform.sh b/target/linux/mediatek/mt7981/base-files/lib/upgrade/platform.sh index 4401aa0de58..f2d64bfcdf5 100644 --- a/target/linux/mediatek/mt7981/base-files/lib/upgrade/platform.sh +++ b/target/linux/mediatek/mt7981/base-files/lib/upgrade/platform.sh @@ -1,9 +1,55 @@ RAMFS_COPY_BIN='mkfs.f2fs blkid blockdev fw_printenv fw_setenv' RAMFS_COPY_DATA="/etc/fw_env.config /var/lock/fw_printenv.lock" + +xiaomi_wr30u_initial_setup() +{ + # initialize UBI and setup uboot-env if it's running on initramfs + [ "$(rootfs_type)" = "tmpfs" ] || return 0 + + local mtdnum="$( find_mtd_index ubi )" + if [ ! "$mtdnum" ]; then + echo "unable to find mtd partition ubi" + return 1 + fi + + local kern_mtdnum="$( find_mtd_index ubi_kernel )" + if [ ! "$kern_mtdnum" ]; then + echo "unable to find mtd partition ubi_kernel" + return 1 + fi + + ubidetach -m "$mtdnum" + ubiformat /dev/mtd$mtdnum -y + + ubidetach -m "$kern_mtdnum" + ubiformat /dev/mtd$kern_mtdnum -y + + if ! fw_printenv -n flag_try_sys2_failed &>/dev/null; then + echo "failed to access u-boot-env. skip env setup." + return 0 + fi + + fw_setenv boot_wait on + fw_setenv uart_en 1 + fw_setenv flag_boot_rootfs 0 + fw_setenv flag_last_success 1 + fw_setenv flag_boot_success 1 + fw_setenv flag_try_sys1_failed 8 + fw_setenv flag_try_sys2_failed 8 + + local board=$(board_name) + case "$board" in + xiaomi,mi-router-wr30u-stock) + fw_setenv mtdparts "nmbm0:1024k(bl2),256k(Nvram),256k(Bdata),2048k(factory),2048k(fip),256k(crash),256k(crash_log),34816k(ubi),34816k(ubi1),32768k(overlay),12288k(data),256k(KF)" + ;; + esac +} + platform_do_upgrade() { local board=$(board_name) case "$board" in + xiaomi,mi-router-wr30u-112m|\ *mt3000* |\ *x3000* |\ *xe3000* |\ @@ -18,6 +64,11 @@ platform_do_upgrade() { *emmc*) mtk_mmc_do_upgrade "$1" ;; + xiaomi,mi-router-wr30u-stock) + CI_KERN_UBIPART=ubi_kernel + CI_ROOT_UBIPART=ubi + nand_do_upgrade "$1" + ;; *) default_do_upgrade "$1" ;; @@ -39,6 +90,8 @@ platform_check_image() { *mt2500* |\ *zr-3020* |\ *360,t7* |\ + xiaomi,mi-router-wr30u-stock|\ + xiaomi,mi-router-wr30u-112m|\ *cetron,ct3003* |\ *jcg,q30* |\ *snand* |\ @@ -65,3 +118,12 @@ platform_check_image() { return 0 } +platform_pre_upgrade() { + local board=$(board_name) + + case "$board" in + xiaomi,mi-router-wr30u-stock) + xiaomi_wr30u_initial_setup + ;; + esac +}