From a04283b4f70a3bc878b4659032b84e401bc5c134 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Tue, 2 Apr 2019 21:50:44 +0800 Subject: [PATCH] ramips: add Xiaomi Mi Router 3 support --- package/boot/uboot-envtools/files/ramips | 1 + .../ramips/base-files/etc/board.d/02_network | 5 + .../ramips/base-files/lib/upgrade/platform.sh | 1 + target/linux/ramips/dts/MIWIFI-R3.dts | 175 ++++++++++++++++++ target/linux/ramips/image/mt7620.mk | 16 ++ 5 files changed, 198 insertions(+) create mode 100644 target/linux/ramips/dts/MIWIFI-R3.dts diff --git a/package/boot/uboot-envtools/files/ramips b/package/boot/uboot-envtools/files/ramips index b70f62656..777179496 100644 --- a/package/boot/uboot-envtools/files/ramips +++ b/package/boot/uboot-envtools/files/ramips @@ -32,6 +32,7 @@ zbt-wg2626) ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000" ;; xiaomi,mir3p|\ +xiaomi,miwifi-r3|\ mir3g) ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000" ;; diff --git a/target/linux/ramips/base-files/etc/board.d/02_network b/target/linux/ramips/base-files/etc/board.d/02_network index 9f7a7108e..5811d9953 100755 --- a/target/linux/ramips/base-files/etc/board.d/02_network +++ b/target/linux/ramips/base-files/etc/board.d/02_network @@ -428,6 +428,10 @@ ramips_setup_interfaces() ucidef_add_switch "switch0" \ "4:lan" "0:wan" "6@eth0" ;; + xiaomi,miwifi-r3) + ucidef_add_switch "switch0" \ + "1:lan" "4:lan" "0:wan" "6@eth0" + ;; zbtlink,zbt-we1226|\ y1) ucidef_add_switch "switch0" \ @@ -554,6 +558,7 @@ ramips_setup_macs() lan_mac=$(mtd_get_mac_binary Factory 0xe006) wan_mac=$(mtd_get_mac_binary Factory 0xe000) ;; + xiaomi,miwifi-r3|\ miwifi-mini) wan_mac=$(cat /sys/class/net/eth0/address) lan_mac=$(macaddr_setbit_la "$wan_mac") diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh b/target/linux/ramips/base-files/lib/upgrade/platform.sh index 5fae15a6d..9c65c1042 100755 --- a/target/linux/ramips/base-files/lib/upgrade/platform.sh +++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh @@ -40,6 +40,7 @@ platform_do_upgrade() { mir4|\ r6220|\ netgear,r6350|\ + xiaomi,miwifi-r3|\ ubnt-erx|\ ubnt-erx-sfp) nand_do_upgrade "$ARGV" diff --git a/target/linux/ramips/dts/MIWIFI-R3.dts b/target/linux/ramips/dts/MIWIFI-R3.dts new file mode 100644 index 000000000..c535a71c6 --- /dev/null +++ b/target/linux/ramips/dts/MIWIFI-R3.dts @@ -0,0 +1,175 @@ +/dts-v1/; + +#include "mt7620a.dtsi" + +#include +#include + +/ { + compatible = "xiaomi,miwifi-r3", "ralink,mt7620a-soc"; + model = "Xiaomi Mi Router R3"; + + aliases { + led-status = &led_status_blue; + }; + + memory@0 { + device_type = "memory"; + reg = <0x0 0x8000000>; + }; + + chosen { + bootargs = "console=ttyS0,115200"; + }; + + gpio-keys-polled { + compatible = "gpio-keys-polled"; + #address-cells = <1>; + #size-cells = <0>; + poll-interval = <20>; + + reset { + label = "reset"; + gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>; + linux,code = ; + }; + }; + + gpio-leds { + compatible = "gpio-leds"; + + led_status_blue: blue { + label = "miwifi-r3:blue:status"; + gpios = <&gpio1 0 GPIO_ACTIVE_LOW>; + }; + + yellow { + label = "miwifi-r3:yellow:status"; + gpios = <&gpio1 2 GPIO_ACTIVE_LOW>; + }; + + red { + label = "miwifi-r3:red:status"; + gpios = <&gpio1 5 GPIO_ACTIVE_LOW>; + }; + }; + + nand { + status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + compatible = "mtk,mt7620-nand"; + + partition@0 { + label = "Bootloader"; + reg = <0x0 0x40000>; + read-only; + }; + + partition@40000 { + label = "Config"; + reg = <0x40000 0x40000>; + }; + + partition@80000 { + label = "Bdata"; + reg = <0x80000 0x40000>; + read-only; + }; + + factory: partition@0xc0000 { + label = "Factory"; + reg = <0xc0000 0x40000>; + read-only; + }; + + partition@100000 { + label = "crash"; + reg = <0x100000 0x40000>; + read-only; + }; + + partition@140000 { + label = "crash_syslog"; + reg = <0x140000 0x40000>; + read-only; + }; + + partition@180000 { + label = "reserved0"; + reg = <0x180000 0x80000>; + read-only; + }; + + partition@200000 { + label = "kernel0_rsvd"; + reg = <0x200000 0x400000>; + }; + + partition@600000 { + label = "kernel"; + reg = <0x600000 0x400000>; + }; + + /* ubi partition is the result of squashing + * next consequent stock partitions: + * - rootfs0 (rootfs partition for stock kernel0), + * - rootfs1 (rootfs partition for stock failsafe kernel1), + * - overlay (used as ubi overlay in stock fw) + * resulting 117,5MiB space for packages. + */ + partition@a00000 { + label = "ubi"; + reg = <0xa00000 0x7600000>; + }; + }; +}; + +&gpio1 { + status = "okay"; +}; + +&ehci { + status = "okay"; +}; + +&ohci { + status = "okay"; +}; + +ðernet { + pinctrl-names = "default"; + pinctrl-0 = <&ephy_pins>; + mtd-mac-address = <&factory 0x28>; + mediatek,portmap = "llllw"; +}; + +&wmac { + ralink,mtd-eeprom = <&factory 0>; +}; + +&pcie { + status = "okay"; +}; + +&pcie0 { + mt76@0,0 { + reg = <0x0000 0 0 0 0>; + mediatek,mtd-eeprom = <&factory 0x8000>; + ieee80211-freq-limit = <5000000 6000000>; + }; +}; + +&pinctrl { + state_default: pinctrl0 { + gpio { + ralink,group = "rgmii1"; + ralink,function = "gpio"; + }; + + pa { + ralink,group = "pa"; + ralink,function = "pa"; + }; + }; +}; diff --git a/target/linux/ramips/image/mt7620.mk b/target/linux/ramips/image/mt7620.mk index e487f529d..f646437d7 100644 --- a/target/linux/ramips/image/mt7620.mk +++ b/target/linux/ramips/image/mt7620.mk @@ -712,6 +712,22 @@ define Device/we1026-5g-16m endef TARGET_DEVICES += we1026-5g-16m +define Device/xiaomi_miwifi-r3 + DTS := MIWIFI-R3 + BLOCKSIZE := 128k + PAGESIZE := 2048 + KERNEL_SIZE := 4096k + IMAGE_SIZE := 32768k + UBINIZE_OPTS := -E 5 + IMAGES += kernel1.bin rootfs0.bin + IMAGE/kernel1.bin := append-kernel | check-size $$$$(KERNEL_SIZE) + IMAGE/rootfs0.bin := append-ubi | check-size $$$$(IMAGE_SIZE) + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata + DEVICE_TITLE := Xiaomi Mi Router R3 + DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci uboot-envtools +endef +TARGET_DEVICES += xiaomi_miwifi-r3 + define Device/zbt-ape522ii DTS := ZBT-APE522II DEVICE_TITLE := Zbtlink ZBT-APE522II