记Mercury_mac1200r-v2固件编译Openwrt

1、准备工作

(1)Ubuntu 18.04.6 LTS

(2)Openwrt源码

(3)路由器一只(Flash已由8MB升级至16MB)

2、Ubuntu环境搭建

安装以下依赖:

#Ubuntu 22.4以上
sudo apt update
sudo apt install build-essential gawk gcc-multilib flex git gettext libncurses5-dev libssl-dev python3-distutils zlib1g-dev
#Older
sudo apt update
sudo apt install build-essential ccache ecj fastjar file g++ gawk \
gettext git java-propose-classpath libelf-dev libncurses5-dev \
libncursesw5-dev libssl-dev python python2.7-dev python3 unzip wget \
python-distutils-extra python3-setuptools python3-dev rsync subversion \
swig time xsltproc zlib1g-dev 
#其他系统自行百度

3、Openwrt源代码

建议使用git cdn加速

git config --global url."https://github.com.cnpmjs.org".insteadOf "https://github.com"

官网源:

git clone https://git.openwrt.org/openwrt/openwrt.git

Mirror:

git clone https://github.com/openwrt/openwrt.git

4、源码配置

注意
不要使用root身份,使用普通用户

接上命令

cd openwrt
#更新安装feeds
./scripts/feeds update -a
./scripts/feeds install -a
#针对设备对openwrt进行配置
make menuconfig
#会出现以下界面
menuconfig

此时你需要根据设备对Target System、Subtaget、Target Profile和Target Images进行选择,上图为我的路由器配置。(如果官方没有你的Profile就需要根据设备选择Generic **)

基础功能配置:

#点Y可以对项目进行勾选
Luci----1. Collections----luci
Luci----2. Modules----Translations----Chinese Simplified (zh_Hans) 
#必要依赖已默认勾选,其他项目请根据对照表进行安装(注意ROM大小)

完成后,移动到Save,保存配置会自动写入`.config`文件

5、获取所有依赖包源代码

#8为线程数 (建议代理,否则会导致部分依赖下载失败)
make -j8 download V=s

6、构建

#第一次编译必须线程数为1(避免不必要的麻烦)
make -j1 V=s

编译完成,没有错误后,会在当前工作目录bin/targets生成固件文件

一般路由器只用刷sysupgrade.bin即可,否则必须先刷入kernel.bin,后从web界面升级sysupgrade.bin
openwrt-ramips-mt76x8-mercury_mac1200r-v2-initramfs-kernel.bin
openwrt-ramips-mt76x8-mercury_mac1200r-v2-squashfs-sysupgrade.bin

7、清理以及重新编译

(1)清理编译环境,则执行以下代码:

make clean

(2)更新,重新编译

cd openwrt
git pull
./scripts/feeds update -a 
./scripts/feeds install -a
make defconfig
make -j8 download

#此时线程可已不使用1
make -j4 V=s

(3)换设备配置

cd openwrt
rm -rf ./tmp && rm -rf .config
make menuconfig
make -j4 V=s

8、源码修改

(1)根据Rom大小修改(8MB->16MB)

以本设备为例,原始文件:

1)原始dts文件

(openwrt/target/linux/ramips/dts/mt7628an_mercury_mac1200r-v2.dts 文件位置)

/dts-v1/;

#include "mt7628an.dtsi"

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

/ {
	compatible = "mercury,mac1200r-v2", "mediatek,mt7628an-soc";
	model = "Mercury MAC1200R v2";

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

	leds {
		compatible = "gpio-leds";

		led_status: status {
			label = "mac1200rv2:green:status";
			gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
		};
	};
};

&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 0x1d800>;
			};

			factory: partition@1d800 {
				label = "factory_info";
				reg = <0x1d800 0x800>;
				read-only;
			};

			art: partition@1e000 {
				label = "art";
				reg = <0x1e000 0x2000>;
				read-only;
			};

			partition@20000 {
				label = "config";
				reg = <0x20000 0x10000>;
			};

			partition@30000 {
				label = "u-boot2";
				reg = <0x30000 0x10000>;
			};

			partition@40000 {
				compatible = "denx,uimage";
				label = "firmware";
				reg = <0x40000 0x7c0000>;
			};
		};
	};
};

&ethernet {
	pinctrl-names = "default";
	mtd-mac-address = <&factory 0xd>;
};

&esw {
	mediatek,portmap = <0x2f>;
};

&wmac {
	status = "okay";
	ralink,mtd-eeprom = <&art 0x0>;
};

&pcie {
	status = "okay";
};

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

2)原始mk文件

(openwrt/target/linux/ramips/image/mt76x8.mk 文件位置)

#找到你选择的Profile,比如我mercury_mac1200r-v2,直接ctrl+f搜索
ine Device/mercury_mac1200r-v2
  IMAGE_SIZE := 7936k
  DEVICE_VENDOR := Mercury
  DEVICE_MODEL := MAC1200R
  DEVICE_VARIANT := v2.0
  DEVICE_PACKAGES := kmod-mt76x2
  SUPPORTED_DEVICES += mac1200rv2
endef
TARGET_DEVICES += mercury_mac1200r-v2

修改后

3)修改后dts文件

#include "mt7628an.dtsi"

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

/ {
	compatible = "mercury,mac1200r-v2", "mediatek,mt7628an-soc";
	model = "Mercury MAC1200R v2";

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

	leds {
		compatible = "gpio-leds";

		led_status: status {
			label = "green:status";
			gpios = <&gpio 11 GPIO_ACTIVE_LOW>;
		};
	};
};

&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 0x1d800>;
			};

			factory: partition@1d800 {
				label = "factory_info";
				reg = <0x1d800 0x800>;
				read-only;
			};

			art: partition@1e000 {
				label = "art";
				reg = <0x1e000 0x2000>;
				read-only;
			};

			partition@20000 {
				label = "config";
				reg = <0x20000 0x10000>;
			};

			partition@30000 {
				label = "u-boot2";
				reg = <0x30000 0x10000>;
			};

			partition@40000 {
				compatible = "denx,uimage";
				label = "firmware";
				reg = <0x40000 0xfc0000>;
			};
		};
	};
};

&ethernet {
	pinctrl-names = "default";
	mtd-mac-address = <&factory 0xd>;
};

&esw {
	mediatek,portmap = <0x2f>;
};

&wmac {
	status = "okay";
	ralink,mtd-eeprom = <&art 0x0>;
};

&pcie {
	status = "okay";
};

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

4)修改后mk文件

define Device/mercury_mac1200r-v2
  IMAGE_SIZE := 15872k
  DEVICE_VENDOR := Mercury
  DEVICE_MODEL := MAC1200R
  DEVICE_VARIANT := v2.0
  DEVICE_PACKAGES := kmod-mt76x2
  SUPPORTED_DEVICES += mac1200rv2
endef
TARGET_DEVICES += mercury_mac1200r-v2

(2)修改 Luci 后台地址以及默认网关

#文件目录openwrt/package/basefiles/files/bin/config_generate`
```diff
        uci -q batch <<-EOF
                delete system.@system[0]
                add system system
+                set system.@system[-1].hostname='OpenWrt'
                set system.@system[-1].timezone='UTC'
                set system.@system[-1].ttylogin='0'
                set system.@system[-1].log_size='64'
                set system.@system[-1].urandom_seed='0'
```
#网关
case "$protocol" in
		static)
			local ipad
			case "$1" in
				lan) ipad=${ipaddr:-"192.168.1.1"} ;;
				*) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
			esac

			netm=${netmask:-"255.255.255.0"}

			uci -q batch <<-EOF
				set network.$1.proto='static'
				set network.$1.ipaddr='$ipad'
				set network.$1.netmask='$netm'
			EOF
			[ -e /proc/sys/net/ipv6 ] && uci set network.$1.ip6assign='60'
		;;
#修改完毕后需要删除tmp
rm -rf ./tmp

(3)修改 SSH 登陆欢迎信息

#文件目录 openwrt/package/base-files/files/etc/banner`

(4)默认打开WIFI以及修改ssid

文件位置 openwrt/package/kernel/mac80211/files/lib/wifi

uci -q batch <<-EOF
			set wireless.radio${devidx}=wifi-device
			set wireless.radio${devidx}.type=mac80211
			set wireless.radio${devidx}.channel=${channel}
			set wireless.radio${devidx}.hwmode=11${mode_band}
			${dev_id}
			${ht_capab}
			set wireless.radio${devidx}.disabled=1 //这个位置默认为关闭1,开启改为0

			set wireless.default_radio${devidx}=wifi-iface
			set wireless.default_radio${devidx}.device=radio${devidx}
			set wireless.default_radio${devidx}.network=lan
			set wireless.default_radio${devidx}.mode=ap
			set wireless.default_radio${devidx}.ssid=OpenWrt //ssid位置
			set wireless.default_radio${devidx}.encryption=none
EOF
		uci -q commit wireless

9、添加源

cd openwrt
gedit feeds.conf.default
#添加完成后,从第四步开始(线程初始为1,否则可为设备最大线程)

10、对照表

|插件中文名        |Luci App|
|--|--|
|网络向导        | luci-app-quickstart|
|实时监控        | luci-app-netdata|
|释放内存        | luci-app-ramfree|
|WireGuard 状态        | luci-app-wireguard|
|Web管理        | luci-app-webadmin|
|TTYD 终端        | luci-app-ttyd|
|磁盘管理        | luci-app-diskman|
|高级设置        | luci-app-advanced|
|定时重启        | luci-app-autoreboot|
|Argon 主题设置        | luci-app-argon-config|
|文件传输        | luci-app-filetransfer|
|关机        | luci-app-poweroff|
|应用商店        | luci-app-store|
|阿里云盘 WebDAV        | luci-app-aliyundrive-webdav|
|Mentohust 锐捷拨号客户端        | luci-app-mentohust|
| Minieap 锐捷拨号客户端 |  luci-app-minieap |
|甜糖星愿自动采集        | luci-app-ttnode|
|Hello World        | luci-app-vssr|
|Clash(frainzy1477)        | luci-app-clash|
|PassWall        | luci-app-passwall|
|Bypass        | luci-app-bypass|
|V2ray 服务器        | luci-app-v2ray-server|
|广告屏蔽大师 Plus+        | luci-app-adbyby-plus|
|iKoolProxy 滤广告        | luci-app-ikoolproxy|
|DNS 过滤器        | luci-app-dnsfilter|
|ShadowSocksR Plus+        | luci-app-ssr-plus|
|AdGuard Home        | luci-app-adguardhome|
|京东签到服务        | luci-app-jd-dailybonus|
|易有云文件管理器        | luci-app-linkease|
|DDNS.to内网穿透        | luci-app-ddnsto|
|微信推送        | luci-app-serverchan|
|全能推送        | luci-app-pushbot|
|上网时间控制        | luci-app-accesscontrol|
|解锁网易云灰色歌曲        | luci-app-unblockmusic|
|OpenClash        | luci-app-openclash|
|阿里DDNS        | luci-app-aliddns|
|动态 DNS(支持阿里腾讯)        | luci-app-ddns|
|QoS Nftables 版        | luci-app-nft-qos|
|SmartDNS        | luci-app-smartdns|
|LXC Containers        | luci-app-lxc|
|天翼家庭云/天翼云盘提速        | luci-app-familycloud|
|网络唤醒        | luci-app-wol|
|WatchCat        | luci-app-watchcat|
|UU游戏加速器        | luci-app-uugamebooster|
|VPN 绕过        | luci-app-vpnbypass|
|Frps        | luci-app-frps|
|Frp 内网穿透        | luci-app-frpc|
|UPnP        | luci-app-upnp|
|Nps 内网穿透        | luci-app-nps|
|迅雷快鸟        | luci-app-xlnetacc|
|OpenConnect VPN        | luci-app-ocserv|
|OpenVPN(客户端)        | luci-app-openvpn|
|uHTTPd        | luci-app-uhttpd|
|KMS 服务器        | luci-app-vlmcsd|
|RP PPPoE Server        | luci-app-rp-pppoe-server|
|IPTV 帮手        | luci-app-iptvhelper|
|组播代理        | luci-app-omcproxy|
|udpxy        | luci-app-udpxy|
|MWAN3 分流助手        | luci-app-mwan3helper|
|AirPlay 2 音频接收器        | luci-app-airplay2|
|Docker CE 容器        | luci-app-docker|
|Docker(Dockerman)        | luci-app-dockerman|
|可道云        | luci-app-kodexplorer|
|NFS 管理        | luci-app-nfs|
|微力同步        | luci-app-verysync|
|USB 打印服务器        | luci-app-usb-printer|
|打印服务器(模块)        | luci-app-p910nd|
|硬盘休眠        | luci-app-hd-idle|
|网络共享(SMB)        | luci-app-samba|
|Aria2 配置        | luci-app-aria2|
|挂载 SMB 网络共享        | luci-app-cifs-mount|
|Rclone        | luci-app-rclone|
|miniDLNA        | luci-app-minidlna|
|Transmission        | luci-app-transmission|
|FTP 服务器        | luci-app-vsftpd|
|PCHiFi 数字转盘遥控        | luci-app-music-remote-center|
|qBittorrent| luci-app-qbittorrent|
|aMule | luci-app-amule|
|BaiduPCS Web        | luci-app-baidupcs-web|
|N2N v2 VPN        | luci-app-n2n_v2|
|SoftEther VPN 服务器        | luci-app-softethervpn|
|IPSec VPN 服务器        | luci-app-ipsec-server|
|OpenVPN 服务器        | luci-app-openvpn-server|
|PPTP VPN 服务器        | luci-app-pptp-server|
|ZeroTier        | luci-app-zerotier|
|IP/MAC绑定        | luci-app-arpbind|
|简单MESH        | luci-app-easymesh|
|流量统计        | luci-app-bandwidthd|
|网速测试        | luci-app-netspeedtest|
|SQM QoS | luci-app-sqm|
|IPv6 端口转发        | luci-app-socatg|
|网速控制        | luci-app-eqos|
|应用过滤        | luci-app-oaf|
|服务质量(QoS)        || luci-app-qos|
|多线多拨        | luci-app-syncdial|
|负载均衡        | luci-app-mwan3|
|Turbo ACC 网络加速|        | luci-app-turboacc|
|网络带宽监视器        | luci-app-nlbwmon|
|实时流量监测        | luci-app-wrtbwmon|
|IPV6|        ipv6helper|
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇