在Linux操作系统中,硬件驱动程序中实现对硬件直接操作,而用户空间,通过通用的系统调用接口(open()
打开相应的驱动设备,ioctl()控制相应的功能等),实现对硬件操作,应用程序没有直接操作底层设备,
通过posix标准,应用程序的系统调用往往是被规定和限值,用户只能通过规定的接口实现对底层硬件的操作,
导致了应用程序在类UINIX操作系统具有非常好的可移植性。大概关系如下:
 
	Linux操作系统对于所有的硬件都是当做一个文件来操作:一切设备皆文件。Linux设备文件一般分为字符设备,
块设备,网络设备。在Linux系统中,除了网络设备之外,所有的设备都被映射到Linux的文件系统中。
常见驱动加载模式一般通过加载“驱动模块文件(.ko)”。
1.优点:缩小内核体积,加载/卸载驱动模块方便。
2.用处:一般一个驱动模块功能单独编译成一个.ko驱动文件,在需要使用改驱动功能时,再进行加载(insmod *****.ko),当不再使用该功能时,可以随时卸载(rmmod ****.ko)。无论时加载还是卸载都要注意驱动之间的依赖关系,否则有可能操作失败。
3.指令 : insmod *.ko 加载ko驱动rmmod *.ko 卸载ko驱动lsmod 查看所有已添加的驱动
# include  <linux/init.h>   # include  <linux/module.h>   # include  <linux/types.h>   # include  <linux/fs.h>   # include  <linux/proc_fs.h>   # include  <linux/device.h> static  struct  file_operations  ms41908_fops =  { . owner      			=  THIS_MODULE, . unlocked_ioctl			=  ms41908_ioctl, . open					=  ms41908_open, . release				=  ms41908_close
} ; static  struct  miscdevice  ms41908_dev =  { . minor					=  MISC_DYNAMIC_MINOR, . name					=  "gms41908" , 		. fops					=  & ms41908_fops, 
} ; 
long  ms41908_ioctl ( struct  file  * file,  unsigned  int  cmd,  unsigned  long  arg) 
{ 
. . . . . . 
} static  int   ms41908_init ( void ) 	
{ 
. . . . . . 
} 
static  void  __exit ms41908_exit ( void ) 	
{ 
. . . . . . . 
} 
module_init ( ms41908_init) ; 
module_exit ( ms41908_exit) ; 
MODULE_LICENSE ( "GPL" ) ; 交叉编译:开发板的编译环境应该与本机编译环境相同,不然可能会无法正确加载驱动。