分类: WINDOWS
2010-07-21 16:55:42
Chapter 2
Development issues
2.1 The build system
One of the biggest challenges to getting started with embedded devices is that you cannot just install a copy of Linux and expect to be able to compile a firmware. Even if you did remember to install a compiler and every development tool offered, you still would not have the basic set of tools needed to produce a firmware image. The embedded device represents an entirely new hardware platform, which is most of the time incompatible with the hardware on your development machine, so in a process called cross compiling you need to produce a new compiler capable of generating code for your embedded platform, and then use it to compile a basic Linux distribution to run on your device.
要开始嵌入式装置最大的问题就是你不能只安装一个LINUX软件,然后就期望它能够编辑软件。尽管你记得自己已经安装了编译器以及所提供的编程工具,你仍然没有要生成软件图像所必须的基本的整一套工具。嵌入式装置代表了一个崭新的硬件平台,这很可能和你开发机上的硬件不能兼容,因此有一个步骤就是交叉编译,你需要生成一个新的编译器,能够为嵌入平台生成代码,然后使用它来编译一个基本的LINUX配送来运行你的装置。
The process of creating a cross compiler can be tricky, it is not something that is regularly attempted and so there is a certain amount of mystery and black magic associated with it. In many cases when you are dealing with embedded devices you will be provided with a binary copy of a compiler and basic libraries rather than instructions for creating your own – it is a time saving step but at the same time often means you will be using a rather dated set of tools. Likewise, it is also common to be provided with a patched copy of the Linux kernel from the board or chip vendor, but this is also dated and it can be difficult to spot exactly what has been modified to make the kernel run on the embedded platform.
生成交叉编译器的步骤很复杂,通常很少有人试图这么做,因而它有着某种神秘和魔术。在狠毒例子中,当你处理嵌入式装置时,你将被提供编译器的二进制副本和基本程序库,而非生成你自己设置的命名,它是时候节约时间了,但同时,也表明,你将使用一套过期的工具。同样的,从董事会或小商贩处买来的LINUX核心将提供一个补丁副本。但这也是过时的,因而要识别出具体哪些为了使核心在嵌入式平台上运行而被修改了部分是很困难的。
2.1.1 Building an image
OpenWrt takes a different approach to building a firmware; downloading, patching and compiling everything from scratch, including the cross compiler. To put it in simpler terms, OpenWrt does not contain any executables or even sources, it is an automated system for downloading the sources, patching them to work with the given platform and compiling them correctly for that platform. What this means is that just by changing the template, you can change any step in the process.
OpenWrt采用不同的方式建成一个软件,下载,打补丁,然后编辑所有的暂时文件,包括交叉编译器。简单说来,OpenWrt并不含有认可可执行文件或资源,它自动下载资源,自动打补丁,让其能够在给定的平台运行,并为了该平台,正确的编辑它们。这些都表明,只要改变模板,你就可以改变程序中的任何步骤。
As an example, if a new kernel is released, a simple change to one of the Makefiles will download the latest kernel, patch it to run on the embedded platform and produce a new firmware image – there is no work to be done trying to track down an unmodified copy of the existing kernel to see what changes had been made, the patches are already provided and the process ends up almost completely transparent. This does not just apply to the kernel, but to anything included with OpenWrt – It is this one simple understated concept which is what allows OpenWrt to stay on the bleeding edge with the latest compilers, latest kernels and latest applications.
例如,入股一个新的核心被释放,Makefiles一个简单的改变都将下载最新的核心,修补它,然后再嵌入式平台上运行,生成一个新的软件图标。要查找现存核心被修改的部分来查看那些地方有变动时不可能的,补丁已经被提供了,而整个步骤的完成几乎都是透明的。这并不能运用到核心,但可以运用到其它的一切程序,包括OpenWrt,它是一个很低调的概念,让OpenWrt在最新编译器,最新的核心和最新的运用程序的各种变换中能够被保存。
So let’s take a look at OpenWrt and see how this all works.
现在让我们看看它是如何工作的。
Download OpenWrt
This article refers to the "Kamikaze" branch of OpenWrt, which can be downloaded via subversion using the following command:
该节指的是OpenWrt的"Kamikaze"分支,可以通过以下指令,用subversion下载:
$ svn checkout svn://svn.openwrt.org/openwrt/trunk kamikaze
Additionally, there is a trac interface on https://dev.openwrt.org/ which can be used to monitor svn commits and browse the source repository.
此外,还有一个trac界面在https://dev.openwrt.org/ 上,可以被用来监控SVN的行为,浏览资源存储库。
The directory structure
There are four key directories in the base:
在同一类别里,有4个关键的目录。
tools and toolchain refer to common tools which will be used to build the firmware image, the compiler, and the C library. The result of this is three new directories, build_dir/host, which is a temporary directory for building the target independent tools, build_dir/toolchain-
tools 和 toolchain指用来建成软件图标,编译器和C程序库的常见工具。这一结果产生3个新的目录,build_dir/host是建成目标独立工具的一个暂时目录,build_dir/toolchain-
package is for exactly that – packages. In an OpenWrt firmware, almost everything is an .ipk, a software package which can be added to the firmware to provide new features or removed to save space. Note that packages are also maintained outside of the main trunk and can be obtained from subversion using the package feeds system:
package具体就是数据包。在一个OpenWrt软件中,几乎每一个程序都是.ipk,一个用来添加软件,提供新特性或清除以节约空间的软件数据包。注意,数据包在主要的端口汇聚外也需要维护,可以从subversion中使用数据包供给系统来获得。
$ ./scripts/feeds update
Those packages can be used to extend the functionality of the build system and need to be sym linked into the main trunk. Once you do that, the packages will show up in the menu for configuration. From kamikaze you would do something like this:
这些数据包可以用来扩展构建系统的功能,需要用符号连接到主要的端口汇聚。一旦你这样做了,该数据包就会展示出配置的菜单。从kamikaze,你需要这样做:
$ ./scripts/feeds search nmap
Search results in feed ’packages’:
nmap Network exploration and/or security auditing utility
$ ./scripts/feeds install nmap
To include all packages, issue the following command:
要包含所有的数据包,编辑一下指令:
$ make package/symlinks
target refers to the embedded platform, this contains items which are specific to a specific embedded platform. Of particular interest here is the "target/linux" directory which is broken down by platform
Target指嵌入平台,包含了特定的嵌入平台项目。在特殊情况下,"target/linux"目录被平台
Both the target and package steps will use the directory "build_dir/
目标和打包步骤都把"build_dir/
Building OpenWrt
While the OpenWrt build environment was intended mostly for developers, it also has to be simple enough that an inexperienced end user can easily build his or her own customized firmware.
OpenWrt的构建环境主要是针对研发者的,因而它应该足够简单,让不熟练的用户也可以轻松的构建自己自定义的软件。
Running the command "make menuconfig" will bring up OpenWrt’s configuration menu screen, through this menu you can select which platform you’re targeting, which versions of the toolchain you want to use to build and what packages you want to install into the firmware image. Note that it will also check to make sure you have the basic dependencies for it to run correctly. If that fails, you will need to install some more tools in your local environment before you can begin.
运行"make menuconfig"指令将引出OpenWrt配置菜单的外观,通过这个菜单,你可以选择你的目标平台。你打算用来构建的工具链版本以及你打算安装到软件图标的数据包。注意,它将检查以确保你已经为其正确运行设定了基本的相关性。如果检查失败了,在开始前,你将需要安装一些本地环境下的工具。
Similar to the linux kernel config, almost every option has three choices, y/m/n which are represented as follows:
和LINUX 核心配置相似,几乎 每一个选项都有3个选择,y/m/n代表如下:
This will not be compiledAfter you’ve finished with the menu configuration, exit and when prompted, save your configuration changes.
If you want, you can also modify the kernel config for the selected target system. simply run "make kernel_menuconfig" and the build system will unpack the kernel sources (if necessary), run menuconfig inside of the kernel tree, and then copy the kernel config to target/linux/
在你完成菜单配置前这不会被编制,在提示时退出,保存你的配置更改。
如果你愿意,你也可以为选中的目标系统修改内核配置。只需要运行"make kernel_menuconfig"创建系统就会解压内核资源(如果必需的话),在内核树内部运行menuconfig,然后把内核配置复制到target/linux/
To begin compiling the firmware, type "make". By default OpenWrt will only display a high level overview of the compile process and not each individual command.
开始编制固件,键入"make"。在默认下OpenWrt只会显示编制过程的高级概述而不是每一个单独的命令。
Example:
make[2] toolchain/install
make[3] -C toolchain install
make[2] target/compile
make[3] -C target compile
make[4] -C target/utils prepare
[...]
例如:
make[2] toolchain/install
make[3] -C toolchain install
make[2] target/compile
make[3] -C target compile
make[4] -C target/utils prepare
[...]
This makes it easier to monitor which step it’s actually compiling and reduces the amount of noise caused by the compile output. To see the full output, run the command "make V=99".
这使得检测哪一个步骤真正在编制变得更加简单,而且能够减少因编制输出而造成的大量噪音。如果要观看整个输出,运行命令"make V=99"。
During the build process, buildroot will download all sources to the "dl" directory and will start patching and compiling them in the "build_dir/