diff --git a/01-Char/.gitignore b/01-Char/.gitignore new file mode 100644 index 000000000..66eb382c9 --- /dev/null +++ b/01-Char/.gitignore @@ -0,0 +1,14 @@ +# Files +*.o +*.ko +*.cmd +*.mod.c +*.mod.o + +Module.symvers +modules.order + +compile_commands.json + +# Directories +.tmp_versions/ diff --git a/01-Char/Makefile b/01-Char/Makefile new file mode 100644 index 000000000..7c2b83d57 --- /dev/null +++ b/01-Char/Makefile @@ -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 diff --git a/01-Char/char_static.c b/01-Char/char_static.c new file mode 100644 index 000000000..33091aa95 --- /dev/null +++ b/01-Char/char_static.c @@ -0,0 +1,41 @@ +#include +#include +#include + +#include + +#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 "); +MODULE_DESCRIPTION("A simple character device driver"); +MODULE_ALIAS("virtual-serial");