当前位置:网站首页>openwrt 编译驱动模块(在openwrt源代码外部任意位置编写代码,独立模块化编译.ko)
openwrt 编译驱动模块(在openwrt源代码外部任意位置编写代码,独立模块化编译.ko)
2022-07-27 14:37:00 【xhoufei2010】
一、硬件平台
MT7620(A9内核)
二、软件平台
1、Ubuntu 12.04
2、openwrt 官方15.05版本SDK开发包
三、功能说明
近期在整理openwrt的驱动,但是网上的资料,大部分都是在 openwr 源代码 package 目录下,建立文件夹,然后在 openwrt 目录下编译。此方法虽然可以编译,但是维护起来不是特别方便。比如单独编译一个模块,还需要依赖于 openwrt 的SDK包。这样,每次需要增加驱动模块,都要在SDK包下建立目录。
个人比较倾向于驱动模块单独建立文件夹,路径不做限制。这样方便代码维护管理,而且在git或者 svn 上传下载方便,与 openwrt 的源码SDK包分离开。
本文章,主要介绍的就是,在任意地方,建立自己的文件夹和编写驱动,然后编译出驱动模块。最大的优势在于,代码的路径不受限制。如果需要修改某一个驱动,仅仅下载该驱动文件,不需要更新整个 openwrt SDK开发包。
四、操作步骤
1、编写C文件
在任意文件夹,例如本文章的路径为 /home/test/ 编写代码,名称为“hello.c”。
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
/* hello_init ---- 初始化函数,当模块装载时被调用,如果成功装载返回0 否则返回非0值 */
static int __init hello_init(void)
{
printk("I bear a charmed life.\n");
return 0;
}
/* hello_exit ---- 退出函数,当模块卸载时被调用 */
static void __exit hello_exit(void)
{
printk("Out, out, brief candle\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");2、编写makefile
编译使用的makefile文件,文件名称为“makefile”。
说明:
本文中,openwrt 的SDK开发包存放路径为 /home/sky/develop/openWrt/openwrt/
openwrt 下载的 kernel ,存放路径为 /home/sky/develop/openWrt/openwrt/build_dir/target-mipsel_24kec+dsp_glibc-2.21/linux-ramips_mt7620/linux-3.18.29/
openwrt 的gcc 交叉编译工具链,路径为:/home/sky/develop/openWrt/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.21/bin/
对于本文中openwrt 的SDK包:
(1)交叉编译工具链为 glibc2.21
(2)目标芯片选择为mt7620
在makefile中,说明了gcc 和 openwrt 的SDK包路径,makefile 内容如下:
######################################## hello ################################
obj-m = hello.o
PWD=$(shell pwd)
KERNEL_DIR=/home/sky/develop/openWrt/openwrt/build_dir/target-mipsel_24kec+dsp_glibc-2.21/linux-ramips_mt7620/linux-3.18.29/
TOOLCHAIN="/home/sky/develop/openWrt/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.21/bin/mipsel-openwrt-linux-gnu-"
###############################################################################
all:
make -C $(KERNEL_DIR) \
ARCH=mips \
CROSS_COMPILE=$(TOOLCHAIN) \
M=$(PWD) \
modules
clean:
rm -f *.ko
rm -f *.o
rm -f *.mod.c
rm -f *.mod.o
rm -f *.order
rm -f *.sysvers
#make command:
#make
#make clean
3、编译
在终端中,进行编译,输入命令 : make
需要清空,则输入命令: make clean
边栏推荐
- C language: custom type
- Voice live broadcast system -- a necessary means to improve the security of cloud storage
- UDP message structure and precautions
- Hematemesis finishing c some commonly used help classes
- C: What is the return value (revolution) in a function
- First understanding of structure
- 【云享读书会第13期】FFmpeg 查看媒体信息和处理音视频文件的常用方法
- 网络设备硬核技术内幕 路由器篇 小结(下)
- Spark RPC
- Zhaoqi scientific innovation and entrepreneurship competition planning and undertaking organization, mass entrepreneurship and innovation platform, project landing and docking
猜你喜欢

Half find

DRF学习笔记(一):数据序列化

Network principle (2) -- network development

Using Lombok results in the absence of parent class attributes in the printed toString
![[sword finger offer] interview question 42: the maximum sum of continuous subarrays -- with 0x80000000 and int_ MIN](/img/01/bbf81cccb47b6351d7265ee4a77c55.png)
[sword finger offer] interview question 42: the maximum sum of continuous subarrays -- with 0x80000000 and int_ MIN

Binder初始化过程
![[sword finger offer] interview question 53-i: find the number 1 in the sorted array -- three templates for binary search](/img/4b/460ac517e9a5d840a0961f5d7d8c9d.png)
[sword finger offer] interview question 53-i: find the number 1 in the sorted array -- three templates for binary search

First understanding of structure
![[sword finger offer] interview question 46: translating numbers into strings - dynamic programming](/img/ba/7a4136fd95ba2463556bc45231e8a2.png)
[sword finger offer] interview question 46: translating numbers into strings - dynamic programming

低代码是开发的未来吗?浅谈低代码平台
随机推荐
DRF学习笔记(五):视图集ViewSet
【云享读书会第13期】视频文件的编码格式
文字批量替换功能
网络原理(2)——网络开发
传音控股披露被华为起诉一事:已立案,涉案金额2000万元
go语言慢速入门——包
Spark troubleshooting finishing
NPM install error unable to access
Binary Insertion Sort
leetcode234题-简单方法判断回文链表
Breaking through soft and hard barriers, Xilinx releases Vitis unified software platform for developers
Spark Bucket Table Join
C语言:函数栈帧
js操作dom节点
Go language slow start -- go operator
Addition, deletion, query and modification of MySQL table data
[sword finger offer] interview question 53-i: find the number 1 in the sorted array -- three templates for binary search
Hj8 consolidated statement record
C language: custom type
UDP 的报文结构和注意事项