This article describes how to write a Linux kernel module that requires two file mytest.c,makefile.
To the same folder directory, then make, do install, you can complete the kernel module compilation generation and installation.
You can then see the information from the module initialization function output through the DMESG command.
MYTEST.C:
#include <linux/module.h> #include <linux/crypto.h> #include <linux/kernel.h> #include <linux/ init.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/highmem.h>static int __init test_init (void) {PRINTK (kern_info "MyTest init\n");p rintk (kern_info "Ha ha\n"); return 0;} static void __exit test_exit (void) {PRINTK (kern_info "HW AES Test exit\n"); Module_init (Test_init); Module_exit (Test_exit); Module_license ("GPL"); Module_author ("Feng");
Makefile:
Koname = mytest.oiftest=$ (Shell lsmod | grep mytest | wc-l) Kerneldir: =/lib/modules/$ (Shell uname-r)/buildpwd: =$ (shell PWD) obj-m:=$ (koname) module:make-c $ (kerneldir) m=$ (PWD) test_install:ifeq ($ (iftest), 1) rmmod Mytestinsmod Mytest.koelseinsmod Mytest.koendifinstall:test_install. Phony:install clean:rm *.o *.mod.c modules.order module.symvers. *.cmd *.korm-rf. tmp_versions
Linux Kernel module Authoring templates