diff --git a/03_module/Makefile b/03_module/Makefile new file mode 100644 index 0000000..8ec6b4c --- /dev/null +++ b/03_module/Makefile @@ -0,0 +1,18 @@ +obj-m += mymodule.o + +# Build for current kernel + +#all: +# make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +#clean: +# make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean + + +# Build for another kernel + +all: + make -C /home/user/Files_Slava/GL_dev/C/linux-kernel/buildroot-2021.02.9/output/build/linux-5.10.7/ M=$(PWD) modules + +clean: + make -C /home/user/Files_Slava/GL_dev/C/linux-kernel/buildroot-2021.02.9/output/build/linux-5.10.7/ M=$(PWD) clean diff --git a/03_module/mymodule.c b/03_module/mymodule.c new file mode 100644 index 0000000..6b50af3 --- /dev/null +++ b/03_module/mymodule.c @@ -0,0 +1,34 @@ +#include +#include +#include + +static const char* module_name = "mymodule"; +static int a = 0; +static int b = 0; +module_param(a, int, 0); +module_param(b, int, 0); + +static int __init hello_init(void) +{ + printk(KERN_INFO "%s: Hello world!\n", module_name); + printk("%s: a = %i\n", module_name, a); + printk("%s: b = %i\n", module_name, b); + printk("%s: a + b = %i\n", module_name, a+b); + return 0; +} + +static void __exit hello_exit(void) +{ + printk(KERN_INFO "%s: Goodbye, world!\n", module_name); + printk("%s: a - b = %i\n", module_name, a-b); +} + +module_init(hello_init); +module_exit(hello_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("ViacheslavHolubnychyi"); +MODULE_DESCRIPTION("simple description"); +MODULE_VERSION("0.1"); + +MODULE_INFO(intree, "Y"); diff --git a/03_module/result_kernel_log.txt b/03_module/result_kernel_log.txt new file mode 100644 index 0000000..3f15438 --- /dev/null +++ b/03_module/result_kernel_log.txt @@ -0,0 +1,34 @@ +Welcome to Buildroot +buildroot login: user +Password: +$ pwd +/home/user +$ ls +mymodule.ko +$ su +$ insmod mymodule.ko +mymodule: Hello world! +mymodule: a = 0 +mymodule: b = 0 +mymodule: a + b = 0 +$ rmmod mymodule +mymodule: Goodbye, world! +mymodule: a - b = 0 +$ insmod mymodule.ko a=2 +mymodule: Hello world! +mymodule: a = 2 +mymodule: b = 0 +mymodule: a + b = 2 +$ rmmod mymodule +mymodule: Goodbye, world! +mymodule: a - b = 2 +$ insmod mymodule.ko a=7 b=4 +mymodule: Hello world! +mymodule: a = 7 +mymodule: b = 4 +mymodule: a + b = 11 +$ rmmod mymodule +mymodule: Goodbye, world! +mymodule: a - b = 3 +$ +