小米路由3硬改适配Openwrt日记

准备工作

1.mt7620a_xiaomi_miwifi-r3mi.dts

文件存放路径:/lede/target/linux/ramips/dts

2.02_network

文件存放路径:/lede/target/linux/ramips/mt7620/base-files/etc/board.d

3.mt7620.mk

文件存放路径:/lede/target/linux/ramips/image

开始

订正源码

mt7620a_xiaomi_miwifi-r3mi.dts

/dts-v1/;

#include "mt7620a.dtsi"

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

/ {
    compatible = "xiaomi,miwifi-r3mi", "ralink,mt7620a-soc";
    model = "Xiaomi Mi Router R3Mi";

    aliases {
        led-boot = &led_blue;
        led-failsafe = &led_blue;
        led-running = &led_blue;
        led-upgrade = &led_blue;
        label-mac-device = &ethernet;
    };

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

    leds {
        compatible = "gpio-leds";

        led_blue: blue {
            label = "miwifi-mini:blue:status";
            gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
            default-state = "on";
        };

        yellow {
            label = "miwifi-mini:yellow:status";
            gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
        };

        red {
            label = "miwifi-mini:red:status";
            gpios = <&gpio1 5 GPIO_ACTIVE_LOW>;
        };
    };

    keys {
        compatible = "gpio-keys";

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

&gpio0 {
    status = "okay";
};

&gpio1 {
    status = "okay";
};

&gpio2 {
    status = "okay";
};

&spi0 {
    status = "okay";

    flash@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>;
            };

            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 0xf80000>;
            };

            partition@fd0000 {
                label = "crash";
                reg = <0xfd0000 0x10000>;
            };

            partition@fe0000 {
                label = "reserved";
                reg = <0xfe0000 0x10000>;
                read-only;
            };

            partition@ff0000 {
                label = "Bdata";
                reg = <0xff0000 0x10000>;
            };
        };
    };
};

&ehci {
    status = "okay";
};

&ohci {
    status = "okay";
};

&ethernet {
    pinctrl-names = "default";
    pinctrl-0 = <&ephy_pins>;

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

    mediatek,portmap = "llllw";
};

&wmac {
    ralink,mtd-eeprom = <&factory 0x0>;
    pinctrl-names = "default";
    pinctrl-0 = <&pa_pins>;
};

&pcie {
    status = "okay";
};

&pcie0 {
    mt76@0,0 {
        reg = <0x0000 0 0 0 0>;
        mediatek,mtd-eeprom = <&factory 0x8000>;
        ieee80211-freq-limit = <5000000 6000000>;
    };
};

&state_default {
    gpio {
        groups = "i2c", "rgmii1";
        function = "gpio";
    };
};

02_network

xiaomi,miwifi-r3)
    ucidef_add_switch "switch0" \
        "1:lan" "4:lan" "0:wan" "6@eth0"
    ;;
    xiaomi,miwifi-r3mi)
    ucidef_add_switch "switch0" \
        "1:lan" "4:lan" "0:wan" "6@eth0"
    ;;

mt7620.mk

define Device/xiaomi_miwifi-mini
  SOC := mt7620a
  IMAGE_SIZE := 15872k
  DEVICE_VENDOR := Xiaomi
  DEVICE_MODEL := MiWiFi Mini
  DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci
  SUPPORTED_DEVICES += miwifi-mini
endef
TARGET_DEVICES += xiaomi_miwifi-mini

define Device/xiaomi_miwifi-r3mi
  SOC := mt7620a
  IMAGE_SIZE := 15872k
  DEVICE_VENDOR := Xiaomi
  DEVICE_MODEL := Mi Router R3Mi
  DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci
  SUPPORTED_DEVICES += miwifi-r3mi
endef
TARGET_DEVICES += xiaomi_miwifi-r3mi

define Device/xiaomi_miwifi-r3
  SOC := mt7620a
  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
  IMAGE/rootfs0.bin := append-ubi | check-size
  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
  DEVICE_VENDOR := Xiaomi
  DEVICE_MODEL := Mi Router R3
  DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci uboot-envtools
endef
TARGET_DEVICES += xiaomi_miwifi-r3

第一次编译


故障内容如下:

  1. 2.4Ghz 获取IP过慢,且5Ghz无法正常驱动
  2. 启动过程中黄灯未常亮,而是蓝灯闪烁启动
  3. 固件网页设置中,无法正常识别到5Ghz无线网卡,且一网卡驱动不上,修改时显示为2.4Ghz无线网卡,怀疑是驱动混乱

第一次尝试解决

1.

xiaomi,miwifi-r3mi|\
xiaomi,miwifi-r3)
    ucidef_add_switch "switch0" \
        "1:lan" "4:lan" "0:wan" "6@eth0"
    ;;


2.

define Device/xiaomi_miwifi-r3mi
  SOC := mt7620a
  IMAGE_SIZE := 16064k
  DEVICE_VENDOR := Xiaomi
  DEVICE_MODEL := Mi Router R3Mi
  DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci uboot-envtools
endef
TARGET_DEVICES += xiaomi_miwifi-r3mi    


3.

/dts-v1/;

#include "mt7620a.dtsi"

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

/ {
    compatible = "xiaomi,miwifi-r3mi", "ralink,mt7620a-soc";
    model = "Xiaomi Mi Router R3Mi";

    aliases {
        led-boot = &led_red;
        led-failsafe = &led_yellow;
        led-running = &led_blue;
        led-upgrade = &led_yellow;
        label-mac-device = &ethernet;
    };

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

    leds {
        compatible = "gpio-leds";

        led_blue: blue {
            label = "miwifi-mini:blue:status";
            gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
            default-state = "on";
        };

        led_yellow: yellow {
            label = "miwifi-mini:yellow:status";
            gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
        };

        led_red: red {
            label = "miwifi-mini:red:status";
            gpios = <&gpio1 5 GPIO_ACTIVE_LOW>;
        };
    };

    keys {
        compatible = "gpio-keys";

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

&gpio0 {
    status = "okay";
};

&gpio1 {
    status = "okay";
};

&gpio2 {
    status = "okay";
};

&spi0 {
    status = "okay";

    flash@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>;
            };

            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 0xf80000>;
            };

            partition@fd0000 {
                label = "crash";
                reg = <0xfd0000 0x10000>;
            };

            partition@fe0000 {
                label = "reserved";
                reg = <0xfe0000 0x10000>;
                read-only;
            };

            partition@ff0000 {
                label = "Bdata";
                reg = <0xff0000 0x10000>;
            };
        };
    };
};

&ehci {
    status = "okay";
};

&ohci {
    status = "okay";
};

&ethernet {
    pinctrl-names = "default";
    pinctrl-0 = <&ephy_pins>;

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

    mediatek,portmap = "llllw";
};

&wmac {
    ralink,mtd-eeprom = <&factory 0x0>;
    pinctrl-names = "default";
    pinctrl-0 = <&pa_pins>;
};

&pcie {
    status = "okay";
};

&pcie0 {
    mt76@0,0 {
        reg = <0x0000 0 0 0 0>;
        mediatek,mtd-eeprom = <&factory 0x8000>;
        ieee80211-freq-limit = <5000000 6000000>;
    };
};

&state_default {
    gpio {
        groups = "i2c", "rgmii1";
        function = "gpio";
    };
};  

第二次编译

./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig
make -j1 V=sk

第二次尝试解决

1.

/dts-v1/;

#include "mt7620a.dtsi"

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

/ {
    compatible = "xiaomi,miwifi-r3mi", "ralink,mt7620a-soc";
    model = "Xiaomi Mi Router R3Mi";

    aliases {
        led-failsafe = &led_red;
        led-running = &led_yellow;
        led-upgrade = &led_blue;
        label-mac-device = &ethernet;
    };

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

    leds {
        compatible = "gpio-leds";

        led_blue: blue {
            label = "miwifi-mini:blue:status";
            gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
            default-state = "on";
        };

        led_yellow: yellow {
            label = "miwifi-mini:yellow:status";
            gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
        };

        led_red: red {
            label = "miwifi-mini:red:status";
            gpios = <&gpio1 5 GPIO_ACTIVE_LOW>;
        };
    };

    keys {
        compatible = "gpio-keys";

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

&gpio0 {
    status = "okay";
};

&gpio1 {
    status = "okay";
};

&gpio2 {
    status = "okay";
};

&spi0 {
    status = "okay";

    flash@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>;
            };

            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 0xf80000>;
            };

            partition@fd0000 {
                label = "crash";
                reg = <0xfd0000 0x10000>;
            };

            partition@fe0000 {
                label = "reserved";
                reg = <0xfe0000 0x10000>;
                read-only;
            };

            partition@ff0000 {
                label = "Bdata";
                reg = <0xff0000 0x10000>;
            };
        };
    };
};

&ehci {
    status = "okay";
};

&ohci {
    status = "okay";
};

&ethernet {
    pinctrl-names = "default";
    pinctrl-0 = <&ephy_pins>;

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

    mediatek,portmap = "llllw";
};

&wmac {
    ralink,mtd-eeprom = <&factory 0x0>;
    pinctrl-names = "default";
    pinctrl-0 = <&pa_pins>;
};

&pcie {
    status = "okay";
};

&pcie0 {
    mt76@0,0 {
        reg = <0x0000 0 0 0 0>;
        mediatek,mtd-eeprom = <&factory 0x8000>;
        ieee80211-freq-limit = <5000000 6000000>;
    };
};

&state_default {
    gpio {
        groups = "i2c", "rgmii1";
        function = "gpio";
    };
};


2.

删除

xiaomi,miwifi-r3mi)
    wan_mac=$(mtd_get_mac_binary factory 0x28)
    lan_mac=$(macaddr_setbit_la "$wan_mac")
    ;;


3.

define Device/xiaomi_miwifi-r3mi
  SOC := mt7620a
  IMAGE_SIZE := 16064k
  DEVICE_VENDOR := Xiaomi
  DEVICE_MODEL := Mi Router R3Mi
  DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci uboot-envtools
endef
TARGET_DEVICES += xiaomi_miwifi-r3mi

第三次编译

./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig
make -j1 V=sk

第三次尝试解决

考虑到可能是乌班图系统问题故更换系统为乌班图20.10


安装环境

sudo apt-get install -y gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils subversion libncurses5-dev ncurses-term zlib1g-dev gawk asciidoc zlib1g-dev git git-man liberror-perl libsigsegv2 vim build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev zlib1g-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc-s1 libc6-dev-i386 subversion flex uglifyjs git gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx-ucl libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync subversion gawk

sudo apt install -y gcc g++ binutils patch bzip2 flex bison make gettext texinfo unzip sharutils libncurses5-dev ncurses-term zlib1g-dev asciidoc autoconf libssl-dev build-essential subversion git-core libncurses5-dev zlib1g-dev gawk flex quilt libssl-dev xsltproc libxml-parser-perl mercurial bzr ecj cvs unzip  zlib1g zlib1g-dev 

拉取源码

git clone https://github.com/coolsnowwolf/lede
cd lede
./scripts/feeds clean
./scripts/feeds update -a
./scripts/feeds install -a

安装宝塔

wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh

开防火墙

sudo ufw allow 8888
#允许外部访问8888端口(tcp/udp)

上传历史文件



开始编译

cd /lede
make menuconfig

遇到报错 Build dependency: Please install GNU 'awk' Prerequisite check failed. Use FORCE=1 to override. make: *** [/home/yuos/lede/include/toplevel.mk:174:staging_dir/host/.prereq-build] 错误 1

sudo apt-get install subversion gawk
#问题解决
make menuconfig
/*选择配置*/
make -j8 download V=s
#下载dl库(国内请尽量全局科学上网)

编译成功




建议搭配魔改版信号文件食用效果更佳


测试图

Last modification:April 4th, 2021 at 05:14 pm
如果觉得我的文章对你有用,请随意赞赏