|
本帖最后由 211988947 于 2022-6-7 16:10 编辑
折腾了几天,踩了无数坑,终于编译出来能用的固件,分享一点经验,云编译部分还不完善,持续更新,恩山排版不好,可以来我的博客查看:编译 OpenWrt 固件 | Pblood' Blog
注意!
不要用 root 用户进行编译,会报错
国内用户编译前最好准备好梯子
默认登陆IP `192.168.1.1` 密码 `password`
在https://openwrt.org/zh/toh/views/toh_fwdownload查看自己的设备是否支持 openwrt,部分设备查不到但是也支持,自行百度
资源汇总
OpenWrt 官方项目结构(21.02)
.
├── bin # 编译输出路径
│ ├── packages # 所有插件包
│ └── targets # 固件及插件输出路径
├── BSDmakefile
├── build_dir
├── config
├── Config.in
├── COPYING
├── dl # dl库
├── feeds # feeds 库
├── feeds.conf.default # feeds源配置文件
├── include
├── key-build
├── key-build.pub
├── key-build.ucert
├── key-build.ucert.revoke
├── LICENSES
├── Makefile
├── package # 软件包
├── README.md
├── rules.mk
├── scripts
├── staging_dir
├── target
├── tmp
├── toolchain
├── tools
├──.config # 编译配置文件
└──
上游源码
软件并不一定兼容所有 openwrt 及发行版本,有能力的可以自己改源码
openwrt
- [openwrt 官方源](https://github.com/openwrt/openwrt) 自带插件很少,但最稳定
- [lede 源](https://github.com/coolsnowwolf/lede) 基于官方[17.01分支](https://github.com/openwrt/openwrt/tree/lede-17.01),自带插件很全,但不是最新
- [Lienol 源](https://github.com/Lienol/openwrt) 基于官方最新分支,自带插件挺多,没有科学,版本也很新,除了多拨创建的虚拟接口需要手动绑定才能正常使用没啥毛病
- [immortalwrt 源](https://github.com/immortalwrt/immortalwrt) 功能很丰富,但是太丰富了以至于出现了很多bug
软件源
- [fw876/helloworld](https://github.com/fw876/helloworld) 科学上网插件集
- 来自神秘网友 kenzok8(ssrp、passwall、openclash 等)
* [kenzok8/openwrt-packages](https://github.com/kenzok8/openwrt-packages)
* [kenzok8/small](https://github.com/kenzok8/small)
* [kenzok8/small-package](https://github.com/kenzok8/small-package) 最新源
- [immortalwrt/packages](https://github.com/immortalwrt/packages) 天灵 openwrt 软件源
* [pblood/openwrt-packages](https://github.com/pblood/openwrt-packages) 个人整理的一些好用的软件
使用方法
修改`feeds.conf.default`文件(feeds源配置文件),按以下格式添加
src-git helloworld https://github.com/fw876/helloworld
helloworld 是软件源的别名,软件会被下载到 feeds/helloworld 目录
添加后执行以下命令下载安装软件
./scripts/feeds update -a
创建软链接到 package/feeds 目录(package目录下的软件会被 make menuconfig 识别)
./scripts/feeds install -a
单独下载并安装
./scripts/feeds update helloworld
./scripts/feeds install -a -p helloworld
dl 库
如果采用源码默认的 dl库, 国内网络环境下载时一般会卡住,用梯子也不好使,这时候可以通过`make menuconfig`更换 dl库 地址解决,[参考教程](https://doc.openwrt.cc/1-General/8-Source-Mirror/)
OpenWrt 官方dl库(下载经常卡在某个地方)
- `https://sources.openwrt.org/` 默认
- `http://downloads.openwrt.org.cn/sources/`
第三方 dl库
https://openwrt.cc/dl/
menuconfig 使用方法
menuconfig 是源码自带的一个用于修改固件配置的图形界面,想要本地编译固件学会使用这个是必不可少的一步

操作方法:
<kbd>空格</kbd>:选择( `*` 代表编入固件,`M` 表示编译成模块或者IPK包, `空`不编译 )
<kbd>上下左右键</kbd>:移动选择条
<kbd>Enter</kbd>:进入/确定
`<Select>`:进入下级菜单
`<Exit>`:返回上级菜单
`<Save>`:保存
`<Load>`:导入配置
基本参数说明
* `Target System` 你的路由器的 Soc 架构
* `Subtarget` 你的路由器 Soc 的型号
* `Target Profile` 你的路由器的型号
- `Target Images` 保存目标镜像的格式
- `Advanced configuration options (for developers)` 开发者选项,启用后可在`Local mirror for source packages`配置 dl 库链接
- `Build the OpenWrt SDK` 是否编译 SDK
- `Languages` 额外的语言环境(Go、Nodejs、PHP、python等)
- `Libraries` 依赖库
* `Libraries` --->`Languages` --->
- `LuCI` 需要安装的软件包
修改完毕保存后配置会自动写入`.config`文件,里面有源码所有配置,包括新添加的,未选择的配置以注释的形式存在
常用插件列表中英文对照表
|插件中文名 |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|
更多插件说明:
<https://www.right.com.cn/forum/thread-3682029-1-1.html>
<https://max.book118.com/html/2021/0405/8133116046003071.shtm>
插件、固件下载
插件下载
- [官方 ipk 库](https://openwrt.pkgs.org/)
- [supes.top/packages](https://op.supes.top/packages/)
- [openwrt常用软件包](https://op.dllkids.xyz/)
固件下载
- [openwrt 官方固件](https://downloads.openwrt.org/) && [openwrt 官方固件索引](https://firmware-selector.openwrt.org/) &&
- [openwrt 天灵固件索引](https://firmware-selector.immortalwrt.org/)
- [第三方 lede 固件](https://openwrt.mpdn.fun:8443/) 第三方使用 lean 源码编译的 openwrt 固件
- [supes.top](https://supes.top/) 第三方固件定制,免费在线编译,几分钟就编译好了,缺点是有他们家的广告
- [清华 openwrt 镜像](https://mirrors.tuna.tsinghua.edu.cn/openwrt/)
其他
* [padavan 固件下载](https://opt.cn2qq.com/padavan/)
本地编译
以[openwrt 官方源](https://github.com/openwrt/openwrt)为例,其它源方法类似。本地编译麻烦的就是环境搭建,直接劝退梯子都没有的小白,但是环境搭建好编译起来还是很方便的。
设备环境:
- ThinkBook 14p(R7-5800H 处理器)
- VMware 16 运行 ubuntu-22.04 桌面版,[VMware镜像备份](https://www.aliyundrive.com/s/Mbh4vTbs4ds)
编译步骤
1. 安装编译依赖
Ubuntu 22.04 的依赖,用于 OpenWrt master,22.03 和 21.02 分支,更多Linux 发行版及依赖查看[官方文档](https://openwrt.org/docs/guide-d ... install-buildsystem)或者上游源码作者教程
```shell
sudo apt install -y build-essential gawk gcc-multilib flex git gettext libncurses5-dev libssl-dev python3-distutils zlib1g-dev
```
2. 下载源代码,更新 feeds 并选择配置
```shell
git clone https://github.com/openwrt/openwrt
cd openwrt
```
这一步经常因网络问题出错,多检查软件是否下载成功
```shell
./scripts/feeds update -a
```
```shell
./scripts/feeds install -a
make menuconfig
```
openwrt 官方源 基础配置:
* `LuCI` --->`Collections` ---> `<*>luci` (Luci 后台,必备)
* `LuCI` --->`Modules` --->`Translations` --->`<*>Chinese Simplified (zh_Hans)` (中文语言)
3. 下载 dl 库,编译固件 (-j 后面是线程数,第一次编译推荐用单线程,方便发现错误)
```shell
# 下载 dl 库(建议焕源)
make download -j8
# 单线程编译
make V=s -j1
# 以最大线程编译
make V=s -j$(nproc)
```
>编译完成后输出路径:`bin/targets`
```shell
.
├── config.buildinfo # 编译配置文件
├── feeds.buildinfo # feeds 源文件
├── openwrt-ramips-mt7620-aigale_ai-br100-initramfs-kernel.bin # 调试固件包(重启路由自动恢复出厂设置)
├── openwrt-ramips-mt7620-aigale_ai-br100.manifest # 所有插件版本信息
├── openwrt-ramips-mt7620-aigale_ai-br100-squashfs-sysupgrade.bin # 固件包
├── packages # 固件包含的所有插件
├── sha256sums
└── version.buildinfo # 版本信息
```
进阶配置
>通过 menuconfig 定制固件已经能满足基本的需求了,这里是更进一步的 DIY,虽然有些是真的没必要
添加自定义插件
>原理是把插件源码放到 package 目录下,编译时会自动遍历
示例:
- 安装最新 [argon](https://github.com/jerrykuku/luci-theme-argon/) 主题
```shell
# openwrt 源码
cd package
git clone https://github.com/jerrykuku/luci-theme-argon.git
# Lean 源码
cd /package/feeds/luci
rm -rf luci-theme-argon
git clone -b 18.06 https://github.com/jerrykuku/luci-theme-argon.git
```
修改 Luci 后台地址
修改文件`/package/basefiles/files/bin/config_generate`
```diff
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'
;;
```
修改主机名
修改文件`/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'
```
修改 SSH 登陆欢迎信息
修改文件`/package/base-files/files/etc/banner`
可以在[此处](http://patorjk.com/software/taag/)定制自己的样式
修改 dts
默认的一般够用,实在不够再更改
在`/target/linux/ramips/dts/`目录下找到自己机型的 dts,修改以下内容
```dts
partition@50000 {
compatible = "denx,uimage";
label = "firmware";
reg = <0x50000 0x1fb0000>;
};
```
其中`1f60000`=32M;`1fb0000`=16M;`7b0000`=8M
附:
[在线进制转换工具](https://c.runoob.com/front-end/58/)
云编译部分还没写好,会在编译 OpenWrt 固件 | Pblood' Blog更新
|
|