基于s3c6410开发板helloworld驱动模块开发

来源:互联网 发布:linux c tcp服务器 编辑:程序博客网 时间:2024/06/12 20:40
【开发环境】
PC:win7 x64
VMware:Ubuntu14.04
s3c6410开发板:linux-2.6.28.6

【源代码】
hello.c
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

//Defining __KERNEL__ and MODULE allows us to access kernel-level code not usually available to userspace programs.
#undef __KERNEL__ //为了引用内核数据结构
#define __KERNEL__
  
#undef MODULE
#define MODULE

// Linux Kernel/LKM headers: module.h is needed by all modules and kernel.h is needed for KERN_INFO.
#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("Dual BSD/GPL");

static int __init hello_init(void)
{
    printk(KERN_INFO "Hello world!\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! this is exit\n");
}
  
module_init(hello_init);
module_exit(hello_cleanup);

MODULE_AUTHOR("andrew yue");  
MODULE_DESCRIPTION("A hello word module for testing module parameters");  
MODULE_VERSION("V1.0");  

Makefile
---------------------------------------------------------------------------------------------------------------
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else 
KDIR := /home/yzli/yzli_lib/s3c-linux-2.6.28.6-TOP6410//移植的linux源码目录

all:
make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=/home/yzli/yzli_lib/arm-2008q3/bin/arm-none-linux-gnueabi-//交叉编译路径

clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers

endif


【问题】
1.error: linux/bounds.h: No such file or directory
-------------------------------------------------------------------------------------
在linux-2.6.28.6源码目录,执行make重新编译一遍(拷贝过来,未编译过)。

2.执行模块卸载时(rmmod hello)提示"rmmod: module 'hello' not found",其实模块已经卸载
---------------------------------------------------------------------------------------------------------------------------
个人理解,是由于移植文件系统时,编译busybox的原因,暂不考虑。详见
http://www.cnblogs.com/feisky/archive/2010/05/29/1746888.html

3.编译后的驱动模块是hello.ko,加载和卸载模块操作如下
-------------------------------------------------------------------------------
加载模块:insmod hello.ko
卸载模块    rmmod hello

0 0
原创粉丝点击