OpenWRT的开发

2023-11-08


Openwrt 官方正式的发行版是已编译好了的映像文件(后缀名bin或trx、trx2),此映像文件可从Openwrt官方网站的下载页面中轻松获取到,连接地址为 OpenWrt官方网站。

准备工作

在开始编译Openwrt之前需要您做些准备工作;与其他编译过程一样,类似的编译工具和编译环境是必不可少的:
一个构建并编译OpenWrt映像的系统,简单说就是准备一个Linux或者类Unix操作系统(比如Ubuntu、Debian,MAC OS,FreeBSD等);
确保安装了所需的依赖关系库, (在debian系统中就是安装各种需要的软件包)
获取到OpenWrt源代码副本
首先, 开机登陆到开发机的操作系统(废话了)。不管是独立安装的或者是运行在虚拟机上的(Vmware 或者 Qemu),推荐使用Linux系统。 在 *BSD 或者是 Max OSX 系统上编译Openwrt也可行,但并不能保证可以成功编译。下文假定您使用的是Debian操作系统,使用 apt-get 来管理包. 您也可以使用其他linux发行版,比如 Ubuntu (分支 Kubuntu, Xubuntu 等即可)。
不过,在虚拟机中编译Openwrt会产生无法预料的问题,所以建议您还是使用物理主机来编译以减少不必要的麻烦。
第二步, 就是安装所需要的各种软件包, 包括编译器,解压工具,特定的库等. 这些工作可以简单的通过键入以下命令 (通常需要root 或者是 sudo 权限),以root权限安装下列软件包(可能并不完整,会有提示,提示缺少即装就可以了):
32位(x86)请执行下列命令:
# apt-get install build-essential asciidoc binutils bzip2 gawk gettext \
  git libncurses5-dev libz-dev patch unzip zlib1g-dev

64位(x86_64)请执行下列命令(多装了哪些库或软件包呢?请您仔细看一看哦):
# apt-get install build-essential asciidoc binutils bzip2 gawk gettext \
  git libncurses5-dev libz-dev patch unzip zlib1g-dev ia32-libs \
  lib32gcc1 libc6-dev-i386


某些依赖的为库或软件包也许操作系统中已经安装过,此时apt-get会作出提示(提示您忽略或重新安装的),别紧张,放轻松些,编译Openwrt不会像编译DD-WRT那样难的(至少本人是体会到了编译DD-WRT的难)。
最后下载一份完整的 Openwrt 源码到编译环境中。关于Openwrt的源代码下载,途径有二,一是通过 subversion ,一是通过 git,建议使用 subversion(SVN) ,因为Openwrt主要以 svn 来维护Openwrt系统的版本。另外,请注意Openwrt中不同的分支版本,一个是用得较多的开发快照,俗称 trunk,二是稳定版,截至至本文截稿前的最新版本是backfire 10.03.1 rc5。
安装Subversion
若你想通过svn下载源代码,你需安装 Subversion。Subversion,或称SVN, 是OpenWrt的project中用来控制版本的系统,它非常类似的 CVS的界面和使用条款。 执行下述命令即可安装SVN,很容易的:
# apt-get install subversion

Subversion 安装完毕,通过SVN命令可获取得到一份OpenWrt纯净源代码。您还得创建一个目录以便存放获取得到的Openwrt源代码,要获取源代码你还得输入 subversion命令来获取 (svn里这种操作称之为'check out') 。命令很简单的,继续看下去就能见到了,别着急,耐心点儿。
编译流程
编译Openwrt需要以一下五个步骤:

通过Subversion命令获得源代码:

更新(或安装) 扩展软件包,即package feeds;
创建一个默认配置以检查编译环境是否搭建好了 (假如需要的话);
用Menuconfig来配置即将编译生成的固件映像文件的配置项;
最后开始编译固件;
下载源代码
最后,下载一份完整的OpenWrt源代码。你可选择:
下载稳定发行版,或
下载开发版 (俗称"trunk"版)。
使用发行版的源码
截止本文时, Openwrt公开发行的稳定版为 OpenWrt 10.03 "backfire"。此版本是最稳定的,但也许不包括最新更新的补丁或最新编写的出的新功能。
下述代码即举例说明了通过svn从brandkfire获得backfire源代码(此版本意思是从trunk分支的补丁也在backfire版本中了,即包含修复补丁):
# mkdir OpenWrt/
# cd OpenWrt/

# svn co svn://svn.openwrt.org/openwrt/branches/backfire

有一次,我在新的一台ubuntu下安装是差了很多中间件 如下。

sudo apt-get install g++ libncurses5-dev flex patch gawk zlib.



注解: 上述svn命令将在当前目录创建一个 OpenWrt/backfire/ 子目录,此目录包含此命令获取到的源代码。
您也可以通过下述命令,下载不含修复补丁的backfire的原版源码:
# svn co svn://svn.openwrt.org/openwrt/tags/backfire_10.03

使用开发版源代码
当前的开发版本分支(trunk)已包含最新的实验补丁。此分支或许还突破了Openwrt原来所不支持的硬件设备的限制哦,惊喜的同时也有风险存在。因此,编译trunk版,慎之~
# mkdir OpenWrt/
# cd OpenWrt/
# svn co svn://svn.openwrt.org/openwrt/trunk/

(trunk 版本多一个git)

sudo apt-get install g++ libncurses5-dev flex patch gawk zlib. git


更多详细资料详见: https://dev.openwrt.org/wiki/GetSource.
跟进并更新源代码
因Openwrt的源代码随时都会变动,故此命令将确保您所获取得到的源码的最新性。下述假设您用的是backfire版本的源码:
## Here, backfire is the directory name of the current release branch you're tracking
# cd OpenWrt/backfire/
# svn up

'svn up' 命令用于更新SVN上更新了,但本地尚未更新的这部分源代码(本人实践证明此命令会将本地源码与SVN上的源码先比较,若SVN有更新才会下载更新的部分,很实用的一个命令)。如果未指定目标路径,则此命令将更新当前目录及当前目录的子目录内的源码。
更新软件包
Feeds是一个openwrt的附加软件包管理器
'packages' - many additional basic router features,
'LuCI' - the default www GUI for OpenWrt, and
'Xwrt' - alternative GUI.
In most typical case, you needs at least 'packages' and 'LuCI'.
Before downloading feeds (additional predefined package build recipies for OpenWrt) you can check which feeds sources you want to include. Just edit the file 'feeds.conf.default' in the base directory of your build environment.
Then start the download with
# ./scripts/feeds update -a

After this the downloaded packages need to be installed. The installation step means they will be available during the 'make menuconfig' step later. Without this 'installation' step the packages will not be selectable in 'make menuconfig'.
# ./scripts/feeds install -a

The feeds configuration file makes it easy to add new or experimental packages sources to the build system. Just edit the file and run the update command.
Note: Please note that this step replaces the old method of creating symlinks, which can be still found on-line in many old forum and user-group entries.
Updating Feeds
Just like the basic source code, you need to regularly update the feeds sources. That is done with the same commands:
# ./scripts/feeds update -a
# ./scripts/feeds install -a

Note: If you know that you do not want to add possible new packages for menuconfig, you may skip the install step, when updating already existing feeds.
生成配置
You may not have to make configration always after updating sources and feeds, but making it ensures that all packages from source and feeds are correctly included in your build configuration.
Defconfig
下一步是检查编译环境,若可进行编译则生成默认配置:
# make defconfig

若defconfig回显提示缺少软件包或编译库等依赖,则按提示安装所缺软件包或库等即可,不难的,细心点就行。
Menuconfig
Menuconfig is a text-based tool which handles the selection of target, packages to include in the build, kernel options etc.
# make menuconfig

This will update the dependencies of your existing configuration automatically and you can now proceed to build your updated images.
The intention with the development of 'menuconfig' has been to create a simple yet powerful environment for the configuration of individual OpenWrt images. Menuconfig is more or less self-explanatory, and even the most specialized configuration needs can be solved with its help. Depending on the the particular target platform, package requirements and kernel module needs, the standard process of configuration will include modifying:
Target system
Package selection
Build system settings
Kernel modules
Target system is selected from the extensive list of supported platforms, with the numerous target profiles – ranging from specific devices to generic profiles, all depending on the particular device at hand. Package selection has the option of either 'selecting all package', which might be un-practical in certain situation, or relying on the default set of packages will be adequate or make an individual selection. It is here needed to mention that some package combinations might break the build process, so it can take some experimentation before the expected result is reached. Added to this, the OpenWrt developers are themselves only maintaining a smaller set of packages – which includes all default packages – but, the feeds-script makes it very simple to handle a locally maintained set of packages and integrate them in the build-process.
If you want to use LuCI, you'll need to go to the Administration menu, then LuCI Components sub-menu, and select the first 3 packages: luci-admin-core, luci-admin-full, and luci-admin-mini.
If you don't need PPP, you can remove it by deselecting it under the Network menu.
Using Menuaconfig: Make sure you mark these packages as a '*' instead of just an 'M'.
If you mark with a '*', the package will be built into the firmware you create.
If you mark it with just an 'M', the package will be built but not installed.
The final step before the process of compiling the intended image(s) is to exit 'menuconfig' – this also includes the option to save a specific configuration or load an already existing, and pre-configured, version.
Exit and save.
Source Mirrors
The 'Build system settings' include some efficient options for changing package locations which makes it easy to handle a local package set:
Local mirror for source packages
Download folder
In the case of the first option, you simply enter a full URL to the web or ftp server on which the package sources are hosted. Download folder would in the same way be the path to a local folder on the build system (or network). If you have a web/ftp-server hosting the tarballs, the OpenWrt build system will try this one before trying to download from the location(s) mentioned in the Makefiles . Similar if a local 'download folder', residing on the build system, has been specified. The 'Kernel modules' option is required if you need specific (non-standard) drivers and so forth – this would typically be things like modules for USB or particular network interface drivers etc.
编译固件
万事具备,只欠东风,通过下面简单的make命令来编译:
# make

在多核电脑中编译
具有多核CPU处理器的电脑进行编译,使用下述参数可令编译过程加速。 常规用法为 <您cpu处理器的数目 + 1> – 例如使用3进程来编译 (即双核CPU), 命令及参数如下:
# make -j 3

后台编译
If you intend to use your system while building, you can have the build process only use idle I/O and CPU capacity like this (dualcore CPU):
# ionice -c 3 nice -n 20 make -j 2

编译简单的基本的软件包
When developing or packaging software for OpenWrt, it is convenient to be able to build only the package in question (e.g. with package cups):
# make package/cups/compile V=99

For a package in the feeds it looks like this:
# make package/feeds/packages/ndyndns/compile V=99

编译错误
如果因某种不知道的原因而编译失败,下面有种简单的方法来得知编译到底错在哪里了:
# make V=99 2>&1 |tee build.log |grep -i error

The above saves a full verbose copy of the build output (with stdout piped to stderr) in build.log and only shows errors on the screen.
举例说明:
# ionice -c 3 nice -n 20 make -j 2 V=99 CONFIG_DEBUG_SECTION_MISMATCH=y 2>&1 \
  |tee build.log |egrep -i '(warn|error)'

The above saves a full verbose copy of the build output (with stdout piped to stderr) in build.log and outputs only warnings and errors while building using only background resources on a dual core CPU.
一键编译
即使用脚本来编译Openwrt固件。许多朋友编译Openwrt是用的脚本来编译的,详见: https://forum.openwrt.org/viewtopic.php?id=28267
生成的固件在哪
编译成功后所生成的固件文件位于bin目录下,可用如下命令查看:
# cd bin/
# ls */

Cleaning Up
You might need to clean your build environment every now and then. The following make targets are useful for that job:
Clean
Cleaning the trunk/ directory after the build process is simple and only requires 'make clean'. It deletes contents of 'bin' and 'build_dir' directories.
## See CAUTION below
# make clean

CAUTION: Make sure to move your compiled OpenWrt images to another location before issuing this command since it erases the contents of the "bin" directory (where the compiled OpenWrt images live).
Dirclean
If you want to clean in addition to the build directories also the cross-compile tools (in toolchain directory), use the 'dirclean' make, which does the same as 'clean' and also deletes 'staging_dir' and 'toolchain' contents. 'Dirclean' is your basic "Full clean" operation.
## See CAUTION below
# make dirclean

CAUTION: Make sure to move your compiled OpenWrt images to another location before issuing this command.
Distclean
If complete cleaning of the build environment is required, then all it takes is 'make distclean'. It practically nukes everything you have compiled or configured and also deletes all downloaded feeds contents and package sources. Making distclean means quite a lot downloading afterwards, so it should not be used lightly. 'Dirclean' is enough for most cases.
## See CAUTION below
# make distclean

CAUTION: In addition to all else, this will erase your build configuration (.config), your toolchain and all other sources. Use with care!
There are numerous other functionalities in the OpenWrt build system, but the above should have covered some of the fundamentals.
Installing OpenWrt
In comparison to the actual building of the desired image(s), the installation of the OpenWrt image can sometimes be a little, or more, of a challenge. It can be as simple as using the tools supplied by the manufacturer of the hardware (web interface or recovery tools), over manually uploading a new firmware via tftp and rebooting, to doing extensive hardware modifications with the intent of enabling JTAG access. Though, generally installation is made possible via the bootloader (Redboot, Uboot etc.) or simple copying onto a CompactFlash-card – all depending on the specific device.
See http://wiki.openwrt.org/doc/howto/installing for the specifics.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

OpenWRT的开发 的相关文章

随机推荐

  • 如何修改手机IP地址

    说起手机换IP大家可能没有对电脑换IP那么熟悉 但是现在智能手机能做到事情越来越多 手机换IP也成为许多工作需要 一部分人还不知道怎么操作 就跟着小编一起来看看手机换IP的几种方法 一 手动换IP 这个适合偶尔换IP 时间富裕的朋友 我们使
  • Tableau Prep使用

    下载了 Tableau Prep 2019 1 4 版本 安装后 注册使用14天的试用版 1 连接数据源 2 创建数据流 如下图 一共创建了2个数据流 分别存到2个不同的csv文件
  • 环境变量的作用和位置

    1 当要求系统运行一个程序而没有告诉它程序所在的完整路径时 系统除了在当前目录下面寻找此程序外 还应到环境变量path中指定的路径去找 用户通过设置环境变量 来更好的运行进程 一般说的环境变量都是指系统的环境变量 2 轻松打开win10环境
  • configure交叉编译 说明

    交叉编译某个应用程序时 通常需要 configure 来生成对应的 Makefile configure 最关键的三个选项是 host HOST 指定软件运行的系统平台 如果没有指定 将会运行 config guess 来检测 build
  • YoloV8改进策略:增加分支,减少漏检

    文章目录 摘要 数据集 如何解决问题 原始网络Yolov8 改进一 改进二 改进三 总结 扩展 YoloV5增加小目标检测的分支 摘要 如何检测小目标 这个一直是比较头疼的问题 如果都是小目标还好说 我们可以采用切图的方式 如果是数据集的目
  • 目标检测——day66 Scaled-YOLOv4: Scaling Cross Stage Partial Network

    Scaled Yolov4 可伸缩跨级部分网络 Scaled YOLOv4 1 Introduction 2 Related work 2 1 Real time object detection 2 2 Model scaling 模型缩
  • Spring boot 文件下载接口

    RequestMapping xzwj 复制代码 public void xzwj HttpServletResponse res String id throws IOException String fileName 12345 png
  • ES6 Set

    ES6 Set 数据结构 定义 特殊情况 set与字符串 Set的用法 数组去重 并集 交集 差集 定义 Set对象提供了一种数据结构 类似于数组 但是没有重复值 特殊情况 Set对象存储的值具有唯一性 所以添加元素时需要判断两个元素的恒等
  • np.meshgrid()函数 以及 三维空间中的坐标位置生成 以及 numpy.repeat()函数介绍

    一 np meshgrid 函数 1 np meshgrid 介绍 X Y np meshgrid x y 代表的是将x中每一个数据和y中每一个数据组合生成很多点 然后将这些点的x坐标放入到X中 y坐标放入Y中 并且相应位置是对应的 下面是
  • Redis主从复制和哨兵模式

    Redis主从复制和哨兵模式 一 Redis主从复制 1 为什么要搭建主从模式 2 主从搭建步骤 第一步 第二步 第三步 第四步 第五步 启动从机 第六步 启动6380的客户端 二 Redis哨兵模式 1 哨兵模式是什么 2 哨兵的作用 3
  • 【华为OD统一考试A卷

    华为OD统一考试A卷 B卷 新题库说明 2023年5月份 华为官方已经将的 2022 0223Q 1 2 3 4 统一修改为OD统一考试 A卷 和OD统一考试 B卷 你收到的链接上面会标注A卷还是B卷 请注意 根据反馈 目前大部分收到的都是
  • 解决MySQL命令行输入密码闪退+不能启动问题

    win10环境 新下载MySQL8 0 26 刚装完还是能用 两天没打开 突然出现了问题 下面记录一下解决过程 右键屏幕底部 打开任务管理器 服务 在服务中点击查看MySQL服务状态是否为开启 MySQL服务没有开启 搜索 cmd 右键单击
  • Ansible脚本搭建k8s平台

    1 官网下载安装virtualBox centos7镜像 2 virtualBox安装centos7镜像 参考http www cnblogs com hihtml5 p 8217062 html 3 下载安装putty通过SSH连接虚拟机
  • Linux 进程基础概念-进程状态、进程构成、进程控制

    目录 Linux 进程 进程基础概念 进程状态 进程的构成 进程控制 进程创建和终止 Linux 进程 参考 linux操作系统 进程的切换与控制 到底有啥关系 知乎 zhihu com Linux进程解析 deep explore的博客
  • 【代码】处理数据集的一些常用脚本

    前言 由于训练模型经常使用到一些处理数据集的脚本 每次重新写都蛮麻烦的 因此决定整理一下之后备用 加快效率 一些是借鉴网上的脚本但是因为时间太久找不到原链接所以比较抱歉没有贴出来原链接 还有一些是自己写的 发出来分享一下 1 voc数据集抽
  • wifi卡慢延迟高_wifi卡怎么办(wifi信号满格但网速慢解决方法)

    最近学霸君有个朋友 天天吹自己家里 100M 光纤 可每晚一起开黑王者的总是说家里 WiFi 莫名卡顿 断流 然后各种理由坑人 让它换路由器吧 又不舍得花这点钱 说是够用就行 生怕自己气成祖安人的学霸君 只好上门帮他看看是不是路由器没设置好
  • [技术发展-26]:新型信息与通信网络的数据安全

    前言 网络安全 通常指计算机网络的安全 实际上也可以指计算机通信网络的安全 计算机通信网络是将若干台具有独立功能的计算机通过通信设备及传输媒体互连起来 在通信软件的支持下 实现计算机间的信息传输与交换的系统 而计算机网络是指以共享资源为目的
  • 【idea插件开发】从0入门idea插件开发,idea插件开发教程,如何开发idea插件

    idea插件介绍 作为一枚程序员 平时最常用的ide就是IntelliJ IDEA 平时会用到各种各样的插件 通过插件的使用 提高自己的开发效率 idea具有全局性 安装好插件后 对idea生效 所有的工程均能找到 idea使用的便捷性 在
  • 单词长度(输入在一行中给出一行文本,以‘.’结束,结尾的句号不能计算在最后一个单词的长度内。在一行中输出这行文本对应的单词的长度,每个长度之间以空格隔开,行末没有最后的空格。)

    单词长度 5分 题目内容 你的程序要读入一行文本 其中以空格分隔为若干个单词 以 结束 你要输出这行文本中每个单词的长度 这里的单词与语言无关 可以包括各种符号 比如 it s 算一个单词 长度为4 注意 行中可能出现连续的空格 输入格式
  • OpenWRT的开发

    Openwrt 官方正式的发行版是已编译好了的映像文件 后缀名bin或trx trx2 此映像文件可从Openwrt官方网站的下载页面中轻松获取到 连接地址为 OpenWrt官方网站 准备工作 在开始编译Openwrt之前需要您做些准备工作