【转】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. windows下mysql安装失败的一个解决案例

    操作系统:windows8.1,之前安装过mysql,这次安装在配置的最后一部执行“Apply security settings”的过程中弹出经典错误: Access denied for user ...

  2. bind函数的作用

    面向连接的网络应用程序分为客户端和服务器端.服务器端的执行流程一般为4步,客户端程序相对简单,一般需要两个步骤. 服务器端执行流程4步如下: (1)调用socket函数,建立一个套接字,该套接字用于接 ...

  3. Linux数据备份与恢复

    Linux数据备份及服务器重要数据类别分析 对 Linux 服务器来讲,当然最理想的就是把整块硬盘中的数据都备份,甚至连分区和文件系统都备份,这样如果硬盘损坏,那么我们可以直接把备份硬盘中的数据导入损 ...

  4. 前端学习笔记之ES6快速入门

    0x1 let和const let ES6新增了let命令,用于声明变量.其用法类似var,但是声明的变量只在let命令所在的代码块内有效. { let x = 10; var y = 20; } x ...

  5. CSS Border(边框)

    CSS Border(边框) 一.CSS 边框属性 CSS边框属性允许你指定一个元素边框的样式和颜色. 示例效果: 二.边框样式 边框样式属性指定要显示什么样的边界. border-style属性用来 ...

  6. JS等比例缩放图片,限定最大宽度和最大高度

    JS等比例缩放图片,限定最大宽度和最大高度 JavaScript //图片按比例缩放 var flag=false; function DrawImage(ImgD,iwidth,iheight){ ...

  7. HDFS的回收站 && 安全模式

    回收站机制 1). HDFS 的回收站机制由 core-site.xml 中 fs.trash.interval 属性(以分钟为单位)设置,默认是 0,表示未启用.注意:配置数值应该为1440,而配置 ...

  8. 移植gdb到海思3716板子的方法【转】

    本文转载自:https://blog.csdn.net/yuhengyue/article/details/78414403 一,移植方法 环境:ubuntu12.04 交叉编译工具链路径:/opt/ ...

  9. Redis中RedisTemplate和Redisson管道的使用

    当对Redis进行高频次的命令发送时,由于网络IO的原因,会耗去大量的时间.所以Redis提供了管道技术,就是将命令一次性批量的发送给Redis,从而减少IO. 一.Jedis对redis的管道进行操 ...

  10. IPTABLES拒绝某个IP某项服务,并记录到日志(rhel7实例)

    #iptables -I INPUT -p icmp -s 192.168.0.1 -j DROP                 \\在INPUT链中插入:如果检测到从192.168.0.1发过来的 ...