OpenWrt mw4530r 开发环境搭建

1、  安装环境

Linux系统,需安装如下依赖包:

yum install binutils bzip2 gawk gcc gcc-c++ gettext makencurses-devel patch unzip wget zlib-devel git

这个不明白,直接安装就可以了。安装完之后要是还有问题就需要根据看出错信息自己下载依赖包了。

2、  下载OpenWRT源码

 我的工作目录:/workPorjectCode/openwrt


svn cosvn://svn.openwrt.org/openwrt/branches/backfire (开发版本,不稳定,不建议下载,但在这个版本中有MW4530R配置项。还是下载个使用)

svn cosvn://svn.openwrt.org/openwrt/branches/backfire(目前稳定版本,建议,但是这个版本配置项中少了好多支持。)

 

3、  检查配置环境

必须使用非root用户进行操作,添加一个普通用户。(注意:如果使用root进行操作的话,会提示检查失败:Checking 'non-root'...failed.)

修改可在root用户下编译

修改 include/prereq-build.m 文件第15行为:

#        ["$$(shell whoami)" != "root" ]

 

4、  下载feeds

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

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

‘LuCI’OpenWrt默认的GUI

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

需要能够连接互联网。

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

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

./scripts/feeds update -a

./scripts/feeds install -a

 5、  进行配置

编译过程使用的交叉编译,交叉编译生成的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.

这两种不同格式的固件区别在于,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


---------------------------------------------------------------------
     Target System (Atheros AR7xxx/AR9xxx)  --->                     
		无线网卡型号
     Subtarget (Generic)  --->                                       
		选择要生成的目标类型,一般选用Generic就可以。
     Target Profile (TP-LINK TL-WDR3500/3600/4300/4310/MW4350R)  --->
		生成目标的设备框架
     Target Images  --->                                             
		生成目标镜像格式,选以下两个
[*] tar.gz                          
     *** Root filesystem images ***  
 [ ] ext4                            
 [ ] jffs2                           
 [*] squashfs                        
     Global build settings  --->                                     
		目前选的是所有配置
 [ ] Advanced configuration options (for developers)  --->           
	开发选项,没看过
 [*] Build the OpenWrt Image Builder                                 
	需要生成目标镜像
 [*] Build the OpenWrt SDK                                           
	需要生成sdk包
 [ ] Build the OpenWrt based Toolchain                               
	建立交叉编译工具,不需要
 [ ] Image configuration  --->                                       
	不需要做什么的
	
     Package features  --->                                          
		就是一个选项
     Base system  --->                                               
		系统的基本配置,这个和原来的一些配置相同功能。
     Administration  --->                                            
		不知道是做什么 的
     Boot Loaders  --->                                              
		不需要配置
     Development  --->                                               
		开发工具配置,不需要
     Emulators  --->                                                 
		无配置
     Firmware  --->                                                  
		无配置
     Kernel modules  --->                                            
     Languages  --->                                                 
		支持的开发语言,不需要
     Libraries  --->                                                 
		库文件,不需要。一般都有自己的
     LuCI  --->                                                      
		Web服务
     Mail  --->                                                      
		不需要
     Multimedia  --->                                                
		多媒体,不需要
     Network  --->                                                   
		网络工具
     Sound  --->                                                     
		声音,不需要
     Utilities  --->                                                 
		实用工具
     Video Streaming  --->                                           
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

如果出现headware  ID 匹配错误可以加参数 -F ,之后再升级openwrt-ar71xx-generic-mw4530r-v1-squashfs-sysupgrade.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文件和代码路径

##############################################
# OpenWrtMakefile for test program
#
#
# Most ofthe variables used here are defined in
# theinclude directives below. We just need to
# specifya basic description of the package,
# whereto build our program, where to find
# thesource files, and where to install the
#compiled program on the router.
#
# Be verycareful of spacing in this file.
# Indentsshould be tabs, not spaces, and
# thereshould be no trailing whitespace in
# linesthat are not commented.
#
##############################################
include $(TOPDIR)/rules.mk
# Nameand release number of this package
PKG_NAME:=test
PKG_RELEASE:=1
 
 
# Thisspecifies the directory where we're going to build the program.
# Theroot build directory, $(BUILD_DIR), is by default the build_mipsel
#directory in your OpenWrt SDK directory
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)
 
 
include $(INCLUDE_DIR)/package.mk
 
 
 
# Specifypackage information for this program.
# Thevariables defined here should be self explanatory.
# If youare running Kamikaze, delete the DESCRIPTION
#variable below and uncomment the Kamikaze define
# directivefor the description below
define Package/test
	#在Base system显示模块名
	SECTION:=test
	#这个模块要加在Base system下
	CATEGORY:=Base system
	#这个模块提示信息
	TITLE:=Helloworld-- prints a snarky message
endef
 
 
 
# Specifywhat needs to be done to prepare for building the package.
# In ourcase, we need to copy the source files to the build directory.
# This isNOT the default.  The default uses thePKG_SOURCE_URL and the
#PKG_SOURCE which is not defined here to download the source from the web.
# Inorder to just build a simple program that we have just written, it is
# mucheasier to do it this way.
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
 
 
# We donot need to define Build/Configure or Build/Compile directives
# Thedefaults are appropriate for compiling a simple program such as this one
 
 
# Specifywhere and how to install the program. Since we only have one file,
# thetest executable, install it by copying it to the /bin directory on
# therouter. The $(1) variable represents the root directory on the router running
#OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
#directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
# commandto copy the binary file from its current location (in our case the build
#directory) to the install directory.
define Package/test/install
	#生成可执行文件目录
	$(INSTALL_DIR) $(1)/sbin
	#echo $(INSTALL_BIN)
	#echo $(PKG_BUILD_DIR)
	#echo $1
	#编译目标文件到安装目录
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/test $(1)/sbin/
endef
 
 
# Thisline executes the necessary commands to compile our program.
# Theabove define directives specify all the information needed, but this
# linecalls BuildPackage which in turn actually uses this information to
# build apackage.
$(eval $(call BuildPackage,test))


#mkdir  src

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

cd src

#include <stdio.h>
#include <unistd.h>
int main(void)
{
     printf("Hell! O' world, why won't my code compile?\n\n");
     return 0;
}

#OCTEON_ROOT=$(PWD)/src/
#CC为交叉编译GCC路径,以后可以跟据情况修改
#CC=~/openwrt/main/staging_dir/toolchain-mips64_gcc-4.4.1_eglibc-2.10.1/usr/bin/mips64-openwrt-linux-gnu-gcc
CC=/workPorjectCode/openwrt/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc
#CFLAGS=-mips64r2 -mabi=64 -marc

SRC:=test.c
test: $(SRC)
	$(CC) $(SRC) -o test
	# remove object files and executable when user executes "make clean"
clean:
	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 来安装这个软件。

(1)将OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2解压
tar –xvf OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2
(2)进入SDK
cd OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1
可以看到里面的目录结构跟我们之前source的目录结构基本相同,所需要编译的软件包,需要放置在package目录下
(3)在package目录下创建helloworld目录
helloworld目录
helloworld/src目录

(4)拷贝上个测试test 目录中的文件到 helloworld目录文件中相应的位置,并且src/makefile内容做想应该的修改。
主要是CC的路径
(5)返回到SDK的根目录
执行make进行编译
编译过程会在build_dir目录下完成,在目录build_dir\target-mips_34kc_uClibc-0.9.33.2\test\ipkg-ar71xx中生成可执行文件
编译结果*.ipk会放在 bin/[yourtarget]/package目录下
(8)上传helloworld_1_bcm47xx.ipk
使用sftp软件上传helloworld_1_bcm47xx.ipk至路由器
执行 opkg install helloworld_1_bcm47xx.ipk
输入hello然后按Tab键,发现openwrt中已经有helloworld可执行命令。
执行 helloworld 查看程序的效果。
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
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值