当前位置: 代码迷 >> 综合 >> 记录一下 模块的编译过程
  详细解决方案

记录一下 模块的编译过程

热度:82   发布时间:2024-01-21 04:47:58.0

 

 

 

Linux驱动加载方式:
1.编译进内核。

2.编译为模块,内核加载/卸载。


2、驱动源码和Makefile:
驱动源码:
hello.c

#include <linux/init.h>
#include <linux/module.h>static int hello_init(void)
{printk(KERN_WARNING"Hello, world !\n");return 0;
}
static void hello_exit(void)
{printk(KERN_INFO "Goodbye,  world\n");
}
module_init(hello_init);
module_exit(hello_exit);

Makefile

ifneq ($(KERNELRELEASE),)obj-m :=hello.oelse
KDIR:= /lib/modules/4.4.0-185-generic/build
PWD:= $(shell pwd)all:make -C $(KDIR) M=$(PWD) modules 
clean:rm -f *.ko *.o *.mod.o *.mod.c .symversendif

3、模块加载与卸载
加载  sudo insmod hello.ko
卸载 sudo rmmod hello
查看 lsmod
加载sudo modprobe hello

 

 

 

  相关解决方案