User Tools

Site Tools


zh-cn:doc:howto:build

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Previous revision
zh-cn:doc:howto:build [2013/02/01 15:48]
zh-cn:doc:howto:build [2015/11/13 15:43] (current)
rolevax [Make options] translation
Line 1: Line 1:
 +====== OpenWrt Buildroot – 使用说明======
 +| -> 返回[[obtain.firmware|获取固件]]或者阅读->​[[about:​toolchain|OpenWrt Buildroot – 关于]] |
 +
 +===== 先决条件 =====
 +  - 在你的电脑上安装**[[buildroot.exigence|OpenWrt Buildroot和它的先决条件]]**。
 +
 +===== 步骤 =====
 +| {{:​meta:​icons:​tango:​48px-emblem-important.svg.png?​nolink}} | 1. 以**非**root用户来进行工作\\ 2. 在''<​buildsystem root>''​目录中完成所有命令,例如''​~/​openwrt/​trunk/''​ |
 +
 +    - 更新OpenWrt源。
 +    - 更新feeds的package 包.
 +    - 配置编译。
 +    - 开始编译。这会自动编译工具链,交叉编译源代码,打包包文件,最后生成可以可以刷写的镜像文件。
 +    - 进入[[generic.flashing|安装OpenWrt]]环节
 +
 +==== 更新源码(source) ====
 +更新源码:
 +<​code>​
 +svn update
 +</​code>​
 +  * OpenWrt源码更新很频繁。建议你使用最新的源来完成工作。
 +
 +
 +==== 更新源(Feeds) ====
 +
 +更新源:
 +<​code>​
 +./​scripts/​feeds update -a
 +</​code>​
 +
 +安装下载好的包:​ (可选)
 +
 +<​code>​
 +./​scripts/​feeds install -a   ​(或者 '​install <​PACKAGENAME>'​ )
 +</​code>​
 +
 +
 +===== 镜像配置 =====
 +开始OpenWrt Buildroot基于[[wp>​ncurses]]的 [[wp>​Text-based user interface|文本]]配置界面:​\\
 +<​code>​
 +make menuconfig
 +</​code>​
 +| 同配置Linux内核类似,几乎每一个设置都有三个选项:​**y** / **m** / **n**,分别代表如下含义:\\ ​  * `` (按下`y`)这个包会被包含进固件镜像\\ ​ * `` (按下`m`)这个包会在生成[[doc:​howto:​generic.flashing|刷新OpenWrt]]的镜像文件以后被编译,但是**不会**被包含进镜像文件 \\ * `` (按下`n`)这个包不会被编译\\ ​ \\  当你保存你的配置后,''​~/​openwrt/​trunk/​.config''​这个文件会按照你的配置被生成。\\ \\编译环境会提供一个这样的配置文件给OpenWrt '​Backfire'​ 10.03.1-RC5。 例如,[[http://​downloads.openwrt.org/​backfire/​10.03.1-rc5/​ar71xx/​config|for ar71xx]]. ​ |  |
 +
 +
 +  * 这个菜单允许你选择目标平台,也就是你想要用来编译你要包含进固件镜像的软件包的工具链(toolchain)的版本。
 +
 +  * 在更新源码和源以后运行这个配置界面,确保你的配置中包含的软件包是最新的。
 +
 +
 +
 +==== 默认配置(Defconfig) ====
 +[[https://​forum.openwrt.org/​viewtopic.php?​pid=140470#​p140470|在启用默认配置以前先选择的你的目标平台]]
 +<​code>​
 +make defconfig
 +</​code>​
 +将会生成一个通用的编译系统配置,这个配置包含了一个对于编译环境的先决条件和依赖的检查,同时会安装缺失的组件并再次运行。
 + 
 +
 +==== 总体配置 ====
 +''​Menuconfig''​拥有一个文本界面,它包括选择要处理的目标平台,要编译的软件包,要被包含进固件文件的软件包和一些内核设置等。
 +
 +<​code>​
 +make menuconfig
 +</​code>​
 +
 +这会自动更新你现在存在的配置的依赖,方便你你准备编译你更新过的镜像。
 +
 +It has from the beginning on been the intention, with the development of '​menuconfig',​ 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 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.
 +
 +这儿有三种选项可选:
 +  * < > 该代码将**不会**被编译
 +  * <M> 该代码将被交叉编译,生成的ipk软件包将被放在 ''/​buildsystem/​bla/​bla/​bla'',​ 但该软件包不会放入固件中
 +  * <*> 该代码将被放入固件中 (on the SqashFS partition)
 +
 +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 the TUI, and choose to ''​save''​ your settings.
 +
 +=== 内核配置 ===
 +While you won't typically need to do this, you can do it:
 +
 +<​code>​
 +make kernel_menuconfig
 +</​code>​
 +
 +See: [[doc:​techref:​buildroot#​Customizing the kernel options]]
 +
 +=== 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.
 +
 +==== Custom files ====
 +In many cases, you may want to have a custom image that has been pre-configured to your link. If so, place your custom files in 
 +<​code><​buildroot dir>/​files/</​code>​
 +
 +For example, let's say that you want an image with a pre-configured ''/​etc/​config/​firewall'',​ then place your modified firewall config in here:
 +<​code><​buildroot dir>/​files/​etc/​config</​code>​
 +
 +
 +===== 构建镜像 =====
 +为构建镜像,一切已就绪。现只需一条命令:​
 +
 +<​code>​
 +make
 +</​code>​
 +
 +或者:
 +<​code>​
 +make world
 +</​code>​
 +
 +该命令会触发一连串的活动。之前也说过,它将会:
 +  - 编译工具链
 +  - 然后用这个工具链交叉编译源文件
 +  - 创建opkg软件包
 +  - 创建可随时[[generic.flashing|刷机]]的镜像。
 +
 +==== 构建选项 ====
 +=== 在多核CPU上构建 ===
 +
 +可通过''​-j''​选项启用多个进程以加速构建过程:
 +<​code>​
 +make -j 3
 +</​code>​
 +  * 使用标准公式 ''<​你的CPU个数 + 1>''​
 +  * 构建过程中若产生随机错误,尝试去掉''​-j''​选项重新构建
 +
 +=== 在后台构建 ===
 +如果你想在构建时干别的,你可以让构建进程只使用闲置的CPU和I/​O资源(双核CPU):
 +
 +<​code>​
 +ionice -c 3 nice -n 20 make -j 2
 +</​code>​
 +
 +=== 构建单个包 ===
 +为OpenWrt开发或打包软件时,可以方便地只构建关心的包(以''​cups''​包为例):
 +
 +<​code>​
 +make package/​cups/​compile V=99
 +</​code>​
 +
 +For the package ''​mc (midnight commander)'',​ which is contained the feed //​packages//​ it looks like this:
 +<​code>​
 +make package/​feeds/​packages/​mc/​compile v=99
 +</​code>​
 +
 +
 +=== 高亮构建错误 ===
 +如果构建不知怎么搞的出错了,亮出错误的最简单方式是:
 +
 +<​code>​
 +make V=99 2>&1 | tee build.log | grep -i error
 +</​code>​
 +
 +以上命令会保存一份详尽的编译输出(同时把stdout泵至stderr)到''/​openwrt/​trunk/​build.log''​,并只在屏幕上输出错误。
 +
 +另一个例子:
 +
 +<​code>​
 +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)'​
 +</​code>​
 +
 +再来一个例子:
 +<​code>​
 +somthing something screen
 +</​code>​
 +
 +以上命令会保存一份详尽的编译输出(同时把stdout泵至stderr)到''​build.log''​,并只在屏幕上输出警告和错误,且在双核CPU上只使用后台资源。
 +
 +=== 收到哔的一声提示 ===
 +取决于你的CPU,构建过程可能要花上很久、或更久的时间。如果你想要提示音,可使用''​echo -e '​\a''':​
 +
 +<​code>​
 +make V=99 ; echo -e '​\a'​
 +</​code>​
 +
 +===== 本地固件 =====
 +编译成功后的固件bin文件在 ''/​openwrt/​trunk/​bin''​ 目录下.
 +
 +<​code>​
 +cd ~/​openwrt/​trunk/​bin
 +ls */
 +</​code>​
 +
 +===== Cleaning Up =====
 +You might need to clean your //build environment//​ every now and then. The following ''​make''​-targets are useful for that job:
 +
 +==== Clean ====
 +<​code>​
 +make clean
 +</​code>​
 +
 +deletes contents of ''​bin''​ and ''​build_dir''​ directories.
 +
 +
 +==== Dirclean ====
 +<​code>​
 +make dirclean
 +</​code>​
 +
 +deletes contents of ''/​bin''​ and ''/​build_dir''​ directories and additionally ''/​staging_dir''​ and ''/​toolchain''​ (=the cross-compile tools). '​Dirclean'​ is your basic "Full clean" operation. ​
 +
 +
 +==== Distclean ====
 +<​code>​
 +make distclean
 +</​code>​
 +
 +nukes everything you have compiled or configured and also deletes all downloaded feeds contents and package sources.
 +
 +
 +**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.
 +
 +
 +===== 例子 =====
 +  * https://​forum.openwrt.org/​viewtopic.php?​pid=129319#​p129319
 +  * https://​forum.openwrt.org/​viewtopic.php?​id=28267
 +
 +
 +===== Troubleshooting =====
 +First get more information on the problem using the make option "make V=99".
 +  * **Missing source code file, due to download problems**.
 + First check if the URL path in the make file contains a trailing slash, then try with it removed (helped several times).
 + ​Otherwise try to download the source code manually and put it into "​dl"​ directory
 +  * **Compilation errors**.
 + Try to update the main source and all the feeds (Warning! May result in other problems).
 + Check for a related bug in ([[https://​dev.openwrt.org/​query|TRAC]]),​ use the filters to find it.
 + ​Otherwise report the problem there, by mentioning the package, the target data (CPU, image, etc.) and the code revisions (main & package).
 + ​Compiling with make -j ... sometimes gives random errors. Try compiling without -j first before reporting the problem.
 +
 +
 +===== 注意 =====
 +  * [[doc:​techref:​buildroot|OpenWrt Buildroot – Technical Reference]]
 +  * [[http://​downloads.openwrt.org/​docs/​buildroot-documentation.html]]
 +  * [[https://​dev.openwrt.org/​browser/​trunk/​docs/​working.tex]]