Linux驱动学习(2) 从usb驱动到input子系统4

替换内核USB鼠标驱动

(一)开发环境介绍
1.使用win7_64的笔记本搭建Virtualbox虚拟机,安装Ubuntu16.04系统作为编译环境。
为了减少内核版本和应用程序的影响,此章采用《Linux内核学习(3)最小系统制作》中搭建的最小系统linux4.15.0+rootfs(Busybox)环境,使用虚拟机启动此最小系统。

(二)屏蔽内核驱动
1.这里必须明白内核如何使用USB鼠标驱动,在内核的“\linux-source-4.15.0\drivers\hid\usbhid\Kconfig”文件中有如下描述

config USB_HID
	tristate "USB HID transport layer"
	default y
	depends on USB && INPUT
	select HID
	---help---
	  Say Y here if you want to connect USB keyboards,
	  mice, joysticks, graphic tablets, or any other HID based devices
	  to your computer via USB, as well as Uninterruptible Power Supply
	  (UPS) and monitor control devices.

	  You can't use this driver and the HIDBP (Boot Protocol) keyboard
	  and mouse drivers at the same time. More information is available:
	  <file:Documentation/input/input.txt>.

	  If unsure, say Y.

	  To compile this driver as a module, choose M here: the
	  module will be called usbhid.

comment "Input core support is needed for USB HID input layer or HIDBP support"
	depends on USB_HID && INPUT=n

这段内容表面,如果要使用自定义的USB鼠标驱动,必须不配置USB_HID,注意这里不能选择HID-GENERIC,即使不编译HID-GENERIC内核也不会将USB鼠标识别为usb总线上的设备。
另外内核中有写好的USB鼠标驱动,代码位置为“\linux-source-4.15.0\drivers\hid\usbhid\usbmouse.c”,但是默认情况下usbmouse并不会编译,在menuconfig中也不会显示,在kconfig中有如下描述:

menu "USB HID Boot Protocol drivers"
	depends on USB!=n && USB_HID!=y && EXPERT

config USB_KBD
	tristate "USB HIDBP Keyboard (simple Boot) support"
	depends on USB && INPUT
	---help---
	  Say Y here only if you are absolutely sure that you don't want
	  to use the generic HID driver for your USB keyboard and prefer
	  to use the keyboard in its limited Boot Protocol mode instead.

	  This is almost certainly not what you want.  This is mostly
	  useful for embedded applications or simple keyboards.

	  To compile this driver as a module, choose M here: the
	  module will be called usbkbd.

	  If even remotely unsure, say N.

config USB_MOUSE
	tristate "USB HIDBP Mouse (simple Boot) support"
	depends on USB && INPUT
	---help---
	  Say Y here only if you are absolutely sure that you don't want
	  to use the generic HID driver for your USB mouse and prefer
	  to use the mouse in its limited Boot Protocol mode instead.

	  This is almost certainly not what you want.  This is mostly
	  useful for embedded applications or simple mice.

	  To compile this driver as a module, choose M here: the
	  module will be called usbmouse.

	  If even remotely unsure, say N.

endmenu

这段配置说明,如果要显示USB HID Boot Protocol drivers,USB配置不为n,USB_HID不为y,必须要有EXPERT配置。在原来配置情况下,显示为:
在这里插入图片描述
在这里插入图片描述
所以如果要显示此菜单的话,需要删掉EXPERT,使配置为:

menu "USB HID Boot Protocol drivers"
	depends on USB!=n && USB_HID!=y

然后选择USB_HID配置为模块,然后menuconfig配置如下:
在这里插入图片描述在这里插入图片描述

这样内核就会将鼠标编译进内核,我们可以测试下,在每个函数下打个log,例如
在这里插入图片描述
这样编译完内核后就可以重启了,在virtualbox中选择设备-USB-指定USB鼠标,会有如下打印。
在这里插入图片描述
可以看到probe函数已经被调用,表面鼠标驱动的确载入成功了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值