fedro开发环境编译openwrt

来源:互联网 发布:卫龙淘宝店不火 编辑:程序博客网 时间:2024/04/30 13:04
Fedora 12 编译 OpenWrt-BackFire
###编译的时候不能以root用户登录fedora
#安装svn工具(在root环境内):
su
#输入密码
yum install subversion
#然后装上各种依赖关系包:
yum install install gcc g++ binutils patch bzip2 flex bison gawk gcc-c++ make autoconf gettext texinfo unzip sharutils subversi-dev ncurses-devel ncurses-term zlib1g-dev patch unzip wget zlib-devel pkg-config libz-dev libc
    

#退出root环境
exit
#进入home目录,建立文件夹(XXX为目前帐号目录):
mkdir /home/XXX/openwrt
cd /home/XXX/openwrt

#使用svn命令行checkout出源代码(将屏幕信息输入download.log内,方便查看):
svn checkout svn://svn.openwrt.org/openwrt/branches/backfire | tee download.log 2>&1
#进入backfire文件夹:
cd backfire
#更新openwrt:
./scripts/feeds update -a | tee update.log 2>&1
#安装所有包:
./scripts/feeds install -a | tee install.01.log 2>&1
####################安装Luci中文语言包,可以不做##########################
vi feeds.conf.default  #加装Luci 中文语言包
#注释src-svn luci http://svn.luci.subsignal.org/luci/backfire/contrib/package这一行后改为:
src-svn luci svn://svnhost.cn/luci-chn/tags/0.9.0/contrib/package
./scripts/feeds update packages luci
./scripts/feeds install -a -p luci    #安装luci的web管理界面
########################################################################
make menuconfig
#####################################################
target system --> bcm63xx     #选择自己的硬件芯片
target image --> 取消 jffs2
luci --> language --> chinese   #如果有安装中文语言包
####################################################

make package/symlinks

#编译
#加 V=99 参数,让编译过程中打印相关信息
make V=99 | tee compile_v1.0.0.log 2>&1
 
编译好的文件在当前目录的bin文件夹下。
试着找找看
openwrt-RG100A_DB120-squashfs-cfe.bin
 
 
 
 
 

######################编译中的杂七杂八###############################

Feeds是OpenWrt环境所需要的软件包套件。最重要的feeds有:

‘packages’一些额外的基础路由器特性软件

‘LuCI’OpenWrt默认的GUI

‘Xwrt’另一种可选的GUI界面

需要能够连接互联网。

在下载之前可以通过查看’feeds.conf.default’文件,来检查哪些文件需要包含在环境中。

更新所有 packages包并安装,只有安装之后,在后面的make menuconfig时,才可以对相关配置进行勾选。

./scripts/feeds update packages luci
./scripts/feeds install -a -p luci    #安装luci的web管理界面

###./scripts/feeds install samba3           #安装samba3,在menus可以看到

Your display is too small to run Menuconfig!
It must be at least 19 lines by 80 columns.
屏幕太小,menuconfig没法运行
把终端最大化就行了
 
make elean 复位编译

#在make menuconfig之前,做一个压缩包,方便不用再次下载
tar -cjf backfire-yuan-8.09.2.tar.bz2 backfire
tar -cjf backfire-luci-8.09.2.tar.bz2 backfire
记得保存dl文件夹与里面的文件,如果想删除backfire文件夹,解压backfire-yuan-8.09.2.tar.bz2,把dl文件夹重新复制进去后,节省下次编译的文件下载时间
如果编译时下载文件的速度过慢,可以将终端的下载目录复制下来后直接用迅雷下载,然后再保证在dl文件内,Ctrl+C,然后再编译

编译过程使用的交叉编译,交叉编译生成的SDK以及image等文件的类型取决于开发环境、应用硬件、以及源码版本。所以要对自己的环境进行了解,才能进行正确的配置。

[openwrt@localhosttrunk]$ make menuconfig

[*]表示:这个包裹选中编译,并安装在升级版本中;

[M]表示:这个软件包选中编译,但并不安装在升级版本中。

在退出Menuconfig的时,会提示是否保存配置。

 

,配置目标系统(Target System)

Target System (Atheros AR71xx/AR93xx) —>

B,配置目标硬件(Target Profile)

Target Profile (…….MW4530R)  —>

C,配置编译出来的image,配置rootfs文件系统的格式这里选择ext4,rootfs文件系统的大小为(48M)。所以需要选squashfs和jffs2.

[plain] view plaincopy在CO<wbr>DE上查看代码片派生到我的代码片
  1. 这两种不同格式的固件区别在于,squashfs安装后,会占用一定的空间来存放系统的一些必要文件,这些文件都只是可读的,这些文件的作用是帮助恢复系统,当OpenWrt崩溃时,可以基于这些文件,使用firstboot脚本重建初始系统,而jffs2则不会存储这样的文件,好处在于节省了空间。一般,我们都使用squashfs格式的固件,方便恢复系统到初始状态  

Target Images  —>

[] ramdisk  —>

***Root filesystem archives ***

[] cpio.gz

[*]tar.gz

***Root filesystem images ***

[*]ext4

[] jffs2

[] squashfs

D,选择编译交叉编译器,还有开发SDK

[*] Build the OpenWrt Image Builder

[*] Build the OpenWrt SDK

E,配置无线网卡,这个不知道选那个,保持原样

Kernel modules  —>

WirelessDrivers  —>

F, LucI系统快速配置接口

LuCI  —>

4. Themes  —>

-*-luci-theme-base…………………………. Common base for all

-*-luci-theme-bootstrap……………………… Bootstrap Theme

<*>luci-theme-freifunk-bno……………….. Freifunk Berlin Nordost Theme

<*>luci-theme-freifunk-generic………………….. Freifunk Generic Theme

<*>luci-theme-openwrt……………………………………. OpenWrt.org

5. Translations  —>

<*>luci-i18n-chinese………………….. Chinese (by Chinese Translators)

-*-luci-i18n-english………………………………………… English


[plain] view plaincopy在CO<wbr>DE上查看代码片派生到我的代码片
  1. ---------------------------------------------------------------------  
  2.      Target System (Atheros AR7xxx/AR9xxx)  --->                       
  3.         无线网卡型号  
  4.      Subtarget (Generic)  --->                                         
  5.         选择要生成的目标类型,一般选用Generic就可以。  
  6.      Target Profile (TP-LINK TL-WDR3500/3600/4300/4310/MW4350R)  --->  
  7.         生成目标的设备框架  
  8.      Target Images  --->                                               
  9.         生成目标镜像格式,选以下两个  
  10. [*] tar.gz                            
  11.      *** Root filesystem images ***    
  12.  [ ] ext4                              
  13.  [ ] jffs2                             
  14.  [*] squashfs                          
  15.      Global build settings  --->                                       
  16.         目前选的是所有配置  
  17.  [ ] Advanced configuration options (for developers)  --->             
  18.     开发选项,没看过  
  19.  [*] Build the OpenWrt Image Builder                                   
  20.     需要生成目标镜像  
  21.  [*] Build the OpenWrt SDK                                             
  22.     需要生成sdk包  
  23.  [ ] Build the OpenWrt based Toolchain                                 
  24.     建立交叉编译工具,不需要  
  25.  [ ] Image configuration  --->                                         
  26.     不需要做什么的  
  27.       
  28.      Package features  --->                                            
  29.         就是一个选项  
  30.      Base system  --->                                                 
  31.         系统的基本配置,这个和原来的一些配置相同功能。  
  32.      Administration  --->                                              
  33.         不知道是做什么 的  
  34.      Boot Loaders  --->                                                
  35.         不需要配置  
  36.      Development  --->                                                 
  37.         开发工具配置,不需要  
  38.      Emulators  --->                                                   
  39.         无配置  
  40.      Firmware  --->                                                    
  41.         无配置  
  42.      Kernel modules  --->                                              
  43.      Languages  --->                                                   
  44.         支持的开发语言,不需要  
  45.      Libraries  --->                                                   
  46.         库文件,不需要。一般都有自己的  
  47.      LuCI  --->                                                        
  48.         Web服务  
  49.      Mail  --->                                                        
  50.         不需要  
  51.      Multimedia  --->                                                  
  52.         多媒体,不需要  
  53.      Network  --->                                                     
  54.         网络工具  
  55.      Sound  --->                                                       
  56.         声音,不需要  
  57.      Utilities  --->                                                   
  58.         实用工具  
  59.      Video Streaming  --->                                             
  60. Xorg  --->    


6、  编译

(1)一般情况,使用一个简单的命令:

[openwrt@localhost trunk]$ make V=s

(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软件包):

make package/cups/compile V=99

只编译某个模块

make package/qos/clean

make package/qos/compile

make package/qos/install

 

只清除某个模块

make package/qos/clean

 

(5)如果特殊原因需要分析编译报错信息:这个不保证很准确,因为grep -i error只过滤显示带有error的行,但是光有这个是看不出问题的。

[openwrt@localhost trunk]$ make V=99 2>&1 |teebuild.log |grep -i error

说明:将编译的所有输出信息保存在build.log中,将error信息打印在屏幕上。

(6)一个复杂指令的应用

[openwrt@localhost trunk]$ ionice -c 3 nice -n 20 make -j 2V=99 CONFIG_DEBUG_SECTION_MISMATCH=y 2>&1 \|tee build.log |egrep -i'(warn|error)'

说明:将编译的所有输出信息保存在build.log中,将error和warning信息打印在屏幕上(这个功能还可以这样实现 make –j V=s>./build.log)。编译过程使用双核CPU,占用后台资源。

 

7、  生成镜像(Image)位置

新生成的镜像会默认放在新建的一个bin目录下。

例如:/bin/ ar71xx /packages

将编译好的镜像做个备份,例如备份到/目录下:

[openwrt@localhosttrunk]$ cp bin /

编译完成后, bin/ar71xx生成文件:

openwrt-ar71xx-generic-mw4530r-v1-squashfs-factory.bin

openwrt-ar71xx-generic-mw4530r-v1-squashfs-sysupgrade.bin

这两个文件的区别是,factory多了一些验证的东西,用于在原厂固件的基础上进行升级,如果已经是OpenWrt,直接使用第二个文件即可。并且,在原厂固件的基础上进行升级时,首先使用factory文件,然后需要再次使用sysupgrade文件,选择不保留原来配置进行升级。

8、  生成的交叉编译工具SDK包

Trunk/bin/ar71xx/OpenWrt-SDK-ar71xx-for-redhat-i686-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2

这个就是定制编译好的OpenWRT SDK交叉编译环境。用这个来进行OpenWrt软件包的开发

 9、  清理工作

建议现在清理编译产生的文件,以免下次编译时造成冲突,(文件如果存在的话,将不会被替换),执行makeclean

注意:在执行clean命令,确保已经将编译好的image进行了备份。清理工作会清楚bin目录。

[openwrt@localhosttrunk]$ make clean  

除了清除生成的目录,还想清除交叉编译工具(以及工具链目录)

[openwrt@localhosttrunk]$ make dirclean

清除所有相关的东西,包括下载的软件包,配置文件,feed内容等:(不建议使用)

[openwrt@localhosttrunk]$ make distclean

对于更新feeds后出现的错误:

ERROR:pleasefix package/feeds/packages/mc/Makefile 等类似的问题,需要执行这条语句进行系统的清理

 

10、  安装OpenWrt

(1)非web页面 升级方式。

使用SCP、wget呀tftp把sysupgrade固件拷贝到某一目录下,如/tmp之下

A.更新openwrt固件(从第版本升级到高版本):

cd/tmp

wgetftp://192.168.1.2/openwrt-ar71xx-generic-mw4530r-v1-squashfs-factory.bin

sysupgrade-i/tmp/*.bin

 

B..在openwrt下恢复固件(或使用AUTOTTL恢复固件):

cd/tmp

wgetftp://192.168.1.2/openwrt-ar71xx-generic-mw4530r-v1-squashfs-factory.bin

mtd-r write *.bin firmware

 

(2) web页面 升级方式。

使用界面进行刷新非常方便,只做简单介绍。无论是原厂界面还是OpenWrt的操作界面,首先选择进入固件升级页,然后选择对应的固件,上传确认即可。需要注意的是,如果是原厂固件,需要先刷factory,此时所得到的就已经是OpenWrt了,然后在该界面上选择sysupgrade文件,进行升级即可。

升级结束后,使用telnet登入,添加密码以开启SSH服务(dropbear开始运行),命令依次如下:

telnet192.168.1.1

passwdadmin

passwdadmin

即可为root用户添加密码admin。

 

11、 如何在OpenWRT环境下做开发

OpenWrt上面应用程序开发有两种方式,一种是利用OpenWrt SDK,一种是利用OpenWrt源码。其实过程都差不是很多。源码会生成bin,SDK只生成ipk包。

在编译根目录下会有一个dl的目录,这个目录其实是“download”的简写,在编译前期,需要从网络下载的数据包都会放在这个目录下,这些软件包的一个特点就是,会自动安装在所编译的固件中,也就是我们make menuconfig的时候,为固件配置的一些软件包。如果我们需要更改这些源码包,只需要将更改好的源码包打包成相同的名字放在这个目录下,然后开始编译即可。编译时,会将软件包解压到build_dir目录下。

Makefile:83: *** missing separator. Stop.注意makefil文件的格式(tab)。


(1)、 利用OpenWrt源码开发

OpenWrt系统开发(四)应用程序开发

OpenWrt上面应用程序开发有两种方式,一种是利用OpenWrt SDK,一种是利用OpenWrt源码。这里主要介绍利用OpenWrt源码,进行开发应用程序,制作成ipk软件可以安装。

1,进入package目录,创建软件目录

#cd   /home/pillar/openwrt/trunk/package

#mkdir test

2,进入test目录,创建Makefile文件和代码路径

[plain] view plaincopy在CO<wbr>DE上查看代码片派生到我的代码片
  1. ##############################################  
  2. # OpenWrtMakefile for test program  
  3. #  
  4. #  
  5. # Most ofthe variables used here are defined in  
  6. # theinclude directives below. We just need to  
  7. # specifya basic description of the package,  
  8. # whereto build our program, where to find  
  9. # thesource files, and where to install the  
  10. #compiled program on the router.  
  11. #  
  12. # Be verycareful of spacing in this file.  
  13. # Indentsshould be tabs, not spaces, and  
  14. # thereshould be no trailing whitespace in  
  15. # linesthat are not commented.  
  16. #  
  17. ##############################################  
  18. include $(TOPDIR)/rules.mk  
  19. # Nameand release number of this package  
  20. PKG_NAME:=test  
  21. PKG_RELEASE:=1  
  22.    
  23.    
  24. # Thisspecifies the directory where we're going to build the program.  
  25. # Theroot build directory, $(BUILD_DIR), is by default the build_mipsel  
  26. #directory in your OpenWrt SDK directory  
  27. PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)  
  28.    
  29.    
  30. include $(INCLUDE_DIR)/package.mk  
  31.    
  32.    
  33.    
  34. # Specifypackage information for this program.  
  35. # Thevariables defined here should be self explanatory.  
  36. # If youare running Kamikaze, delete the DESCRIPTION  
  37. #variable below and uncomment the Kamikaze define  
  38. # directivefor the description below  
  39. define Package/test  
  40.     #在Base system显示模块名  
  41.     SECTION:=test  
  42.     #这个模块要加在Base system下  
  43.     CATEGORY:=Base system  
  44.     #这个模块提示信息  
  45.     TITLE:=Helloworld-- prints a snarky message  
  46. endef  
  47.    
  48.    
  49.    
  50. # Specifywhat needs to be done to prepare for building the package.  
  51. # In ourcase, we need to copy the source files to the build directory.  
  52. # This isNOT the default.  The default uses thePKG_SOURCE_URL and the  
  53. #PKG_SOURCE which is not defined here to download the source from the web.  
  54. # Inorder to just build a simple program that we have just written, it is  
  55. # mucheasier to do it this way.  
  56. define Build/Prepare  
  57.     mkdir -p $(PKG_BUILD_DIR)  
  58.     $(CP) ./src/* $(PKG_BUILD_DIR)/  
  59. endef  
  60.    
  61.    
  62. # We donot need to define Build/Configure or Build/Compile directives  
  63. # Thedefaults are appropriate for compiling a simple program such as this one  
  64.    
  65.    
  66. # Specifywhere and how to install the program. Since we only have one file,  
  67. # thetest executable, install it by copying it to the /bin directory on  
  68. # therouter. The $(1) variable represents the root directory on the router running  
  69. #OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install  
  70. #directory if it does not already exist. Likewise $(INSTALL_BIN) contains the  
  71. # commandto copy the binary file from its current location (in our case the build  
  72. #directory) to the install directory.  
  73. define Package/test/install  
  74.     #生成可执行文件目录  
  75.     $(INSTALL_DIR) $(1)/sbin  
  76.     #echo $(INSTALL_BIN)  
  77.     #echo $(PKG_BUILD_DIR)  
  78.     #echo $1  
  79.     #编译目标文件到安装目录  
  80.     $(INSTALL_BIN) $(PKG_BUILD_DIR)/test $(1)/sbin/  
  81. endef  
  82.    
  83.    
  84. # Thisline executes the necessary commands to compile our program.  
  85. # Theabove define directives specify all the information needed, but this  
  86. # linecalls BuildPackage which in turn actually uses this information to  
  87. # build apackage.  
  88. $(eval $(call BuildPackage,test))  


#mkdir  src

3.进入src目录,创建相关源文件

cd src

[objc] view plaincopy在CO<wbr>DE上查看代码片派生到我的代码片
  1. #include <stdio.h>  
  2. #include <unistd.h>  
  3. int main(void)  
  4. {  
  5.      printf("Hell! O' world, why won't my code compile?\n\n");  
  6.      return 0;  
  7. }  

[cpp] view plaincopy在CO<wbr>DE上查看代码片派生到我的代码片
  1. #OCTEON_ROOT=$(PWD)/src/  
  2. #CC为交叉编译GCC路径,以后可以跟据情况修改  
  3. #CC=~/openwrt/main/staging_dir/toolchain-mips64_gcc-4.4.1_eglibc-2.10.1/usr/bin/mips64-openwrt-linux-gnu-gcc  
  4. CC=/workPorjectCode/openwrt/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc  
  5. #CFLAGS=-mips64r2 -mabi=64 -marc  
  6.   
  7. SRC:=test.c  
  8. test: $(SRC)  
  9.     $(CC) $(SRC) -o test  
  10.     # remove object files and executable when user executes "make clean"  
  11. clean:  
  12.     rm *.o  

4.回到主路径 /home/pillar/openwrt/trunk /,编译选项配置保存并编译

make menuconfig

  Base system —>

   test

选项设置为M,保存退出

然后编译该模块(必须在trunk下make):

make package/test/compile

到目录为至,已经可以使用scp直接把编译好的程序上转到设备运行了。

trunk\build_dir\target-mips_34kc_uClibc-0.9.33.2

5,更新package

make package/test/install

makepackage/index

生成安装包路径:trunk\bin\ar71xx\packages


(2)、 利用OpenWrt SDK开发

自己在dl里面创建自己的软件包,然后更改相关的配置文件,让openwrt可以识别这个文件包。

对于自己新建的package,而这个package又不需要随固件一起安装,换句话说,就是可以当做一个可选软件包的话。我们可以利用我们的SDK环境来单独编译,编译后会生成一个ipk的文件包。然后利用 opkg install xxx.ipk 来安装这个软件。

[plain] view plaincopy在CO<wbr>DE上查看代码片派生到我的代码片
  1. (1)将OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2解压  
  2. tar –xvf OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2  
  3. (2)进入SDK  
  4. cd OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1  
  5. 可以看到里面的目录结构跟我们之前source的目录结构基本相同,所需要编译的软件包,需要放置在package目录下  
  6. (3)在package目录下创建helloworld目录  
  7. helloworld目录  
  8. helloworld/src目录  
  9.   
  10. (4)拷贝上个测试test 目录中的文件到 helloworld目录文件中相应的位置,并且src/makefile内容做想应该的修改。  
  11. 主要是CC的路径  
  12. (5)返回到SDK的根目录  
  13. 执行make进行编译  
  14. 编译过程会在build_dir目录下完成,在目录build_dir\target-mips_34kc_uClibc-0.9.33.2\test\ipkg-ar71xx中生成可执行文件  
  15. 编译结果*.ipk会放在 bin/[yourtarget]/package目录下  
  16. (8)上传helloworld_1_bcm47xx.ipk  
  17. 使用sftp软件上传helloworld_1_bcm47xx.ipk至路由器  
  18. 执行 opkg install helloworld_1_bcm47xx.ipk  
  19. 输入hello然后按Tab键,发现openwrt中已经有helloworld可执行命令。  
  20. 执行 helloworld 查看程序的效果。  
  21. Hell! O' world, why won't my code compile?  


12、 OpenWRT目录结构说明

 

? tools

? toolchain

? package

? target

tools和toolchain通常是用作固化内核,编译和c库的工具,编译的结果会产生三个新的目录:

build_dir/host ,这是一个临时用来建立target工具;

build_dir /toolchain-<arch>*这是用来建立特殊结构的toolchain;

staging_dir/toolchain-<arch>*toolchain安装的目录;

如果你不需要增加新版本的原件就不需要对toolchain目录进行修改。

Bin     目录存放生成的ipk和bin包

Dl      目录存放下载的源码包,会是build_dir目录下编译

Feeds       目录为feeds.conf.default脚本生成,为系统第三方应用程序管理包**

Logs        目录为编译出错时生成错误信息目录

Package     目录为部分一些额外的基础路由器特性软件

       base-files\files目录为根文件系统配置目录

Scripts     **





 
0 0