linux /etc/mdev.conf配置詳解

採用以下的實例mdev配置寫法在我的arm 板子上並沒有完全奏效,實驗發現我的版本的mdev只會匹配第一條DEVNAME並執行他的規則,匹配第一個後就不在去檢查後面的規則,比如@@兩個對於mmcblk0p1的規則永遠只執行第一個

touch /dev/mdev.log 會保存mdev的log ,對比busybox中的源碼提示rule matched, line -1(沒有查到命令)

最終的mdebv.conf

mmcblk[0-9]p[0-9] 0:0 666 */etc/hotplug/sdcard_hotplug $ACTION

#!/bin/sh
if [ $1 == "add" ]; then
echo "acttion = $ACTION dev= $MDEV" >> /mnt/tt.log
mkdir /mnt/sdcard
mount /dev/mmcblk[0-9]p[0-9] /mnt/sdcard
elif [ $1 == "remove" ]; then
echo "acttion = $ACTION dev= $MDEV" >> /mnt/tt.log
umount -l /mnt/sdcard
rm /mnt/sdcard -rf
fi

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

mdev是busybox下的udev的精簡版,適合在嵌入式系統下管理設備

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

這裏有人作出了更好的腳本處理機制:

http://lists.busybox.net/pipermail/busybox/2007-May/027309.html

再貼上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:
這個文件的格式如下:
    <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".
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.

# 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/hotplug.sh
sda1            0:0     0600    =udisk   * /bin/hotplug.sh
vntwpa          1:1     777              * /bin/ltls.sh  //$MDEV 參數 爲"usb-wifi"vntwpa  執行腳本ltls.sh
# .*            1:1     777              * /bin/ltls.sh

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

[root@FriendlyARM /mnt]# cat ltls.sh
#!/bin/sh

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

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

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


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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章