[修改] 导入模板
This commit is contained in:
14
01-Char/.gitignore
vendored
Normal file
14
01-Char/.gitignore
vendored
Normal 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
21
01-Char/Makefile
Normal 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
41
01-Char/char_static.c
Normal 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");
|
||||
Reference in New Issue
Block a user