Openwrt 学习记录:编译环境安装及目录介绍(一)

1.需要的组件:
sudo apt-get install binutils bzip2 gawk  flex bison autoconf gcc gcc g++ gettext texinfo sharutils  make ncurses-term patch unzip wget  zlib1g-dev  gawk asciidoc libz-dev libncurses5-dev  


sudo apt-get install subversion screen git-core  mercurial   build-essential libssl-dev libncurses5-dev 
sudo apt-get install build-essential subversion libncurses5-dev zlib1g-dev gawk gcc-multilib flex git-core gettext libssl-dev


2.下载源码:

Office:https://openwrt.org/


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


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


3.为了防止文件读写权限造成问题,需要将源码copy到openwet的根目录下进行所有操作。
[root@localhost trunk]# adduser openwrt  
[root@localhost trunk]# passwd openwrt  
[root@localhost trunk]# su openwrt
4、将代码copy到openwrt user目录。
5、下载feeds(OpenWrt环境所需要的软件包套件)
‘packages’一些额外的基础路由器特性软件
‘LuCI’OpenWrt默认的GUI
‘Xwrt’另一种可选的GUI界面
 在下载之前可以通过查看’feeds.conf.default’文件,来检查哪些文件需要包含在环境中。
[openwrt@localhost trunk]$ ./scripts/feeds update -a
安装feeds包,只有安装之后,在后面的make menuconfig时,才可以对相关配置进行勾选。
[openwrt@localhost trunk]$ ./scripts/feeds install -a
如果更新了feeds的配置文件,需要添加新的软件包用于生成系统。只需进行重复操作:
[openwrt@localhost trunk]$ ./scripts/feeds update -a
[openwrt@localhost trunk]$ ./scripts/feeds install -a


6.配置
[openwrt@localhost trunk]$ make defconfig
[openwrt@localhost trunk]$ make prereq
[openwrt@localhost trunk]$ make menuconfig
通过文本对话框进行选项配置,最主要的配置项有:
Target system(目标系统类型)
Package selection(软件包选择)
Build system settings  (编译系统设置)
Kernel modules  (内核模块)
[*]表示:这个包裹选中编译,并安装在firmware中;
[M]表示:这个软件包选中编译,但并不安装在firmware中。
其中选中Image SDK可以构建内核二次打包、和开发环境。
在退出Menuconfig的时,会提示是否保存配置。注意初次编译最好编译SDK: Build the OpenWrt SDK选项


7.编译
编译
(1)一般情况,使用一个简单的命令:
[openwrt@localhost trunk]$ make
(2)在多核处理器系统上为提高速度,可使用(例如用3核处理器):
[openwrt@localhost trunk]$ make –j 3
(3)在后台进行编译,使用空闲的I/O资源和CPU性能,可使用(例如使用双核处理器)
[openwrt@localhost trunk]$ onice -c 3 nice -n 20 make -j 2
(4)编译一个单独的软件包(例如在cups软件包):
[openwrt@localhost trunk]$ make package/cups/compile V=99
(5)如果特殊原因需要分析编译报错信息:
[openwrt@localhost trunk]$ make V=99 2>&1 |tee build.log |grep -i error
说明:将编译的所有输出信息保存在build.log中,将error信息打印在屏幕上。
(6)一个复杂指令的应用
[openwrt@localhost trunk]$ 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)'
说明:将编译的所有输出信息保存在build.log中,将error和warning信息打印在屏幕上。编译过程使用双核CPU,占用后台资源。


8.清理
清理工作
建议现在清理编译产生的文件,以免下次编译时造成冲突,(文件如果存在的话,将不会被替换),执行make clean
注意:在执行clean命令,确保已经将编译好的image进行了备份。清理工作会清楚bin目录。
[openwrt@localhost trunk]$ make clean  
除了清除生成的目录,还想清除交叉编译工具(以及工具链目录)
[openwrt@localhost trunk]$ make dirclean
清除所有相关的东西,包括下载的软件包,配置文件,feed内容等:(不建议使用)
[openwrt@localhost trunk]$ make distclean
对于更新feeds后出现的错误:
ERROR:please fix package/feeds/packages/mc/Makefile 等类似的问题,需要执行这条语句进行系统的清理


openwrt目录结构:
代码上来看有几个重要目录package, target, build_root, bin, dl.…
-- tool  和toolchain:是变异固件image需要的通用工具、编译器和C库文件。编译过程中将生成三个临时文件夹
---build_dir/host目录是建立工具链时的临时目录(与编译目标无关的临时工具的临时文件夹)
---build_dir/toolchain-*是特定体系的交叉编译的工具链的目录
---staging_dir/toolchain-* 则是工具链的安装位置
b)  target 目录包含特定平台的文件。其中linux目录下为各个平台ARCH对应的内核patches、配置文件等。imagebuilder目录则描述如何生成这个平台的固件。
–--target/linux/目录里面是各个平台(arch)的相关代码
---target/linux//config-3.10文件就是配置文件了
c )   dl目录是'download'的缩写, 在 编译前期,需要从网络下载的编译工具、目标、package都会放在这个目录下。如果我们需要更改这些源码包,只需要将更改好的源码包打包成相同的名字放在这个目录下,然后开始编 译即可。编译时,会将软件包解压到build_dir目录下。
d) 而在build_dir/目录下作为所有目标package编译的临时目录。
e)  package软件包目录:在openwrt中,基础的软件包目录为package,额外的软件包在feeds中,feeds中的软件包扩展了openwrt的基本功能。绝大部分编译出的软件都是ipk格式。
http://blog.csdn.net/mrwangwang/article/details/39006941

你可能感兴趣的:(openwrt)