Skip to content

Instantly share code, notes, and snippets.

@BenSYZ
Last active August 11, 2021 03:28
Show Gist options
  • Save BenSYZ/71026ad184b206c5f9e42be33b542250 to your computer and use it in GitHub Desktop.
Save BenSYZ/71026ad184b206c5f9e42be33b542250 to your computer and use it in GitHub Desktop.
# 最后生成的目标,即module_example.ko
obj-m:=module_example.o
CURRENT_PATH := $(shell pwd)
LINUX_KERNEL := $(shell uname -r)
LINUX_KERNEL_PATH := /usr/lib/modules/$(LINUX_KERNEL)/build
all:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
clean:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
static int __init lkp_init(void){
printk("<1>Hello, world! from the kernel space...\n");
return 0;
}
static void __exit lkp_exit(void){
printk("<1>Goodbye, world! leaving the kernel space...\n");
}
module_init(lkp_init);
module_exit(lkp_exit);
MODULE_LICENSE("GPL");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment