Openwrt官方编译教程


欢迎来到Lean的Openwrt源码仓库!

Welcome to Lean's git source of OpenWrt and packages

中文:如何编译自己需要的 OpenWrt 固件

注意:

  1. 要用 root 用户 git 和编译!!!
  2. 国内用户编译前最好准备好梯子
  3. 默认登陆IP 192.168.1.1, 密码 password

编译命令如下:

  1. 首先装好 Ubuntu 64bit,推荐 Ubuntu 18 LTS x64
  2. 命令行输入 sudo apt-get update ,然后输入 sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync
  3. git clone https://github.com/coolsnowwolf/lede 命令下载好源代码,然后 cd lede 进入目录
  4. ./scripts/feeds update -a
    ./scripts/feeds install -a
    make menuconfig
  5. 最后选好你要的路由,输入 make -j1 V=s (-j1 后面是线程数。第一次编译推荐用单线程,国内请尽量全局科学上网)即可开始编译你要的固件了。

本套代码保证肯定可以编译成功。里面包括了 R20 所有源代码,包括 IPK 的。

你可以自由使用,但源码编译二次发布请注明我的 GitHub 仓库链接。谢谢合作!

二次编译:

cd lede
git pull
./scripts/feeds update -a && ./scripts/feeds install -a
make defconfig
make -j8 download
make -j$(($(nproc) + 1)) V=s

如果需要重新配置:

rm -rf ./tmp && rm -rf .config
make menuconfig
make -j$(($(nproc) + 1)) V=s

编译完成后输出路径:/lede/bin/targets

特别提示:

  1. 源代码中绝不含任何后门和可以监控或者劫持你的 HTTPS 的闭源软件,SSL 安全是互联网最后的壁垒。安全干净才是固件应该做到的;
  2. 如有技术问题需要讨论,欢迎加入 QQ 讨论群:OP共享技术交流群 ,号码 297253733 ,加群链接: 点击链接加入群聊【OP共享技术交流群】:点击加入
  3. 想学习OpenWrt开发,但是摸不着门道?自学没毅力?基础太差?怕太难学不会?跟着佐大学OpenWrt开发入门培训班助你能学有所成 报名地址:点击报名

软路由介绍

友情推荐不恰饭:如果你在寻找一个低功耗小体积性能不错的 x86/x64 路由器,我个人建议可以考虑 小马v1 的铝合金版本 (N3710 4千兆):页面介绍

Donate

如果你觉得此项目对你有帮助,可以捐助我们,以鼓励项目能持续发展,更加完善

Alipay 支付宝

alipay_donate.jpg

Wechat 微信

wechat_donate.jpg

English Version:How to make your Openwrt firmware.

Note:

  1. DO NOT USE ROOT USER TO CONFIGURE!!!
  2. Login IP is 192.168.1.1 and login password is "password".

Let's start!

First, you need a computer with a linux system. It's better to use Ubuntu 18 LTS 64-bit.

Next you need gcc, binutils, bzip2, flex, python3.5+, perl, make, find, grep, diff, unzip, gawk, getopt, subversion, libz-dev and libc headers installed.

To install these program, please login root users and type sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3.5 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget swig rsync in terminal

Third, logout of root users. And type this git clone https://github.com/coolsnowwolf/lede in terminal to clone this source.

After these please type cd lede to cd into the source.

Please Run ./scripts/feeds update -a to get all the latest package definitions defined in feeds.conf / feeds.conf.default respectively and ./scripts/feeds install -a to install symlinks of all of them into package/feeds/ .

Please use make menuconfig to choose your preferred configuration for the toolchain and firmware.

Use make menuconfig to configure your image.

Simply running make will build your firmware. It will download all sources, build the cross-compile toolchain, the kernel and all choosen applications.

To build your own firmware you need to have access to a Linux, BSD or MacOSX system (case-sensitive filesystem required). Cygwin will not be supported because of the lack of case sensitiveness in the file system.

Note: Addition Lean's private package source code in ./package/lean directory. Use it under GPL v3.

GPLv3 is compatible with more licenses than GPLv2: it allows you to make combinations with code that has specific kinds of additional requirements that are not in GPLv3 itself. Section 7 has more information about this, including the list of additional requirements that are permitted.


补充

光官方教程你就想整好所有问题?

  1. 如果你在WSL(windows的Linux子系统)里面编译,会遇到一个很迷的问题:Windows的环境变量因为有空格不能直接在Linux中使用,所以你需要这一条命令(我也忘了是在哪,或者你可以参考这几篇文章:https://www.bilibili.com/read/cv1820955/https://dxysun.com/2018/06/02/linuxForMake/
    export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
  2. 同样是WSL的问题,你可能会发现最后一个i386无法找到源,也就是E: Unable to locate package linux-libc-dev:i386报错。
    这时你需要添加源:
    sudo dpkg --add-architecture i386
    sudo apt update
    sudo apt install linux-libc-dev:i386
  3. 第一次编译一定要单线程 make -j1 V=s 这样就算有错误也能找到(同时做好电脑开几天的准备,群里有dalao第一次挂了三天才完),还有,每次改配置后也推荐单线程,第二次编译可以开多线程了(也不能开多,内存不够照样失败)附上一张结束的末尾输出样例:
    image.png
  4. 编译错误先复制下来百度,翻译看看也是可以的,解决后最好 make clean 一下再开单线程编译。
  5. 如何以正确的姿势更新源码:https://www.maxlicheng.com/openwrt/642.html
  6. 如果你真的不想百度/Google自己的编译错误,送你一行代码: wget -qO- git.io/fix.sh|sudo sh
    image.png
  7. 待续
Last modification:January 21st, 2021 at 11:47 pm
如果觉得我的文章对你有用,请随意赞赏