📄 linux设备驱动程序学习(15)-linux设备模型(热插拔、mdev 与 firmware) - linux设备驱动程序 - tekkaman ninja.htm
字号:
style="COLOR: rgb(0,0,204)">/sculld*/dev
产生的<FONT
face="Courier New">设备节点文件,那么设备节点文件就会被错误地创建为块设备。</FONT></SPAN></FONT></FONT></P>
<P><SPAN style="COLOR: rgb(0,0,204)"><FONT
color=#0000ff>我认为这个bug的解决办法有如下两种:</FONT></SPAN></P>
<P><FONT color=#660099><SPAN
style="COLOR: rgb(0,0,204)">(1)在你写驱动的时候,只在/sys/class
和 /sys/block 中的类</SPAN><SPAN
style="COLOR: rgb(0,0,204)">设备目录中存在包含设备号的“dev”属性文件。(你无法保证被人的驱动会这么做)</SPAN></FONT></P>
<P><SPAN style="COLOR: rgb(0,0,204)"><FONT
color=#0000ff>(2)修正mdev源码:</FONT></SPAN></P>
<P><SPAN style="COLOR: rgb(0,0,204)"><FONT
color=#0000ff>修改/busybox-1.9.0/util-linux/mdev.c文件的第328行:</FONT></SPAN><BR></P>
<TABLE style="BORDER-COLLAPSE: collapse"
borderColor=#999999 cellSpacing=0 cellPadding=0
width="95%" bgColor=#f1f1f1 border=1>
<TBODY>
<TR>
<TD>
<P
style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN
style="COLOR: rgb(0,0,0)"><SPAN
style="COLOR: rgb(0,0,255)">if</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">!</SPAN><SPAN
style="COLOR: rgb(255,0,0)">strcmp</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN>action<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(255,0,255)">"remove"</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><BR>
make_device<SPAN
style="COLOR: rgb(0,0,204)">(</SPAN>temp<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> 1<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN></SPAN></CODE></P>
<P
style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN
style="COLOR: rgb(0,0,0)"><SPAN
style="COLOR: rgb(0,0,255)">else</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">if</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">!</SPAN><SPAN
style="COLOR: rgb(255,0,0)">strcmp</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN>action<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(255,0,255)">"add"</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">{</SPAN><BR>
<SPAN style="COLOR: rgb(255,1,2)">if
(env_path[2]=='l') make_device(temp,0);
//tekkamanninja</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">if</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN>ENABLE_FEATURE_MDEV_LOAD_FIRMWARE<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><BR> load_firmware<SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(255,0,0)">getenv</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(255,0,255)">"FIRMWARE"</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> temp<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,204)">}</SPAN></SPAN></CODE></P></TD></TR></TBODY></TABLE>
<P><SPAN style="COLOR: rgb(0,0,204)"><FONT
color=#0000ff>也就是在增加设备节点文件之前检查</FONT></SPAN><SPAN
style="COLOR: rgb(0,0,204)"><FONT
color=#0000ff>/sys/目录下的</FONT></SPAN><SPAN
style="COLOR: rgb(0,0,204)"><FONT
color=#0000ff>路径是否为/c<SPAN
style="COLOR: rgb(255,1,2)">l</SPAN>ass和/b<SPAN
style="COLOR: rgb(255,1,2)">l</SPAN>ock(通过检查路径字符串的第3个字符是否为‘l’)。<BR></FONT></SPAN></P>
<P><SPAN style="COLOR: rgb(0,0,204)"><FONT
color=#0000ff>本人推荐第二种做法!</FONT></SPAN></P></TD></TR></TBODY></TABLE></DIV>
<DIV> </DIV>
<DIV><FONT color=#0000ff
size=3><STRONG>mdev使用</STRONG></FONT></DIV>
<DIV>mdev的使用在busybox中的mdev.txt文档已经将得很详细了。但作为例子,我简单讲讲我的使用过程:</DIV>
<DIV> </DIV>
<DIV>(1)在编译时加上对mdev的支持(我是使用的是busybox1.9.0):<BR>
Linux System Utilities
---> <BR>
[*]
mdev
<BR>
[*] Support
/etc/mdev.conf <BR>
[*] Support command
execution at device addition/removal <BR></DIV>
<DIV> </DIV>
<DIV>(2)在启动时加上使用mdev的命令:<BR></DIV>
<DIV>我在自己创建的根文件系统(nfs)中的/linuxrc文件中<SPAN
style="COLOR: rgb(255,1,2)">添加</SPAN>了如下指令:<BR>
<TABLE style="BORDER-COLLAPSE: collapse"
borderColor=#999999 cellSpacing=0 cellPadding=0
width="95%" bgColor=#f1f1f1 border=1>
<TBODY>
<TR>
<TD>
<P
style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN
style="COLOR: rgb(0,0,0)"><SPAN
style="COLOR: rgb(0,0,204)">#</SPAN>挂载<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>sys为sysfs文件系统<BR> echo
<SPAN
style="COLOR: rgb(255,0,255)">"----------mount
/sys as
sysfs"</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>bin<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>mount <SPAN
style="COLOR: rgb(0,0,204)">-</SPAN>t tmpfs mdev
<SPAN style="COLOR: rgb(0,0,204)">/</SPAN>dev
<BR> <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>bin<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>mount <SPAN
style="COLOR: rgb(0,0,204)">-</SPAN>t sysfs
sysfs <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>sys<BR> echo
<SPAN
style="COLOR: rgb(255,0,255)">"----------Starting
mdev......"</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>bin<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>echo <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN><SPAN
style="COLOR: rgb(255,1,2)">sbin</SPAN><SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>mdev <SPAN
style="COLOR: rgb(0,0,204)">></SPAN> <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>proc<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>sys<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>kernel<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>hotplug<BR> mdev
<SPAN style="COLOR: rgb(0,0,204)">-</SPAN>s
</SPAN></CODE></P></TD></TR></TBODY></TABLE>注意:是<CODE><SPAN
style="COLOR: rgb(0,0,0)"><SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>bin<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>echo <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN><SPAN
style="COLOR: rgb(255,1,2)">sbin</SPAN><SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>mdev <SPAN
style="COLOR: rgb(0,0,204)">></SPAN> <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>proc<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>sys<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>kernel<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>hotplug,<SPAN
style="COLOR: rgb(255,1,2)">并非</SPAN></SPAN></CODE><CODE><SPAN
style="COLOR: rgb(0,0,0)"><SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>bin<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>echo <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN><SPAN
style="COLOR: rgb(255,1,2)">bin</SPAN><SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>mdev <SPAN
style="COLOR: rgb(0,0,204)">></SPAN> <SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>proc<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>sys<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>kernel<SPAN
style="COLOR: rgb(0,0,204)">/</SPAN>hotplug。<SPAN
style="COLOR: rgb(0,1,255)">busybox的文档有错!!</SPAN></SPAN></CODE><BR><BR></DIV>
<DIV>(3)在你的驱动中加上对类设备接口的支持,并在类设备目录下添加包含设备号的名为“dev”的属性文件。</DIV>
<DIV> </DIV>
<DIV>(4)至于/etc/mdev.conf文件,可有可无,不影响使用,只是添加了些功能。</DIV>
<DIV>
为了实验我在/etc创建了mdev.conf文件并输入了:</DIV>
<DIV>
<TABLE style="BORDER-COLLAPSE: collapse"
borderColor=#999999 cellSpacing=0 cellPadding=0
width="95%" bgColor=#f1f1f1 border=1>
<TBODY>
<TR>
<TD>
<P
style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN
style="COLOR: rgb(0,0,0)"> sculld<SPAN
style="COLOR: rgb(0,0,204)">[</SPAN>0<SPAN
style="COLOR: rgb(0,0,204)">-</SPAN>1<SPAN
style="COLOR: rgb(0,0,204)">]</SPAN> 0<SPAN
style="COLOR: rgb(0,0,204)">:</SPAN>0 666 <SPAN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -