[修改] 导入模板

This commit is contained in:
gaoyang3513
2024-01-17 14:43:04 +00:00
parent 7dc07cf4d7
commit 5ac64b70d8
3 changed files with 76 additions and 0 deletions

14
01-Char/.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
# Files
*.o
*.ko
*.cmd
*.mod.c
*.mod.o
Module.symvers
modules.order
compile_commands.json
# Directories
.tmp_versions/

21
01-Char/Makefile Normal file
View File

@ -0,0 +1,21 @@
ifneq ($(KERNELRELEASE),)
obj-m := char_static.o
else
ifneq ($(ARCH),)
KERNELDIR ?= ${HOME}/Source/04-RK3568/02-Projects/SDK_RK3568_Linux_LBCat2/kernel
ROOTFS ?= ${HOME}/nfs/rootfs
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
endif
PWD := $(shell pwd)
modules:
@$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
@$(MAKE) -C $(KERNELDIR) M=$(PWD) INSTALL_MOD_PATH=$(ROOTFS) modules_install
clean:
@rm -rf *.o *.ko .*.cmd *.mod* modules.order Module.symvers .tmp_versions
endif

41
01-Char/char_static.c Normal file
View File

@ -0,0 +1,41 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#define VSER_MAJOR 256
#define VSER_MINOR 0
#define VSER_DEV_CNT 1
#define VSER_DEV_NAME "vser"
static int __init vser_init(void)
{
int ret;
dev_t dev;
dev = MKDEV(VSER_MAJOR, VSER_MINOR);
ret = register_chrdev_region(dev, VSER_DEV_CNT, VSER_DEV_NAME);
if (ret)
goto reg_err;
return 0;
reg_err:
return ret;
}
static void __exit vser_exit(void)
{
dev_t dev;
dev = MKDEV(VSER_MAJOR, VSER_MINOR);
unregister_chrdev_region(dev, VSER_DEV_CNT);
}
module_init(vser_init);
module_exit(vser_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Kevin Jiang <jiangxg@farsight.com.cn>");
MODULE_DESCRIPTION("A simple character device driver");
MODULE_ALIAS("virtual-serial");