【转】OpenWRT开发自定义应用方法

转自:http://blog.csdn.net/rudyn/article/details/38616783

  OpenWRT编译成功完成后,所有的产品都会放在编译根目录下的bin/{TARGET}/,例如:我所编译的产物都放在./bin/ar74xx/下,其中有一个packages文件夹:里面包含了我们在配置文件里设定的所有编译好的软件包。默认情况下,会有默认选择的软件包。需要主要的是,编译完成后,一定要将编译好的bin目录进行备份。

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

  新建和编译自己的packages:

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

cd package
mkdir Helloworld ; cd Helloworld
mkdir src
touch src/Makefile /* Helloworld 编译Makefile */
touch ./Makefile /*建立顶层Makefile,这个Makefile文件是OpenWRT读的*/

  Helloworld.c程序:

/****************
* Helloworld.c
*****************/ #include <stdio.h>
#include <unistd.h>
int main(void)
{
printf("Hello world\n");
return 0;
}

  编辑Helloworld的编译Makefile:

# build helloworld executable when user executes "make"  

helloworld: helloworld.o
$(CC) $(LDFLAGS) helloworld.o -o helloworld helloworld.o: helloworld.c
$(CC) $(CFLAGS) -c helloworld.c # remove object files and executable when user executes "make clean"
clean:
rm *.o helloworld

  编写模块编译Makefile:

Makefile文件模板内容如下:
##############################################
# OpenWrt Makefile for helloworld program
#
#
# Most of the variables used here are defined in
# the include directives below. We just need to
# specify a basic description of the package,
# where to build our program, where to find
# the source files, and where to install the
# compiled program on the router.
#
# Be very careful of spacing in this file.
# Indents should be tabs, not spaces, and
# there should be no trailing whitespace in
# lines that are not commented.
#
############################################## include $(TOPDIR)/rules.mk # Name and release number of this package
PKG_NAME:=helloworld
PKG_RELEASE:=1 # This specifies the directory where we're going to build the program.
# The root 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 # Specify package information for this program.
# The variables defined here should be self explanatory.
# If you are running Kamikaze, delete the DESCRIPTION
# variable below and uncomment the Kamikaze define
# directive for the description below
define Package/helloworld
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Helloworld -- prints a snarky message
endef # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
define Package/helloworld/description
If you can't figure out what this program does, you're probably
brain-dead and need immediate medical attention.
endef # Specify what needs to be done to prepare for building the package.
# In our case, we need to copy the source files to the build directory.
# This is NOT the default. The default uses the PKG_SOURCE_URL and the
# PKG_SOURCE which is not defined here to download the source from the web.
# In order to just build a simple program that we have just written, it is
# much easier to do it this way.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef # We do not need to define Build/Configure or Build/Compile directives
# The defaults are appropriate for compiling a simple program such as this one # Specify where and how to install the program. Since we only have one file,
# the helloworld executable, install it by copying it to the /bin directory on
# the router. 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
# command to copy the binary file from its current location (in our case the build
# directory) to the install directory.
define Package/helloworld/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef # This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,helloworld))

  

返回目录最顶层,执行make menuconfig,在utils中选中刚加的模块名(这里是根据sections中定义的),保存.config。

执行make.

如果要单独编译模块:

makepackage/helloworld/compile
make package/helloworld/install

  

编译结果会放在bin/{TARGET}/package目录下:helloworld*.ipk

利用tftp将ipk文件上传到板子里面,用opkg install 命令加载模块,加载成功后执行helloworld,这时就是执行之前编写的helloworld程序

参考资料:http://wenku.baidu.com/view/31a903befd0a79563c1e7275.html

【转】OpenWRT开发自定义应用方法的更多相关文章

  1. spring boot集成mybatis-plus插件进行自定义sql方法开发时报nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    spring boot集成mybatis-plus插件进行自定义sql方法开发时报nested exception is org.apache.ibatis.binding.BindingExcept ...

  2. [转]jquery开发自定义的插件总结

    本文转自:http://www.cnblogs.com/Jimmy009/archive/2013/01/17/jquery%E6%8F%92%E4%BB%B6.html 前几天在玩jquery,今天 ...

  3. BizTalk开发系列(二十二) 开发自定义Map Functoid

    尽管 BizTalk Server 提供许多Functoid以支持一系列不同的操作,但仍可能会遇到需要其他方法的情况.<BizTalk开发系列 Map扩展开发>介绍了通过使用自定义 XSL ...

  4. 11Mybatis_mybatis开发Dao的方法

    在介绍开发Dao的方法之前先介绍下SqlSession. 1.先介绍一下SqlSessionFactoryBuilder:通过SqlSessionFactoryBuilder创建会话工厂SqlSess ...

  5. openwrt开发

    之前写过一篇日志,是关于如何搭建自己的OpenWRT开发环境.经过最近一段时间的开发学习和实践,对OpenWRT环境的开发有了一定的了解.在这里将我的开发心得做个整理. 1.搭建开发环境 首先,我们需 ...

  6. 开发自定义View

    当开发者打算派生自己的UI组件时,首先定义一个继承View基类的子类,然后重写View类的一个或多个方法,通常可以被用户重写的方法如下:构造器:重写构造器是定制View的最基本方法,当Java代码创建 ...

  7. JSP进阶 之 SimpleTagSupport 开发自定义标签

    绝大部分 Java 领域的 MVC 框架,例如 Struts.Spring MVC.JSF 等,主要由两部分组成:控制器组件和视图组件.其中视图组件主要由大量功能丰富的标签库充当.对于大部分开发者而言 ...

  8. 在 Visual C++ 中开发自定义的绘图控件

    本文讨论的重点介于两者 之间 — 公共控件赋予您想要的大部分功能,但控件的外观并不是您想要的.例如,列表视图控件提供在许多视图风格中显示数据列表的方式 — 小图标.大图标.列表和详细列表(报告).然而 ...

  9. C++ 开发OCX 的方法和注意事项

    C++ 开发OCX 的方法和注意事项 前言 ActiveX控件是一种实现了一系列特定接口而使其在使用和外观上更象一个控件的COM组件.ActiveX控件这种技术涉及到了几乎所有的COM和OLE的技术精 ...

随机推荐

  1. SQL Server怎么备份数据库

    1.打开 2.选择需要备份的数据库,右键 Tasks 3.Tasks的下垃菜单 4.add选备份路径,添加名字 5.OK

  2. 优化netbeans启动速度

    NetBeans优化的目的是提高NetBeans的启动速度和运行速度.下面介绍的NetBeans优化技巧是在版本6.0beta2上的优化.经过实验,大大提高了NetBeans的启动速度. 1,修改英文 ...

  3. NodeJS中间层搭建

    前言 最近碰了个壁,公司开发的一个新项目里我大胆地提出要前后端完全分离,用JavaScript模板引擎.ajax.路由等技术替代繁琐的前后端混合的业务逻辑,项目进行到一半前辈提出来仅仅靠前端的力量无法 ...

  4. javascript 设置元素滚动大小

    3. 滚动大小 最后要介绍的是滚动大小(scroll dimension),指的是包含滚动内容的元素的大小. 有些元素(例如 元素),即使没有执行任何代码也能自动地添加滚动条:但另外一些元素,则需要通 ...

  5. yum安装memchache

    转载地址:http://www.cnblogs.com/jiunadianshi/articles/2001334.html 标准的CentOS5软件仓库里面是没有memcache相应的包的,所以,我 ...

  6. hive + hadoop 环境搭建

    机器规划: 主机 ip 进程 hadoop1 10.183.225.158 hive server hadoop2 10.183.225.166 hive client 前置条建: kerberos部 ...

  7. Idea 切换git账号

    重置一下账号设置,再次执行拉取或推送会提示重新输入账号密码 进入项目根目录执行:git config --system --unset credential.helper

  8. apache——(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : AH00072: make_sock: could not bind to address [::]:443

    问题:命令行运行httpd.exe时报错 (OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次.  : AH00072: make_sock: could not bind t ...

  9. 关于Visual Studio 2010自动添加头部注释信息

    作为一个万年潜水党,不关这一篇文章技术含量如何,也算是一个好的开始吧.   在日常的开发中我们经常需要为类库添加注释和版权等信息,这样我们就需要每次去拷贝粘贴同样的文字,为了减少这种重复性的工作,我们 ...

  10. zpar使用方法之Chinese Word Segmentation

    第一步在这里: http://people.sutd.edu.sg/~yue_zhang/doc/doc/qs.html 你可以找到这句话, 所以在命令行中分别敲入 make zpar make zp ...