mdev會把所有的設備檔都動態地創建在/dev/目錄下,如果程式使用dev目錄子目錄下的設備,就必須修改程式,比較麻煩,當然也可以在mdev運行之後,手工創建子目錄,然後再用 ln -s 做設備檔的軟鏈結




MDEV 入門()

翻譯:tekkamanninja Email - 1 -

MDEV Primer
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
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.
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)
配置 (/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:
    <device regex> <uid>:<gid> <octal permissions>
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:
    <device regex> <uid>:<gid> <octal permissions> [<@|$|*> <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.
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".
解析到設備 'hdc' 匹配,MDEV 將會被設置為 "hdc"

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
目錄。 在運行時,內核將會按固件檔案名調用 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


# cat /etc/mdev.conf

# system all-writable devices
full            0:0     0666
null            0:0     0666
ptmx            0:0     0666
random          0:0     0666
tty             0:0     0666
zero            0:0     0666

# console devices
tty[0-9]*       0:5     0660
vc/[0-9]*       0:5     0660

# serial port devices
s3c2410_serial0 0:5     0666    =ttySAC0
s3c2410_serial1 0:5     0666    =ttySAC1
s3c2410_serial2 0:5     0666    =ttySAC2
s3c2410_serial3 0:5     0666    =ttySAC3

# loop devices
loop[0-9]*      0:0     0660    =loop/

# i2c devices
i2c-0           0:0     0666    =i2c/0
i2c-1           0:0     0666    =i2c/1

# frame buffer devices
fb[0-9]         0:0     0666

# input devices
mice            0:0     0660    =input/
mouse.*         0:0     0660    =input/
event.*         0:0     0660    =input/
ts.*            0:0     0660    =input/

# rtc devices
rtc0            0:0     0644    >rtc
rtc[1-9]        0:0     0644

# misc devices
mmcblk0p1       0:0     0600    =sdcard  */bin/
sda1            0:0     0600    =udisk   * /bin/
vntwpa          1:1     777              * /bin/  //
$MDEV 參數 為"usb-wifi" vntwpa  執行腳本
# .*            1:1     777              * /bin/

1-1.*           1:1     777              * /bin/llll

[root@FriendlyARM /mnt]# cat

echo $MDEV    >  /dev/ttySAC0  // 有變化的設備 會在/dev產生 相應設備 如:1-1.1 /sys classblock下也會變化

echo $ACTION    >  /dev/ttySAC0 // 設備狀態"remove"   "add"

#echo  - n  "enter your name:"
#read name

#echo "ltls  "  > /dev/ttySACO
if [ "$MDEV" = "vntwpa" ];then
        echo "going to vntwpa " > /dev/ttySAC0



    立你斯 發表在 痞客邦 留言(0) 人氣()