8

为特定版本的 OpenWrt 编译包

 3 years ago
source link: https://rapiz.me/2020/compile-for-openwrt/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在阅读本文之前

  • 你需要懂得如何编译一个最新版本的 OpenWrt 固件。

如果你已经有了一台运行 OpenWrt 的设备,并且装着不是你编译的固件,贸然装包/升级很可能会导致路由器不可用。因为不同版本的包、固件之间有依赖关系,最好的包还是在当时环境下编译出来的包。但当时的编译环境很可能已经丢失了,或者你对之前怎么编译出来的一无所知。这时候怎么办呢?

OpenWrt 和 Luci 的版本

OpenWrt 本身的代码版本和 Luci 的版本是最重要的。前者不匹配会导致包不可用,后者不匹配会导致 Luci 界面不可用。

幸运的是,两者都会将 commit 写在版本号里。登陆路由器 LuCI 界面,你能看到类似这样一行版本号:

Powered by LuCI Master (git-19.339.73009-ea6d0d2) / OpenWrt SNAPSHOT r11638-3ee7670 

其中 ea6d0d2 就是 LuCI 编译时的 commit, 3ee7670 则是 OpenWrt 的。

所以我们只需要将代码 checkout 到对应的 commit, 然后再进行编译就可以了。注意,这样编译出的内核 checksum 仍然很难和已有你的固件匹配,复现 checksum 是几乎不可能的

大概的流程会像这样:

git clone "OpenWrt 的仓库地址"
cd openwrt
git checkout "你想要的 openwrt commit 位置,比如 3ee7670" # 这一步会回到以前的 OpenWrt 代码
./scripts/feeds update -a # 这一步会把所有包的代码拉下来
cd feeds/luci
git pull --unshallow # 默认只保留两个历史记录,我们需要所有的历史记录以便回滚 LuCi
git checkout "你想要的 luci commit 位置, 比如 ea6d0d2"
cd ..
# 接下来就是普通的编译流程
./scripts/feeds install -a
make menuconfig
make
# ...

为特定版本的 OpenWrt 编译软件包,你需要:

  • 找到 OpenWrt 和 LuCI 的版本号
  • 将代码(主目录下,和 feeds/luci 下) checkout 到对应的位置

注意,有些时候你不只需要回滚 LuCI, feeds/package 等目录也可能需要回滚到一个恰当的时间点。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK