Linux 内置驱动加载顺序是什么? [英] What is the Linux built-in driver load order?

查看:36
本文介绍了Linux 内置驱动加载顺序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自定义内置驱动加载顺序(先加载一些内置驱动模块,再加载依赖模块)?

How can we customize the built-in driver load order (to make some built-in driver module load first, and the dependent module load later)?

推荐答案

内置驱动程序不会加载,因此是内置的.当内核自行设置时,它们的初始化函数被调用并且驱动程序被激活.这些 init 函数在 init/main.c::do_initcalls() 中调用.所有的 init 调用都是按级别分类的,分别在 initcall_levelsinclude/linux/init.h

Built-in drivers wont be loaded, hence built-in. Their initialization functions are called and the drivers are activated when kernel sets up itself. These init functions are called in init/main.c::do_initcalls(). All init calls are classified in levels, which are defined in initcall_levels and include/linux/init.h

这些级别实际上是在链接描述文件中定义的符号(arch/*/kernel/vmlinux.lds.*).在内核编译时,链接器收集所有标记为module_init() 或其他*_initcall() 的函数,按级别分类,将同一级别的所有函数放在同一个放置,并像函数指针数组一样创建.

These levels are actuall symbols defined in linker script (arch/*/kernel/vmlinux.lds.*). At kernel compile time, the linker collects all function marked module_init() or other *_initcall(), classify in levels, put all functions in the same level together in the same place, and create like an array of function pointers.

do_initcall_level() 在运行时所做的就是调用数组中指针指向的每个函数.do_initcall_level 中除了levels 之外没有调用策略,但是数组中的顺序是在link time 中决定的.

What do_initcall_level() does in the run-time is to call each function pointed by the pointers in the array. There is no calling policy, except levels, in do_initcall_level, but the order in the array is decided in the link time.

那么,现在你可以看到驱动程序的启动顺序在链接时是固定的,但是你能做什么?

So, now you can see that the driver's initiation order is fixed at the link time, but what can you do?

  1. 将您的 init 函数置于更高级别,或
  2. 将您的设备驱动程序放在 Makefile
  3. 中的较高位置
  1. put your init function in the higher level, or
  2. put your device driver at the higher position in Makefile

如果您已阅读以上内容,第一个就很清楚了.即)如果合适,请改用 early_initcall().

The first one is clear if you've read the above. ie) use early_initcall() instead if it is appropriate.

第二个需要多一点解释.Makefile 中的顺序很重要的原因在于当前内核构建系统的工作方式以及链接器的工作方式.长话短说,构建系统获取 obj-y 中的所有目标文件并将它们链接在一起.它高度依赖于环境,但链接器很有可能将 obj-y 中的第一个目标文件放在较低地址中,因此更早调用.

The second one needs a bit more explanation. The reason why the order in a Makefile matter is how the current kernel build system works and how the linkers works. To make a long story short, the build system takes all object files in obj-y and link them together. It is highly environment dependent but there is high probability that the linker place first object file in the obj-y in lower address, thus, called earlier.

如果您只想比同一目录中的其他驱动程序更早地调用您的驱动程序,这是最简单的方法.

If you just want your driver to be called earlier than other drivers in the same directory, this is simplest way to do it.

这篇关于Linux 内置驱动加载顺序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆