求助,以前用QQ登的星纪元漫画免费观看现无法登入,怎么办

本文转载自:
linux设备驱动归纳总结(一):内核的相关基础概念
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
一.linux设备驱动的作用
内核:用于管理软硬件资源,并提供运行环境。如分配4G虚拟空间等。
linux设备驱动:是连接硬件和内核之间的桥梁。
linux系统按个人理解可按下划分:
应用层:包括POSIX接口,LIBC,图形库等,用于给用户提供访问&内核的接口。属于用户态,ARM运行在用户模式(usr)或&者系统模式(sys)下。
内核层:应用程序调用相关接口后,会通过系统调用,执行SWI指&令切换ARM的工作模式到超级用户(svc)模式下,根据用&户函数的要求执行相应的操作。
硬件层:硬件设备,当用户需要操作硬件时,内核会根据驱动接口&操作硬件设备
图结构如下:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
二.内核代码树介绍
linux-2.6.29
|-arch :&包含和硬件体系结构相关的代码
|-block :&硬盘调度算法,不是驱动
|-firmware :&固件,如BOIS
|-Documentation:&标准官方文档
|-dirver : linux设备驱动
|-fs :&内核所支持的文件体系
|-include&:头文件。linux/module.h linux/init.h&常用库。
|-init&:库文件代码,C库函数在内核中的实现。
init/main.c -&start_kernel-&内核执行第一条代码
|-ipc :&进程件通信
|-mm&:内存管理
|-kernel :&内核核心部分,包括进程调度等
|-net&:网络协议
|-sound :&所有音频相关
其中,跟设备驱动有关并且经常查阅的文件夹有:
include : linux, asm-arm
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
三.内核补丁:
补丁一般都是基于某个版本内核生成的,用于升级旧内核。
打补丁需要注意:
1.对应版本的补丁只能用于对应版本的内核。
2.如果在已打补丁的内核再打补丁,需要先卸载原来补丁。
打补丁的方法:
1.制作补丁:
diff -Nur linux-2.6.30/ linux-2.6.30.1/ & linux-2.6.30.1.patch
//N为新加的文件全部修改
//linux-2.6.30&旧版本
//linux-2.6.30.1&新版本
//目标补丁
2.打补丁:
cd linux-2.6.30 //!!注意在原文件夹的目录中打补丁
patch -p1 & ../linux-2.6.30.1.patch //-p1是忽略一级目录
cd linux-2.6.30 //!!注意在原文件夹的目录中打补丁
patch -R & ../linux-2.6.30.1.patch //撤销补丁
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
四.内核中的Makefile:
对于内核,Makefile分为5类:
Documentation/kbuild/makefiles.txt描述如下:
50 The Makefiles have five parts:
52 Makefile&总Makefile,控制内核的编译
53 .config&内核配置文件,配置内核时生成,&如make menuconfig后
54 arch/$(ARCH)/Makefile&对应体系结构的Makefile
55 scripts/Makefile.* Makefile共用的规则
56 kbuild Makefiles&各子目录下的Makefile,被上层的Makefile调用。
简单来说,编译内核会执行以下两步骤,它们分别干了以下的事情。
1一般的,我们会拷贝一个对应体系结构的配置文件到主目录下并改名为&.config,这样就在make menuconfig生成的图形配置中&已经有了一些默认的配置,减少用户的劳动量。不过这一步不做也没关系的。
2.make menuconfig
2.1、由总Makefile决定编译的体系结构(ARCH).&编译工具(CROSS_COMPILE),并知道需要进去哪些内核根下的哪些目录进行编译。
2.2、由arch/$(ARCH)/Makefile,决定arch/$(ARCH)下还有&的哪些目录和文件需要编译。
2.3、知道了需要编译的目录后,递归的进入哪些目录下,读取每一个Kconfig的信息,生成了图形配置的界面。
2.4、通过我们在图形配置界面中选项为[*]、[M]或者[]。
2.5、保存并退出配置,会根据配置生成一份新的配置文件.config,并在同时生成include/config/auto.conf(这是.config的去注释版)。文件里面保存着CONFIG_XXXX等变量应该取y还是取m。
3.1、根据Makefile包含的目录和配置文件的要求,进去个子目录进行编译,最后会在各子目录下&生成一个.o或者.a文件,然后总Makefile指定的连接脚本&arch/$(ARCH)/kernel/vmlinux.lds生成vmlinux,并通过压缩编程bzImage,或者按要求在对应的子目录下编译成&模块。。
但是,具体是怎么生成配置文件的呢?
注:我使用的内核是2.6.29。
1.在总Makefile中,根据以下语句进入需要编译的目录
470 # Objects we will link into vmlinux / subdirs we need to visit
471 init-y := init/
472 drivers-y := drivers/ sound/ firmware/
473 net-y := net/
474 libs-y := lib/
475 core-y := usr/
476 endif # KBUILD_EXTMOD
639 core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
上面说明了,根目录下的init、driver、sound、firmware、net、lib、usr等目录,在编译时都会进去读取目录下的Makefile并进行编译。
2.在总Makefile中包含的目录还是不够的,内核还需要根据对应的CPU体系架构,
决定还需要将哪些子目录将要编译进内核。在总Makefile中有一个语句:
529 include $(srctree)/arch/$(SRCARCH)/Makefile //在这里,我定义SRCARCH = arm
可以看出,在总Makefile中进去读取相应体系&结构的Makefile-&arch/$(SRCARCH)/Makefile。
arch/$(SRCARCH)/Makefile中指定arch/$(SRCARCH)路径下的哪些子目录需要被编译。
在&arch/arm/Makefile&下:
95 head-y := arch/arm/kernel/head$(MMUEXT).o arch/arm/kernel/init_task.o
187 # If we have a machine-specific directory, then include it in the build.
188 core-y += arch/arm/kernel/ arch/arm/mm/ arch/arm/common/
189 core-y += $(machdirs) $(platdirs)
190 core-$(CONFIG_FPE_NWFPE) += arch/arm/nwfpe/
191 core-$(CONFIG_FPE_FASTFPE) += $(FASTFPE_OBJ)
192 core-$(CONFIG_VFP) += arch/arm/vfp/
194 drivers-$(CONFIG_OPROFILE) += arch/arm/oprofile/
196 libs-y := arch/arm/lib/ $(libs-y)
上面看到,指定需要进入arch/arm/kernel/、arch/arm/mm/、arch/arm/common/&等目录编译,至于core-y、&core-$(CONFIG_FPE_NWFPE)这些是什么东西呢?
其中,y表示编译成模块,m表示编译进内核(上面没有,因为默认情况下ARM全部编译进&内核),但$(CONFIG_OPROFILE)又是什么呢?&这些是根据用户在make menuconfig中设置后,生成的值赋给了CONFIG_OPROFILE。
3.那make menuconfig后的配置信息是怎么来的?
这是由各子目录下的Kconfig提供选项功用户选择并配置。
如arch/arm/Kconfig。&所有的配置都是根据arch/$(ARCH)/Kconfig文件通过Kconfig的语法source读取&各个包含的子目录Kconfig来生成一个配置界面。每个Makefile目录下都有一个&对应的Kconfig文件,用于生成配置界面来给用户决定内核如何配置,配置后会确定一个。&CONFIG_XXX的的值(如上面的CONFIG_OPROFILE),来决定编译进内核,还是编译成模块或者不编译。
如在arch/arm/Kconfig下:
595 source "arch/arm/mach-clps711x/Kconfig"
597 source "arch/arm/mach-ep93xx/Kconfig"
599 source "arch/arm/mach-footbridge/Kconfig"
601 source "arch/arm/mach-integrator/Kconfig"
603 source "arch/arm/mach-iop32x/Kconfig"
605 source "arch/arm/mach-iop33x/Kconfig"
这些就是用来指定,需要读取以下目录下的Kconfig文件来生成一个使用make menuconfig时的配置界面。
至于子目录下的Kconfig是怎么样的,待会介绍。
总结Kconfig的作用:
3.1.在make menuconfig下可以配置选项;
3.2.在.config中确定CONFIG_XXX的的值。
4.只是读取以上的两个Makefile还是不够了,内核还会把包含的子目录一层一层的&读取它里面的Makefile和Kconfig。
上面啰啰嗦嗦地讲了这么久,无非就是想说,内核的编译并不是一个Makefile搞定的,需要通过根目录下的总Makefile来包含一下子Makefile(不管是根目录下的子目录还是/arch/arm中的子目录)。而Kconfig,为用户提供一个交互界面来选择如何配置并生成配置选项。
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
五、子目录下的Makefile和Kconfig
上面我一直介绍的都是两个比较大的Makefile&&总Makefile和&arch/$(ARCH)/Makefile。接下来看一下实例。
一、在makefile中,y表示编译进内核,m表示编译成模块,不写代表不编译。&所以,配置最简单的方法就是,直接修改子目录的Makefile&。
先看看arch/arm/Makefile:
/*arch/arm/mach-s3c2440/Makefile&*/
12 obj-$(CONFIG_CPU_S3C2440) += s3c2440.o dsc.o
13 obj-$(CONFIG_CPU_S3C2440) += irq.o
14 obj-$(CONFIG_CPU_S3C2440) += clock.o //配置2440的时钟进入模块
15 obj-$(CONFIG_S3C2440_DMA) += dma.o
如果我要取消s3c2440的时钟(当然这是必须要开的,只是举例)。&可以直接修改arch/arm/mach-s3c2440/Makefile&将obj-$( CONFIG_CPU_S3C2440) += clock.o改为
obj- += clock.o
如果你想编译成模块也可以修改成:
obj-m += clock.o
在这里&CONFIG_CPU_S3C2440的值默认是y,所以内核是要将时钟编译进内核的。也许有人会问,那我直接修改&CONFIG_CPU_S3C2440的值为m不就可以将时钟编译成模块了,何必修改Makefile这么麻烦呢?的确是这样,只要我们通过在&make menuconfig&的界面中配置后就能够改变&CONFIG_CPU_S3C2440的值。接下来看看如何实现。
二、在一般的编译内核时,我们都是
看看具体实现的步骤:
以下的执行环境是在PC机上,我使用的内核是linux-2.6.29:
2.1.进入内核目录
cd linux-2.6.29
2.2.&在driver目录下模拟一个名为test1驱动的文件夹
mkdir driver/test1
2.3.&在目录下随便些一个C文件,只要不报错。
vim test1.c
我的test1.c如下:
1 void foo()
2.4vim Makefile //在目录下编写一个简单的Makefile
Makefile文件编写如下:
obj-$(CONFIG_TEST1) += test1.o
CONFIG_TEST1是决定test1是否编译进内核或者编译成模块的。这就是通&过同一目录下的Kconfig来在配置界面中生成选项,由用户在make menuconfig中选择。
2.5所以还要同一目录下写一个Kconfig:
vim Kconfig
Kconfig修改如下:
menu "test1 driver here" //这是在图形配置显示的
config TEST1
bool "xiaobai test1 driver" //这同样也是在图形配置显示的
This is test1 //这个也是在图形配置显示的。
说白了,就是在图形配置的driver下多了一个配置选项,用户配置后将&CONFIG_TEST1的值存放在.config中,Makefile通过读取.config的去注&释版include/config/auto.conf读取到CONFIG_TEST的值,再进行编译。
但是,以上几步还不能达到目的,因为虽然在总Makefile中已经包含了&目录driver,但是driver目录的Makefile中并没有包含test目录。因此&需要在driver/Makefile中添加:
103 obj-$(CONFIG_PPC_PS3) += ps3/
104 obj-$(CONFIG_OF) += of/
105 obj-$(CONFIG_SSB) += ssb/
106 obj-$(CONFIG_VIRTIO) += virtio/
107 obj-$(CONFIG_STAGING) += staging/
108 obj-y += platform/
109 obj-$(CONFIG_TEST1) += test1/ //这是我添加的
虽然Makefile中已经包含了,但这样还是不行。因为当需要配置ARM时,&ARM结构下的Kconfig并没有包含test的Kconfig。这样的话就不会出现在&图形配置界面中,因此在arch/arm/Kconfig中添加:
1230 menu "Device Drivers" //要在Device Drivers这个选项里面添加
1232 source "drivers/base/Kconfig"
1234 source "drivers/connector/Kconfig"
。。。。。。。。
1330 source "drivers/test/Kconfig" //这是我添加的
1332 endmenu
大功告成!
这样,make menuconfig界面写的Driver Devices下就多了一个&"test1 friver here"的目录,里面有一个配置选项"xiaobai test1 driver"。
Kconfig文件的语法在documentation/kbuild/kconfig-language.txt文件中&有详细的讲解,上面我只是简单实现了一下,都是皮毛。
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
六.内核和模块的编译
编译内核很简单,只需要配置完毕后执行make命令,将指定的文件编译进内核
bzImage或者编译成模块。
make = make bzImage + make modules
因此如果值编译内核,即只编译配置文件中-y选项,可以直接用命令
make bzImage
如果值编译模块,即只编译配置文件中的-m选项,可以之直接使用命令
make modules
模块可以编译当然也可以清除,使用命令
make modules clean
如果只想单独编译一个模块,可以使用命令
make M=drivers/test/ modules //只单独编译drivers/test中的.ko
make M=drivers/test/ modules clean //清除
上面的是在内核目录下的操作,但当我写驱动时,我并不可能在内核目录下编
写,但我编译时却要依赖内核中的规则和Makefile,所以就有了以下的方法,
同时这也是一般的编写驱动时Makefile的格式。
指定内核Makefile并单独编译
make -C /root/linux-2.6.29 M=`pwd` module
make -C /root/linux-2.6.29 M=`pwd` module clean
//-C&指定内核Makefile的路径,可以使用相对路径。
//-M&指定要编译的文件的路径,同样课使用相对路径。
编译生成的模块可以指定存放的目录
make -C /root/linux-2.6.29 M=`pwd` modules_install INSTALL_MOD_PATH=/nfsroot
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
说了这么久估计都说糊涂了,其实我只是想表达一下内核编译时大体上究竟是怎么样的一个过程。
我以编译S3C2440的内核为例再说一遍:
1一般我们会想将一份S3C2440的默认配置拷贝到内核跟目录下并改名为.config。
2.make menuconfig
2.1、由总Makefile决定编译的体系结构(ARCH).&编译工具(CROSS_COMPILE),并知道需要进去哪些内核根下的哪些目录进行编译。
2.2、由arch/$(ARCH)/Makefile,决定arch/$(ARCH)下还有&的哪些目录和文件需要编译。
2.3、知道了需要编译的目录后,递归的进入哪些目录下,读取每一个Kconfig的信息,生成了图形配置的界面。
2.4、通过我们在图形配置界面中选项为[*]、[M]或者[]。
2.5、保存并退出配置,会根据配置生成一份新的配置文件.config,并在同时生成include/config/auto.conf(这是.config的去注释版)。文件里面保存着CONFIG_XXXX等变量应该取y还是取m。
3.1、根据Makefile包含的目录和配置文件的要求,进去个子目录进行编译,最后会在各子目录下&生成一个.o或者.a文件,然后总Makefile指定的连接脚本&arch/$(ARCH)/kernel/vmlinux.lds生成vmlinux,并通过&压缩编程bzImage,或者按要求在对应的子目录下编译成&模块。
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
阅读(...) 评论()君,已阅读到文档的结尾了呢~~
头文件及内核函数说明总结-linux设备驱动程序,rand函数头文件,swap函数头文件,system函数头文件,sleep函数头文件,abs函数头文件,max函数头文件,malloc函数头文件,strlen函数头文件,fill 函数 头文件
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
头文件及内核函数说明总结-linux设备驱动程序
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口您所在位置: &
&nbsp&&nbsp&nbsp&&nbsp
头文件及内核函数说明总结-linux设备驱动程序.docx 6页
本文档一共被下载:
次 ,您可全文免费在线阅读后下载本文档。
下载提示
1.本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
2.该文档所得收入(下载+内容+预览三)归上传者、原创者。
3.登录后可充值,立即自动返金币,充值渠道很便利
需要金币:250 &&
头文件及内核函数说明总结-linux设备驱动程序
你可能关注的文档:
··········
··········
linux设备驱动程序编写头文件及内核函数相关定义1、常用头文件:#include&linux/module.h&//必备,定义模块#include&linux/init.h&//必备,定义模块初始化#include&linux/fs.h&//定义注册函数rdgister_chrdev_region#include&linux/miscdevice.h&//定义杂项设备驱动misc#include&linux/moduleparam.h&//定义模块可以传递参数#include&linux/ioctl.h&//定义执行各种硬件控制的函数#include&linux/device.h&//定义总线设备bus_type#include&linux/slab.h&//定义内存管理的两个函数kmalloc、kfree,分配内存空间#include&linux/errno.h&//定义读写函数read、write有效的错误码#include&linux/err.h&//定义linuxkernel错误返回,使用错误返回等与err相关的定义与操作#include&linux/list.h&//定义内核链表#include&linux/mutex.h&//定义内核头文件采用互斥方式(初始化方法:DEFINE_MUTEX(name);或者void?mutex_init(struct?mutex?*lock);使用方法:void?mutex_lock?(struct?mutex?*lock);尝试得到互斥量,否则进入睡眠,不能被中断,否则会导致进程无法杀死。)staticstructfile_operationsled_dev_fops={//file_operations将驱动程序连接到设备编号 .owner
=THIS_MODULE,//必备,初始化owner成员 .unlocked_ioctl =leds_ioctl,}staticstructmiscdeviceled_dev={ .minor
=MISC_DYNAMIC_MINOR, .name
=DEVICE_NAME, .fops
=&led_dev_fops,//fops为指向file_operations结构的指针};2、结尾模块申明:module_init(xxx_init);定义加载内核函数insmodmodule_exit(xxx_exit);定义卸载内核函数rmmodMODULE_LICENSE(&GPL&);模块许可证申明MODULE_AUTHOR(&xxx&);模块编写作者MODULE_DESCRIPTION(&xxx&)模块用途描述MODULE_VERSION(&xxx&)模块版本描述MODULE_ALIAS(&xxx&)模块别名3、当前目录:#include&linux/***.h&是在linux-2.6.29/include/linux下面寻找源文件。#include&asm/***.h&是在linux-2.6.29/arch/arm/include/asm下面寻找源文件。#include&mach/***.h&是在linux-2.6.29/arch/arm/mach-s3c2410/include/mach下面寻找源文件。#include&plat/regs-adc.h&在linux-2.6.31_TX0\linux-2.6.31_TX2440A\arch\arm\plat-s3c\include\plat4、头文件总汇:#include&stdio.h&//标准输入输出#include&stdlib.h&//标准库#include&linux/init.h&//初始化头文件#include&linux/module.h&//最基本的文件,支持动态添加和卸载模块。HelloWorld驱动要这一个文件就可以了#include&linux/kernel.h&驱动要写入内核,与内核相关的头文件#include&linux/fs.h&//包含了文件操作相关struct的定义,例如大名鼎鼎的structfile_operations?????????//包含了structinode的定义,MINOR、MAJOR的头文件。#include&sys/ioctl.h
正在加载中,请稍后...博客访问: 233917
博文数量: 141
博客积分: 106
博客等级: 民兵
技术积分: 613
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: LINUX
原文地址: 作者:
在编写linux设备驱动程序的时候,如果在不参考已有驱动程序的情况下,我们该如何不多不少地用#include包含所需的头文件呢?&
下面,来通过一个实验来介绍。
运行环境:Source& Insight& @& Windows& xp
内核代码:Linux& 2.6.32
实验代码:& 简单ramblock实验
#define DEV_MAJOR 251
static struct gendisk *my_rmbk;
static struct request_queue *my_rq;
DEFINE_SPINLOCK(rmbk_lock);
#define RAMBLOCK_SIZE (1024*1024)
const struct block_device_operations rmbk_fops = {
.owner = THIS_MODULE,
static void do_rmbk_request(struct request_queue *q)
printk("Do_ramdisk_requestn");
static int ramdisk_init(void)
/* 注册块设备 */
register_blkdev(DEV_MAJOR, "ramdisk");
/* 分配gendisk结构体*/
my_rmbk = alloc_disk(16);
/* 为块设备准备一个请求队列 */
my_rq = blk_init_queue(do_rmbk_request, &rmbk_lock);
sprintf(my_rmbk, "ramdisk");
my_rmbk-&major = DEV_MAJOR;
my_rmbk-&first_minor = 0;
my_rmbk-&fops = &rmbk_fops;
my_rmbk-&queue = my_rq;
set_capacity(my_rmbk, RAMBLOCK_SIZE / 512);
/* 添加分区信息到内核列表 */
add_disk(my_rmbk);
static void ramdisk_exit(void)
del_gendisk(my_rmbk);
blk_cleanup_queue(my_rq);
put_disk(my_rmbk);
unregister_blkdev(DEV_MAJOR, "ramdisk");
module_init(ramdisk_init);
module_exit(ramdisk_exit);
MODULE_LICENSE("GPL");
上面是没有写#include语句的源代码,直接编译程序,看会报告那些函数未知&
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:6:& warning:& data& definition& has& no& type& or& storage& class
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:6:& warning:& type& defaults& to& 'int'& in& declaration& of& 'DEFINE_SPINLOCK'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:6:& warning:& parameter& names& (without& types)& in& function& declaration
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:10:& error:& variable& 'rmbk_fops'& has& initializer& but& incomplete& type
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:11:& error:& unknown& field& 'owner'& specified& in& initializer
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:11:& error:& 'THIS_MODULE'& undeclared& here& (not& in& a& function)
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:11:& warning:& excess& elements& in& struct& initializer
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:11:& warning:& (near& initialization& for& 'rmbk_fops')
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:& In& function& 'do_rmbk_request':
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:16:& error:& implicit& declaration& of& function& 'printk'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:& In& function& 'ramdisk_init':
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:22:& error:& implicit& declaration& of& function& 'register_blkdev'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:25:& error:& implicit& declaration& of& function& 'alloc_disk'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:25:& warning:& assignment& makes& pointer& from& integer& without& a& cast
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:28:& error:& implicit& declaration& of& function& 'blk_init_queue'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:28:& error:& 'rmbk_lock'& undeclared& (first& use& in& this& function)
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:28:& error:& (Each& undeclared& identifier& is& reported& only& once
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:28:& error:& for& each& function& it& appears& in.)
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:32:& error:& implicit& declaration& of& function& 'sprintf'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:32:& warning:& incompatible& implicit& declaration& of& built-in& function& 'sprintf'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:32:& error:& dereferencing& pointer& to& incomplete& type
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:33:& error:& dereferencing& pointer& to& incomplete& type
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:34:& error:& dereferencing& pointer& to& incomplete& type
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:35:& error:& dereferencing& pointer& to& incomplete& type
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:36:& error:& dereferencing& pointer& to& incomplete& type
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:38:& error:& implicit& declaration& of& function& 'set_capacity'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:41:& error:& implicit& declaration& of& function& 'add_disk'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:& In& function& 'ramdisk_exit':
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:50:& error:& implicit& declaration& of& function& 'del_gendisk'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:51:& error:& implicit& declaration& of& function& 'blk_cleanup_queue'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:52:& error:& implicit& declaration& of& function& 'put_disk'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:53:& error:& implicit& declaration& of& function& 'unregister_blkdev'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:& At& top& level:
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:58:& warning:& data& definition& has& no& type& or& storage& class
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:58:& warning:& type& defaults& to& 'int'& in& declaration& of& 'module_init'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:58:& warning:& parameter& names& (without& types)& in& function& declaration
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:59:& warning:& data& definition& has& no& type& or& storage& class
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:59:& warning:& type& defaults& to& 'int'& in& declaration& of& 'module_exit'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:59:& warning:& parameter& names& (without& types)& in& function& declaration
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:61:& error:& expected& declaration& specifiers& or& '...'& before& string& constant
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:61:& warning:& data& definition& has& no& type& or& storage& class
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:61:& warning:& type& defaults& to& 'int'& in& declaration& of& 'MODULE_LICENSE'
/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.c:61:& warning:& function& declaration& isn't a prototype
make[2]:& ***& [/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk/ramblock.o]& Error& 1
make[1]:& ***& [_module_/home/profiles/2440/rootfs/exps_wqkfsc/ramdisk]& Error& 2
make[1]:& Leaving& directory& `/home/profiles/2440/linux-2.6.32.2'
make:& ***& [all]& Error& 2
第6行 warning DECLARE_SPINLOCK
第10行 error rmbk_fops 为struct& block_device_operations
第11行 error .owner =& THIS_MODULE
第16行 error printk
第22行 error register_blkdev
第25行 error alloc_disk
第28行 error blk_init_queue、rmbk_lock
第32行 error sprintf
第32-36行 error 都是上面引起的连带错误
第38行 error set_capacity
第41行 error add_disk
第50行 error del_gendisk
第51行 error blk_cleanup_queue
第52行 error put_disk
第53行 error unregister_blkdev
第58-59行 warning module_init,module_exit的警告
第61行 error&warning MODULE_LICENSE发出的
先说明一下source& insight里面经常用到的两个快捷键
Jump& to& difinition(跳至定义处):& CTRL+=或者CTRL+左键单击关键词
Lookup& reference(查找引用):CTRL+\& 搜索关键词
DECLARE_SPINLOCK是一个宏,要Lookup& reference(查找引用):#define&& DECLARE_MUTEX
Spinlock_types.h& (e:\friendly2.6.32.2\include\linux):#define&& DEFINE_SPINLOCK(x) spinlock_t& x& =& __SPIN_LOCK_UNLOCKED(x)
包含:#define&& &linux/spinlock_types.h&
block_device_operations,Jump& to& difinition,跳到定义处
怎么查看这个文件的路径呢?
Project-&Add& and& Remove& Project& Files...-&右击被选中的文件-&Copy& List-&Copy& selected& item(s)
e:\friendly2.6.32.2\include\linux\Blkdev.h
包含:#include& &linux/blkdev.h&
THIS_MODULE,& 同样的,按住鼠标左键,单击这个词
路径:e:\friendly2.6.32.2\include\linux\Module.h
包含:#include& &linux/module.h&
Jump& to& difinition: printk
路径: e:\friendly2.6.32.2\include\linux\Kernel.h
包含:#include& &linux/kernel.h&
Jump& to& difinition: register_blkdev
路径: e:\friendly2.6.32.2\block\Genhd.c
包含:???
出现问题了,文件并不在include目录或者子目录中,包含这个文件也没用,而我们用Jump& to& difinition也只能跳转到Genhd.c
出现int& register_blkdev(unsigned& int& major,& const& char& *name)
这个时候就需要命令Lookup& reference(查找引用)。并且搜索的词也是关键,我们需要搜索这个函数的声明,就需要尽量包含整个函数声明的语句。
如int& register_blkdev(unsigned& int& major,& const& char& *name)这整段话搜索的话,很可能不成功,因为包含了变量的名字major,& name,不一定能匹配到。
我们应该搜索如"register_blkdev(unsigned int"或者"register_blkdev("这样的关键字,那么就试一试吧。
Fs.h& (e:\friendly2.6.32.2\include\linux):extern& int& register_blkdev(unsigned& int,& const& char& *);
Genhd.c& (e:\friendly2.6.32.2\block):int& register_blkdev(unsigned& int& major,& const& char& *name)
找到了e:\friendly2.6.32.2\include\linux\Fs.h
那我们就包含#include& &linux/fs.h&
Jump& to& difinition: alloc_disk
路径: e:\friendly2.6.32.2\block\Genhd.c
找到:struct& gendisk& *alloc_disk(int& minors)
Lookup& reference关键字:alloc_disk(int
Genhd.c& (e:\friendly2.6.32.2\block):struct& gendisk& *alloc_disk(int& minors)
Genhd.h& (e:\friendly2.6.32.2\include\linux):extern& struct& gendisk& *alloc_disk(int& minors);
包含:#include& &linux/genhd.h&
我们可以在这个文件里看看,应该和一般的硬盘操作有关的函数都在里面,可以找到
set_capacity、add_disk、del_gendisk、put_disk
Jump& to& difinition: blk_init_queue
路径: e:\friendly2.6.32.2\block\Blk-core.c
找到:struct& request_queue& *blk_init_queue(request_fn_proc& *rfn,& spinlock_t& *lock)
Lookup& reference关键字:blk_init_queue(request_fn_proc
Blk-core.c& (e:\friendly2.6.32.2\block):struct& request_queue& *blk_init_queue(request_fn_proc& *rfn,& spinlock_t& *lock)
Blkdev.h& (e:\friendly2.6.32.2\include\linux):extern& struct& request_queue& *blk_init_queue(request_fn_proc& *,& spinlock_t& *);
包含:#include& &linux/blkdev.h&,这里还可以找到blk_cleanup_queue
rmbk_lock,第6行已解决
Jump& to& difinition: sprintf
路径: e:\friendly2.6.32.2\lib\Vsprintf.c
找到:int& sprintf(char& *& buf,& const& char& *fmt,& ...)
Lookup& reference关键字:sprintf(char& *& buf
Kernel.h& (e:\friendly2.6.32.2\include\linux):extern& int& sprintf(char& *& buf,& const& char& *& fmt,& ...)
Vsprintf.c& (e:\friendly2.6.32.2\lib):int& sprintf(char& *& buf,& const& char& *fmt,& ...)
包含:#include& &linux/kernel.h&,其实和printk在一个文件里面
上面已解决
set_capacity,第25行已解决
add_disk,第25行已解决
del_gendisk,第25行已解决
第51行 error blk_cleanup_queue
put_disk,第25行已解决
unregister_blkdev,第28行已解决
Jump& to& difinition: module_init是找不到的,我们知道它是一个宏
所以只能Lookup& reference关键字:#define&& module_init
Init.h& (e:\friendly2.6.32.2\include\linux):#define&& module_init(x) __initcall(x);
Init.h& (e:\friendly2.6.32.2\include\linux):#define&& module_init(initfn)
包含:#include& &linux/init.h&,& module_exit也包含在里面
同样的只能Lookup& reference关键字:MODULE_LICENSE
Module.h& (e:\friendly2.6.32.2\include\linux):#define&& MODULE_LICENSE(_license)& MODULE_INFO(license,& _license)
Nand_ecc.c& (e:\friendly2.6.32.2\drivers\mtd\nand):#define&& MODULE_LICENSE(x) /* x */
Pq.h& (e:\friendly2.6.32.2\include\linux\raid):#define&& MODULE_LICENSE(licence)
包含:#include& &linux/module.h&
添加上头文件
#include &linux/spinlock_types.h&
#include &linux/blkdev.h&
#include &linux/module.h&
#include &linux/kernel.h&
#include &linux/fs.h&
#include &linux/genhd.h&
#include &linux/init.h&
再次编译,Finished!
17:18&发表于百度空间,今搬至CU。
阅读(554) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。

我要回帖

更多关于 星纪元官网 的文章

 

随机推荐