Support for Xiaomi Mi 3C

Dear @anjmis04
most likely it is not sufficient just to add those lines :slight_smile:
I am not familiar with OpenWrt.
I had digged a little bit into the code ... and I saw that the software architecture of OpenWrt is for my taste not well structured, and could be done much better. But that's a lot of work, because it has grown for many years based on the architecture it has.
Formerly I had developed and made a commit to the Padavan firmware for the Mi-3C, which is now in the official repository of "hanwckf" on Github. That code, which was originally developed by Andy Padavan, is much easier to understand and self explaining. Also with lots of commenting, which helps to get much faster insight.
Adapting a router to OpenWrt seems for me to be more complex.
Therefore I was looking for smart people like @eduardo010174, who want to engange in this community to develop the firmware for the Mi-3C.
A couple of posts ago I had asked him what else he had changed for his first build.
Maybe this gives me more insight to support him in a better way.

6@eth0 is the logical port connected to cpu of router.
is the cpu port

yes exatly same.

Dear @eduardo010174
Thanks for your explanation!
Could you figure out why your first build led to a brick?
Did you change any further files besides the one where the ports are set?

First i move my directory from master for 19.07-Snapshot

git clone https://github.com/openwrt/openwrt.git
cd openwrt
git pull
git branch
git checkout openwrt-19.07
git pull
./scripts/feeds update -a
./scripts/feeds install -a

go to openwrt/target/linux/ramips

next create new dts for MIWIFI-3C in
openwrt/target/linux/ramips/dts/MIWIFI-3C.dts

/dts-v1/;

#include "mt7628an.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

/ {
	compatible = "xiaomi,miwifi-3c", "mediatek,mt7628an-soc";
	model = "MiWiFi 3C";

	aliases {
		led-boot = &led_blue;
		led-failsafe = &led_blue;
		led-running = &led_blue;
		led-upgrade = &led_blue;
	};

	chosen {
		bootargs = "console=ttyS0,115200";
	};

	memory@0 {
		device_type = "memory";
		reg = <0x0 0x4000000>;
	};

	leds {
		compatible = "gpio-leds";

		led_blue: status_blue {
			label = "miwifi-3c:blue:status";
			gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
		};
		status_red {
			label = "miwifi-3c:red:status";
			gpios = <&gpio1 5 GPIO_ACTIVE_LOW>;
		};
		status_amber {
			label = "miwifi-3c:amber:status";
			gpios = <&gpio1 12 GPIO_ACTIVE_LOW>;
		};
	};

	keys {
		compatible = "gpio-keys-polled";
		poll-interval = <20>;

		reset {
			label = "reset";
			gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};
	};
};

&pinctrl {
	state_default: pinctrl0 {
		gpio {
			ralink,group = "refclk", "wled_an", "gpio";
			ralink,function = "gpio";
		};
	};
};

&wmac {
	status = "okay";
};

&ethernet {
	mtd-mac-address = <&factory 0x28>;
};

&spi0 {
	status = "okay";

	m25p80@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <10000000>;

		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;

			partition@0 {
				label = "u-boot";
				reg = <0x0 0x30000>;
				read-only;
			};

			partition@30000 {
				label = "u-boot-env";
				reg = <0x30000 0x10000>;
				read-only;
			};

			factory: partition@40000 {
				label = "factory";
				reg = <0x40000 0x10000>;
				read-only;
			};

			partition@50000 {
				compatible = "denx,uimage";
				label = "firmware";
				reg = <0x50000 0xfb0000>;
			};
		};
	};
};

edit and add
openwrt/target/linux/ramips/image/mt76x8.mk


define Device/miwifi-3c
  DTS := MIWIFI-3C
  IMAGE_SIZE := $(ralink_default_fw_size_16M)
  DEVICE_TITLE := Xiaomi MiWiFi 3C
  DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += miwifi-3c

edit and add
openwrt/target/linux/ramips/base-files/lib/ramips.sh

	*"MiWiFi Mini")
		name="miwifi-mini"
		;;
	*"MiWiFi Nano")
		name="miwifi-nano"
		;;
	*"MiWifi 3C")
	    name="miwifi-3c"
	    ;;
	*"MLW221")
		name="mlw221"
		;;
	*"MLWG2")
		name="mlwg2"

at the moment only clone from MIWIFI-NANO

add changes in the switch names (fixed Fix)
edit openwrt/target/linux/ramips/base-files/etc/board.d/02_network

	mac1200rv2|\
	miwifi-nano|\
	miwifi-3c)
		ucidef_add_switch "switch0" \
			"0:wan" "2:lan:2" "4:lan:1" "6@eth0"
		;;
	mt7621|\
	mt7628|\
1 Like

Ok i try create firmware now without ports fix.
OpenWrt 19.07-SNAPSHOT Not tested ...

Possible real brick
Create full backup first

https://drive.google.com/file/d/1oCWxjrZtxLFNAhWi890WU_zuySb2lZz4/view?usp=sharing

only add openwrt/target/linux/ramips/base-files/etc/board.d/02_network

	mac1200rv2|\
	miwifi-nano|\
	miwifi-3c|\
	mt7621|\
	mt7628|\

Serial uart logs its more easy for debug what generate the problem ...
I suspect its mtd partition its not correct

Dear @eduardo010174,
Thank you very much! :+1:
I have tested your latest build, but it seems to be broken.
I have flashed it via BREED. I has installed correctly. First I saw the front LED of the device for a couple of seconds blinking. Afterwards it turned steady blue.
I have tested all ports. All were blinking when the cable was connected. But no IP address was assigned.
I have then downloaded the latest firmware for the Mi-Nano (19.07.6) and flashed it via BREED. And it works.
Did you create a generic "miwifi-3c" port assignment in your latest build, or did you take the file unchanged? If it was unchanged, then it will not take the "miwifi-nano" port assignment, because you are referring to "miwifi-3c".

Support for Xiaomi Mi 3C - #47 by eduardo010174 i edit with changes

Thanks for updating!
Then I am wondering why it doesn't work. Because everything seems to be correct.

what uart serial show?

Using MiWifi Nano Firmware, I wonder if the device is transmitting with all four antennas, because miwifi nano has only two antenna whereas 3C has four. I am experiencing signal loss compared to stock firmware.

Dear @anjmis04,
are you able to quantify your experience?
What do you understand by signal loss?

I had answered you yesterday my experiences with Mi-Nano 19.07.5 firmware compared to stock firmware.

On my router OpenWrt works fine.

Dear @eduardo010174,
I have no serial interface connected to my router.

I am getting high latency on Wifi, while doing speedtest I get 1-2 Mbps while I have 50Mbps connection, with wired connection, I am getting normal speed about 47-48Mbps.

Dear @anjmis04,
this is strange, because I have the same transfer rates as on stock. Both provide the maximum available.
Did you do a reset in BREED before flashing OpenWrt?
If that also doesn't help, then you could try a different build. Maybe the one you are using of the day, where you had downloaded, is buggy. OpenWrt is constantly providing new versions.
According to the following site the last build was provided on Tue Jan 19 17:57:45 2021:

https://downloads.openwrt.org/releases/19.07.6/targets/ramips/mt76x8/

Is this the one you have installed?

The one I have tested and I am still using is the version, that was released before this one.

@eduardo010174 also tested the version I have and couldn't figure out any problems.

humm i have idea.
i try build exatly firmware openwrt from nano.
i don't touch in anything.
for test if it's work ...

ok i found the problem ahhaha

@minax007 its gen your problem of not have ip network

That might be the issue :slight_smile:
It seems that there are a couple of bugs with the latest release because @anjmis04 reported bad throughput.

Humm i possible go to other versions if its need ...
With git it's possible.