Hello World驱动模块尝试<2>_将驱动加载到mini210s开发板

来源:互联网 发布:喵喵淘宝u站 编辑:程序博客网 时间:2024/06/05 09:26

基于上一篇文章的进展继续驱动的学习。。。。。。。

主要参考资料:http://blog.csdn.net/dg1683wen/article/details/6861044

首先,构建内核源码树。我使用的是友善之臂自带的Linux源码:linux-2.6.35.7-20120912.tgz

首先将内核源码linux-2.6.35.7-20120912.tgz拷贝到Ubuntu系统目录/home/liuhui8989/Linuxshare下

解压:tar zxvf linux-2.6.35.7-20120912.tgz 得到linux-2.6.35.7文件夹。

开始构建源码树,根据友善之臂手册知道,首先在linux-2.6.35.7目录下执行

cp mini210_linux_defconfig .config

然后直接执行make或者make zImage即可完成内核源码树的构建。


开始写hello world驱动,此处驱动是加载到开发板中,与Ubuntu系统的不同之处在于交叉编译器的指定,此处需指定为arm-linux-gcc

在/home/liuhui8989/Upload_minicom/Example下新建文件夹hello_mini210s,该文件夹下新建两文件hello.c和Makefile

//hello.c

#include<linux/init.h>
#include<linux/module.h>
MODULE_LICENSE("liuhui8989 BSD/GPL");
int init_moduless(void)
{
printk("<0>""hello.world-this is the kernel speaking\n");
return 0;
}
void cleanup_moduless(void)
{
printk(KERN_ALERT"Short is the life of a kernel\n");
}


module_init(init_moduless);
module_exit(cleanup_moduless);


#Makefile

obj-m:=hello.o
CC=arm-linux-gcc
KERNELDIR:=/home/liuhui8989/LinuxShare/linux-2.6.35.7
PWD:=$(shell pwd)
modules:
[此处为Tab键] $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
[此处为Tab键] $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

构建完成两文件后,直接make就OK得到我们想要的驱动程序。


将上面构建源码树产生的zImage文件烧写到开发板中,进入系统,连接好开发板,进入minicom界面。

将/home/liuhui8989/Upload_minicom/Example/hello_mini210s目录下make产生的hello.ko文件下载到开发板中。

加载驱动程序:

[root@FriendlyARM /]# insmod hello.ko                                           
[ 1290.351906] hello.world-this is the kernel speaking

打印出了信息表示驱动加载成功。

还可以这样查看

[root@FriendlyARM /]# lsmod                                                     
hello 693 0 - Live 0xbf0a7000 (P)                                               
rtl8192cu 489899 0 - Live 0xbf01e000                                            
tvp5150_tiny210 14147 0 - Live 0xbf015000                                       
snd_soc_mini210_wm8960 2936 0 - Live 0xbf00f000                                 
snd_soc_wm8960 15882 1 snd_soc_mini210_wm8960, Live 0xbf006000 

同样发现了hello

卸载驱动:

[root@FriendlyARM /]# rmmod hello                                               
[ 2679.617061] Short is the life of a kernel                                    
rmmod: module 'hello' not found 


至此简单驱动的开发完成。。。。。



原创粉丝点击