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

查看:522
本文介绍了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/main.c::do_initcalls()中调用.所有初始化调用都按级别进行分类,这些级别在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中没有任何调用策略,但是数组中的顺序由链接时间决定.

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中的较高位置
  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天全站免登陆