openwrt源码编译

1,838 阅读1分钟

openwrt源码编译

环境:

OS: Ubuntu 20.04
openwrt: 21.02
目标设备: Xiaomi Redmi Router AC2100

1. 下载openwrt源码

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

下载指定目录下载指定分支的最后一次提交:

git clone --depth 1 -b openwrt-21.02 https://github.com/openwrt/openwrt openwrt-21.02

2. 编译前准备

2.1 安装必要编译软件

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 python3-distutils python3-setuptools python3-dev rsync subversion swig time xsltproc zlib1g-dev

2.2 获取packages

获取feeds.conf.default定义的所有packags

./scripts/feeds update -a

加速

src-git packages https://ghproxy.com/https://github.com/openwrt/packages.git;openwrt-21.02
src-git luci https://ghproxy.com/https://github.com/openwrt/luci.git;openwrt-21.02
src-git routing https://ghproxy.com/https://github.com/openwrt/routing.git;openwrt-21.02
src-git telephony https://ghproxy.com/https://github.com/openwrt/telephony.git;openwrt-21.02
#src-git packages https://git.openwrt.org/feed/packages.git;openwrt-21.02
#src-git luci https://git.openwrt.org/project/luci.git;openwrt-21.02
#src-git routing https://git.openwrt.org/feed/routing.git;openwrt-21.02
#src-git telephony https://git.openwrt.org/feed/telephony.git;openwrt-21.02
#src-link custom /usr/src/openwrt/custom-feed
src-git packages https://gitee.com/itas109/openwrt-packages.git;openwrt-21.02
src-git luci https://gitee.com/itas109/openwrt-luci.git;openwrt-21.02
src-git routing https://gitee.com/itas109/openwrt-routing.git;openwrt-21.02
src-git telephony https://gitee.com/itas109/openwrt-telephony.git;openwrt-21.02
#src-git packages https://git.openwrt.org/feed/packages.git;openwrt-21.02
#src-git luci https://git.openwrt.org/project/luci.git;openwrt-21.02
#src-git routing https://git.openwrt.org/feed/routing.git;openwrt-21.02
#src-git telephony https://git.openwrt.org/feed/telephony.git;openwrt-21.02
#src-link custom /usr/src/openwrt/custom-feed

2.3 安装packages

安装packages到feeds

./scripts/feeds install -a

2.4 配置编译选项

$ make menuconfig

选择路由器型号 Target System 选择 MediaTek Ralink MIPS

Subtarget 选择 MT7621 based boards

Target Profile 选择 Phicomm K2P

勾选Build the Openwrt SDK ,方便日后交叉编译;

2.5 编译

修改文件scripts/download.pl加速下载:

1、查找sourceforge,所有http,ftp等网址前均添加http://d.vmess.com/?
如: push @mirrors, "https://downloads.sourceforge.net/$1";  改为  push @mirrors, "http://d.vmess.com/?https://downloads.sourceforge.net/$1";

2、修改 push @mirrors, $mirror;    改为   push @mirrors, "http://d.vmess.com/?$mirror";

github的资源也可修改如下加速:

https://ghproxy.com/
https://openwrt.cc/
http://gw.stasoft.net/dl/

下载依赖源码

make download V=s

编译

$ make V=s -j16

提前下载依赖库源码放到 openwrt 源码目录中

进入 openwrt 源码目录中,执行以下命令

git clone https://e.coding.net/yao7778899/openwrt-dependent-dl.git dl
# 依赖库源码总计约850M