[#6 soluzione, problema]
Ho installato #7 il pacchetto kernel-devel in opensuse Lead 15. Ora con il comando make ho il modulo compilato e pronto per essere caricato nel kernel.
Codice:
[#7 applicazione]
zypper in kernel-devel
cd /home/zabnicola/hello_mod_zab/hello/
ls
m_example.c
Makefile
EOF
vim Makefile
obj-m += m_example.o
all:
make -C /lib/modules/5.3.18-lp152.50-default/build
M=/home/zabnicola/hello_mod_zab/hello/ modules
clean:
make -C /lib/modules/5.3.18-lp152.50-default/build M=/home/zabnicola/hello_mod_zab/hello/ clean
EOF
make
make: Entering directory '/usr/src/linux-5.3.18-lp152.50-obj/x86_64/default'
CC [M] /home/zabnicola/hello_mod_zab/hello/m_example.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/zabnicola/hello_mod_zab/hello/m_example.mod.o
LD [M] /home/zabnicola/hello_mod_zab/hello/m_example.ko
make: Leaving directory '/usr/src/linux-5.3.18-lp152.50-obj/x86_64/default'
insmod m_example.ko
dmesg | tail -1
[ 8929.885648] Load module 1
rmmod m_example.ko
dmesg | tail -1
[ 9103.987749] Cleaning up module 1
--
Aggiungo la funzione di rimozione del modulo dal kernel.
Codice:
[#8 Linguaggio]
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
MODULE_LICENSE("GPL");
MODULE_AUTHOR("zabnicola");
MODULE_DESCRIPTION("A Simple Hello World module");
static int __init hello_init(void){
printk(KERN_INFO "Load module 1\n");
return 0; // Non-zero return means that the module couldn't be loaded.
}
static void __exit hello_cleanup(void){
printk(KERN_INFO "Cleaning up module 1\n");
}
module_init(hello_init);
module_exit(hello_cleanup);
EOF