openWrt入门2——初步认识工程

  学习openWrt,首先要从工程入手,这你需要知道一些makefile的知识。从编译入手。首先,你需要将代码checkout或clone下来。

  如果是使用git进行代码管理,那么执行以下的命令,在我接触openwrt的时候,还不支持git代码管理,只有svn。

  trunk:

    工程:

git clone git://git.openwrt.org/openwrt.git

软件包:

git clone git://git.openwrt.org/packages.git

12.09 branch:

    工程:

git clone git://git.openwrt.org/12.09/openwrt.git

软件包:

git clone git://git.openwrt.org/12.09/packages.git

如果是使用svn的话,则执行下面的命令:

  trunk:

    工程:

svn co svn://svn.openwrt.org/openwrt/trunk/

软件包:

svn co svn://svn.openwrt.org/openwrt/packages

12.09:

    工程:

svn co svn://svn.openwrt.org/openwrt/branches/attitude_adjustment

软件包:

svn co svn://svn.openwrt.org/openwrt/branches/packages_12.09

如果你想吧整个的openwrt都checkout下来也可以,包含所有的版本的软件包以及分支版本的工程:

svn co svn://svn.openwrt.org/openwrt
git clone git://git.openwrt.org/

代码checkout/clone可能要一段时间,接下来,就以12.09为主进行说明吧,还有一点需要注意的就是,最好使用对应版本的软件包,虽然不是对应版本的软件包也是可以使用的,但是对应的,有经过官方的测试,会有对应的维护,而如果是跨版本的,那么出现的一些异常情况,可能就需要你自己解决了。还有就是自己移植的软件包,那么也需要自己维护了。可以先make help,看看有什么帮助说明。

cd attitude_adjustment
make help
This is the buildsystem for the OpenWrt Linux distribution.

Please use "make menuconfig" to configure your appreciated
configuration for the toolchain and firmware.

You need to have installed gcc, binutils, patch, bzip2, flex,
make, gettext, pkg-config, unzip, libz-dev and libc headers.

Run "./scripts/feeds update" to get the latest package definitions
defined in feeds.conf / feeds.conf.default respectively
and "./scripts/feeds install" to install symlinks into "package/feeds/*".

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.

You can use "scripts/flashing/flash.sh" for remotely updating your embedded
system via tftp.

The OpenWrt system is documented in docs/. You will need a LaTeX distribution
and the tex4ht package to build the documentation. Type "make -C docs/" to build it.

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.
Sunshine!
Your OpenWrt Project
http://openwrt.org

从帮助中,知道你需要安装gcc, binutils, patch, bzip2, flex,make, gettext, pkg-config, unzip, libz-dev and libc headers.也就是除了对应的一些开发工具,还有就是开发对应的头文件。

  Ubuntu/debian的话,执行下面的命令,安装对应的开发工具,有玩过内核的,应该都知道make menuconfig,openwrt也支持字符界面的操作。

sudo apt-get install build-essential automake m4 gawk flex bison unzip bzip2 patch gettext pkg-config zlib1g-dev
make menuconfig
Checking 'non-root'... ok.
Checking 'working-make'... ok.
Checking 'case-sensitive-fs'... ok.
Checking 'getopt'... ok.
Checking 'fileutils'... ok.
Checking 'working-gcc'... ok.
Checking 'working-g++'... ok.
Checking 'ncurses'... ok.
Checking 'zlib'... ok.
Checking 'gawk'... ok.
Checking 'unzip'... ok.
Checking 'bzip2'... ok.
Checking 'patch'... ok.
Checking 'perl'... ok.
Checking 'python'... ok.
Checking 'wget'... ok.
Checking 'git'... ok.
Checking 'gnutar'... ok.
Checking 'svn'... ok.
Checking 'gnu-find'... ok.
Checking 'getopt-extended'... ok.
Collecting package info: done
Collecting target info: done
Your configuration changes were NOT saved.

如果出现Build dependency: Please install ncurses. (Missing libncurses.so or ncurses.h)的错误,那是执行make menuconfig的时候,缺少ncurses库或头文件的支持。因为make menuconfig是使用ncurses来实现的字符界面。执行下面的命令,安装编译需要的头文件及库文件。

sudo apt-get install libncurses5-dev

make_menuconfig

  在执行了对应的一系列操作后,字符界面就出来了。由于没有设备,那么我们也只能继续在虚拟机上玩了,那就把配置修改成x86版本的。先使用默认的配置。退出,并保存配置,会在工程的目录下生成.config的隐藏配置文件。然后就可以开始编译了,执行make进行编译操作。

make #执行make 不带log
make V=99 # 执行make,会打印编译的log
make -j 6 V=99 #执行6个任务同时进行编译,一般最佳为CPU核心数的2倍,不过机子这样会很卡,不带-j为单进程编译,具体可以make --help查看帮助

编译需要一段的时间,openwrt工程会帮你生成编译工具链,安装包,以及会帮你生成img文件系统。是个非常强大的工程。好了,现在这篇文章就先到这里了,下一篇文章,将对openwrt的目录进行适当的解析。

参考资料:

https://dev.openwrt.org/wiki/GetSource

http://wiki.openwrt.org/doc/howto/build?s[]=make

转载请注明: 转载自elkPi.com

本文链接地址: openWrt入门2——初步认识工程

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Scroll to top