mdevbusybox下的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 classblock下也會變化


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


 



 



http://dev.firnow.com/course/6_system/linux/Linuxjs/20091121/183116.html


 

arrow
arrow
    全站熱搜

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