Skip to content

Ubuntu #2

Description

@Milaaaaaa

https://milaaaaaa.github.io/ubuntu/

Ubuntu编译并安装新驱动程序

内容

以编译模块的方法在ubuntu内核中增加一个新的设备驱动程序,功能为实现简单的字符设备(如键盘)读写。

环境

ubuntu版本:16.04.6
内核版本:4.15.0-74-generic
虚拟机:VMware

步骤
1.安装源码和工具包

执行命令查看是否安装源码。

ls -l /usr/src

执行命令查看内核版本。

uname -r

查看当前内核是否有对应的源码,若无需要去官网下载当前内核版本对应的源码,并将其解压至/usr/src文件夹中。清华开源镜像站

下载工具包:

apt-get install build-essential

2.编译驱动程序hello.c

hello.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/uaccess.h>

MODULE_LICENSE(

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions