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


小米路由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

开始

更换内核

[scode type="blue"]

  • 更新于2021-10-17
    我发现最新的5.10内核会导致垃圾路由(比如小米路由3硬改16M flash版)无法正确生成.bin刷机包,取消所有插件以及主题后仍然超出0.19M左右,故尝试更换内核并记录

    注释配置文件

    内核文件:lede/include/kernel-version.mk

LINUX_VERSION-5.4 = .150
# LINUX_VERSION-5.10 = .70
#注释5.10,启用5.4
LINUX_KERNEL_HASH-5.4.150 = f424a9bbb05007f04c17f96a2e4f041a8001554a9060d2c291606e8a97c62aa2
# LINUX_KERNEL_HASH-5.10.70 = 75736c33711d7f298889ee4981b18774882045323e5c46af9ad3b022082db232
#注释5.10,启用5.4

注释后建议执行

make distclean
# 清除所有相关的东西,包括下载的软件包,配置文件,feed内容等

重新拉取软件包

cd lede/package
git clone https://github.com/kenzok8/openwrt-packages.git
git clone https://github.com/kenzok8/small.git
# 添加插件
cd lede
./scripts/feeds update -a
./scripts/feeds install -a
# 更新插件包

[/scode]

订正源码

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_yellow;
        led-failsafe = &led_red;
        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 = "blue:status";
            gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
            default-state = "on";
        };

        led_yellow: yellow {
            label = "yellow:status";
            gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
            default-state = "on";
        };

        led_red: red {
            label = "red:status";
            gpios = <&gpio1 5 GPIO_ACTIVE_LOW>;
            default-state = "on";
        };
    };

    keys {
        compatible = "gpio-keys";

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

&gpio1 {
    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

第一次编译

[scode type="red"]
故障内容如下:

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

第一次尝试解决

1.[scode type="blue"]

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

[/scode]
2.[scode type="blue"]

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    

[/scode]
3.[scode type="blue"]

/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";
    };
};  

[/scode]

第二次编译

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

第二次尝试解决

1.[scode type="yellow"]

/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";
    };
};

[/scode]
2.
[scode type="yellow"]
删除

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

[/scode]
3.[scode type="yellow"]

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

[/scode]

第三次编译

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

第三次尝试解决

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

[button color="info" <a href="" type="round"]镜像下载[/button]

安装环境

    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

拉取源码

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)

上传历史文件

[button color="info" icon="glyphicon glyphicon-cloud" url="https:\/\/wwi.lanzoui.com\/iO7oYwfso0j" type=""]工程文件下载[/button]

开始编译

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库(国内请尽量全局科学上网)
make v=99

编译成功

[button color="info" icon="glyphicon glyphicon-cloud" url="https:\/\/wwi.lanzoui.com\/iO7oYwfso0j" type=""]蓝奏云盘[/button]
建议搭配魔改版信号文件食用效果更佳
[button color="info" icon="glyphicon glyphicon-cloud" url="https:\/\/pan.yuos.top\/s\/AquY" type=""]小渔网盘[/button]

声明:我来时天晴,你来时风止|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 【小渔】小米路由3硬改适配Openwrt日记


待到那一天,一手撑苍天,一眼俯人间。