openwrt--编译源码

准备工作

首先,系统我用的是ubuntu2004,openwrt版本是github上最新版本的代码。

安装需要的软件

sudo apt-get install git g++ make libncurses5-dev subversion libssl-dev gawk libxml-parser-perl unzip wget python xz-utils vim zlibc zlib1g zlib1g-dev openjdk-8-jdk build-essential ccache gettext xsltproc rsync

编译源码

下载源码

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

更新并安装软件包

切换到下载好的源码下输入以下指令

./scripts/feeds update -a 
./scripts/feeds install -a

选择芯片

切换到源码目录下,输入make menuconfig打开菜单,在最顶层选择以下选项,我用的是卓钛的JS7628。

Target System (MediaTek Ralink MIPS)
Subtarget (MT76x8 based boards)
Target Profile (Jotale JS76x8 32M)

下载依赖

openwrt编译的时候需要下载一些依赖包,切换到下载好的源码下输入以下指令

make download V=s

开始编译

make V=s

安装交叉编译链

源码编译完以后,源码下就已经生成交叉编译链了,路径在**openwrt/staging_dir/toolchain-mipsel_24kc_gcc-11.3.0_musl/bin/**下。我们只需要将该路径加入到环境变量中就可以了。

    echo export STAGING_DIR="/home/moqi/sources/openwrt/staging_dir"  >> ~/.bashrc
    echo export PATH="$PATH:/home/moqi/sources/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-11.3.0_musl/bin" >> ~/.bashrc
    source ~/.bashrc

在命令行输入mipsel-openwrt-linux-gcc -v测试安装是否成功,如果有以下输出证明已经成功了。

    COLLECT_LTO_WRAPPER=/home/moqi/tool/openwrt-toolchain/toolchain-mipsel_24kc_gcc-11.3.0_musl/bin/../libexec/gcc/mipsel-openwrt-linux-musl/11.3.0/lto-wrapper
    Target: mipsel-openwrt-linux-musl
    Configured with: /home/moqi/sources/openwrt/build_dir/toolchain-mipsel_24kc_gcc-11.3.0_musl/gcc-11.3.0/configure --with-bugurl=http://bugs.openwrt.org/ --with-pkgversion='OpenWrt GCC 11.3.0 r19830-849ffbd5ab' --prefix=/home/moqi/sources/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-11.3.0_musl --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=mipsel-openwrt-linux-musl --with-gnu-ld --enable-target-optspace --disable-libgomp --disable-libmudflap --disable-multilib --disable-libmpx --disable-nls --disable-libssp --without-isl --without-cloog --with-host-libstdcxx=-lstdc++ --with-float=soft --with-gmp=/home/moqi/sources/openwrt/staging_dir/host --with-mpfr=/home/moqi/sources/openwrt/staging_dir/host --with-mpc=/home/moqi/sources/openwrt/staging_dir/host --disable-decimal-float --with-diagnostics-color=auto-if-env --enable-__cxa_atexit --disable-libstdcxx-dual-abi --with-default-libstdcxx-abi=new --with-mips-plt --with-headers=/home/moqi/sources/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-11.3.0_musl/include --enable-languages=c,c++ --enable-shared --enable-threads --with-slibdir=/home/moqi/sources/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-11.3.0_musl/lib --enable-lto --with-libelf=/home/moqi/sources/openwrt/staging_dir/host --disable-libsanitizer
    Thread model: posix
    ...

生成交叉编译链

切换到源码目录下,输入make menuconfig打开菜单,在最顶层选择以下选项

    [*] Package the OpenWrt-based Toolchain

选择好以后,重新编译一遍就能得到交叉编译链,编译完以后的文件在 /home/moqi/sources/openwrt/bin/targets/ramips/mt76x8/openwrt-toolchain-ramips-mt76x8_gcc-11.3.0_musl.Linux-x86_64.tar.xz

添加编译选项

添加驱动

wifi驱动
Kernel modules  --->
    Wireless Drivers  --->
        <*> kmod-mt76........... MediaTek MT76x2/MT7603 wireless driver (metapackage)

添加软件

LUCI
LuCI  --->
    1. Collections  --->
        <*> luci................... LuCI interface with Uhttpd as Webserver (default)

单独编译源码

  1. 全新编译:
make ./package/utils/ugps/{clean,compile} V=s
  1. 单独编译:
make ./package/utils/ugps/compile V=s
  1. 清空:
make ./package/utils/ugps/clean V=s
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值