openwrt中添加自定义驱动模块和APP

2023-11-04

驱动模块添加:

1:make menuconfig中的 kernel modules

其中的各个配置选项来自于下面目录中的.mk文件


这里以other.mk为对照,后续我们添加的驱动模块,添加到other分支当中

2:建立模块目录,路径是package/kernel/example。mkdir -p package/kernel/example

3:进行package/kernel/example目录,建立Makefile文件,内容如下

#Kernel module example
include $(TOPDIR)/rules.mk

include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=example
PKG_RELEASE:=1

include $(INCLUDE_DIR)/package.mk


EXTRA_CFLAGS:= \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(EXTRA_KCONFIG)))) \
	$(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(EXTRA_KCONFIG)))) \

MAKE_OPTS:=ARCH="$(LINUX_KARCH)" \
	CROSS_COMPILE="$(TARGET_CROSS)" \
	SUBDIRS="$(PKG_BUILD_DIR)" \
	EXTRA_CFLAGS="$(EXTRA_CFLAGS)"

define KernelPackage/example
  SUBMENU:=Other modules
  TITLE:=Support Module for example
  # DEPENDS:=@XXX   #如果有依赖,这个名字可去make menuconfig里面找到 Symbol:XXX
  FILES:=$(PKG_BUILD_DIR)/example.ko
  AUTOLOAD:=$(call AutoLoad,81,example) #系统启动时自动装载
endef

#PKG_BUILD_DIR:/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7621/example 
#建立 PKG_BUILD_DIR ,并将代码拷贝到此处
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)/              
	$(CP) -R ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Compile
	$(MAKE) -C "$(LINUX_DIR)" $(MAKE_OPTS) CONFIG_EXAMPLE=m modules
endef

$(eval $(call KernelPackage,example))

4:在package/kernel/example目录下建立src目录,mkdir -p package/kernel/example/src

5:在package/kernel/example/src目录下建立源码文件example.c和对应的Makefile,Kconfig

example.c

#include <linux/module.h>
#include <linux/version.h>
#include <linux/kmod.h>




static int __init example_init(void)
{
	printk("hello example openwrt\n");
	return 0;
}

static void __exit example_exit(void)
{
	printk("hello example openwrt exit\n");
}

module_init(example_init);
module_exit(example_exit);

MODULE_AUTHOR("hello world");
MODULE_DESCRIPTION("example driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:" DRV_NAME);
Makefile:

obj-${CONFIG_EXAMPLE}+= example.o


Kconfig:

config EXAMPLE
    tristate "Just a example"
    help
    This is a example, for debugging kernel model.
    If unsure, say N.



6:在trunk目录make menuconfig-->kernel module-->other module-->kmod-example选中。保存Config后,输入make ./package/kernel/example/compile V=s进行编译




应用程序编译

1:在trunk/package应用目录。参考其他的应用文件。创建helloworld文件夹,并进入。创建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

define Build/Configure
endef


define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		CC="$(TARGET_CC)" \
		CFLAGS="$(TARGET_CFLAGS) -Wall" \
		LDFLAGS="$(TARGET_LDFLAGS)"
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))

2:在helloworld目录 创建src文件夹,并进入。 创建Makefile和helloworld.c:

# 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

helloworld.c

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char**argv)
{
    printf("Hell! O' world, why won't my code compile?\n\n");
    return 0;
}

3:返回trunk目录,make menuconfig-->Utilities-->helloworld。然后make ./package/helloworld/compile V=s





本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

openwrt中添加自定义驱动模块和APP 的相关文章

  • openwrt opkg错误的问题解决办法之一

    解决方法 echo nameserver 114 114 114 114 gt tmp resolv conf rm f var lock opkg lock opkg update
  • [OpenWrt] Flash 由4M改8M(或者16M), openwrt源码的修改

    http www right com cn forum thread 75309 1 1 html trunk tools firmware utils src mktplinkfw c 只修改fw max len为0xfc0000 16M
  • openwrt reboot流程

    openwrt 系统中 当执行了 reboot 命令 系统将会发生什么事情呢 如何进行重启的呢 下面来一起看一下 reboot 应用层操作 首先 reboot 是由busybox 它是一个集成了常用Linux命令和工具的软件 提供的一个Li
  • 解决GO语言编译程序在openwrt(mipsle架构)上运行提示Illegal instruction问题

    RT 最近在研究openwrt mipsle架构 上运行go语言编译出来的程序 一运行就报 Illegal instruction 这样的错误 百度和Google搜索了一遍 得出两种解决方案 PS 更新一遍 当时写这个文档的时候没有发现Go
  • Openwrt编译报错 TCP Fast Open is not available for client mode 的解决办法

    报错信息 configure error TCP Fast Open is not available for client mode please rerun without enable tfo client gmake 3 Makef
  • Buildroot用户指南

    第一章 关于Buildroot Buildroot是一个包含Makefile和修补程序 patch 的集合 这个集合可以使你很容易的为你的目标构建交叉工具链 cross compilationtoolchain 根文件系统 root fil
  • luci的国际化(多语言)

    语言的选择在dispatch函数入口出完成 如果配置文件 etc config luci中配置的lang为auto 则根据浏览器所带的信息选择一个合适的语言 否则就使用lang定义的语言 然后使用i18n lua中的setlanguage设
  • 启明智显分享

    提示 作为Espressif 乐鑫科技 大中华区合作伙伴及sigmastar 厦门星宸 VAD合作伙伴 启明智显不仅用心整理了你在开发过程中可能会遇到的问题以及快速上手的简明教程供开发小伙伴参考 同时也用心整理了乐鑫及星宸科技的新产品 新方
  • 在K2P路由器,非官方openwrt固件,安装软件遇到的坑!

    手上有一台斐讯K2P A2版本的路由器 一直空闲在宿舍 最近发现这个路由器被破解了 可以刷上不死breed 还有很多大神做的固件 因此我想用它刷上openwrt系统后 安装某软件 从而直接在路由器上完成学校的宽带验证登陆 接下来我就介绍我在
  • 基于WR703N路由器的WIFI机器人

    可以说 wifi机器人是一个比较成熟作品了 特别是使用wr703制作wifi机器人的有很多例子 因为1 其体积小 2 实时获取视频相比STM32容易 STM32F1系列性能不够 使用OV系列的摄像头较为吃力 3 可以使用路由器连接外网 使用
  • 基于openwrt,aria2下载器安装与配置

    迅雷下载不好用 所以用这个下载器aria2 需要安装软件 在可用软件列表中安装aria2和luci app aria2 安装完后有可能需要重启路由器 需要注意的问题 1 aria2只是一个下载工具 并没有图形界面 2 文件下载的位置 在ar
  • PHP启动warning:PHP Startup: Unable to load dynamic library 'curl.so'

    高通ar9531上面 openwrt1806这个版本 通过opkg安装了官方的php及其扩展 但新的板子php启动的时候报了warning 没有太仔细看 但是后面运行cgi程序时 发现了问题 回头看warning日志 PHP Warning
  • 编写 LuCI CBI 模型

    编写 LuCI CBI 模型 CBI模型是描述UCI配置文件结构的Lua文件 并且CBI解析器将lua文件转为HTML呈现给用户 所有 CBI 模型文件都必须返回类型为luci cbi Map的对象 CBI 模型文件的范围由 luci cb
  • 从零开始编译OpenWrt固件

    从零开始编译OpenWrt固件 前言 进来阅读这篇文章的相信都是对OpenWrt有一定的了解的 对于OpenWrt的介绍这里就不再赘述 可以自行查找相关百科了解 OpenWrt是适合于嵌入式设备的一个Linux发行版 可以通过其提供的相关工
  • 1-OpenWrt编译过程-2

    前言 接触 op 已达四年 今年开始梳理整体所学 具体还参考了佐大的视频 对 op 缺乏系统知识的可以尝试 总体而言官方文档和源码是最好的教程 文章目录 编译OpenWrt 概述 1 更新安装所有可选的软件包 2 编译设置 make men
  • openwrt 缺少 libc.so.6 libm.so.6 libpthread.so.0

    在开发openwrt时 编译内核的时候 自己写的代码在openwrt 编译报错 提示缺少依赖库文件 Package Gateway Auto is missing dependencies for the following librari
  • openwrt恢复出厂设置有两种方法

    1 输入以下指令 firstboot mtd r erase rootfs data 2 输入以下指令 mount root firstboot reboot f
  • 刷新完固件后opkg update报错的解决方法

    刷新完固件后opkg update报错的解决方法 一 更改设备ip 当你使用lan口接入局域网后 如果你ping不通局域网上的其他设备ip 那么需要更改ip vim etc config network 修改lan口的ip为局域网下同一网段
  • OpenWRT git clone fatal:无法找到“http”的远程帮助程序

    我正在尝试将 LINC Switch 安装到 OpenWRT 并遇到以下问题 git clone https github com FlowForwarding LINC Switch git 并得到一个错误 git fatal Unabl
  • 安装“opkg”?

    我正在尝试将软件包安装到我的 OpenWrt SDK 中 为此 您必须通过键入以下内容来使用 OPKG 包管理器 opkg update opkg install

随机推荐

  • ccwow服务器维护,牧师 - 军团再临 - 178魔兽世界

    牧师职业大厅 军团再临资料片中最大的改动便是神器和职业大厅了 如同德拉诺版本的要塞系统一样 7 0的职业大厅便像是一个强化版的要塞 不过在这里你不再是一个人 相同职业的玩家都会和你在一起来共同探索破碎群岛对抗燃烧军团 那让我们走进虚空之光神
  • calico固定podip

    实现方法 利用calico组件的两个kubernetes注解 1 gt cni projectcalico org ipAddrs 2 gt cni projectcalico org ipv4pools 场景1 单个pod固定ip 利用c
  • HttpClient release connection 该放手的时候必须放手

    Apache commons 系列的HttpClient 相信大家都用过 选择它而非JDK 的java net HttpURLConnection 是为了使用HttpClient 封装的几个实用的功能 目前使用最多的版本还是httpclie
  • 腾讯云2022年双11云服务器配置及报价表汇总

    活动直达 点此进入腾讯云2022年双11活动主会场 腾讯云2022年双11活动的既有轻量应用服务器又有云服务器 购买资格分为个人企业同享和企业用户专享 因此 价格表可分为个人企业同享轻量应用服务器 个人企业同享云服务器 企业专享轻量应用服务
  • 618来袭!我用Python脚本实现了淘宝定时自动秒杀,小白也能轻松搞定!

    准备工作 我们需要把秒杀的商品加入购物车 因为脚本点击的是全选 所以不需要的商品要移出购物车 展示篇幅有限 淘宝秒杀程序的完整源代码已经打包好了 需要的朋友可以扫码加v 我分享给你 过程分析 1 打开某宝网站 pq webdriver Ch
  • 基于Fisco的测压工具使用笔记

    基本过程就是这样了 因为当初写的时候是用OneNote写的 复制过来是图片形式 然后主要的坑就是官方的源码有错误 官方也给了修改意见 根据 修改意见 修改源码 修改完我还碰到一个坑 不知道为什么这个位置缺少文件 移动到这个文件下添加solc
  • 【LeetCode】Day211-不用加减乘除做加法

    题目 剑指 Offer 65 不用加减乘除做加法 中等 题解 不能用加减乘除的题 要考虑位运算 设两数字的二进制形式a b s a b a i 代表a的二进制的第i位 则分为以下四种情况 a i b i 无进位和n i 进位c i 1 0
  • 字符串的总结(atoi和itoa函数的实现)

    目录 一 常见的字符串函数 strlen strcpy strcat strcmp 二 关于atoi函数的实现 三 关于itoa函数的实现 一 常见字符串的函数 strlen strcpy strcat strcmp 1 strlen 求字
  • 在网址上输入www.xxx.com到返回界面给用户发生了什么?

    在网址上输入www xxx com到返回界面给用户发生了什么 DNS域名解析 https blog csdn net m0 37812513 article details 78775629 gt tcp三次握手建立连接 https blo
  • Shiro 如何使用注解式进行授权操作呢?

    转自 Shiro 如何使用注解式进行授权操作呢 下文笔者讲述Shiro进行注解式授权操作的方法分享 如下所示 Shiro注解授权 常使用以下注解字段 如 RequiresRoles RequiresPermissions RequiresA
  • 关闭TCP中135、139、445、593、1025 等端口的操作方法 (转)(记录下)

    操作要领 封闭端口 杜绝网络病毒对这些端口的访问权 以保障计算机安全 减少病毒对上网速度的影响 近日发现有些人感染了新的网络蠕虫病毒 该病毒使用冲击波病毒专杀工具无法杀除 请各位尽快升级计算机上的杀毒软件病毒库 在断开计算机网络连接的情况下
  • AndeSight头文件缺失错误

    使用AndeSight开发山景Demo遇到的问题 路径别带中文名字 一个都不要 其实主要就是一个 当我导入demo之后 编译时遇到问题 缺失 h文件 各种缺失 那么这里我们也可以一个个导入 但是很难受 这里实际上只要在baseSDK建立工程
  • 西门子PLC入门-PLC介绍

    PLC全名 可编程逻辑控制器 Programmable Logic Controller 一种具有微处理器的用于自动化控制的数字运算控制器 可以将控制指令随时载入内存进行储存与执行 PLC由CPU 指令及数据内存 输入 输出接口 电源 数字
  • Stream流处理快速上手最佳实践

    一 引言 JAVA1 8得益于Lambda所带来的函数式编程 引入了一个全新的Stream流概念Stream流式思想类似于工厂车间的 生产流水线 Stream流不是一种数据结构 不保存数据 而是对数据进行加工处理 Stream可以看作是流水
  • 【前端面试题】/【Vue】组件中的data为什么要定义成一个函数而不是一个对象?

    Q 组件中的data为什么要定义成一个函数而不是一个对象 A 因为当定义为一个数组 对象时候 我们改变data中其中一个数据的值的时候 会影响到其他的数据 导致数据污染 而定义为一个函数 则可以避免这个情况 参考 每个组件都是 Vue 的实
  • Cadence(OrCAD)原理图导入到PADS Layout遇到的问题和解决方法

    看到有网友留言说将Cadence画的原理图导入到PADS Layout中没有成功 先在Cadence中导出原理图的网表 当然这里的网表是PADS Layout支持的 asc格式 然后在PADS Layout导入该网表文件 最终出现提示错误的
  • ARM汇编指令

    ARM汇编指令 1 汇编语法 1 1 mov movw r0 63500 0xf80c 将63500放到r0寄存器的低八位中 movt r0 25667 0x6443f80c 将25667放到r0寄存器的高八位中 1 2 lsl 左移 st
  • (十)服务器K8S集群部署SpringBoot项目实战

    1 准备springboot项目 可以在 https start spring io 网站准备一个项目 这里作为k8s的学习所以springboot项目中准备一个简单的访问接口即可 2 服务器环境准备 安装Jdk 1 更新系统软件包 sud
  • MybatisPlus分页类型转换 不要在用循环转换了

    使用MybatisPlus查询的sql 返回的必须是一个对应表实体的泛型分页数据 我们给前端返回只需返回VO 我们可能会循环进行对象复制从新赋值 优化 MybatisPlus分页对象有直接转换的方法 优化前 最终分页对象 Page
  • openwrt中添加自定义驱动模块和APP

    驱动模块添加 1 make menuconfig中的 kernel modules 其中的各个配置选项来自于下面目录中的 mk文件 这里以other mk为对照 后续我们添加的驱动模块 添加到other分支当中 2 建立模块目录 路径是pa