openWrt软件开发教程1(交叉编译和ipk包生成)

2023-10-19 14:49

本文主要是介绍openWrt软件开发教程1(交叉编译和ipk包生成),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、交叉编译

1.      建立交叉编译环境

在使用buildroot对openwrt进行编译之后,在buildroot目录下会有一个名叫staging_dir的目录,针对当前平台的toolchain都在这个目录下。

1.1增加toolchain的目录到PATH目录中

Vim ~/.bash_profile

添加代码:

# add openWrt cross-compile path

PATH=$PATH:/home/jason/openWrt/trunk/staging_dir/toolchain-i386_gcc-4.6-linaro_uClibc-0.9.33.2/bin/

1.2   增加staging_dir的目录到toolchain PATH

Vim ~/.bash_profile

添加代码:

STAGING_DIR=/home/jason/openWrt/trunk/staging_dir/

exportSTAGING_DIR

1.3 保存退出

2.      编译

2.1 configure

 ./configure--target=i486-openwrt-linux-uclibc

2.2 make

make CC=i486-openwrt-linux-uclibc-gcc LD=i486-openwrt-linux-uclibc-ld

二、编译ipk包

1.      编译SDK

在buildroot目录下make menuconfig,然后选中SDK进行编译


选中后,进行make编译。

编译完成后,对应生成的SDK会出现类似这样的目录:“openWrt/trunk/bin/x86”,进入SDK后,打印当前工作路径如下:

“/openWrt/trunk/bin/x86/OpenWrt-SDK-x86-for-redhat-x86_64-gcc-4.6-linaro_uClibc-0.9.33.2”

2.      创建工程

在sdk的package目录下创建我们的工程“helloworld”:

新建目录中包含src目录,这个目录就是我们的源代码所在地,另外一个非常重要的文件Makefile,这个Makefile的组成与GNU的有所不同,有点类似于制作rpm包时的spec文件。到后面会有更详细的介绍。以下是具体文件的位置:


其中helloworld.c的内容如下:


Src目录下的Makefile文件内容如下:

最后是helloworld目录下的Makefile的内容:

##############################################

# OpenWrtMakefile for helloworld 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:=helloworld

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

definePackage/helloworld

SECTION:=utils

CATEGORY:=Utilities

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.

defineBuild/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,

# thehelloworld 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.

definePackage/helloworld/install

$(INSTALL_DIR) $(1)/bin

$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld$(1)/bin/

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,helloworld))

这个Makefile的语法规则还是参考官网吧:

http://wiki.openwrt.org/doc/devel/packages

3.      编译

将当前目录返回到SDK:

执行make进行编译。如果一切顺利,最后的结果会保存在SDK/bin/x86/packages目录下,名称为helloword_1_x86.ipk。

4.      安装最新编译的包

通过scp将该包拷贝到目的机器上,通过opkg包管理工具进行安装:

Opkg install helloworld_1_x86.ipk

一切顺利,包安装成功,在当前路径下执行helloworld查看程序执行结果。


这篇关于openWrt软件开发教程1(交叉编译和ipk包生成)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/240500

相关文章

python生成随机唯一id的几种实现方法

《python生成随机唯一id的几种实现方法》在Python中生成随机唯一ID有多种方法,根据不同的需求场景可以选择最适合的方案,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习... 目录方法 1:使用 UUID 模块(推荐)方法 2:使用 Secrets 模块(安全敏感场景)方法

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

Java JDK1.8 安装和环境配置教程详解

《JavaJDK1.8安装和环境配置教程详解》文章简要介绍了JDK1.8的安装流程,包括官网下载对应系统版本、安装时选择非系统盘路径、配置JAVA_HOME、CLASSPATH和Path环境变量,... 目录1.下载JDK2.安装JDK3.配置环境变量4.检验JDK官网下载地址:Java Downloads

java使用protobuf-maven-plugin的插件编译proto文件详解

《java使用protobuf-maven-plugin的插件编译proto文件详解》:本文主要介绍java使用protobuf-maven-plugin的插件编译proto文件,具有很好的参考价... 目录protobuf文件作为数据传输和存储的协议主要介绍在Java使用maven编译proto文件的插件

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

Visual Studio 2022 编译C++20代码的图文步骤

《VisualStudio2022编译C++20代码的图文步骤》在VisualStudio中启用C++20import功能,需设置语言标准为ISOC++20,开启扫描源查找模块依赖及实验性标... 默认创建Visual Studio桌面控制台项目代码包含C++20的import方法。右键项目的属性:

深度解析Spring AOP @Aspect 原理、实战与最佳实践教程

《深度解析SpringAOP@Aspect原理、实战与最佳实践教程》文章系统讲解了SpringAOP核心概念、实现方式及原理,涵盖横切关注点分离、代理机制(JDK/CGLIB)、切入点类型、性能... 目录1. @ASPect 核心概念1.1 AOP 编程范式1.2 @Aspect 关键特性2. 完整代码实

Java Web实现类似Excel表格锁定功能实战教程

《JavaWeb实现类似Excel表格锁定功能实战教程》本文将详细介绍通过创建特定div元素并利用CSS布局和JavaScript事件监听来实现类似Excel的锁定行和列效果的方法,感兴趣的朋友跟随... 目录1. 模拟Excel表格锁定功能2. 创建3个div元素实现表格锁定2.1 div元素布局设计2.

SpringBoot连接Redis集群教程

《SpringBoot连接Redis集群教程》:本文主要介绍SpringBoot连接Redis集群教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 依赖2. 修改配置文件3. 创建RedisClusterConfig4. 测试总结1. 依赖 <de

Nexus安装和启动的实现教程

《Nexus安装和启动的实现教程》:本文主要介绍Nexus安装和启动的实现教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Nexus下载二、Nexus安装和启动三、关闭Nexus总结一、Nexus下载官方下载链接:DownloadWindows系统根