当前位置:网站首页>hello world驱动
hello world驱动
2022-07-17 03:02:00 【鸡蛋炒肉】
记录自己学习linux驱动的成长之旅。(2022/07/16 22:03)
再牛逼的梦想,也抵不住傻逼般的坚持!
(该篇文章算不上是原创,网上查找了其他多个同学的笔记,自己整理做了验证)
Makefile
(这里既可以用Makefile,也可以直接使用GCC进行编译,但GCC的话同样需要制定默认的kernel路径)
PWD := $(shell pwd)
CROSS_COMPILE = arm-sigmastar-linux-uclibcgnueabihf-
CC:=$(CROSS_COMPILE)gcc
all:
make -C $(KERN_DIR) M=$(PWD) CROSS_COMPILE=$(CROSS_COMPILE) modules
clean:
make -C $(KERN_DIR) M=$(PWD) CROSS_COMPILE=$(CROSS_COMPILE) modules clean
rm -rf modules.order
obj-m += hello.o
hello.c
#include <linux/init.h> //这个头文件包含了你的模块初始化与清除的函数
#include <linux/module.h> //这个头文件包含了许多符号与函数的定义,这些符号与函数多与加载模块有关
#include <linux/kernel.h>
//指定license版本 若不指定
// “GPL” 是指明了 这是GNU General Public License的任意版本
// “GPL v2” 是指明 这仅声明为GPL的第二版本
// “GPL and addtional”
// “Dual BSD/GPL”
// “Dual MPL/GPL”
// “Proprietary” 私有的
// 除非你的模块显式地声明一个开源版本,否则内核会默认你这是一个私有的模块(Proprietary)
MODULE_LICENSE(“GPL”);
#if 0 //如下非必要 需要可自行添加
MODULE_AUTHOR // 声明作者
MODULE_DESCRIPTION // 对这个模块作一个简单的描述,这个描述是"human-readable"的
MODULE_VERSION // 这个模块的版本
MODULE_ALIAS // 这个模块的别名
MODULE_DEVICE_TABLE // 告诉用户空间这个模块支持什么样的设备
#endif
//设置初始化入口函数
static int __init hello_world_init(void)
{
printk(“hello china!!!\n”);
return 0;
}
//设置出口函数
static void __exit hello_world_exit(void)
{
printk(“see you china!!!\n”);
}
//将上述定义的init()和exit()函数定义为模块入口/出口函数
module_init(hello_world_init);
module_exit(hello_world_exit);
边栏推荐
- 容器适配器-栈,队列,优先级队列
- 针孔微创牙龈手术(Pinhole Gum Rejuvenation)
- [nodejs] npm/nrm cannot load the file because the script solution is prohibited in this system
- Session和Cookie的工作原理
- EfficientNet系列(1): EfficientNetV2网络详解
- The biggest bug I've ever written in my career as a programmer! Netizen: high and low is a P8 level!
- baddy:初始化内存域
- [Paper Abstract] screenshots of methods for recording abstracts of interest and papers in special fields.
- 掩饰性治疗
- Animation animation clip frame skipping, animation queue
猜你喜欢
随机推荐
Redis批量删除特定前缀的KEY
The adaptation of go language under windows10:vscode
(21) blender source code analysis: click the mouse to add the message to the queue
51单片机——双字节乘以双字节
程序员生涯写过最大的Bug!网友:高低是个P8水平!
剑指 Offer 59 - II. 队列的最大值
Accumulation of natural language processing knowledge points
go环境安装
Explanation of Hoff transformation
dapr系列(一)
大文件上传
Redis data migration: Method 2 AOF
[Paper Abstract] screenshots of methods for recording abstracts of interest and papers in special fields.
Frrouting use
Common herbs and ingredients for kidney conditioning
厲害,竟然把VSCode玩成了IDEA的效果,有點哇塞
Sword finger offer 59 - ii Maximum value of queue
Sword Finger offer 59 - II. Valeur maximale de la file d'attente
Group 卷积
HCIP第七天笔记








