[PATCH] ramips: add support for Xiaomi Mi Router 4C

Adrian Schmutzler mail at adrianschmutzler.de
Tue Aug 18 16:40:12 EDT 2020


Hi,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces at lists.openwrt.org]
> On Behalf Of ataberkozen123 at gmail.com
> Sent: Dienstag, 18. August 2020 20:12
> To: openwrt-devel at lists.openwrt.org
> Cc: Ataberk Özen <ataberkozen123 at gmail.com>
> Subject: [PATCH] ramips: add support for Xiaomi Mi Router 4C
> 
> From: Ataberk Özen <ataberkozen123 at gmail.com>
> 
> This commit adds support for Xiaomi's Mi Router 4C device.
> 
> Specifications:
> 
> - CPU: MediaTek MT7628AN (580MHz)
> - Flash: 16MB
> - RAM: 16MB DDR2
> - 2.4 GHz: IEEE 802.11b/g/n with Integrated LNA and PA
> - Antennas: 4x external single band antennas
> - WAN: 1x 10/100M
> - LAN: 2x 10/100M
> - LEDs: 2x yellow/blue. Programmable (labelled as power on case) - Non-
> programmable (shows WAN activity)
> - Button: Reset
> 
> How to install:
> 
> 1- Use https://github.com/acecilia/OpenWRTInvasion to gain telnet and ftp
> access.

I hesitate to add a device that solely depends on an OEM firmware exploit.

Apart from that, just referring to some (non-OEM) external tool is quite inconvenient. If the page is deleted tomorrow, we won't know how to flash anymore.

So, I'd be happy about some alternate method and/or some details to reconstruct what the external tool does.

Best

Adrian

> 2- Push openwrt firmware to /tmp/ using ftp.
> 3- Connect to router using telnet. (IP: 192.168.31.1 - Username: root - No
> password)
> 4- Use command "mtd -r write /tmp/firmware.bin OS1" to flash into the
> router..
> 5- It takes around 2 minutes. After that router will restart itself to OpenWrt.
> 
> Signed-off-by: Ataberk Özen <ataberkozen123 at gmail.com>
> ---
>  package/boot/uboot-envtools/files/ramips           |   1 +
>  target/linux/ramips/dts/mt7628an_xiaomi_mir4c.dts  | 133
> +++++++++++++++++++++
>  target/linux/ramips/image/mt76x8.mk                |   9 ++
>  .../mt76x8/base-files/etc/board.d/02_network       |   4 +
>  .../ramips/mt76x8/base-files/etc/init.d/bootcount  |   3 +
>  5 files changed, 150 insertions(+)
>  create mode 100644 target/linux/ramips/dts/mt7628an_xiaomi_mir4c.dts
> 
> diff --git a/package/boot/uboot-envtools/files/ramips
> b/package/boot/uboot-envtools/files/ramips
> index 80a91f0..d42dbd3 100644
> --- a/package/boot/uboot-envtools/files/ramips
> +++ b/package/boot/uboot-envtools/files/ramips
> @@ -29,6 +29,7 @@ buffalo,wsr-1166dhp|\
>  buffalo,wsr-600dhp|\
>  mediatek,linkit-smart-7688|\
>  samknows,whitebox-v8|\
> +xiaomi,mir4c|\
>  xiaomi,miwifi-nano|\
>  zbtlink,zbt-wg2626)
>  	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
> diff --git a/target/linux/ramips/dts/mt7628an_xiaomi_mir4c.dts
> b/target/linux/ramips/dts/mt7628an_xiaomi_mir4c.dts
> new file mode 100644
> index 0000000..f5fd3cf
> --- /dev/null
> +++ b/target/linux/ramips/dts/mt7628an_xiaomi_mir4c.dts
> @@ -0,0 +1,133 @@
> +/dts-v1/;
> +
> +#include "mt7628an.dtsi"
> +
> +#include <dt-bindings/gpio/gpio.h>
> +#include <dt-bindings/input/input.h>
> +
> +/ {
> +	compatible = "xiaomi,mir4c", "mediatek,mt7628an-soc";
> +	model = "Xiaomi Mi Router 4C";
> +
> +	aliases {
> +		led-boot = &power_yellow;
> +		led-failsafe = &power_yellow;
> +		led-running = &power_blue;
> +		led-upgrade = &power_yellow;
> +		label-mac-device = ðernet;
> +	};
> +
> +	chosen {
> +		bootargs = "console=ttyS0,115200";
> +	};
> +
> +	leds {
> +		compatible = "gpio-leds";
> +
> +		power_blue: power_blue {
> +			label = "mir4c:blue:power";
> +			gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
> +		};
> +
> +		power_yellow: power_yellow {
> +			label = "mir4c:yellow:power";
> +			gpios = <&gpio 44 GPIO_ACTIVE_LOW>;
> +		};
> +	};
> +
> +	keys {
> +		compatible = "gpio-keys";
> +
> +		reset {
> +			label = "reset";
> +			gpios = <&gpio 38 GPIO_ACTIVE_LOW>;
> +			linux,code = <KEY_RESTART>;
> +		};
> +	};
> +};
> +
> +&state_default {
> +	gpio {
> +		groups = "gpio", "refclk", "wdt", "wled_an";
> +		function = "gpio";
> +	};
> +};
> +
> +&ehci {
> +	status = "disabled";
> +};
> +
> +&ohci {
> +	status = "disabled";
> +};
> +
> +&esw {
> +	mediatek,portmap = <0x3d>;
> +	mediatek,portdisable = <0x29>;
> +};
> +
> +&wmac {
> +	status = "okay";
> +};
> +
> +&ethernet {
> +	mtd-mac-address = <&factory 0x28>;
> +};
> +
> +&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 {
> +				label = "firmware";
> +				reg = <0x160000 0xea0000>;
> +				compatible = "denx,uimage";
> +			};
> +		};
> +	};
> +};
> diff --git a/target/linux/ramips/image/mt76x8.mk
> b/target/linux/ramips/image/mt76x8.mk
> index 908e2df..99fae05 100644
> --- a/target/linux/ramips/image/mt76x8.mk
> +++ b/target/linux/ramips/image/mt76x8.mk
> @@ -680,6 +680,15 @@ define Device/xiaomi_mir4a-100m  endef
> TARGET_DEVICES += xiaomi_mir4a-100m
> 
> +define Device/xiaomi_mir4c
> +  IMAGE_SIZE := 16064k
> +  DEVICE_VENDOR := Xiaomi
> +  DEVICE_MODEL := Mi Router 4C
> +  DEVICE_PACKAGES := uboot-envtools
> +  SUPPORTED_DEVICES += mir4c
> +endef
> +TARGET_DEVICES += xiaomi_mir4c
> +
>  define Device/xiaomi_miwifi-nano
>    IMAGE_SIZE := 16064k
>    DEVICE_VENDOR := Xiaomi
> diff --git a/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
> b/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
> index 5a5ba58..ce08752 100755
> --- a/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
> +++ b/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
> @@ -126,6 +126,10 @@ ramips_setup_interfaces()
>  		ucidef_add_switch "switch0" \
>  			"4:lan:1" "2:lan:2" "0:wan" "6 at eth0"
>  		;;
> +	xiaomi,mir4c)
> +		ucidef_add_switch "switch0" \
> +			"4:lan" "2:lan" "1:wan" "6 at eth0"
> +		;;
>  	xiaomi,miwifi-nano)
>  		ucidef_add_switch "switch0" \
>  			"0:lan:2" "2:lan:1" "4:wan" "6 at eth0"
> diff --git a/target/linux/ramips/mt76x8/base-files/etc/init.d/bootcount
> b/target/linux/ramips/mt76x8/base-files/etc/init.d/bootcount
> index 3c21433..1449083 100755
> --- a/target/linux/ramips/mt76x8/base-files/etc/init.d/bootcount
> +++ b/target/linux/ramips/mt76x8/base-files/etc/init.d/bootcount
> @@ -8,6 +8,9 @@ boot() {
>  		[ -n "$(fw_printenv bootcount bootchanged 2>/dev/null)" ]
> &&\
>  			echo -e "bootcount\nbootchanged\n" |
> /usr/sbin/fw_setenv -s -
>  		;;
> +	xiaomi,mir4c)
> +		fw_setenv flag_boot_success 1
> +		;;
>  	xiaomi,miwifi-nano)
>  		fw_setenv flag_boot_success 1
>  		;;
> --
> 2.7.4
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openpgp-digital-signature.asc
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20200818/6d7ed587/attachment-0001.sig>


More information about the openwrt-devel mailing list