Chinaunix首页 | 论坛 | 博客
  • 博客访问: 474446
  • 博文数量: 1958
  • 博客积分: 44693
  • 博客等级: 大将
  • 技术积分: 22125
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-29 15:19
文章分类

全部博文(1958)

文章存档

2012年(560)

2011年(1398)

分类: LINUX

2011-04-20 09:19:41

busybox下mdev的使用以及mdev.conf的规则配置


mdev是busybox下精简版的udev,适合在嵌入式系统下管理设备使用

mdev会把所有的设备都动态创建在/dev/目录下,比如有些程序使用dev目录子目录下设备名,就需要修改程序,比较麻烦,当然也可以在mdev运行之后,手工创建目录,然后再做ln的链接

这里有人作出了更好的脚本处理机制:

  1. On Wed, 2007-05-02 at 17:54 -0400, Mike Frysinger wrote:
  2. > there are a few common/important set of device nodes that only work when in
  3. > the proper subdirectory ... for example, all of ALSA userland requires the
  4. > sound nodes to be in /dev/snd/ and all of the input device nodes need to be
  5. > in /dev/input/
  6. >
  7. > we're using the attached patch by Sonic Zhang in our Blackfin distribution ...
  8. > it simply changes the syntax from:
  9. > <device regex> <uid>:<gid> <octal perms> [command]
  10. > to:
  11. > <device regex> <uid>:<gid> <octal perms> [subdir] [<@|$|*> command]

  12. Sometimes it is good to be able to rename the device itself too. For
  13. example, zapctl should go to zap/ctl and not zap/zapctl

  14. What about this syntax:
  15. <device regex> <uid>:<gid> <octal perms> [subdir [dest]] [<@|$|*> command]

  16. or:
  17. <device regex> <uid>:<gid> <octal perms> [[subdir/][dest]] [<@|$|*> command]

  18. where this happens if dest is specified:

  19. if last char in param is '/' then
  20.     mkdir -p $param
  21. else
  22.     mkdir -p $(dirname $param)
  23.     MDEV=$(basename $param)
  24. fi
  25. create $MDEV

  26. > the patch isnt 100% correct right now ... i'd like to see what ideas other
  27. > people have

  28. I use a script, /lib/mdev/subdir_dev:
  29. 脚本 /lib/mdev/subdir_dev
  30. #!/bin/sh
  31. #这是个用于将设备移动到$1/subdir 的脚本
  32. # scripts that moves devices to the $1/ subdir.

  33. if [ "$ACTION" = remove ] ; then
  34.     mv $1/$MDEV $MDEV
  35.     rmdir $1 2>/dev/null
  36. else
  37.     mkdir -p $1
  38.     mv $MDEV $1/$2
  39. fi

  40. and the mdev.conf looks like this:

  41. # alsa sound devices
  42. pcm.*        root:audio 0660    */lib/mdev/subdir_dev snd
  43. ...

  44. # zaptel devices
  45. zapctl        root:dialout 0660 */lib/mdev/subdir_dev zap ctl
  46. zaptimer    root:dialout 0660 */lib/mdev/subdir_dev zap timer
  47. ...


  48. I copied all my mdev stuff here:
  49. http://dev.alpinelinux.org/~ncopa/mdev/

  50. (I have a script that will differ usb disks from scsi disks and that
  51. will load modules for usb devices (like webcams)
  52. 我有一个脚本,可以区分usb 磁盘和 scsi 磁盘,并且为usb设备,比如webcams 加载模块

  53. It would be very nice if mdev could handle subdirs and renaming devices
  54. without depending on external scripts.
  55. 如果mdev可以处理subdirs  和 不依赖于外部 脚本而 重命名设备,那就更好了。

  56. Natanael Copa

再贴上mdev的使用说明

-------------------------------------------

MDEV 入门(转)

Busybox-1.7.0/docs/mdev.txt
翻译:tekkamanninja Email:
 - 1 -

-------------
MDEV Primer
MDEV 入门
-------------
For those of us who know how to use mdev, a primer might seem lame. For
这份文档对于那些知道如何使用mdev 的人看来可能有些肤浅。
everyone else, mdev is a weird black box that they hear is awesome, but can't
但对于其他人,mdev 可能是一个神秘的黑匣子,以至让人敬畏。
seem to get their head around how it works. Thus, a primer.
而这份文档又不足以让他们知道mdev 是如何工作的。 因此,这是一份入门文档。
-----------
Basic Use
基本使用方法
-----------
Mdev has two primary uses: initial population and dynamic updates. Both
mdev 有两个主要的应用:初始化对象和动态更新。
require sysfs support in the kernel and have it mounted at /sys. For dynamic
两个应用都需要内核 sysfs 的支持,且必须挂载到 /sys 。为了实现动态更新,
updates, you also need to have hotplugging enabled in your kernel.
你还必须在内核配置时增加热插拔支持(hotplugging)。
Here's a typical code snippet from the init script:
以下是系统初始化脚本中一个典型的使用mdev 的代码片段:
    [1] mount -t sysfs sysfs /sys
    [2] echo /bin/mdev > /proc/sys/kernel/hotplug
    [3] mdev -s

Of course, a more "full" setup would entail executing this before the previous
当然,一个对mdev 更完整的安装还必须在以上代码片段前执行下面的命令:
code snippet:
    [4] mount -t tmpfs mdev /dev
    [5] mkdir /dev/pts
    [6] mount -t devpts devpts /dev/pts

The simple explanation here is that [1] you need to have /sys mounted before
简单说明一下上面的代码:[1]你必须在执行mdev 前挂载 /sys 。
executing mdev. Then you [2] instruct the kernel to execute /bin/mdev whenever
随后你 [2] 命令内核在增删设备时执行 /bin/mdev ,
a device is added or removed so that the device node can be created or
使设备节点文件会被创建和删除。
destroyed. Then you [3] seed /dev with all the device nodes that were created
最后你 [3] 设置mdev,让它在系统启动时创建所有的设备节点。
while the system was booting.
For the "full" setup, you want to [4] make sure /dev is a tmpfs filesystem
而对mdev 更完整的安装,你必须[4]确保 /dev 是 tmpfs 文件系统
(assuming you're running out of flash). Then you want to [5] create the
(假设文件系统在 flash 外运行)。 而且你必须 [5] 创建

-------------
MDEV Config (/etc/mdev.conf)
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.
如果你的系统需要一些比默认的 root/root 660 更多的权限,
你可以使用 mdev 的可选配置文件,以控制设备节点的 所有者 和 权限。

The file has the format:
这个文件的格式如下:
    :
For example:
例如:
    hd[a-z][0-9]* 0:3 660
The config file parsing stops at the first matching line. If no line is
这个配置文件在第一个匹配行处停止解析。 如果没有匹配行,
matched, then the default of 0:0 660 is used. To set your own default, simply
那么就使用默认的 0:0 660 。 你也可以通过在最后创建如下的全匹配
create your own total match like so:
行,来设置你自己的默认设置:
    .* 1:1 777
If you also enable support for executing your own commands, then the file has
如果你想 mdev 在找到匹配行时可以执行自定义的命令,那么文件格式如下:
the format:
    : [<@|$|*> ]
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.
    * 在创建设备节点后和删除设备节点前都运行命令。
The command is executed via the system() function (which means you're giving a
这些命令是通过系统函数(system())执行的(也就是说你在对shell 下命令)
command to the shell), so make sure you have a shell installed at /bin/sh.
,所以请确保你已在 /bin/sh 安装了shell。
For your convenience, the shell env var $MDEV is set to the device name. So if
为了方便,shell 的环境变量 $MDEV 会被设置成设备名。 例如
the device 'hdc' was matched, MDEV would be set to "hdc".
mdev 解析到设备 'hdc' 匹配,MDEV 将会被设置为 "hdc"。

----------
FIRMWARE
固件
----------
Some kernel device drivers need to request firmware at runtime in order to
有些设备驱动程序在运行时,为了正确的初始化设备,需要上传固件。
properly initialize a device. Place all such firmware files into the
请将所有的固件文件放入
/lib/firmware/ directory. At runtime, the kernel will invoke mdev with the
/lib/firmware/ 目录。 在运行时,内核将会按固件文件名调用 mdev ,
filename of the firmware which mdev will load out of /lib/firmware/ and into
之后 mdev 会通过 sysfs 接口将固件从 /lib/firmware/
the kernel via the sysfs interface. The exact filename is hardcoded in the
装载到内核。 确定的文件名被固化在内核中,
kernel, so look there if you need to want to know what to name the file in
如有必要,你必须知道如何在用户空间命名这个文件。
userspace.


阅读(1099) | 评论(0) | 转发(1) |
0

上一篇:ldconfig

下一篇:【科普】UBI文件系统简介

给主人留下些什么吧!~~