USB驱动移植及mdev热插拔的实现

来源:互联网 发布:手机换主题软件 编辑:程序博客网 时间:2024/06/05 19:45
基于之前移植的的内核,把驱动分别进行移植,这篇主要进行USB驱动移植,并阐明与热插拔相关的mdev,在2.6.30内核中,USB驱动已经比较完善了,移植是只要简单对配置单进行修改即可,添加的内容如下:

Device Drivers  --->

       SCSI device support  --->

              SCSI device support

              SCSI disk support  看配置单的help,如果套采用USB存储设备,应当选择这项

       HID Devices  --->

              Generic HID support

              USB Human Interface Device (full HID) support   添加USB人机交互接口设备支持

USB support  --->   该菜单下有很多USB相关设置,但这里先只让USB可以识别U盘,其他功能需要时添加

              Support for Host-side USB  支持USB主机,这是使用USB的前提

              USB announce new devices  让USB声明设备的id,生产厂商编号等

              USB device filesystem   支持USB文件系统,使用户可以直接访问USB设备

OHCI HCD support  OHCI支持,也就是支持USB1.0,我的开发板是1.0,嵌入式

中一般采用1.0

              USB Mass Storage support 支持USB大容量存储设备

这样配置完成,就可以使用USB了。而且配合之前制作的文件系统,可以支持热插拔。当插上U盘后,系统会自动挂载U盘到/mnt/udisk/目录下。

 

下面讲一下如何利用busybox的mdev实现热插拔。主要参看busybox的docs/mdev.txt即可,里面给出了详细的说明。这里只说明重要的几点。(我用的是busybox 1.13.0)

Here's a typical code snippet from the init script:

[0] mount -t proc proc /proc

[1] mount -t sysfs sysfs /sys

[2] echo /sbin/mdev > /proc/sys/kernel/hotplug (这里注意,原文是/bin/mdev,有问题)

[3] mdev –s

这一段内容,给出了我们在初始化脚本中应当添加的内容,即在文件系统的/etc/init.d/rcS脚本中添加的内容。所作的工作主要是挂载了procfs和sysfs,然后将/bin/mdev/的输出信息重定向到/proc/sys/kernel/hotplug,用以通报新设备插入的信息。

Alternatively, without procfs the above becomes:

[1] mount -t sysfs sysfs /sys

[2] sysctl -w kernel.hotplug=/bin/mdev

[3] mdev –s

或者你可以不采用procfs,那么上面的代码要做修改。

Of course, a more "full" setup would entail executing this before the previous

code snippet:

[4] mount -t tmpfs -o size=64k,mode=0755 tmpfs /dev

[5] mkdir /dev/pts

[6] mount -t devpts devpts /dev/pts

另外,更加完整的设置需要在上面的代码之前完成这些操作。挂载tampfs和devpts。

这样,初始化脚本的内容就完成了。

下面再说一个mdev相关的配置文件/etc/mdev.conf

Mdev has an optional config file for controlling ownership/permissions of device nodes if your system needs something more than the default root/root 660 permissions.

也就是说,这个文件不是必需的,只是当你不采用默认的权限时进行设置。

这里不再过多的分别给出这个文件中每一部分的讲解,只给出最后的文件中的语句格式,具体的可以查看/docs/mdev.txt。

<device regex> <uid>:<gid> <octal permissions> [=path] [@|$|*<command>]

或者

<device regex> <uid>:<gid> <octal permissions> [>path] [@|$|*<command>]

其中Path和command是可选的,command前的符号解释为

The special characters have the meaning:

       @ Run after creating the device.

       $ Run before removing the device.

* Run both after creating and before removing the device.

以我文件系统采用的语句为例,说明一下:

sd[a-z]*[0-9] 0:0 0660 @(mount -t vfat -o iocharset=utf8 /dev/$MDEV /mnt/udisk)

sd[a-z]*[0-9] 0:0 0660 *(umount /mnt/udisk)

设备节点名称为sd[a-z]结合数字0-9,uid和gid均为0,即root/root,权限为660,即本用户具有读写权限,同组用户具有读写权限,其他组用户没有权限。第一句中

@(mount -t vfat -o iocharset=utf8 /dev/$MDEV /mnt/udisk)

在创建设备节点后,执行挂载/dev/$MDEV到/mnt/udisk的操作,采用的字符格式为utf8,其中,$MDEV的解释为

For your convenience, the shell env var $MDEV is set to the device name. So if the device "hdc" was matched, MDEV would be set to "hdc".

也就是代表了dev目录下设备节点的名称。

第二句sd[a-z]*[0-9] 0:0 0660 *(umount /mnt/udisk)

在删除设备前执行卸载操作。

完成这些操作,就可以支持热插拔操作了。整理一下只有两步:

1. 在/etc/init.d/rcS中添加相应内容;

2. 填写mdev.conf文件。


原创粉丝点击