[OpenWrt-Devel] [PATCH v2] ramips: add support for Xiaomi Mi Router 4A (100M Edition)

markus at mscheck.de markus at mscheck.de
Mon May 6 10:27:10 EDT 2019


Hi David,

thank you for your feedback and your explanation. I'll include the 
changes and resubmit the patch after testing that everything still 
works. For the LEDs I think it makes sense leaving them as is so that 
they mimic the behavior of the stock firmware.

Regards,
Markus

Am 2019-05-06 15:04, schrieb David Bauer:
> Hello Markus,
> 
> see my comments inline:
> 
> On 06.05.19 11:15, Markus Scheck wrote:
>> - SoC:      MediaTek MT7628AN
>> - Flash:    16MB (Winbond W25Q128JV)
>> - RAM:      64MB
>> - Serial:   As marked on PCB, 3V3 logic, baudrate is 115200
>> - Ethernet: 3x 10/100 Mbps (switched, 2x LAN + WAN)
>> - WIFI0:    MT7628AN 2.4GHz 802.11b/g/n
>> - WIFI1:    MT7612EN 5GHz 802.11ac
>> - Antennas: 4x external (2 per radio), non-detachable
>> - LEDs:     Programmable power-LED (two-colored, yellow/blue)
>>             Non-programmable internet-LED (shows WAN-activity)
>> - Buttons:  Reset
>> 
>> INSTALLATION:
>> 
>> 1. Connect to the serial port of the router and power it up.
>>    If you get a prompt asking for boot-mode, go to step 3.
>> 2. Unplug the router after
>>        > Erasing SPI Flash...
>>        > raspi_erase: offs:20000 len:10000
>>    occurs on the serial port. Plug the router back in.
>> 3. At the prompt select option 2 (Load system code then
>>    write to Flash via TFTP.)
>> 4. Enter 192.168.1.1 as the device IP and 192.168.1.2 as the
>>    Server-IP.
>> 5. Connect your computer to LAN1 and assign it as 192.168.1.2/24.
>> 6. Rename the sysupgrade image to test.bin and serve it via TFTP.
>> 7. Enter test.bin on the serial console and press enter.
>> 
>> Signed-off-by: Markus Scheck <markus at mscheck.de>
>> ---
>>  .../ramips/base-files/etc/board.d/02_network  |   4 +
>>  target/linux/ramips/base-files/lib/ramips.sh  |   3 +
>>  target/linux/ramips/dts/XIAOMI-MIR4A-100M.dts | 147 
>> ++++++++++++++++++
>>  target/linux/ramips/image/mt76x8.mk           |   8 +
>>  4 files changed, 162 insertions(+)
>>  create mode 100644 target/linux/ramips/dts/XIAOMI-MIR4A-100M.dts
>> 
>> 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 c2646876a2..29a1e7b54c 100755
>> --- a/target/linux/ramips/base-files/etc/board.d/02_network
>> +++ b/target/linux/ramips/base-files/etc/board.d/02_network
>> @@ -450,6 +450,10 @@ ramips_setup_interfaces()
>>  		ucidef_add_switch "switch0" \
>>  			"1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6 at eth0"
>>  		;;
>> +	xiaomi,mir4a-100m)
>> +		ucidef_add_switch "switch0" \
>> +			"4:lan:1" "2:lan:2" "0:wan" "6t at eth0"
>> +		;;
> 
> You can replace "6t at eth0" with "6 at eth0". Tagging is always used by 
> default.
> 
>>  	zbtlink,zbt-we1226|\
>>  	y1)
>>  		ucidef_add_switch "switch0" \
>> diff --git a/target/linux/ramips/base-files/lib/ramips.sh 
>> b/target/linux/ramips/base-files/lib/ramips.sh
>> index 093303892c..a9e7e746cd 100755
>> --- a/target/linux/ramips/base-files/lib/ramips.sh
>> +++ b/target/linux/ramips/base-files/lib/ramips.sh
>> @@ -649,6 +649,9 @@ ramips_board_detect() {
>>  	*"X8")
>>  		name="x8"
>>  		;;
>> +	*"Xiaomi Mi Router 4A (100M Edition)")
>> +		name="xiaomi,mir4a-100m"
>> +		;;
>>  	*"Y1")
>>  		name="y1"
>>  		;;
> 
> You can completely omit this change in ramips.sh. By default, the
> boardname is extracted from the machines compatible-string in it's
> device-tree. :)
> 
>> diff --git a/target/linux/ramips/dts/XIAOMI-MIR4A-100M.dts 
>> b/target/linux/ramips/dts/XIAOMI-MIR4A-100M.dts
>> new file mode 100644
>> index 0000000000..b843bb203e
>> --- /dev/null
>> +++ b/target/linux/ramips/dts/XIAOMI-MIR4A-100M.dts
>> @@ -0,0 +1,147 @@
>> +//SPDX-License-Identifier: GPL-2.0-or-later OR MIT
>> +/dts-v1/;
>> +
>> +#include "mt7628an.dtsi"
>> +
>> +#include <dt-bindings/gpio/gpio.h>
>> +#include <dt-bindings/input/input.h>
>> +
>> +/ {
>> +	compatible = "xiaomi,mir4a-100m", "mediatek,mt7628an-soc";
>> +	model = "Xiaomi Mi Router 4A (100M Edition)";
>> +
>> +	chosen {
>> +		bootargs = "console=ttyS0,115200";
>> +	};
>> +
>> +	memory at 0 {
>> +		device_type = "memory";
>> +		reg = <0x0 0x4000000>;
>> +	};
>> +
>> +	aliases {
>> +		led-boot = &power_yellow;
>> +		led-failsafe = &power_yellow;
>> +		led-running = &power_blue;
>> +		led-upgrade = &power_yellow;
>> +	};
> 
> This might be a matter of personal preference, but i would use the blue
> indicator for led-boot instead of the yellow one.
> 
>> +
>> +	gpio-leds {
> 
> Rename the node (not the compatible) from 'gpio-leds' to 'leds'.
> 
>> +		compatible = "gpio-leds";
>> +
>> +		power_blue: power_blue {
>> +			label = "mir4a-100m:blue:power";
>> +			gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
>> +		};
>> +
>> +		power_yellow: power_yellow {
>> +			label = "mir4a-100m:yellow:power";
>> +			gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
>> +		};
>> +	};
>> +
>> +	gpio-keys {
> 
> Rename the node (not the compatible) from 'gpio-keys' to 'keys'.
> 
>> +		compatible = "gpio-keys-polled";
>> +		poll-interval = <20>;
>> +
>> +		reset {
>> +			label = "reset";
>> +			gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
>> +			linux,code = <KEY_RESTART>;
>> +		};
>> +	};
>> +};
>> +
>> +&spi0 {
>> +	status = "okay";
>> +
>> +	flash at 0 {
>> +		compatible = "jedec,spi-nor";
>> +		reg = <0>;
>> +		spi-max-frequency = <10000000>;
>> +
>> +		partitions {
>> +			compatible = "fixed-partitions";
>> +			#address-cells = <1>;
>> +			#size-cells = <1>;
>> +
>> +			partition at 0 {
>> +				label = "bootloader";
>> +				reg = <0x0 0x20000>;
>> +				read-only;
>> +			};
>> +
>> +			partition at 20000 {
>> +				label = "config";
>> +				reg = <0x20000 0x10000>;
>> +				read-only;
>> +			};
>> +
>> +			factory: partition at 30000 {
>> +				label = "factory";
>> +				reg = <0x30000 0x10000>;
>> +				read-only;
>> +			};
>> +
>> +			partition at 40000 {
>> +				label = "crash";
>> +				reg = <0x40000 0x10000>;
>> +				read-only;
>> +			};
>> +
>> +			partition at 50000 {
>> +				label = "cfg_bak";
>> +				reg = <0x50000 0x10000>;
>> +				read-only;
>> +			};
>> +
>> +			partition at 60000 {
>> +				label = "overlay";
>> +				reg = <0x60000 0x100000>;
>> +				read-only;
>> +			};
>> +
>> +			partition at 160000 {
>> +				compatible = "denx,uimage";
>> +				label = "firmware";
>> +				reg = <0x160000 0xea0000>;
>> +			};
>> +		};
>> +	};
>> +};
>> +
>> +&pcie {
>> +	status = "okay";
>> +
>> +	pcie-bridge {
>> +		mt76 at 0,0 {
>> +			reg = <0x0000 0 0 0 0>;
>> +			device_type = "pci";
>> +			mediatek,mtd-eeprom = <&factory 0x8000>;
>> +			mediatek,2ghz = <0>;
>> +		};
>> +	};
>> +};
> 
> Commit f9b8328d794473fcd044197ec64abf87761793e4 reworked how PCIe nodes
> are referenced. Instead of recreating the whole hierarchy, try 
> something
> like
> 
> &pcie {
> 	status = "okay";
> };
> 
> &pcie0 {
> 	wifi at 0,0 {
> 		[...]
> 	};
> };
> 
> Note how 'mt76 at 0,0' switched wo the more generic 'wifi at 0,0'.
> 
>> +
>> +&pinctrl {
>> +	state_default: pinctrl0 {
>> +		gpio {
>> +			ralink,group = "gpio";
>> +			ralink,function = "gpio";
> 
> You have to specify which pins should work in GPIO mode. You can omit
> the gpio pin here, as by itself it is already set to GPIO mode.
> 
> Instead you need to specify 'ralink,function = "gpio"' for the "wdt" 
> and
> "wled_an" pingroup.
> 
> Take a look at the MT7628 datasheet (Google). On Page 23/24 you will 
> see
> the Pin-Sharing scheme. GPIO0-GPIO31 are gpio0, GPIO32-GPIO63 are 
> gpio1.
> 
>> +		};
>> +	};
>> +};
>> +
>> +&ethernet {
>> +	pinctrl-names = "default";
> 
> As you did not specify any pins, this definition should be removed. I'm
> also pretty sure you do not need to specify pins for the ethernet 
> driver.
> 
>> +	mtd-mac-address = <&factory 0x28>;
>> +};
>> +
>> +&esw {
>> +	mediatek,portmap = <0x2f>;
>> +	mediatek,portdisable = <0x2a>;
>> +};
>> +
>> +&wmac {
>> +	status = "okay";
>> +};
> 
> The reference to the caldata seems to be missing here. Usually, it is
> saved at 0x0 on the factory partition, however the MAC address should
> map to 0x04 in this case.
> 
>> diff --git a/target/linux/ramips/image/mt76x8.mk 
>> b/target/linux/ramips/image/mt76x8.mk
>> index 571ddf3d51..82659254cb 100644
>> --- a/target/linux/ramips/image/mt76x8.mk
>> +++ b/target/linux/ramips/image/mt76x8.mk
>> @@ -446,6 +446,14 @@ define Device/wrtnode2r
>>  endef
>>  TARGET_DEVICES += wrtnode2r
>> 
>> +define Device/xiaomi_mir4a-100m
>> +  DTS := XIAOMI-MIR4A-100M
>> +  IMAGE_SIZE := $(ralink_default_fw_size_16M)
> 
> IMAGE_SIZE should match the size of the "firmware" partition.
> ralink_default_fw_size_16M is defined as 16121856 (F60000) bytes, so
> this does not match for your board.
> 
> In you case, the firmware parttion is 14976kb large.
> 
>> +  DEVICE_TITLE := Xiaomi Mi Router 4A (100M Edition)
>> +  DEVICE_PACKAGES := kmod-mt76x2
>> +endef
>> +TARGET_DEVICES += xiaomi_mir4a-100m
>> +
>>  define Device/zbtlink_zbt-we1226
>>    DTS := ZBT-WE1226
>>    IMAGE_SIZE := $(ralink_default_fw_size_8M)
>> 

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list