#include<linux/init.h> #include<linux/module.h> int add(int i,int j){ return i+j; } int sub(int i,int j){ return i-j; } EXPORT_SYMBOL(add); EXPORT_SYMBOL(sub); MODULE_LICENSE("GPL");
#include<linux/init.h> #include<linux/module.h> #include "head.h" int a=5; int b=3; module_param(a,int,S_IRWXU); module_param(b,int,S_IRWXU); static int __init hello_init(){ printk(KERN_INFO"hello is module!\n"); printk(KERN_INFO"a = %d\n",a); printk(KERN_INFO"b = %d\n",b); printk(KERN_INFO"a + b = %d\n",add(a,b)); printk(KERN_INFO"a = %d\n",a); printk(KERN_INFO"b = %d\n",b); printk(KERN_INFO"a - b = %d\n",sub(a,b)); return 0; } static void __exit hello_exit(){ printk(KERN_INFO"hello is unmod!\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("GPL");
#ifndef _HEAD_H #define _HEAD_H extern int add(int ,int ); extern int sub(int ,int ); #endif
ifeq ($(KERNELRELEASE),) KERNELDIR =/home/farsight/work/kernel/linux-3.0.8 PWD =$(shell pwd) modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules cp add_sub.ko /opt/filesystem/s5pv210 modules_install: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install clean: rm -rf *.so *.o *.ko .tmp_versions *.mod.c *.order *.symvers else obj-m :=add_sub.o endi
原文地址:http://blog.csdn.net/muyang_ren/article/details/45824235