My First Linux Module
Today, I successfully build my first Linux Hello module.
First of all add a directory named Hello in the Kernel/driver, and add a file hello.c, write codes like bellow:
#include <linux/init.h>#include<linux/module.h>Static int__init Hello_init (void) {PRINTK (Kern_err"Hello, world!\n."); return 0;}Static void__exit Hello_exit (void) {PRINTK (Kern_err"Goodbye, world!\n");} Module_init (Hello_init); Module_exit (Hello_exit); Module_author ("Bob, Zhang"); Module_license ("Dual BSD/GPL"); Module_description ("A Simple Hello World demo"); Module_alias ("A Simple Module");
Then create a Kconfig file:
config HELLO " HELLO World driver! " default M help HELLO World
and create a Makefile file:
Obj-m + = hello.o
Next ADD the Kconfig and Makefile into the Kconfig file and Makefile file in parent directory.
Finally Run the commands bellow:
Make Arch=arm cross_compile=$tool _prefix my_kernel_defconfig make Arch=arm cross_compile=$tool _ Prefix modulesmkdir ./moduls_temp make arch=arm cross_compile= $tool _prefix Modules_ Install Install_mod_path=./modules_temp
At last, the demo run is like this:
My First Linux Module