第一个驱动程序编写

本文档展示了如何在RISC-V架构上构建Linux内核模块。使用了指定的目录路径和交叉编译工具,提供了makefile内容,包括编译和清理目标。模块名为first_drv,并包含了miscdevice头文件,表明是与设备驱动相关的开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考驱动程序中misc.c头文件。

  1. KERN_DIR = /home/sunxiaopeng/src/work/github/k510_buildroot/k510_crb_lp3_v1_2_defconfig/build/linux-4.17
    
    
    all:
            make ARCH=riscv CROSS_COMPILE="/home/sunxiaopeng/src/work/github/k510_buildroot/k510_crb_lp3_v1_2_defconfig/host/bin/riscv64-linux-"  -C $(KERN_DIR) M=`pwd` modules
    
    clean:
    
            make ARCH=riscv CROSS_COMPILE="/home/sunxiaopeng/src/work/github/k510_buildroot/k510_crb_lp3_v1_2_defconfig/host/bin/riscv64-linux-"  -C $(KERN_DIR) M=`pwd` modules clean
            #make -C $(KERN_DIR) M=`pwd` modules clean
            rm -rf modules.order
    
    
    obj-m   += first_drv.o
    

#include <linux/module.h>

#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/stat.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/tty.h>
#include <linux/kmod.h>
#include <linux/gfp.h>
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
static int __init hello_init(void)
{
    printk(KERN_ALERT "welcome, hello\n");
    return 0;
}

// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
static void __exit hello_exit(void)
{
    printk(KERN_ALERT "bye, hello\n");
}

// ▒▒▒▒
MODULE_LICENSE("GPL");

module_init(hello_init);
module_exit(hello_exit);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunxiaopengsun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值