免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1046 | 回复: 0

[内核入门] 内核request_module学习不解之处 [复制链接]

论坛徽章:
0
发表于 2015-12-16 16:08 |显示全部楼层
学习内核代码i2c过程中,driver/of/of_i2c.c中,of_i2c_register_devices的时候会调用到request_module("%s%s", I2C_MODULE_PREFIX, info.type);

1,不理解这里为什么要调用request_module?    --- 为了加载i2c设备驱动的ko吗? 我看了我们的工程代码,I2C设备都是直接编译进内核的,不是ko。
  
2,关于request_module函数加载的模块名,相关资料显示是根据dts文件和一个叫modules.alias文件决定的。arch wiki上显示modules.alias文件路径为:/lib/modules/`uname -r`/modules.alias, 可是android系统不知道该文件的位置?



附上我找到的相关资料:

以下来自内核邮件列表:

If we are registering an i2c device that has a device tree node like
this real-world example:

      rtc@68 {
        compatible = "dallas,ds1337";
        reg = <0x68>;
      };

of_i2c_register_devices() will try to load a module called ds1337.ko.
There is no such module, so it will fail.  If we look in modules.alias
we will find entries like these:

.
.
.
alias i2c:ds1339 rtc_ds1307
alias i2c:ds1338 rtc_ds1307
alias i2c:ds1337 rtc_ds1307
alias i2c:ds1307 rtc_ds1307
alias i2c:ds1374 rtc_ds1374
.
.
.

The module we want is really called rtc_ds1307.ko.  If we request a
module called "i2c:ds1337", the userspace module loader will do the
right thing (unless it is busybox) and load rtc_ds1307.ko.  So we add
the I2C_MODULE_PREFIX to the request_module() string.

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
---
drivers/of/of_i2c.c |    2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
index c85d3c7..f37fbeb 100644
--- a/drivers/of/of_i2c.c
+++ b/drivers/of/of_i2c.c
@@ -61,7 +61,7 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
                info.of_node = of_node_get(node);
                info.archdata = &dev_ad;

-               request_module("%s", info.type);
+               request_module("%s%s", I2C_MODULE_PREFIX, info.type);

                result = i2c_new_device(adap, &info);
                if (result == NULL) {
--
1.7.2.3

---------------------------------
以下来自arch wiki:
so where is the modules.alias file?
grep snd_intel8x0m /lib/modules/`uname -r`/modules.alias
  alias pci:v00008086d00002416sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00008086d00002426sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00008086d00002446sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00008086d00002486sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00008086d000024C6sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00008086d000024D6sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00008086d0000266Dsv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00008086d000027DDsv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00008086d00007196sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00001022d00007446sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v00001039d00007013sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v000010DEd000001C1sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v000010DEd00000069sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v000010DEd00000089sv*sd*bc*sc*i* snd_intel8x0m
  alias pci:v000010DEd000000D9sv*sd*bc*sc*i* snd_intel8x0m
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP